Spaces:
Runtime error
Runtime error
Download app.py from Seewhatson/mcp-client: direct link, hf CLI and curl.
- Browser
- Download file 999 Bytes
-
https://huggingface.co/spaces/Seewhatson/mcp-client/resolve/main/app.py
- Command line
-
hf download hf://spaces/Seewhatson/mcp-client/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Seewhatson/mcp-client/resolve/main/app.py
999 Bytes
| import gradio as gr | |
| from mcp.client.stdio import StdioServerParameters # This import is not used | |
| from smolagents import InferenceClientModel, CodeAgent, ToolCollection | |
| from smolagents.mcp_client import MCPClient | |
| mcp_client = None # Initialize to None | |
| try: | |
| mcp_client = MCPClient( | |
| {"url": "http://localhost:7860/gradio_api/mcp/sse"} | |
| ) | |
| tools = mcp_client.get_tools() | |
| model = InferenceClientModel() | |
| agent = CodeAgent(tools=[*tools], model=model) | |
| demo = gr.ChatInterface( | |
| fn=lambda message, history: str(agent.run(message)), | |
| type="messages", | |
| examples=["Prime factorization of 68"], | |
| title="Agent with MCP Tools", | |
| description="This is a simple agent that uses MCP tools to answer questions.", | |
| ) | |
| demo.launch() | |
| except Exception as e: | |
| print(f"An error occurred: {e}") # Add some error logging | |
| # You might want to raise e again or handle it more gracefully | |
| finally: | |
| if mcp_client: | |
| mcp_client.disconnect() |