|
| 1 | +import asyncio |
| 2 | +import json |
| 3 | +from mcp.client.session import ClientSession |
| 4 | +from mcp.client.sse import sse_client |
| 5 | +from .utils import render_utility_result |
| 6 | + |
| 7 | +# to start the server, run: |
| 8 | +# cargo run --release --bin mcp-sse |
| 9 | + |
| 10 | +async def main(): |
| 11 | + # The URL where the Rust SSE server is listening. |
| 12 | + server_url = "http://127.0.0.1:8000/sse" |
| 13 | + |
| 14 | + async with sse_client(server_url) as (read, write): |
| 15 | + async with ClientSession(read, write) as session: |
| 16 | + await session.initialize() |
| 17 | + |
| 18 | + # List available tools |
| 19 | + tools = await session.list_tools() |
| 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) |
| 41 | + |
| 42 | + |
| 43 | +if __name__ == "__main__": |
| 44 | + asyncio.run(main()) |
0 commit comments