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
26
5
27
## Overview
@@ -13,60 +35,290 @@ The Model Context Protocol allows applications to provide context for LLMs in a
13
35
14
36
## Installation
15
37
38
+
We recommend the use of [uv](https://docs.astral.sh/uv/) to manage your Python projects:
39
+
16
40
```bash
17
41
uv add mcp
18
42
```
19
43
44
+
Alternatively, add mcp to your `requirements.txt`:
45
+
```
46
+
pip install mcp
47
+
# or add to requirements.txt
48
+
pip install -r requirements.txt
49
+
```
50
+
51
+
## Overview
52
+
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.
53
+
54
+
### Key design principles
55
+
- Servers are extremely easy to build with clear, simple interfaces
56
+
- Multiple servers can be composed seamlessly through a shared protocol
57
+
- Each server operates in isolation and cannot access conversation context
58
+
- Features can be added progressively through capability negotiation
59
+
60
+
### Server provided primitives
61
+
-[Prompts](https://modelcontextprotocol.io/docs/concepts/prompts): Templatable text
-[Tools](https://modelcontextprotocol.io/docs/concepts/tools): Functions that models can call
64
+
- Utilities:
65
+
- Completion: Auto-completion provider for prompt arguments or resource URI templates
66
+
- Logging: Logging to the client
67
+
- Pagination*: Pagination for long results
68
+
69
+
### Client provided primitives
70
+
-[Sampling](https://modelcontextprotocol.io/docs/concepts/sampling): Allow servers to sample using client models
71
+
- Roots: Information about locations to operate on (e.g., directories)
72
+
73
+
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.
74
+
20
75
## Quick Start
21
76
77
+
### Creating a Server
78
+
79
+
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.
80
+
81
+
```python
82
+
from mcp.server import Server, NotificationOptions
83
+
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:
184
+
185
+
| Primitive | Control | Description | Example Use |
Capabilities are negotiated during connection initialization. Servers only need to implement the decorators for capabilities they support.
240
+
241
+
## Client Interaction
242
+
243
+
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.
244
+
245
+
### Request Context
246
+
247
+
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.
321
+
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