Spaces:
Sleeping
Sleeping
JCentercreation
commited on
Commit
·
8db71b7
1
Parent(s):
2c98d8b
MCP client disconnet
Browse files
app.py
CHANGED
@@ -4,27 +4,28 @@ import os
|
|
4 |
from mcp import StdioServerParameters
|
5 |
from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClient
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
tools = mcp_client.get_tools()
|
14 |
|
15 |
-
model = InferenceClientModel(token=os.getenv("HF_TOKEN"))
|
16 |
|
17 |
-
agent = CodeAgent(tools=[*tools], model=model)
|
18 |
|
19 |
-
demo = gr.ChatInterface(
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
)
|
26 |
|
27 |
-
demo.launch()
|
28 |
|
29 |
finally:
|
30 |
-
mcp_client.disconnect()
|
|
|
4 |
from mcp import StdioServerParameters
|
5 |
from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClient
|
6 |
|
7 |
+
try:
|
8 |
+
mcp_client = MCPClient(
|
9 |
+
{
|
10 |
+
"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"
|
11 |
+
}
|
12 |
+
)
|
13 |
|
14 |
+
tools = mcp_client.get_tools()
|
15 |
|
16 |
+
model = InferenceClientModel(token=os.getenv("HF_TOKEN"))
|
17 |
|
18 |
+
agent = CodeAgent(tools=[*tools], model=model, additional_authorized_imports=["json", "ast", "urllib", "base64")
|
19 |
|
20 |
+
demo = gr.ChatInterface(
|
21 |
+
fn= lambda message, history: str(agent.run(message)),
|
22 |
+
type="messages",
|
23 |
+
examples=["Prime factorization of 68"],
|
24 |
+
title="Agent with MCP tool",
|
25 |
+
description="This agent can use the MCP tool to answer questions.",
|
26 |
+
)
|
27 |
|
28 |
+
demo.launch()
|
29 |
|
30 |
finally:
|
31 |
+
mcp_client.disconnect()
|