| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This documents v1.x, the maintenance line of the MCP Python SDK. v2 is the current stable release: pip install mcp now installs 2.x. See the v2 documentation and the migration guide for what changed and how to upgrade.
Staying on v1.x? Keep a <2 upper bound on your requirement (for example mcp>=1.28,<2) so an unpinned resolve stays on the 1.x line. v1.x remains supported for existing deployments and continues to receive critical bug fixes and security patches; its documentation is at https://py.sdk.modelcontextprotocol.io/v1/.
The Model Context Protocol allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This Python SDK implements the full MCP specification, making it easy to:
We recommend using uv to manage your Python projects.
If you haven't created a uv-managed project yet, create one:
uv init mcp-server-demo
cd mcp-server-demoThen add MCP to your project dependencies:
uv add "mcp[cli]<2"Alternatively, for projects using pip for dependencies:
pip install "mcp[cli]<2"To run the mcp command with uv:
uv run mcpLet's create a simple MCP server that exposes a calculator tool and some data:
"""
FastMCP quickstart example.
Run from the repository root:
uv run examples/snippets/servers/fastmcp_quickstart.py
"""
from mcp.server.fastmcp import FastMCP
# Create an MCP server
mcp = FastMCP("Demo", json_response=True)
# 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}!"
# Add a prompt
@mcp.prompt()
def greet_user(name: str, style: str = "friendly") -> str:
"""Generate a greeting prompt"""
styles = {
"friendly": "Please write a warm, friendly greeting",
"formal": "Please write a formal, professional greeting",
"casual": "Please write a casual, relaxed greeting",
}
return f"{styles.get(style, styles['friendly'])} for someone named {name}."
# Run with streamable HTTP transport
if __name__ == "__main__":
mcp.run(transport="streamable-http")Full example: examples/snippets/servers/fastmcp_quickstart.py
You can install this server in Claude Code and interact with it right away. First, run the server:
uv run --with "mcp<2" examples/snippets/servers/fastmcp_quickstart.pyThen add it to Claude Code:
claude mcp add --transport http my-server http://localhost:8000/mcpAlternatively, you can test it with the MCP Inspector. Start the server as above, then in a separate terminal:
npx -y @modelcontextprotocol/inspectorIn the inspector UI, connect to http://localhost:8000/mcp.
The Model Context Protocol (MCP) lets you build servers that expose data and functionality to LLM applications in a secure, standardized way. Think of it like a web API, but specifically designed for LLM interactions. MCP servers can:
We are passionate about supporting contributors of all levels of experience and would love to see you get involved in the project. See the contributing guide to get started.
This project is licensed under the MIT License - see the LICENSE file for details.
| Back | FazBrowse Home | New Git URL |