Skip to content

Commit 569acf0

Browse files
authored
Fix first Python demo so it works
You can't do async with ... outside of an async def function
1 parent 6063b09 commit 569acf0

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

README.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ Connections between clients and servers are established through transports like
7676
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.
7777

7878
```python
79+
# /// script
80+
# dependencies = [
81+
# "mcp"
82+
# ]
83+
# ///
7984
from mcp.server import Server, NotificationOptions
8085
from mcp.server.models import InitializationOptions
8186
import mcp.server.stdio
@@ -122,20 +127,25 @@ async def handle_get_prompt(
122127
]
123128
)
124129

125-
# Run the server as STDIO
126-
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
127-
await server.run(
128-
read_stream,
129-
write_stream,
130-
InitializationOptions(
131-
server_name="example",
132-
server_version="0.1.0",
133-
capabilities=server.get_capabilities(
134-
notification_options=NotificationOptions(),
135-
experimental_capabilities={},
130+
async def run():
131+
# Run the server as STDIO
132+
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
133+
await server.run(
134+
read_stream,
135+
write_stream,
136+
InitializationOptions(
137+
server_name="example",
138+
server_version="0.1.0",
139+
capabilities=server.get_capabilities(
140+
notification_options=NotificationOptions(),
141+
experimental_capabilities={},
142+
)
136143
)
137144
)
138-
)
145+
146+
if __name__ == "__main__":
147+
import asyncio
148+
asyncio.run(run())
139149
```
140150

141151
### Creating a Client

0 commit comments

Comments
 (0)