Fix first Python demo so it works
You can't do async with ... outside of an async def function
This commit is contained in:
parent
6063b09d04
commit
569acf077d
1 changed files with 22 additions and 12 deletions
10
README.md
10
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.
|
||||
|
||||
```python
|
||||
# /// script
|
||||
# dependencies = [
|
||||
# "mcp"
|
||||
# ]
|
||||
# ///
|
||||
from mcp.server import Server, NotificationOptions
|
||||
from mcp.server.models import InitializationOptions
|
||||
import mcp.server.stdio
|
||||
|
|
@ -122,6 +127,7 @@ async def handle_get_prompt(
|
|||
]
|
||||
)
|
||||
|
||||
async def run():
|
||||
# Run the server as STDIO
|
||||
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
|
||||
await server.run(
|
||||
|
|
@ -136,6 +142,10 @@ async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
|
|||
)
|
||||
)
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
import asyncio
|
||||
asyncio.run(run())
|
||||
```
|
||||
|
||||
### Creating a Client
|
||||
|
|
|
|||
Loading…
Reference in a new issue