@@ -25,7 +25,7 @@ flowchart LR
25
25
subgraph "Server Process"
26
26
server2[MCP Server]
27
27
end
28
-
28
+
29
29
client1 <-->|Transport Layer| server1
30
30
client2 <-->|Transport Layer| server2
31
31
```
@@ -34,23 +34,32 @@ flowchart LR
34
34
35
35
### Protocol layer
36
36
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.
38
38
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 >
54
63
55
64
Key classes include:
56
65
@@ -116,11 +125,11 @@ MCP has these main types of messages:
116
125
sequenceDiagram
117
126
participant Client
118
127
participant Server
119
-
128
+
120
129
Client->>Server: initialize request
121
130
Server->>Client: initialize response
122
131
Client->>Server: initialized notification
123
-
132
+
124
133
Note over Client,Server: Connection ready for use
125
134
```
126
135
@@ -169,35 +178,44 @@ Errors are propagated through:
169
178
170
179
Here's a basic example of implementing an MCP server:
171
180
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: {}
192
193
}
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 >
201
219
202
220
## Best practices
203
221
0 commit comments