-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mcp.py
More file actions
57 lines (40 loc) · 1.36 KB
/
test_mcp.py
File metadata and controls
57 lines (40 loc) · 1.36 KB
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
import asyncio
import base64
from langchain_mcp_adapters.client import MultiServerMCPClient
AUTH_HEADER = base64.b64encode(b"SuperUser:SYS").decode("utf-8")
async def get_tools():
client = MultiServerMCPClient(
{
"minimal": {
"transport": "http",
"url": "http://localhost:8080/mcp/sample",
"headers": {"Authorization": f"Basic {AUTH_HEADER}"},
}
}
)
tools = await client.get_tools()
for tool in tools:
print("- ", tool.name)
print("Available MCP tools:")
for tool in sorted(tools, key=lambda item: item.name):
if tool.name == "mcp_sample_GetPeopleYoungerThan":
try:
out = await tool.ainvoke({"Age": 30})
print(out)
except Exception as e:
print(f"Error invoking {tool.name}: {e}")
elif tool.name == "mcp_sample_multiply":
try:
out = await tool.ainvoke({"a": 5, "b": 7})
print(out)
except Exception as e:
print(f"Error invoking {tool.name}: {e}")
return tools
async def main():
tools = await get_tools()
# print(tools)
if tools== [] or tools is None:
print("No tools available. Exiting.")
return
if __name__ == "__main__":
asyncio.run(main())