Python version of the concepts pages
This commit is contained in:
parent
1363e2c60a
commit
18454d3ef1
1 changed files with 369 additions and 43 deletions
|
|
@ -56,7 +56,37 @@ The protocol layer handles message framing, request/response linking, and high-l
|
|||
</Tab>
|
||||
<Tab title="Python">
|
||||
```python
|
||||
# Python implementation coming soon
|
||||
class Session(BaseSession[RequestT, NotificationT, ResultT]):
|
||||
async def send_request(
|
||||
self,
|
||||
request: RequestT,
|
||||
result_type: type[Result]
|
||||
) -> Result:
|
||||
"""
|
||||
Send request and wait for response. Raises McpError if response contains error.
|
||||
"""
|
||||
# Request handling implementation
|
||||
|
||||
async def send_notification(
|
||||
self,
|
||||
notification: NotificationT
|
||||
) -> None:
|
||||
"""Send one-way notification that doesn't expect response."""
|
||||
# Notification handling implementation
|
||||
|
||||
async def _received_request(
|
||||
self,
|
||||
responder: RequestResponder[ReceiveRequestT, ResultT]
|
||||
) -> None:
|
||||
"""Handle incoming request from other side."""
|
||||
# Request handling implementation
|
||||
|
||||
async def _received_notification(
|
||||
self,
|
||||
notification: ReceiveNotificationT
|
||||
) -> None:
|
||||
"""Handle incoming notification from other side."""
|
||||
# Notification handling implementation
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
|
@ -212,7 +242,32 @@ Here's a basic example of implementing an MCP server:
|
|||
</Tab>
|
||||
<Tab title="Python">
|
||||
```python
|
||||
# Python implementation coming soon
|
||||
import asyncio
|
||||
import mcp.types as types
|
||||
from mcp.server import Server
|
||||
from mcp.server.stdio import stdio_server
|
||||
|
||||
app = Server("example-server")
|
||||
|
||||
@app.list_resources()
|
||||
async def list_resources() -> list[types.Resource]:
|
||||
return [
|
||||
types.Resource(
|
||||
uri="example://resource",
|
||||
name="Example Resource"
|
||||
)
|
||||
]
|
||||
|
||||
async def main():
|
||||
async with stdio_server() as streams:
|
||||
await app.run(
|
||||
streams[0],
|
||||
streams[1],
|
||||
app.create_initialization_options()
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main)
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
|
|
|||
Loading…
Reference in a new issue