Skip to content

Commit a2e6868

Browse files
committed
Add Python stubs
1 parent 61f6e34 commit a2e6868

File tree

1 file changed

+65
-47
lines changed

1 file changed

+65
-47
lines changed

docs/concepts/architecture.mdx

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ flowchart LR
2525
subgraph "Server Process"
2626
server2[MCP Server]
2727
end
28-
28+
2929
client1 <-->|Transport Layer| server1
3030
client2 <-->|Transport Layer| server2
3131
```
@@ -34,23 +34,32 @@ flowchart LR
3434

3535
### Protocol layer
3636

37-
The protocol layer handles message framing, request/response linking, and high-level communication patterns.
37+
The protocol layer handles message framing, request/response linking, and high-level communication patterns.
3838

39-
```typescript
40-
class Protocol<Request, Notification, Result> {
41-
// Handle incoming requests
42-
setRequestHandler<T>(schema: T, handler: (request: T, extra: RequestHandlerExtra) => Promise<Result>): void
43-
44-
// Handle incoming notifications
45-
setNotificationHandler<T>(schema: T, handler: (notification: T) => Promise<void>): void
46-
47-
// Send requests and await responses
48-
request<T>(request: Request, schema: T, options?: RequestOptions): Promise<T>
49-
50-
// Send one-way notifications
51-
notification(notification: Notification): Promise<void>
52-
}
53-
```
39+
<Tabs>
40+
<Tab title="TypeScript">
41+
```typescript
42+
class Protocol<Request, Notification, Result> {
43+
// Handle incoming requests
44+
setRequestHandler<T>(schema: T, handler: (request: T, extra: RequestHandlerExtra) => Promise<Result>): void
45+
46+
// Handle incoming notifications
47+
setNotificationHandler<T>(schema: T, handler: (notification: T) => Promise<void>): void
48+
49+
// Send requests and await responses
50+
request<T>(request: Request, schema: T, options?: RequestOptions): Promise<T>
51+
52+
// Send one-way notifications
53+
notification(notification: Notification): Promise<void>
54+
}
55+
```
56+
</Tab>
57+
<Tab title="Python">
58+
```python
59+
# Python implementation coming soon
60+
```
61+
</Tab>
62+
</Tabs>
5463

5564
Key classes include:
5665

@@ -116,11 +125,11 @@ MCP has these main types of messages:
116125
sequenceDiagram
117126
participant Client
118127
participant Server
119-
128+
120129
Client->>Server: initialize request
121130
Server->>Client: initialize response
122131
Client->>Server: initialized notification
123-
132+
124133
Note over Client,Server: Connection ready for use
125134
```
126135

@@ -169,35 +178,44 @@ Errors are propagated through:
169178

170179
Here's a basic example of implementing an MCP server:
171180

172-
```typescript
173-
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
174-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
175-
176-
const server = new Server({
177-
name: "example-server",
178-
version: "1.0.0"
179-
}, {
180-
capabilities: {
181-
resources: {}
182-
}
183-
});
184-
185-
// Handle requests
186-
server.setRequestHandler(ListResourcesRequestSchema, async () => {
187-
return {
188-
resources: [
189-
{
190-
uri: "example://resource",
191-
name: "Example Resource"
181+
<Tabs>
182+
<Tab title="TypeScript">
183+
```typescript
184+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
185+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
186+
187+
const server = new Server({
188+
name: "example-server",
189+
version: "1.0.0"
190+
}, {
191+
capabilities: {
192+
resources: {}
192193
}
193-
]
194-
};
195-
});
196-
197-
// Connect transport
198-
const transport = new StdioServerTransport();
199-
await server.connect(transport);
200-
```
194+
});
195+
196+
// Handle requests
197+
server.setRequestHandler(ListResourcesRequestSchema, async () => {
198+
return {
199+
resources: [
200+
{
201+
uri: "example://resource",
202+
name: "Example Resource"
203+
}
204+
]
205+
};
206+
});
207+
208+
// Connect transport
209+
const transport = new StdioServerTransport();
210+
await server.connect(transport);
211+
```
212+
</Tab>
213+
<Tab title="Python">
214+
```python
215+
# Python implementation coming soon
216+
```
217+
</Tab>
218+
</Tabs>
201219

202220
## Best practices
203221

0 commit comments

Comments
 (0)