Skip to content

Commit 135fa82

Browse files
authored
Merge pull request modelcontextprotocol#25 from modelcontextprotocol/davidsp/more-docs
docs: Initial frame for the guide documentation
2 parents f17c440 + b86bd50 commit 135fa82

File tree

5 files changed

+323
-2
lines changed

5 files changed

+323
-2
lines changed

docs/guide/_index.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,32 @@ title: Guide
33
cascade:
44
type: docs
55
---
6+
The Model Context Protocol (MCP) is a protocol designed to enable LLM assistant surfaces to receive contextual information from specialized servers. Whether you're building an IDE coding assistant, a chat interface, or any other LLM-powered application, MCP provides a standardized way to obtain and utilize relevant context.
7+
8+
## What is MCP?
9+
10+
MCP separates the concerns of providing context from the LLM interaction loop itself. This separation allows developers to:
11+
12+
- Create pluggable context providers that work across multiple LLM surfaces
13+
- Implement custom context gathering workflows without modifying the LLM application
14+
- Combine multiple context sources to enhance LLM interactions
15+
16+
## Key Components
17+
18+
The protocol consists of two main parts:
19+
20+
1. **MCP Servers**: Processes or services that provide context through various means (file systems, databases, APIs, etc.)
21+
2. **MCP Clients**: Applications that connect to MCP servers to obtain context for LLM interactions
22+
23+
## How to Use This Guide
24+
25+
This guide is structured to help you understand and implement MCP in your applications:
26+
27+
1. Start with the installation and basic setup instructions
28+
2. Learn about core concepts and components
29+
3. Follow practical examples for both client and server implementations
30+
4. Explore advanced features and best practices
31+
32+
Whether you're building a new MCP server, integrating MCP into an existing application, or just exploring the protocol, this guide will help you navigate the implementation process.
33+
34+
Let's begin by setting up your development environment and getting familiar with the basic concepts.

