Repository navigation
Expand file tree
/
Copy pathclient.py
More file actions
57 lines (44 loc) · 1.45 KB
/
Copy pathclient.py
File metadata and controls
57 lines (44 loc) · 1.45 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
from mcp import ClientSession, StdioServerParameters, types
from mcp.client.stdio import stdio_client
# Create server parameters for stdio connection
server_params = StdioServerParameters(
command="uvx", # Executable
args=[
"--quiet",
"--refresh",
"git+https://github.com/emsi/slow-mcp",
"--transport",
"stdio",
],
env=None, # Optional environment variables
)
# Optional: create a sampling callback
async def handle_sampling_message(
message: types.CreateMessageRequestParams,
) -> types.CreateMessageResult:
return types.CreateMessageResult(
role="assistant",
content=types.TextContent(
type="text",
text="Hello, world! from model",
),
model="gpt-3.5-turbo",
stopReason="endTurn",
)
async def run():
async with stdio_client(server_params) as (read, write):
async with ClientSession(
read, write, #sampling_callback=handle_sampling_message
) as session:
# Initialize the connection
await session.initialize()
resources = await session.list_resources()
# List available tools
tools = await session.list_tools()
print(f"Tools: {tools}")
# Call a tool
result = await session.call_tool("run_command")
print(f"Result: {result}")
if __name__ == "__main__":
import asyncio
asyncio.run(run())