arre99 commited on
Commit
cf55632
·
1 Parent(s): a2703b0

polished up the mcp client script

Browse files
Files changed (2) hide show
  1. mcp_client.py +16 -10
  2. mcp_client_template.py +0 -15
mcp_client.py CHANGED
@@ -5,8 +5,11 @@ from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClien
5
 
6
 
7
  if __name__ == "__main__":
 
 
8
 
9
  try:
 
10
  mcp_client = MCPClient(
11
  {"url": "https://agents-mcp-hackathon-f1-mcp-server.hf.space/gradio_api/mcp/sse", "transport": "sse"})
12
  tools = mcp_client.get_tools()
@@ -14,6 +17,10 @@ if __name__ == "__main__":
14
  print("### MCP tools ### ")
15
  print("\n".join(f"{t.name}: {t.description}" for t in tools))
16
 
 
 
 
 
17
  # Define model
18
  model = InferenceClientModel(
19
  model_id="Qwen/Qwen2.5-32B-Instruct",
@@ -22,17 +29,16 @@ if __name__ == "__main__":
22
 
23
  agent = CodeAgent(tools=[*tools], model=model)
24
 
25
- run_inference = False # TEMP
26
- if run_inference:
27
 
28
- chat_interface = gr.ChatInterface(
29
- fn=lambda message, history: str(agent.run(message)),
30
- type="messages",
31
- examples=["Prime factorization of 68"],
32
- title="Agent with MCP Tools",
33
- description="This is a simple agent that uses MCP tools to answer questions."
34
- )
 
 
35
 
36
- chat_interface.launch()
37
  finally:
38
  mcp_client.close()
 
5
 
6
 
7
  if __name__ == "__main__":
8
+
9
+ only_list_tools = True
10
 
11
  try:
12
+
13
  mcp_client = MCPClient(
14
  {"url": "https://agents-mcp-hackathon-f1-mcp-server.hf.space/gradio_api/mcp/sse", "transport": "sse"})
15
  tools = mcp_client.get_tools()
 
17
  print("### MCP tools ### ")
18
  print("\n".join(f"{t.name}: {t.description}" for t in tools))
19
 
20
+ if only_list_tools:
21
+ mcp_client.close()
22
+ exit(0)
23
+
24
  # Define model
25
  model = InferenceClientModel(
26
  model_id="Qwen/Qwen2.5-32B-Instruct",
 
29
 
30
  agent = CodeAgent(tools=[*tools], model=model)
31
 
 
 
32
 
33
+ chat_interface = gr.ChatInterface(
34
+ fn=lambda message, history: str(agent.run(message)),
35
+ type="messages",
36
+ examples=["Prime factorization of 68"],
37
+ title="Agent with MCP Tools",
38
+ description="This is a simple agent that uses MCP tools to answer questions."
39
+ )
40
+
41
+ chat_interface.launch()
42
 
 
43
  finally:
44
  mcp_client.close()
mcp_client_template.py DELETED
@@ -1,15 +0,0 @@
1
- from smolagents.mcp_client import MCPClient
2
-
3
-
4
- mcp_client = MCPClient(
5
- {"url": "https://abidlabs-mcp-tools2.hf.space/gradio_api/mcp/sse", "transport": "sse"}
6
- )
7
-
8
-
9
-
10
-
11
- if __name__ == "__main__":
12
-
13
- # List all available tools from the MCP server
14
- with mcp_client as tools:
15
- print("\n".join(f"{t.name}: {t.description}" for t in tools))