Spaces:
Sleeping
Sleeping
First version as a MVP
Browse files- app.py +60 -18
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,33 +1,75 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
-
|
4 |
from mcp import StdioServerParameters
|
5 |
from smolagents import InferenceClientModel, CodeAgent, MCPClient
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
mcp_client = MCPClient({"url": HF_MCP_URL})
|
10 |
-
model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN"))
|
11 |
-
tools = mcp_client.get_tools()
|
12 |
-
agent = CodeAgent(tools=tools, model=model)
|
13 |
|
14 |
-
def
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
|
19 |
tools = mcp_client.get_tools()
|
|
|
|
|
20 |
agent = CodeAgent(tools=tools, model=model)
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
with gr.Row():
|
25 |
-
|
26 |
-
chatbot = gr.ChatInterface(fn=run_agent)
|
27 |
with gr.Column(scale=1):
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
demo.launch()
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
|
|
3 |
from mcp import StdioServerParameters
|
4 |
from smolagents import InferenceClientModel, CodeAgent, MCPClient
|
5 |
+
import pandas as pd
|
6 |
|
7 |
+
DEFAULT_MCP_URL = "https://alihmaou-mcp-tools.hf.space/gradio_api/mcp/sse"
|
8 |
+
HF_TOKEN = os.getenv("HUGGINGFACE_API_TOKEN")
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
def reload_tools_from_url(mcp_url_input):
|
11 |
+
global tools, agent, mcp_client, mcp_url
|
12 |
|
13 |
+
mcp_url=mcp_url_input
|
14 |
+
mcp_client = MCPClient({"url": mcp_url,"transport": "sse"}) # Might be deprecated soon but didnt find out the clean way
|
15 |
tools = mcp_client.get_tools()
|
16 |
+
|
17 |
+
model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN"))
|
18 |
agent = CodeAgent(tools=tools, model=model)
|
19 |
+
|
20 |
+
# Tableau structuré : nom, description, inputs attendus
|
21 |
+
rows = []
|
22 |
+
for tool in tools:
|
23 |
+
input_fields = ", ".join(param for param in tool.inputs)
|
24 |
+
rows.append({
|
25 |
+
"Tool name": tool.name,
|
26 |
+
"Description": tool.description,
|
27 |
+
"Params": input_fields
|
28 |
+
})
|
29 |
+
df = pd.DataFrame(rows)
|
30 |
+
return gr.DataFrame(value=df)
|
31 |
|
32 |
with gr.Blocks() as demo:
|
33 |
+
gr.Markdown("""
|
34 |
+
<div align="center">
|
35 |
+
<h1>🚀 MCP Tools Explorer – Agents-MCP-Hackathon (June 2025)</h1>
|
36 |
+
<p>
|
37 |
+
🔍 Query any MCP-compatible endpoint, 🛠️ browse available tools in a clean table view, and 🤖 test real-time interactions using a `smolagent` powered by `HuggingFace`.
|
38 |
+
Perfect for 🧪 exploring fellow participants’ tools or 🧰 debugging your own MCP server during the event!
|
39 |
+
</p>
|
40 |
+
</div>
|
41 |
+
""",)
|
42 |
+
|
43 |
with gr.Row():
|
44 |
+
|
|
|
45 |
with gr.Column(scale=1):
|
46 |
+
gr.Markdown("""
|
47 |
+
<div align="center">
|
48 |
+
<h2>🛠️ Set an MCP server and discover the tools</h2>
|
49 |
+
</div>
|
50 |
+
""")
|
51 |
+
mcp_url_input = gr.Textbox(label="🧩 MCP Tools server endpoint", value=DEFAULT_MCP_URL)
|
52 |
+
tool_table = gr.DataFrame(headers=["Tool name", "Description", "Params"], interactive=False, label="🔧 MCP Tools availables", wrap=True)
|
53 |
+
reload_btn = gr.Button("🔄 Refresh and set MCP tools list")
|
54 |
+
reload_btn.click(fn=reload_tools_from_url, inputs=[mcp_url_input], outputs=tool_table)
|
55 |
+
mcp_url_input.change(fn=reload_tools_from_url, inputs=[mcp_url_input], outputs=tool_table)
|
56 |
+
mcp_url_input.submit(fn=reload_tools_from_url, inputs=[mcp_url_input], outputs=tool_table)
|
57 |
+
|
58 |
+
with gr.Column(scale=2):
|
59 |
+
gr.Markdown("""
|
60 |
+
<div align="center">
|
61 |
+
<h2>🔎 Test them with smolagents</h2>
|
62 |
+
</div>
|
63 |
+
""")
|
64 |
+
chatbot = gr.ChatInterface(
|
65 |
+
fn=lambda message, history: str(agent.run(message)),
|
66 |
+
type="messages",
|
67 |
+
)
|
68 |
|
69 |
demo.launch()
|
70 |
+
|
71 |
+
try:
|
72 |
+
if mcp_client:
|
73 |
+
mcp_client.disconnect()
|
74 |
+
except Exception as e:
|
75 |
+
print(f"[Warning] Failed to disconnect MCP client: {e}")
|
requirements.txt
CHANGED
@@ -3,3 +3,4 @@ gradio [mcp]
|
|
3 |
mcp
|
4 |
fastmcp
|
5 |
python-dotenv
|
|
|
|
3 |
mcp
|
4 |
fastmcp
|
5 |
python-dotenv
|
6 |
+
pandas
|