Feedback

Chat Icon

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

Introduction to FastMCP
37%

Creating Your First FastMCP Server

Now that we have FastMCP installed, we can create our first server. This is how we instantiate a FastMCP server:

from fastmcp import FastMCP

mcp = FastMCP("My MCP Server")

To add a tool, we simply define a Python function and decorate it with @mcp.tool. For example:

@mcp.tool
def sum(a: int, b: int) -> int:
    """Returns the sum of two numbers."""
    return a + b

This defines a tool called sum that takes two integers as input and returns their sum. The @mcp.tool decorator registers this function as a tool that can be called by clients.

Now, depending on the transport we want to use, we can start the server with different configurations.

For HTTP, we can run:

if __name__ == "__main__":
    mcp.run(transport="http", host="localhost", port=8000)

For STDIO, we can run:

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!