layers2024 commited on
Commit
33ba2b7
·
verified ·
1 Parent(s): ed5b006

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. .gitignore +28 -0
  2. README.md +2 -8
  3. mcp-client.py +28 -0
  4. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+
7
+ # Virtual environments
8
+ venv/
9
+ env/
10
+ ENV/
11
+ fastmcp-env/
12
+
13
+ # IDE
14
+ .vscode/
15
+ .idea/
16
+ *.swp
17
+ *.swo
18
+
19
+ # OS
20
+ .DS_Store
21
+ Thumbs.db
22
+
23
+ # Logs
24
+ *.log
25
+
26
+ # Environment variables
27
+ .env
28
+ .env.local
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Mcp Client
3
- emoji: 🏆
4
- colorFrom: indigo
5
- colorTo: indigo
6
  sdk: gradio
7
  sdk_version: 5.44.1
8
- app_file: app.py
9
- pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: mcp-client
3
+ app_file: mcp-client.py
 
 
4
  sdk: gradio
5
  sdk_version: 5.44.1
 
 
6
  ---
 
 
mcp-client.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ from smolagents import InferenceClientModel, CodeAgent, MCPClient
5
+
6
+
7
+ try:
8
+ mcp_client = MCPClient(
9
+ # {"url": "http://127.0.0.1:7860/gradio_api/mcp"}
10
+ {"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"}
11
+ )
12
+ tools = mcp_client.get_tools()
13
+
14
+ model = InferenceClientModel(token=os.getenv("HF_API_TOKEN"))
15
+ agent = CodeAgent(tools=[*tools], model=model,
16
+ additional_authorized_imports=["json", "ast", "urllib", "base64"])
17
+
18
+ demo = gr.ChatInterface(
19
+ fn=lambda message, history: str(agent.run(message)),
20
+ type="messages",
21
+ examples=["Analyze the sentiment of the following text 'This is awesome'"],
22
+ title="Agent with MCP Tools",
23
+ description="This is a simple agent that uses MCP tools to answer questions.",
24
+ )
25
+
26
+ demo.launch()
27
+ finally:
28
+ mcp_client.disconnect()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ smolagents[mcp]