forked from modelcontextprotocol/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote_streamablehttp_client.py
More file actions
83 lines (67 loc) · 2.83 KB
/
Copy pathremote_streamablehttp_client.py
File metadata and controls
83 lines (67 loc) · 2.83 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
74
75
76
77
78
79
80
81
82
83
"""
Remote MCP Server Client Example — TWZRD Agent Intel
=====================================================
This example shows how to connect to a remote MCP server using
streamable-http transport, which is the recommended transport for
production/hosted MCP servers.
TWZRD Agent Intel (https://intel.twzrd.xyz) is a live production MCP server
providing trust scoring for Web3 AI agents. It accepts the standard MCP
streamable-http transport with no authentication required for free tools.
MCP config (for Claude Desktop / claude_desktop_config.json):
{
"mcpServers": {
"twzrd-agent-intel": {
"url": "https://intel.twzrd.xyz/mcp"
}
}
}
Install:
pip install mcp
This example demonstrates:
- Connecting to a remote MCP server via streamable-http
- Calling tools on the remote server
- Handling tool results
"""
import asyncio
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
# Live production MCP server — no authentication required for free tools
SERVER_URL = "https://intel.twzrd.xyz/mcp"
# Example Web3 agent wallet address
EXAMPLE_WALLET = "D1QkbFJKiPsymJ65RKHhF6DFB8sPMfpBaFBzuHKfJGWi"
async def main() -> None:
print(f"Connecting to remote MCP server: {SERVER_URL}")
print("-" * 50)
async with streamablehttp_client(SERVER_URL) as (read_stream, write_stream, _):
async with ClientSession(read_stream, write_stream) as session:
# Initialize the connection
init_result = await session.initialize()
print(f"Server: {init_result.serverInfo.name} v{init_result.serverInfo.version}")
print()
# List available tools
tools_result = await session.list_tools()
print(f"Available tools ({len(tools_result.tools)}):")
for tool in tools_result.tools:
print(f" - {tool.name}: {tool.description}")
print()
# Call the score_agent tool (free, no payment required)
print(f"Calling score_agent for wallet: {EXAMPLE_WALLET}")
score_result = await session.call_tool(
"score_agent",
arguments={"wallet": EXAMPLE_WALLET},
)
print("Score result:")
for content_item in score_result.content:
print(f" {content_item.text}")
print()
# Call the preflight_check tool (free, no payment required)
print(f"Calling preflight_check for wallet: {EXAMPLE_WALLET}")
preflight_result = await session.call_tool(
"preflight_check",
arguments={"wallet": EXAMPLE_WALLET},
)
print("Preflight result:")
for content_item in preflight_result.content:
print(f" {content_item.text}")
if __name__ == "__main__":
asyncio.run(main())