-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient_example_json.py
More file actions
executable file
·73 lines (61 loc) · 1.92 KB
/
Copy pathclient_example_json.py
File metadata and controls
executable file
·73 lines (61 loc) · 1.92 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""
Example using JSON server configuration.
"""
import json
import sys
from gopher_mcp_python import GopherAgent
# Server configuration for local MCP servers
SERVER_CONFIG = json.dumps(
{
"succeeded": True,
"code": 200000000,
"message": "success",
"data": {
"servers": [
{
"version": "2025-01-09",
"serverId": "1",
"name": "server1",
"transport": "http_sse",
"config": {"url": "http://127.0.0.1:3001/mcp", "headers": {}},
"connectTimeout": 5000,
"requestTimeout": 30000,
},
{
"version": "2025-01-09",
"serverId": "2",
"name": "server2",
"transport": "http_sse",
"config": {"url": "http://127.0.0.1:3002/mcp", "headers": {}},
"connectTimeout": 5000,
"requestTimeout": 30000,
},
],
},
}
)
def main():
provider = "AnthropicProvider"
model = "claude-3-haiku-20240307"
try:
# Create agent with JSON server configuration
agent = GopherAgent.create_with_server_config(provider, model, SERVER_CONFIG)
print("GopherAgent created!")
# Get question from command line args or use default
args = sys.argv[1:]
question = " ".join(args) if args else "What is the weather like in New York?"
print(f"Question: {question}")
# Run the query
answer = agent.run(question)
print("Answer:")
print(answer)
# Cleanup
agent.dispose()
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()