Feedback

Chat Icon

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

Using FastMCP Advanced Features (Puppy Guide MCP)
41%

The FastMCP Class

Now, we need to instantiate the FastMCP class in our main.py file:

from fastmcp import FastMCP

mcp = FastMCP(
    name="Puppy Guide",
    list_page_size=10,
    instructions="You are a helpful assistant that provides information "
                  "about the real age of dogs in human years."
)

The FastMCP class is the main class of the FastMCP library and has a number of parameters that we can use to customize its behavior. In this example, we used:

  • name: The name of our MCP application.

  • list_page_size: To control the maximum number of items returned per page when listing tools, resources, prompts, or resource templates.

  • instructions: A string that describes how to interact with the MCP server. It's sent to clients during the initialization handshake to help them understand the server's purpose and functionality.

More parameters are available, and we will explore them in the next sections.

Let's move all of these configurations to a separate file called .env to keep code and configuration separate. We will use the python-dotenv library to load the environment variables from the .env file. First, we need to install the library:

uv add "python-dotenv==1.2.1"

Then, we can create the .env file with the following content:

cat > .env << EOF
MCP_NAME="Puppy Guide"
MCP_LIST_PAGE_SIZE=10
MCP_INSTRUCTIONS="You are a helpful assistant that provides information about the real age of dogs in human years."
EOF

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

Enroll 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!