Skip to content

Commit fe6dd9f

Browse files
Merge branch 'main' into spec/sampling-includecontext
2 parents 961e2cf + 6a4dc0f commit fe6dd9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2051
-856
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
package-lock.json linguist-generated=true
2+
schema/*/schema.json linguist-generated=true

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818

1919
- run: npm ci
2020

21-
- run: npm run validate:schema
21+
- name: Check TypeScript definitions
22+
run: npm run check:schema:ts
2223

23-
- run: npm run generate:json
2424
- name: Verify that `npm run generate:json` did not change outputs (if it did, please re-run it and re-commit!)
25-
run: git diff --exit-code
25+
run: npm run check:schema:json

.github/workflows/markdown-format.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,28 @@ on:
44
push:
55
paths:
66
- '**/*.md'
7+
- '**/*.mdx'
78
pull_request:
89
paths:
910
- '**/*.md'
11+
- '**/*.mdx'
1012

1113
jobs:
1214
format:
1315
runs-on: ubuntu-latest
1416
steps:
1517
- uses: actions/checkout@v4
16-
18+
1719
- name: Setup Node.js
1820
uses: actions/setup-node@v4
1921
with:
2022
node-version: '20'
21-
23+
2224
- name: Install dependencies
2325
run: npm ci
24-
26+
2527
- name: Check markdown formatting
26-
run: npm run format:check
28+
run: npm run check:docs:format
29+
30+
- name: Check markdown links
31+
run: npm run check:docs:links

CONTRIBUTING.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,32 @@ npm install # install dependencies
3232

3333
## Making Changes
3434

35-
Note that schema changes are made to `schema.ts`. `schema.json` is generated from
36-
`schema.ts` using `npm run validate:schema`.
35+
Note that schema changes are made to `schema.ts`, and `schema.json` is generated from
36+
`schema.ts`.
3737

3838
1. Create a new branch:
3939

4040
```bash
4141
git checkout -b feature/your-feature-name
4242
```
4343

44-
2. Make your changes
45-
3. Validate your changes:
44+
2. Make your changes.
45+
46+
3. Validate schema changes and generate `schema.json`:
47+
48+
```bash
49+
npm run check:schema:ts
50+
npm run generate:json
51+
```
52+
53+
4. Validate documentation changes and apply formatting:
4654

4755
```bash
48-
npm run validate:schema # validate schema
49-
npm run generate:json # generate JSON schema
56+
npm run check:docs
57+
npm run format
5058
```
5159

52-
4. Run docs locally (optional):
60+
5. Preview documentation locally (optional):
5361

