Add Python stubs
This commit is contained in:
parent
61f6e3483d
commit
a2e6868c40
1 changed files with 65 additions and 47 deletions
|
|
@ -36,21 +36,30 @@ flowchart LR
|
||||||
|
|
||||||
The protocol layer handles message framing, request/response linking, and high-level communication patterns.
|
The protocol layer handles message framing, request/response linking, and high-level communication patterns.
|
||||||
|
|
||||||
```typescript
|
<Tabs>
|
||||||
class Protocol<Request, Notification, Result> {
|
<Tab title="TypeScript">
|
||||||
// Handle incoming requests
|
```typescript
|
||||||
setRequestHandler<T>(schema: T, handler: (request: T, extra: RequestHandlerExtra) => Promise<Result>): void
|
class Protocol<Request, Notification, Result> {
|
||||||
|
// Handle incoming requests
|
||||||
|
setRequestHandler<T>(schema: T, handler: (request: T, extra: RequestHandlerExtra) => Promise<Result>): void
|
||||||
|
|
||||||
// Handle incoming notifications
|
// Handle incoming notifications
|
||||||
setNotificationHandler<T>(schema: T, handler: (notification: T) => Promise<void>): void
|
setNotificationHandler<T>(schema: T, handler: (notification: T) => Promise<void>): void
|
||||||
|
|
||||||
// Send requests and await responses
|
// Send requests and await responses
|
||||||
request<T>(request: Request, schema: T, options?: RequestOptions): Promise<T>
|
request<T>(request: Request, schema: T, options?: RequestOptions): Promise<T>
|
||||||
|
|
||||||
// Send one-way notifications
|
// Send one-way notifications
|
||||||
notification(notification: Notification): Promise<void>
|
notification(notification: Notification): Promise<void>
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
</Tab>
|
||||||
|
<Tab title="Python">
|
||||||
|
```python
|
||||||
|
# Python implementation coming soon
|
||||||
|
```
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
Key classes include:
|
Key classes include:
|
||||||
|
|
||||||
|
|
@ -169,35 +178,44 @@ Errors are propagated through:
|
||||||
|
|
||||||
Here's a basic example of implementing an MCP server:
|
Here's a basic example of implementing an MCP server:
|
||||||
|
|
||||||
```typescript
|
<Tabs>
|
||||||
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
<Tab title="TypeScript">
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
```typescript
|
||||||
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
||||||
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
|
|
||||||
const server = new Server({
|
const server = new Server({
|
||||||
name: "example-server",
|
name: "example-server",
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
}, {
|
}, {
|
||||||
capabilities: {
|
capabilities: {
|
||||||
resources: {}
|
resources: {}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle requests
|
|
||||||
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
||||||
return {
|
|
||||||
resources: [
|
|
||||||
{
|
|
||||||
uri: "example://resource",
|
|
||||||
name: "Example Resource"
|
|
||||||
}
|
}
|
||||||
]
|
});
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// Connect transport
|
// Handle requests
|
||||||
const transport = new StdioServerTransport();
|
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
||||||
await server.connect(transport);
|
return {
|
||||||
```
|
resources: [
|
||||||
|
{
|
||||||
|
uri: "example://resource",
|
||||||
|
name: "Example Resource"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Connect transport
|
||||||
|
const transport = new StdioServerTransport();
|
||||||
|
await server.connect(transport);
|
||||||
|
```
|
||||||
|
</Tab>
|
||||||
|
<Tab title="Python">
|
||||||
|
```python
|
||||||
|
# Python implementation coming soon
|
||||||
|
```
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
## Best practices
|
## Best practices
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue