Introduction to FastMCP
Running the Development Server
To run the server, simply execute the server.py script:
cd $HOME/workspace/fastmcp_demo
uv run python server.py
The command above will start the FastMCP server on http://localhost:8000/mcp (what we configured in the mcp.run() method). You should see output in the terminal indicating that the server is running and listening for incoming requests.
However, in development environments, it's common to change the port or other configurations frequently. To avoid having to modify the code every time, we can use the FastMCP CLI, which allows us to start the server with different configurations without changing the code:
uv run fastmcp run server.py:mcp \
--transport http \
--host localhost \
--port 8000
When we run the server with the CLI, it will ignore the mcp.run() method in our code and use the configurations provided in the command instead. This allows us to easily customize the server's transport, host, port, and other options from the CLI directly.
Note that you can also leverage uv features in your development workflow. For example, you can use the --with option to temporarily install packages for the duration of a single command execution without permanently adding them to your project.
For example, you want to test your server with fastmcp==2.0.0 without changing your current fastmcp==3.0.2 installation, you can run:
uv run --with "fastmcp==2.0.0" fastmcp run server.py:mcp \
--transport http \
--host localhost \
--port 8000
Note on MCP Instance Names
Note that instead of using server.py:mcp, you can also use server.py if your mcp server instance has one of the following names:
mcpappserver
FastMCP automatically looks for these common names when you run fastmcp run server.py without specifying the instance.
However, if your code looks like this:
from fastmcp import FastMCP
my_custom_mcp = FastMCP("My MCP Server")
[...Practical MCP with FastMCP & LangChain
Engineering the Agentic ExperienceEnroll now to unlock current content and receive all future updates for free. Your purchase supports the author and fuels the creation of more exciting content. Act fast, as the price will rise as the course nears completion!
