-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient_example.py
More file actions
44 lines (36 loc) · 1.09 KB
/
client_example.py
File metadata and controls
44 lines (36 loc) · 1.09 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
"""
Sample client script demonstrating how to use the MCP server.
"""
import asyncio
import json
import requests
from pprint import pprint
async def main():
# MCP server URL
mcp_url = "http://127.0.0.1:8000/mcp"
# Get MCP info
print("Getting MCP server info...")
response = requests.get(mcp_url)
pprint(response.json())
# Get available tools
print("\nGetting available tools...")
response = requests.get(f"{mcp_url}/tools")
tools = response.json()["tools"]
# Print available tools
print(f"\nFound {len(tools)} MCP tools:")
for i, tool in enumerate(tools, 1):
print(f"{i}. {tool['name']} - {tool.get('description', '').split('\n')[0]}")
# Execute the "getUsers" tool
print("\nExecuting 'getUsers' tool...")
tool_data = {
"name": "getUsers",
"parameters": {
"limit": 5
}
}
response = requests.post(f"{mcp_url}/run", json=tool_data)
result = response.json()
print("\nTool execution result:")
pprint(result)
if __name__ == "__main__":
asyncio.run(main())