You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python implementation of the [Model Context Protocol](https://modelcontextprotocol.io) (MCP), providing both client and server capabilities for integrating with LLM surfaces.
4
23
@@ -13,60 +32,285 @@ The Model Context Protocol allows applications to provide context for LLMs in a
13
32
14
33
## Installation
15
34
35
+
We recommend the use of [uv](https://docs.astral.sh/uv/) to manage your Python projects:
36
+
16
37
```bash
17
38
uv add mcp
18
39
```
19
40
41
+
Alternatively, add mcp to your `requirements.txt`:
42
+
```
43
+
pip install mcp
44
+
# or add to requirements.txt
45
+
pip install -r requirements.txt
46
+
```
47
+
48
+
## Overview
49
+
MCP servers provide focused functionality like resources, tools, prompts, and other capabilities that can be reused across many client applications. These servers are designed to be easy to build, highly composable, and modular.
50
+
51
+
### Key design principles
52
+
- Servers are extremely easy to build with clear, simple interfaces
53
+
- Multiple servers can be composed seamlessly through a shared protocol
54
+
- Each server operates in isolation and cannot access conversation context
55
+
- Features can be added progressively through capability negotiation
56
+
57
+
### Server provided primitives
58
+
-[Prompts](https://modelcontextprotocol.io/docs/concepts/prompts): Templatable text
-[Tools](https://modelcontextprotocol.io/docs/concepts/tools): Functions that models can call
61
+
- Utilities:
62
+
- Completion: Auto-completion provider for prompt arguments or resource URI templates
63
+
- Logging: Logging to the client
64
+
- Pagination*: Pagination for long results
65
+
66
+
### Client provided primitives
67
+
-[Sampling](https://modelcontextprotocol.io/docs/concepts/sampling): Allow servers to sample using client models
68
+
- Roots: Information about locations to operate on (e.g., directories)
69
+
70
+
Connections between clients and servers are established through transports like **stdio** or **SSE** (Note that most clients support stdio, but not SSE at the moment). The transport layer handles message framing, delivery, and error handling.
71
+
20
72
## Quick Start
21
73
74
+
### Creating a Server
75
+
76
+
MCP servers follow a decorator approach to register handlers for MCP primitives like resources, prompts, and tools. The goal is to provide a simple interface for exposing capabilities to LLM clients.
77
+
78
+
```python
79
+
from mcp.server import Server, NotificationOptions
80
+
from mcp.server.models import InitializationOptions
The MCP Python SDK provides decorators that map to the core protocol primitives. Each primitive follows a different interaction pattern based on how it is controlled and used:
181
+
182
+
| Primitive | Control | Description | Example Use |
Capabilities are negotiated during connection initialization. Servers only need to implement the decorators for capabilities they support.
237
+
238
+
## Client Interaction
239
+
240
+
The MCP Python SDK enables servers to interact with clients through request context and session management. This allows servers to perform operations like LLM sampling and progress tracking.
241
+
242
+
### Request Context
243
+
244
+
The Request Context provides access to the current request and client session. It can be accessed through `server.request_context` and enables:
Issues and pull requests are welcome on GitHub at https://github.com/modelcontextprotocol/python-sdk.
313
+
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](CONTRIBUTING.md) to get started.
0 commit comments