docs/guide/overview.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Overview
3+
type: docs
4+
weight: 2
5+
cascade:
6+
type: docs
7+
---
8+
9+
# SDK Documentation
10+
11+
MCP provides SDKs in multiple languages to help you integrate with the protocol. Currently available SDKs:
12+
13+
## Python SDK
14+
The Python SDK offers server and client implementations along with type definitions:
15+
16+
- [Python SDK on PyPI](https://pypi.org/project/mcp-python/)
17+
- [Python SDK Documentation](/sdk/python)
18+
- [Python SDK Source]({{< param "github_base" >}}/python-sdk)
19+
20+
## TypeScript SDK
21+
The TypeScript SDK provides client and server implementations:
22+
23+
- [TypeScript SDK on NPM](https://www.npmjs.com/package/@modelcontextprotocol/sdk)
24+
- [TypeScript SDK Documentation](/sdk/typescript)
25+
- [TypeScript SDK Source]({{< param "github_base" >}}/typescript-sdk)
26+
27+
## Getting Started
28+
29+
Choose your preferred SDK from above and follow the installation instructions in its documentation. The SDKs follow similar patterns for usage but may have language-specific idioms.
30+
31+
Each SDK provides:
32+
33+
- Client implementation for connecting to MCP servers
34+
- Server implementation for creating MCP servers
35+
- Type definitions for the protocol
36+
- Utility functions for common operations
37+
- Examples and sample code
38+
39+
See the individual SDK documentation for detailed installation and usage instructions.

docs/guide/python/_index.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Python
3+
type: docs
4+
weight: 2
5+
cascade:
6+
type: docs
7+
---
8+
9+
The MCP Python SDK provides a comprehensive implementation of the Model Context Protocol, split into several key components:
10+
11+
## Core Components
12+
13+
- **Client Module**: Implements the MCP client interface for connecting to servers
14+
- **Server Module**: Provides a decorator-based API for implementing MCP servers
15+
- **Types Module**: Contains all protocol type definitions and models
16+
- **Shared Components**: Common utilities and base classes used by both client and server
17+
18+
## Transport Options
19+
20+
The SDK supports multiple transport mechanisms for client-server communication:
21+
22+
- **stdio**: Communication over standard input/output streams, ideal for local process-to-process communication
23+
- **SSE (Server-Sent Events)**: HTTP-based transport with server push capabilities, suitable for web deployments
24+
25+
Each transport option has its own benefits:
26+
27+
- stdio is simple and secure for local usage
28+
- SSE works well with existing HTTP infrastructure
29+
- WebSocket provides low-latency bidirectional communication
30+
31+
## Key Design Principles
32+
33+
- **Async-first**: Built on anyio for async/await patterns and compatibility with both asyncio and trio
34+
- **Type Safety**: Full typing support via Pydantic models
35+
- **Protocol Conformance**: Strict adherence to the MCP specification
36+
- **Extensibility**: Easy to extend with custom functionality
37+
38+
## Installation
39+
40+
Install the MCP Python SDK using pip:
41+
42+
```bash
43+
pip install mcp-python
44+
```
45+
or add it to your [pyproject.toml](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/) using [uv]( {{< param "uv_docs" >}} ).
46+
```bash
47+
uv add mcp-python
48+
```
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
---
2+
title: Server
3+
type: docs
4+
weight: 1
5+
cascade:
6+
type: docs
7+
---
8+
9+
This guide walks you through setting up and implementing a basic MCP server using Python.
10+
11+
## Installation
12+
13+
Install the MCP Python SDK using pip:
14+
15+
```bash
16+
pip install mcp-python
17+
```
18+
or add it to your [pyproject.toml](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/) using [uv]( {{< param "uv_docs" >}} ).
19+
```bash
20+
uv add mcp-python
21+
```
22+
23+
## Server API Overview
24+
25+
The Python SDK provides a decorator-based API for implementing MCP servers. The main `Server` class offers decorators for handling different types of requests:
26+
27+
### Resource Handling
28+
- `@server.list_resources()`: Lists available resources
29+
- `@server.read_resource()`: Reads content of a specific resource
30+
- `@server.subscribe_resource()`: Handles resource subscription requests
31+
- `@server.unsubscribe_resource()`: Handles unsubscribe requests
32+
33+
### Tool Support
34+
- `@server.list_tools()`: Lists available tools
35+
- `@server.call_tool()`: Handles tool execution requests
36+
37+
### Prompt Management
38+
- `@server.list_prompts()`: Lists available prompts
39+
- `@server.get_prompt()`: Retrieves specific prompt templates
40+
41+
### Progress & Logging
42+
- `@server.progress_notification()`: Handles progress updates
43+
- `@server.set_logging_level()`: Controls server logging
44+
45+
The decorators automatically handle request/response formatting and protocol compliance, allowing you to focus on implementing the core functionality.
46+
47+
## Basic Server Implementation
48+
49+
Here's a minimal example of implementing an MCP server:
50+
51+
```python
52+
from mcp_python.server import Server
53+
import anyio
54+
55+
# Create a new server instance
56+
server = Server("example-server")
57+
58+
# Implement resource handling
59+
@server.list_resources()
60+
async def list_resources():
61+
# Return list of available resources
62+
return [
63+
{
64+
"uri": "example://resource1",
65+
"name": "Example Resource 1",
66+
"description": "An example resource"
67+
}
68+
]
69+
70+
@server.read_resource()
71+
async def read_resource(uri):
72+
# Return content for the requested resource
73+
if uri == "example://resource1":
74+
return "Example resource content"
75+
raise ValueError(f"Unknown resource: {uri}")
76+
77+
# Main server loop
78+
async def main():
79+
# Use stdio transport for this example
80+
async with stdio_server() as (read_stream, write_stream):
81+
await server.run(
82+
read_stream,
83+
write_stream,
84+
server.create_initialization_options()
85+
)
86+
87+
if __name__ == "__main__":
88+
anyio.run(main)
89+
```
90+
91+
## Advanced Server Features
92+
93+
### Adding Tool Support
94+
95+
```python
96+
@server.list_tools()
97+
async def list_tools():
98+
return [
99+
{
100+
"name": "example-tool",
101+
"description": "An example tool",
102+
"parameters": {
103+
"type": "object",
104+
"properties": {
105+
"param1": {"type": "string"}
106+
}
107+
}
108+
}
109+
]
110+
111+
@server.call_tool()
112+
async def call_tool(name, **kwargs):
113+
if name == "example-tool":
114+
return f"Tool executed with params: {kwargs}"
115+
raise ValueError(f"Unknown tool: {name}")
116+
```
117+
118+
### Adding Prompt Support
119+
120+
```python
121+
@server.list_prompts()
122+
async def list_prompts():
123+
return [
124+
{
125+
"name": "example-prompt",
126+
"description": "An example prompt",
127+
"parameters": {
128+
"type": "object",
129+
"properties": {
130+
"param1": {"type": "string"}
131+
}
132+
}
133+
}
134+
]
135+
136+
@server.get_prompt()
137+
async def get_prompt(name, arguments):
138+
if name == "example-prompt":
139+
return PromptResponse(
140+
messages=[
141+
Message(
142+
role="user",
143+
content=f"Example prompt with args: {arguments}"
144+
)
145+
],
146+
desc="Example prompt response"
147+
)
148+
raise ValueError(f"Unknown prompt: {name}")
149+
```
150+
151+
## Running the Server
152+
153+
Start the server from the command line:
154+
155+
```bash
156+
python your_server.py
157+
```
158+
159+
For SSE or WebSocket transport, you'll need to use an ASGI server like Hypercorn:
160+
161+
```bash
162+
hypercorn your_server:app --bind 0.0.0.0:8000
163+
```
164+
165+
## Best Practices
166+
167+
1. Always implement proper error handling for all server methods
168+
2. Use typing hints for better code clarity and IDE support
169+
3. Document your server's capabilities and resources
170+
4. Implement logging for debugging purposes
171+
5. Follow the MCP specification for consistent behavior
172+
173+
## Common Patterns
174+
175+
### Resource Updates
176+
177+
```python
178+
async def notify_resource_update(uri, session):
179+
await session.send_resource_updated(uri)
180+
```
181+
182+
### Progress Notifications
183+
184+
```python
185+
async def long_running_operation(session):
186+
for i in range(100):
187+
await session.send_progress_notification(
188+
"operation-1",
189+
progress=i,
190+
total=100
191+
)
192+
```
193+
194+
### Logging
195+
196+
```python
197+
async def log_operation(session):
198+
await session.send_log_message(
199+
level="info",
200+
data="Operation completed",
201+
logger="example-server"
202+
)
203+
```

site/hugo.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ module:
1313
imports:
1414
- path: github.com/imfing/hextra
1515

16-
17-
1816
contentDir: ../docs
1917

18+
params:
19+
github_base: "https://github.com/modelcontextprotocol"
20+
uv_docs: "https://docs.astral.sh/uv/"
21+
2022
markup:
2123
goldmark:
2224
renderer:

0 commit comments

Comments
 (0)