-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathserver_notification_client.py
More file actions
36 lines (26 loc) · 979 Bytes
/
server_notification_client.py
File metadata and controls
36 lines (26 loc) · 979 Bytes
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
# Snippets demonstrating handling known and custom server notifications
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
# Create dummy server parameters for stdio connection
server_params = StdioServerParameters(
command="uv",
args=["run"],
env={},
)
# Create a custom handler for the resource list changed notification
async def custom_resource_list_changed_handler() -> None:
"""Custom handler for resource list changed notifications."""
print("RESOURCE LIST CHANGED")
async def run():
async with stdio_client(server_params) as (read, write):
async with ClientSession(
read,
write,
resource_list_changed_callback=custom_resource_list_changed_handler,
) as session:
# Initialize the connection
await session.initialize()
# Do client stuff here
if __name__ == "__main__":
asyncio.run(run())