Spaces:
Runtime error
Runtime error
Looked through mcp_client.py in smolagents library and adjusted code
Browse filesUsed the fully managed context manager instead of the manual try and finally
Changed example prompt to ask about the weather (which should hopefully call our MCP server)
app.py
CHANGED
@@ -6,24 +6,20 @@ from smolagents import CodeAgent, InferenceClientModel
|
|
6 |
from smolagents.mcp_client import MCPClient
|
7 |
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
)
|
14 |
-
tools = mcp_client.get_tools()
|
15 |
|
16 |
-
|
17 |
-
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
finally:
|
29 |
-
mcp_client.close()
|
|
|
6 |
from smolagents.mcp_client import MCPClient
|
7 |
|
8 |
|
9 |
+
with MCPClient(
|
10 |
+
# {"url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse"}
|
11 |
+
{"url": "https://techno-1-mcp-sentiment.hf.space/gradio_api/mcp/sse", "transport": "streamable-http"}
|
12 |
+
) as 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)),
|
19 |
+
type="messages",
|
20 |
+
examples=["What's the weather like?"],
|
21 |
+
title="Agent with MCP Tools",
|
22 |
+
description="This is a simple agent that uses MCP tools to answer questions.",
|
23 |
+
)
|
24 |
|
25 |
+
demo.launch()
|
|
|
|