home / mcp / sample mcp server
MCP Server Sample
Configuration
View docs{
"mcpServers": {
"antonscap-mcp-server-sample": {
"command": "mcp",
"args": [
"install",
"server.py"
]
}
}
}MCP lets your applications provide context to large language models through a standardized server interface. You can connect to multiple MCP servers to expose data sources, tools, and templates, enabling flexible, secure, and composable AI workflows.
You run a local MCP server that exposes a calculator tool and a dynamic greeting data resource. Your MCP client can connect to this server to perform calculations and fetch personalized responses, enabling interactive AI-assisted tasks. Start the MCP runtime, install your server script, and then connect with your preferred MCP client (for example, Claude Desktop or an MCP-enabled IDE). Once connected, invoke the calculator tool to add numbers and request the personalized greeting resource by name to get a tailored message like “Hello, Alice!”.
From the client side, you’ll discover the server’s capabilities as defined in your server script. The server exposes a tool named add that performs addition and a resource named greeting that returns a personalized string. You can integrate these capabilities into your AI prompts, allowing the model to compute results and fetch contextual greetings on demand.
Prerequisites you need before installing the MCP server: - Python 3.10 or higher - MCP SDK 1.2.0 or higher - uv package manager (the MCP project manager) - A development environment where you can run commands from your shell or terminal.
1) Create a new MCP project managed by uv and enter the project directory:
uv init mcp-server-sample
cd mcp-server-sample2) Add MCP CLI support to your project dependencies:
uv add "mcp[cli]"3) Run the MCP runtime locally so you can develop and test your server interactively:
uv run mcp4) Create your server script (for example, save as server.py) that defines the MCP server, its tools, and resources. A simple example is provided below.
# server.py
from mcp.server.fastmcp import FastMCP
# Create an MCP server
mcp = FastMCP("Demo")
# Add an addition tool
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
# Add a dynamic greeting resource
@mcp.resource("greeting://{name}")
def get_greeting(name: str) -> str:
"""Get a personalized greeting"""
return f"Hello, {name}!"5) Install the server script with the MCP tool to register it for the client landscape and begin interacting with it. You can also test locally with the MCP Inspector.
mcp install server.py6) Start a development session to interact with the server via MCP Inspector or a connected MCP client.
mcp dev server.pyThis sample demonstrates a minimal MCP server that exposes a calculator tool and a data resource. It is designed for educational purposes and can be extended with more tools, resources, and prompts as you build your own MCP-enabled applications.
Made with ❤️ by Antonio Scapellato.
If you encounter issues starting the MCP runtime, ensure your Python version matches the required minimum and that uv is correctly installed in your environment. Verify that server.py defines at least one tool and one resource, and that the mcp command is available in your shell.
An addition tool exposed by the server that takes two integers and returns their sum.