|
1 | 1 | import asyncio |
| 2 | +import json |
2 | 3 | from mcp.client.session import ClientSession |
3 | | -# Import the sse_client instead of stdio_client |
4 | 4 | from mcp.client.sse import sse_client |
| 5 | +from .utils import render_utility_result |
5 | 6 |
|
6 | | -# Instructions: |
7 | | -# 1. Start the Rust SSE server in a separate terminal: |
8 | | -# cargo run --release --bin mcp-rust-server (or whatever your SSE binary is named) |
9 | | -# 2. Run this Python script. |
| 7 | +# to start the server, run: |
| 8 | +# cargo run --release --bin mcp-sse |
10 | 9 |
|
11 | 10 | async def main(): |
12 | 11 | # The URL where the Rust SSE server is listening. |
13 | | - # The sse_client requires the full endpoint, which is typically /mcp. |
14 | | - server_url = "http://127.0.0.1:8001/sse" |
| 12 | + server_url = "http://127.0.0.1:8000/sse" |
15 | 13 |
|
16 | | - # Use the sse_client context manager with the server URL |
17 | 14 | async with sse_client(server_url) as (read, write): |
18 | 15 | async with ClientSession(read, write) as session: |
19 | 16 | await session.initialize() |
20 | 17 |
|
21 | 18 | # List available tools |
22 | 19 | tools = await session.list_tools() |
23 | | - |
24 | | - print("Tools:", tools) |
25 | | - |
26 | | - # Call the 'add' tool |
27 | | - add_result = await session.call_tool("add", {"a": 2, "b": 3}) |
28 | | - print("Add result:", add_result) |
29 | | - |
30 | | - # Call the 'multiply' tool |
31 | | - multiply_result = await session.call_tool("multiply", {"a": 4, "b": 5}) |
32 | | - print("Multiply result:", multiply_result) |
33 | | - |
34 | | - # Call the 'reverse' tool |
35 | | - reverse_result = await session.call_tool("reverse", {"text": "hello"}) |
36 | | - print("Reverse result:", reverse_result) |
37 | | - |
38 | | - # Calling the tools we created to mimic resources and prompts |
39 | | - about_result = await session.call_tool("about_info", {}) |
40 | | - print("About Info result:", about_result) |
41 | | - |
42 | | - greeting_result = await session.call_tool("greeting", {"name": "Alice"}) |
43 | | - print("Greeting result:", greeting_result) |
44 | | - |
45 | | - summary_result = await session.call_tool("summarize", {"text": "This is a long text that should be summarized."}) |
46 | | - print("Summary result:", summary_result) |
| 20 | + print("Tools:") |
| 21 | + render_utility_result(tools) |
| 22 | + |
| 23 | + # Call the 'about info' tool |
| 24 | + about_info_result = await session.call_tool("about_info", {}) |
| 25 | + print("About info result:") |
| 26 | + render_utility_result(about_info_result) |
| 27 | + |
| 28 | + code_analyze_result = await session.call_tool("analysis_scan", {"path": "../", "display": "matrix"}) |
| 29 | + print("Code analysis result:") |
| 30 | + render_utility_result(code_analyze_result) |
| 31 | + |
| 32 | + # Call the 'security scan' tool |
| 33 | + security_scan_result = await session.call_tool("security_scan", {"path": "../"}) |
| 34 | + print("Security scan result:") |
| 35 | + render_utility_result(security_scan_result) |
| 36 | + |
| 37 | + # Call the 'dependency scan' tool |
| 38 | + dependency_scan_result = await session.call_tool("dependency_scan", {"path": "../"}) |
| 39 | + print("Dependency scan result:") |
| 40 | + render_utility_result(dependency_scan_result) |
47 | 41 |
|
48 | 42 |
|
49 | 43 | if __name__ == "__main__": |
|
0 commit comments