Building a Custom MCP Server with FastMCP

by Annett Schwarze | 2026-06-12

The Model Context Protocol (MCP) provides a standardized way for AI applications to interact with external systems. An MCP server can expose tools, resources, and data sources that are not directly available to the language model itself.

Implementing a custom MCP server is straightforward with Python and the FastMCP framework. In this article, we create a simple MCP server that exposes a few tools and connect it to Claude Desktop using the standard stdio transport.

To prepare the project, create a Python virtual environment and install the required dependencies:

% mkdir mcp-server
% cd mcp-server
% python3 -m venv .venv
% source .venv/bin/activate
(.venv) % python -m pip install --upgrade pip
(.venv) % pip install fastmcp
(.venv) % pip freeze > requirements.txt
    
MCP Server

For this example, create a file named `server.py` with the following content:

from fastmcp import FastMCP

mcp = FastMCP("My MCP Server")

@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b

@mcp.tool()
def greet(name: str) -> str:
    """Greet a user."""
    return f"Hello {name}!"

if __name__ == "__main__":
    mcp.run()
    

To verify that the MCP server is working correctly, start it from a terminal. Stop it by pressing Ctrl-C.

(.venv) % python server.py
    
MCP Server

One of the primary responsibilities of an MCP server is to expose tools that can be invoked by an MCP client. In FastMCP, tools are registered using the `@mcp.tool()` decorator. Each decorated Python function becomes available to the client and can be called by the language model when appropriate.

To use the MCP server with Claude Desktop, it must first be registered in the Claude Desktop configuration. Add an entry to the `mcpServers` section of the `claude_desktop_config.json` file. The following example shows the configuration for a Windows environment:

{
  "mcpServers": {
    "my-mcp-server": {
      "command": "C:\\Data\\prj\\mcp-server\\.venv\\Scripts\\python.exe",
      "args": [
        "C:\\Data\\prj\\mcp-server\\server.py"
      ]
    }
  }
}
    
MCP Server

After updating the configuration, restart Claude Desktop. The client will automatically launch the MCP server when required and communicate with it using the configured stdio transport.

Once the server is available, its tools can be invoked directly from a prompt. For example:

Use the add tool to compute 12 + 30

Claude Desktop will recognize that the MCP server provides a suitable tool and perform the tool invocation automatically.

MCP Server

This simple example demonstrates how MCP servers can extend AI applications with custom functionality. By exposing tools through the Model Context Protocol, developers can integrate databases, APIs, file systems, business applications, and other external services into clients such as Claude Desktop, Claude Code, Visual Studio Code, and Cursor.

While this example only exposes two simple functions, the same approach can be used to build powerful integrations that provide AI applications with access to real-time data and enterprise systems.

 

www.admadic.de | webmaster@admadic.de | Legal Notice and Trademarks | Privacy
© 2005-2007 - admaDIC | All Rights Reserved
All other trademarks and/or registered trademarks are the property of their respective owners