Download app.py from DOOM1812/Model-context-protocol: direct link, hf CLI and curl.
- Browser
- Download file 942 Bytes
-
https://huggingface.co/spaces/DOOM1812/Model-context-protocol/resolve/main/app.py
- Command line
-
hf download hf://spaces/DOOM1812/Model-context-protocol/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DOOM1812/Model-context-protocol/resolve/main/app.py
942 Bytes
| import gradio as gr | |
| import os | |
| from smolagents import InferenceClientModel, CodeAgent, MCPClient | |
| # MCP Server URL - Replace with your remote endpoint | |
| MCP_SERVER_URL = "https://waysaheadglobal-model-context-protocol.hf.space/sse" | |
| # Load tools from MCP Server | |
| try: | |
| mcp_client = MCPClient({"url": MCP_SERVER_URL}) | |
| tools = mcp_client.get_tools() | |
| # Load LLM model using your Hugging Face token | |
| model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN")) | |
| agent = CodeAgent(tools=[*tools], model=model) | |
| # Gradio Chat Interface | |
| demo = gr.ChatInterface( | |
| fn=lambda message, history: str(agent.run(message)), | |
| title="IMDL MCP Agent 🧠", | |
| description="Ask anything from the PostgreSQL data tools", | |
| examples=["Show me KPIs for May 2025", "Generate brand-wise revenue trends", "How many events happened last quarter?"], | |
| ) | |
| demo.launch() | |
| finally: | |
| mcp_client.disconnect() | |