-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcheck_mcp.py
More file actions
61 lines (52 loc) · 1.89 KB
/
check_mcp.py
File metadata and controls
61 lines (52 loc) · 1.89 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
import asyncio
import os
import mcp
from mcp.client.stdio import StdioServerParameters
from mcp import ClientSession
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
async def main():
# Configure the stdio client
server_params = StdioServerParameters(
command="python",
args=[
"signal_mcp/main.py",
"--user-id",
os.environ["SENDER_NUMBER"],
"--transport",
"stdio",
],
)
async with mcp.stdio_client(server_params) as transport:
stdio, write = transport
async with ClientSession(stdio, write) as session:
await session.initialize()
# List available tools
response = await session.list_tools()
print(response.tools)
# Call a tool to send a message
send_result = await session.call_tool(
"send_message_to_user",
{
"message": "Hello from MCP stdio client!",
"user_id": os.environ["RECEIVER_NUMBER"],
},
)
print(f"Send result: {send_result}")
# Receive a message with timeout
print("Waiting for message...")
receive_result = await session.call_tool(
"receive_message",
{"timeout": 10}, # 5 second timeout
)
print(f"Receive result: {receive_result}")
# Check if we received a message (might be None if timeout)
if isinstance(receive_result, tuple) and len(receive_result) >= 2:
message, sender, group = receive_result
if message and sender:
print(f"Received message from {sender}: {message}")
if group:
print(f"In group: {group}")
if __name__ == "__main__":
asyncio.run(main())