Abraham E. Tavarez commited on
Commit
2de3fd1
·
0 Parent(s):

MCP Client ready

Browse files
Files changed (7) hide show
  1. .gitignore +10 -0
  2. .python-version +1 -0
  3. README.md +0 -0
  4. app.py +32 -0
  5. pyproject.toml +11 -0
  6. requirements.txt +2 -0
  7. uv.lock +0 -0
.gitignore ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.13
README.md ADDED
File without changes
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from mcp.client.stdio import StdioServerParameters
3
+ from smolagents import InferenceClientModel, CodeAgent, ToolCollection
4
+ from smolagents.mcp_client import MCPClient
5
+
6
+ mcp_client = None
7
+
8
+ try:
9
+ # Connect to the MCP Sentiment Server
10
+ mcp_client = MCPClient({"url": "http://127.0.0.1:7860/gradio_api/mcp/sse"})
11
+
12
+ # get the tools that we can use to answer questions.
13
+ tools = mcp_client.get_tools()
14
+
15
+ # Now that we have the tools, we can create a simple agent that uses them to answer questions.
16
+ model = InferenceClientModel()
17
+ agent = CodeAgent(model=model, tools=[*tools])
18
+
19
+ demo = gr.ChatInterface(
20
+ fn=lambda message, history: str(agent.run(message)),
21
+ type="messages",
22
+ examples=["Prime factorization of 68"],
23
+ title="Agent with MCP Tools",
24
+ description="This is a simple agent that uses MCP tools to answer questions.",
25
+ # messages=[],
26
+ )
27
+
28
+ demo.launch()
29
+
30
+ finally:
31
+ if mcp_client is not None:
32
+ mcp_client.disconnect()
pyproject.toml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "gradio-mcp-client"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.13"
7
+ dependencies = [
8
+ "gradio[mcp]>=5.32.0",
9
+ "mcp>=1.9.0",
10
+ "smolagents[mcp]>=1.17.0",
11
+ ]
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ smolagents[mcp]
uv.lock ADDED
The diff for this file is too large to render. See raw diff