mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 23:04:25 +01:00
Fix first Python demo so it works
You can't do async with ... outside of an async def function
This commit is contained in:
34
README.md
34
README.md
@@ -76,6 +76,11 @@ Connections between clients and servers are established through transports like
|
|||||||
MCP servers follow a decorator approach to register handlers for MCP primitives like resources, prompts, and tools. The goal is to provide a simple interface for exposing capabilities to LLM clients.
|
MCP servers follow a decorator approach to register handlers for MCP primitives like resources, prompts, and tools. The goal is to provide a simple interface for exposing capabilities to LLM clients.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
# /// script
|
||||||
|
# dependencies = [
|
||||||
|
# "mcp"
|
||||||
|
# ]
|
||||||
|
# ///
|
||||||
from mcp.server import Server, NotificationOptions
|
from mcp.server import Server, NotificationOptions
|
||||||
from mcp.server.models import InitializationOptions
|
from mcp.server.models import InitializationOptions
|
||||||
import mcp.server.stdio
|
import mcp.server.stdio
|
||||||
@@ -122,20 +127,25 @@ async def handle_get_prompt(
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Run the server as STDIO
|
async def run():
|
||||||
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
|
# Run the server as STDIO
|
||||||
await server.run(
|
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
|
||||||
read_stream,
|
await server.run(
|
||||||
write_stream,
|
read_stream,
|
||||||
InitializationOptions(
|
write_stream,
|
||||||
server_name="example",
|
InitializationOptions(
|
||||||
server_version="0.1.0",
|
server_name="example",
|
||||||
capabilities=server.get_capabilities(
|
server_version="0.1.0",
|
||||||
notification_options=NotificationOptions(),
|
capabilities=server.get_capabilities(
|
||||||
experimental_capabilities={},
|
notification_options=NotificationOptions(),
|
||||||
|
experimental_capabilities={},
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import asyncio
|
||||||
|
asyncio.run(run())
|
||||||
```
|
```
|
||||||
|
|
||||||
### Creating a Client
|
### Creating a Client
|
||||||
|
|||||||
Reference in New Issue
Block a user