-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathnotifications.py
More file actions
23 lines (17 loc) · 862 Bytes
/
notifications.py
File metadata and controls
23 lines (17 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from mcp.server.fastmcp import Context, FastMCP
from mcp.server.lowlevel.server import NotificationOptions
from mcp.server.session import ServerSession
# Setup Server Capabilities
notification_options = NotificationOptions(prompts_changed=False, resources_changed=True, tools_changed=False)
mcp = FastMCP(name="Notifications Example", notification_options=notification_options)
@mcp.tool()
async def process_data(data: str, ctx: Context[ServerSession, None]) -> str:
"""Process data with logging."""
# Different log levels
await ctx.debug(f"Debug: Processing '{data}'")
await ctx.info("Info: Starting processing")
await ctx.warning("Warning: This is experimental")
await ctx.error("Error: (This is just a demo)")
# Notify about resource changes
await ctx.session.send_resource_list_changed()
return f"Processed: {data}"