Skip to content

Commit 64ea38a

Browse files
committed
Removes handling for custom and unknown notifications
1 parent fba717b commit 64ea38a

File tree

7 files changed

+84
-667
lines changed

7 files changed

+84
-667
lines changed

README.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,8 +2160,6 @@ Servers may send notifications, which derive from the `ServerNotification` class
21602160
1. For each notification type you want to support, write a callback function that follows implements the matching protocol, such as `ToolListChangedFnT` for the tool list changed notification.
21612161
2. Pass that function to the appropriate parameter when instantiating your client, e.g. `tool_list_changed_callback` for the tool list changed notification. This will be called every time your client receives the matching notification.
21622162

2163-
You can also use this pattern with the `UnknownNotificationFnT` protocol to handle notification types that aren't anticipated in the SDK or by your code. This would handle custom notification types from the server.
2164-
21652163
<!-- snippet-source examples/snippets/clients/server_notification_client.py -->
21662164
```python
21672165
# Snippets demonstrating handling known and custom server notifications
@@ -2170,7 +2168,6 @@ import asyncio
21702168

21712169
from mcp import ClientSession, StdioServerParameters
21722170
from mcp.client.stdio import stdio_client
2173-
from mcp.types import ServerNotification
21742171

21752172
# Create dummy server parameters for stdio connection
21762173
server_params = StdioServerParameters(
@@ -2186,19 +2183,12 @@ async def custom_resource_list_changed_handler() -> None:
21862183
print("RESOURCE LIST CHANGED")
21872184

21882185

2189-
# Create a fallback handler for custom notifications we aren't aware of.
2190-
async def fallback_notification_handler(notification: ServerNotification) -> None:
2191-
"""Fallback handler for unknown notifications."""
2192-
print(f"UNKNOWN notification caught: {notification.root.method}")
2193-
2194-
21952186
async def run():
21962187
async with stdio_client(server_params) as (read, write):
21972188
async with ClientSession(
21982189
read,
21992190
write,
22002191
resource_list_changed_callback=custom_resource_list_changed_handler,
2201-
unknown_notification_callback=fallback_notification_handler,
22022192
) as session:
22032193
# Initialize the connection
22042194
await session.initialize()
@@ -2213,10 +2203,6 @@ if __name__ == "__main__":
22132203
_Full example: [examples/snippets/clients/server_notification_client.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/clients/server_notification_client.py)_
22142204
<!-- /snippet-source -->
22152205

2216-
If your client expects to connect to a server that sends custom notifications, you can create your handler or handlers, then pass them in a dictionary where the key is the notification literal and the value is a reference to the handler function. This dictionary is then passed in to the `custom_notification_handlers` parameter of the `ClientSession` constructor.
2217-
2218-
For a runnable example, see [examples/snippets/clients/custom_notifications_example.py](https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/clients/custom_notifications_example.py).
2219-
22202206
### Client Display Utilities
22212207

22222208
When building MCP clients, the SDK provides utilities to help display human-readable names for tools, resources, and prompts:

0 commit comments

Comments
 (0)