-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsse_client.py
49 lines (42 loc) · 1.63 KB
/
sse_client.py
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
import asyncio
import json
from mcp.client.session import ClientSession
from mcp.client.sse import sse_client
async def main():
async with sse_client("http://localhost:8000/sse") as (read_stream, write_stream):
async with ClientSession(read_stream, write_stream) as session:
print("Initializing session...")
await session.initialize()
print("Session initialized")
# Scan code for security issues
results = await session.call_tool(
"semgrep_scan",
{
"code_files": [
{
"filename": "hello_world.py",
"content": "def hello(): print('Hello, World!')",
}
]
},
)
print("\n\nWe have results!\n")
print("Raw result object:")
print("=" * 80)
print(results)
print("\n\nPretty-printed result from semgrep_scan:")
print("=" * 80)
print(json.dumps(json.loads(results.content[0].text), indent=2))
print("\n\n")
print("Hope that was helpful!")
if __name__ == "__main__":
# you can run the client with:
# uv run python examples/sse_client.py
print("Hello!")
print("First, make sure the SSE MCP server is listening on port 8000.")
print("One way you can run it is with:\n")
print("\tdocker run -p 8000:8000 ghcr.io/semgrep/mcp:latest\n")
print("in another tab in the terminal.")
print("Now try running the SSE client:")
print("=" * 80)
asyncio.run(main())