Raju KC commited on
Commit
894ed41
·
0 Parent(s):

Initial commit

Browse files
Files changed (2) hide show
  1. requirements.txt +2 -0
  2. server.py +26 -0
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ smolagents[mcp]
server.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gradio
2
+ from mcp.client.stdio import StdioServerParameters
3
+ from smolagents import InferenceClientModel, CodeAgent, ToolCollection
4
+ from smolagents.mcp_client import MCPClient
5
+
6
+ try:
7
+ mcp_client = MCPClient(
8
+ ## Try this working example on the hub:
9
+ # {"url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse"}
10
+ {"url": "http://localhost:7860/gradio_api/mcp/sse"},
11
+ )
12
+ tools = mcp_client.get_tools()
13
+
14
+ model = InferenceClientModel()
15
+ agent = CodeAgent(tools=[*tools], model=model)
16
+
17
+ demo = gr.ChatInterface(
18
+ fn=lambda message, history: str(agent.run(message, history=history)),
19
+ type="messages",
20
+ examples=["Prime factorization of 68"],
21
+ title="Agent with MCP Tools",
22
+ description="This is a simple agent that uses MCP tools to answer questions",
23
+ )
24
+ demo.launch()
25
+ finally:
26
+ mcp_client.disconnect()