5462
```bash
5563
npm run serve:docs
@@ -64,10 +72,11 @@ When contributing to the documentation:
6472
- Include code examples where appropriate
6573
- Use proper MDX formatting and components
6674
- Test all links and code samples
75+
- You may run `npm run check:docs:links` to look for broken internal links.
6776
- Use appropriate headings: "When to use", "Steps", and "Tips" for tutorials
6877
- Place new pages in appropriate sections (concepts, tutorials, etc.)
69-
- Update docs.json when adding new pages
70-
- Follow existing file naming conventions (kebab-case.mdx)
78+
- Update `docs.json` when adding new pages
79+
- Follow existing file naming conventions (`kebab-case.mdx`)
7180
- Include proper frontmatter in MDX files
7281

7382
### Specification Proposal Guidelines

docs/clients.mdx

Lines changed: 205 additions & 65 deletions
Large diffs are not rendered by default.

docs/development/roadmap.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ description: Our plans for evolving Model Context Protocol
77

88
The Model Context Protocol is rapidly evolving. This page outlines our current thinking on key priorities and direction for approximately **the next six months**, though these may change significantly as the project develops. To see what's changed recently, check out the **[specification changelog](/specification/2025-03-26/changelog/)**.
99

10-
<Note>The ideas presented here are not commitments—we may solve these challenges differently than described, or some may not materialize at all. This is also not an _exhaustive_ list; we may incorporate work that isn't mentioned here.</Note>
10+
<Note>
11+
12+
The ideas presented here are not commitments—we may solve these challenges differently than described, or some may not materialize at all. This is also not an _exhaustive_ list; we may incorporate work that isn't mentioned here.
13+
14+
</Note>
1115

1216
We value community participation! Each section links to relevant discussions where you can learn more and contribute your thoughts.
1317

docs/docs/concepts/architecture.mdx

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ The protocol layer handles message framing, request/response linking, and high-l
3838

3939
<Tabs>
4040
<Tab title="TypeScript">
41+
4142
```typescript
4243
class Protocol<Request, Notification, Result> {
4344
// Handle incoming requests
@@ -53,8 +54,10 @@ The protocol layer handles message framing, request/response linking, and high-l
5354
notification(notification: Notification): Promise<void>
5455
}
5556
```
57+
5658
</Tab>
5759
<Tab title="Python">
60+
5861
```python
5962
class Session(BaseSession[RequestT, NotificationT, ResultT]):
6063
async def send_request(
@@ -86,25 +89,27 @@ The protocol layer handles message framing, request/response linking, and high-l
8689
"""Handle incoming notification from other side."""
8790
# Notification handling implementation
8891
```
92+
8993
</Tab>
9094
</Tabs>
9195

9296
Key classes include:
9397

94-
* `Protocol`
95-
* `Client`
96-
* `Server`
98+
- `Protocol`
99+
- `Client`
100+
- `Server`
97101

98102
### Transport layer
99103

100104
The transport layer handles the actual communication between clients and servers. MCP supports multiple transport mechanisms:
101105

102106
1. **Stdio transport**
107+
103108
- Uses standard input/output for communication
104109
- Ideal for local processes
105110

106-
2. **HTTP with SSE transport**
107-
- Uses Server-Sent Events for server-to-client messages
111+
2. **Streamable HTTP transport**
112+
- Uses HTTP with optional Server-Sent Events for streaming
108113
- HTTP POST for client-to-server messages
109114

110115
All transports use [JSON-RPC](https://www.jsonrpc.org/) 2.0 to exchange messages. See the [specification](/specification/) for detailed information about the Model Context Protocol message format.
@@ -114,36 +119,39 @@ All transports use [JSON-RPC](https://www.jsonrpc.org/) 2.0 to exchange messages
114119
MCP has these main types of messages:
115120

116121
1. **Requests** expect a response from the other side:
117-
```typescript
118-
interface Request {
119-
method: string;
120-
params?: { ... };
121-
}
122-
```
122+
123+
```typescript
124+
interface Request {
125+
method: string;
126+
params?: { ... };
127+
}
128+
```
123129

124130
2. **Results** are successful responses to requests:
125-
```typescript
126-
interface Result {
127-
[key: string]: unknown;
128-
}
129-
```
131+
132+
```typescript
133+
interface Result {
134+
[key: string]: unknown;
135+
}
136+
```
130137

131138
3. **Errors** indicate that a request failed:
132-
```typescript
133-
interface Error {
134-
code: number;
135-
message: string;
136-
data?: unknown;
137-
}
138-
```
139+
140+
```typescript
141+
interface Error {
142+
code: number;
143+
message: string;
144+
data?: unknown;
145+
}
146+
```
139147

140148
4. **Notifications** are one-way messages that don't expect a response:
141-
```typescript
142-
interface Notification {
143-
method: string;
144-
params?: { ... };
145-
}
146-
```
149+
```typescript
150+
interface Notification {
151+
method: string;
152+
params?: { ... };
153+
}
154+
```
147155

148156
## Connection lifecycle
149157

@@ -176,6 +184,7 @@ After initialization, the following patterns are supported:
176184
### 3. Termination
177185

178186
Either party can terminate the connection:
187+
179188
- Clean shutdown via `close()`
180189
- Transport disconnection
181190
- Error conditions
@@ -191,13 +200,14 @@ enum ErrorCode {
191200
InvalidRequest = -32600,
192201
MethodNotFound = -32601,
193202
InvalidParams = -32602,
194-
InternalError = -32603
203+
InternalError = -32603,
195204
}
196205
```
197206

198207
SDKs and applications can define their own error codes above -32000.
199208

200209
Errors are propagated through:
210+
201211
- Error responses to requests
202212
- Error events on transports
203213
- Protocol-level error handlers
@@ -208,6 +218,7 @@ Here's a basic example of implementing an MCP server:
208218

209219
<Tabs>
210220
<Tab title="TypeScript">
221+
211222
```typescript
212223
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
213224
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
@@ -237,8 +248,10 @@ Here's a basic example of implementing an MCP server:
237248
const transport = new StdioServerTransport();
238249
await server.connect(transport);
239250
```
251+
240252
</Tab>
241253
<Tab title="Python">
254+
242255
```python
243256
import asyncio
244257
import mcp.types as types
@@ -267,6 +280,7 @@ Here's a basic example of implementing an MCP server:
267280
if __name__ == "__main__":
268281
asyncio.run(main())
269282
```
283+
270284
</Tab>
271285
</Tabs>
272286

@@ -275,23 +289,26 @@ Here's a basic example of implementing an MCP server:
275289
### Transport selection
276290

277291
1. **Local communication**
292+
278293
- Use stdio transport for local processes
279294
- Efficient for same-machine communication
280295
- Simple process management
281296

282297
2. **Remote communication**
283-
- Use SSE for scenarios requiring HTTP compatibility
298+
- Use Streamable HTTP for scenarios requiring HTTP compatibility
284299
- Consider security implications including authentication and authorization
285300

286301
### Message handling
287302

288303
1. **Request processing**
304+
289305
- Validate inputs thoroughly
290306
- Use type-safe schemas
291307
- Handle errors gracefully
292308
- Implement timeouts
293309

294310
2. **Progress reporting**
311+
295312
- Use progress tokens for long operations
296313
- Report progress incrementally
297314
- Include total progress when known
@@ -304,17 +321,20 @@ Here's a basic example of implementing an MCP server:
304321
## Security considerations
305322

306323
1. **Transport security**
324+
307325
- Use TLS for remote connections
308326
- Validate connection origins
309327
- Implement authentication when needed
310328

311329
2. **Message validation**
330+
312331
- Validate all incoming messages
313332
- Sanitize inputs
314333
- Check message size limits
315334
- Verify JSON-RPC format
316335

317336
3. **Resource protection**
337+
318338
- Implement access controls
319339
- Validate resource paths
320340
- Monitor resource usage
@@ -329,12 +349,14 @@ Here's a basic example of implementing an MCP server:
329349
## Debugging and monitoring
330350

331351
1. **Logging**
352+
332353
- Log protocol events
333354
- Track message flow
334355
- Monitor performance
335356
- Record errors
336357

337358
2. **Diagnostics**
359+
338360
- Implement health checks
339361
- Monitor connection state
340362
- Track resource usage

0 commit comments

Comments
 (0)