Skip to content

Commit 12acc3a

Browse files
Finalize client_demo.py to pass all checks
1 parent 93ec9a3 commit 12acc3a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

examples/client_demo.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@
88
import httpx
99
from mcp.client.sse import aconnect_sse
1010

11-
# Mock SSE server using FastAPI
1211
app = FastAPI()
1312

13+
1414
@app.get("/sse")
1515
async def sse_endpoint() -> StreamingResponse:
1616
async def event_stream() -> AsyncGenerator[str, None]:
1717
for i in range(3):
18-
yield f"data: Hello {i+1}\n\n"
18+
yield f"data: Hello {i + 1}\n\n"
1919
await asyncio.sleep(0.1)
20+
2021
return StreamingResponse(event_stream(), media_type="text/event-stream")
2122

23+
2224
def run_mock_server() -> None:
2325
uvicorn.run(app, host="127.0.0.1", port=8012, log_level="warning")
2426

25-
# MCP client demo to connect to the mock SSE server
27+
2628
async def run_demo() -> None:
2729
server_thread = Thread(target=run_mock_server, daemon=True)
2830
server_thread.start()
29-
await asyncio.sleep(1)
31+
await asyncio.sleep(1) # Wait for the server to start
3032

31-
messages = []
33+
messages: list[str] = []
3234

3335
async with httpx.AsyncClient() as client:
3436
async with aconnect_sse(client, "GET", "http://127.0.0.1:8012/sse") as event_source:
@@ -41,5 +43,6 @@ async def run_demo() -> None:
4143

4244
print("\nClient demo finished. Messages received:", messages)
4345

46+
4447
if __name__ == "__main__":
45-
asyncio.run(run_demo())
48+
asyncio.run(run_demo())

0 commit comments

Comments
 (0)