Feedback

Chat Icon

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

Your First MCP Server
28%

Prototyping an MCP Server

In this section, we will prototype a simple MCP server that provides a single tool to the model: a set of calculator functions that can perform basic sum operation.

This is the flow we will follow:

  • The model will receive a user query that requires performing a calculation, for example: What is the sum of 5 and 10?.

  • The model will recognize that it needs to perform a calculation and our application will call the appropriate tool provided by our MCP server, for example: sum(5, 10).

  • The MCP server will execute the tool, perform the calculation, and return the result to the application, for example: 15.

Let's start by the sum tool. The following command creates a new file called calculator_server.py and adds the code for the sum tool:

cat <<EOF > $HOME/workspace/mcp-server/calculator_server.py
# Import the FastMCP class from the MCP SDK
from mcp.server.fastmcp import FastMCP

# Create a new MCP server instance
mcp_server = FastMCP("Calculator Server")

# Add a tool
@mcp_server.tool()

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!