Spaces:
Sleeping
Sleeping
Download src/client_example.py from MCP-1st-Birthday/ContextPilot: direct link, hf CLI and curl.
- Browser
- Download file 786 Bytes
-
https://huggingface.co/spaces/MCP-1st-Birthday/ContextPilot/resolve/main/src/client_example.py
- Command line
-
hf download hf://spaces/MCP-1st-Birthday/ContextPilot/src/client_example.py
-
curl -L -o client_example.py https://huggingface.co/spaces/MCP-1st-Birthday/ContextPilot/resolve/main/src/client_example.py
786 Bytes
| # client_example.py | |
| from mcp import ClientSession, StdioServerParameters | |
| import asyncio | |
| async def run(): | |
| # Start your MCP server | |
| server_params = StdioServerParameters( | |
| command="python", | |
| args=["mcp_server.py"] | |
| ) | |
| async with ClientSession(server_params) as session: | |
| await session.initialize() | |
| # Call your context-pilot tool | |
| result = await session.call_tool("context-pilot", { | |
| "msg": "How do I implement authentication in FastAPI?", | |
| "chat_history": [ | |
| {"role": "user", "content": "Tell me about Python web frameworks"}, | |
| {"role": "assistant", "content": "Flask and FastAPI are popular..."} | |
| ] | |
| }) | |
| print(result) | |
| asyncio.run(run()) |