|
1 |
| -# MCP Server |
| 1 | +# MCP Python SDK |
2 | 2 |
|
3 |
| -This is the MCP Server implementation in Python. |
| 3 | +The **Model Context Protocol (MCP)** allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. |
4 | 4 |
|
5 |
| -It only contains the [API Reference](api.md) for the time being. |
| 5 | +This Python SDK implements the full MCP specification, making it easy to: |
| 6 | + |
| 7 | +- **Build MCP servers** that expose resources, prompts, and tools |
| 8 | +- **Create MCP clients** that can connect to any MCP server |
| 9 | +- **Use standard transports** like stdio, SSE, and Streamable HTTP |
| 10 | + |
| 11 | +If you want to read more about the specification, please visit the [MCP documentation](https://modelcontextprotocol.io). |
| 12 | + |
| 13 | +## Quick Example |
| 14 | + |
| 15 | +Here's a simple MCP server that exposes a tool, resource, and prompt: |
| 16 | + |
| 17 | +```python title="server.py" |
| 18 | +from mcp.server.fastmcp import FastMCP |
| 19 | + |
| 20 | +mcp = FastMCP("Test Server") |
| 21 | + |
| 22 | + |
| 23 | +@mcp.tool() |
| 24 | +def add(a: int, b: int) -> int: |
| 25 | + """Add two numbers""" |
| 26 | + return a + b |
| 27 | + |
| 28 | + |
| 29 | +@mcp.resource("greeting://{name}") |
| 30 | +def get_greeting(name: str) -> str: |
| 31 | + """Get a personalized greeting""" |
| 32 | + return f"Hello, {name}!" |
| 33 | + |
| 34 | + |
| 35 | +@mcp.prompt() |
| 36 | +def greet_user(name: str, style: str = "friendly") -> str: |
| 37 | + """Generate a greeting prompt""" |
| 38 | + return f"Write a {style} greeting for someone named {name}." |
| 39 | +``` |
| 40 | + |
| 41 | +Test it with the [MCP Inspector](https://github.com/modelcontextprotocol/inspector): |
| 42 | + |
| 43 | +```bash |
| 44 | +uv run mcp dev server.py |
| 45 | +``` |
| 46 | + |
| 47 | +## Getting Started |
| 48 | + |
| 49 | +<!-- TODO(Marcelo): automatically generate the follow references with a header on each of those files. --> |
| 50 | +1. **[Install](installation.md)** the MCP SDK |
| 51 | +2. **[Learn concepts](concepts.md)** - understand the three primitives and architecture |
| 52 | +3. **[Explore authorization](authorization.md)** - add security to your servers |
| 53 | +4. **[Use low-level APIs](low-level-server.md)** - for advanced customization |
| 54 | + |
| 55 | +## API Reference |
| 56 | + |
| 57 | +Full API documentation is available in the [API Reference](api.md). |
0 commit comments