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