You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
review: Server.middleware wraps every request and notification (t04/t18); t25 TODO
ServerMiddleware now wraps the entire _on_request and _on_notify body so it
observes initialize, notifications/initialized, METHOD_NOT_FOUND, validation
failures, and pre-init drops - everything the old incoming_messages stream
saw. params is the raw Mapping[str, Any] | None (not the typed model);
ctx.request_id is None distinguishes a notification; call_next() raises
MCPError for request-side failures so middleware can observe them, returns
None for notifications. _on_notify keeps its swallow-at-boundary behavior
but middleware sees the raise first.
ServerRunner._on_request/_on_notify restructured: build ctx from raw inputs
first (_extract_meta validates only _meta via RequestParams so ctx.meta
keeps the alias-converted shape), then compose Server.middleware around an
_inner() containing validation/init/gate/lookup/handler.
_compose_server_middleware helper shared by both paths.
_handle_initialize returns InitializeResult (outer _dump_result serializes)
so middleware can transform it. _make_context now takes meta directly.
t25: TODO at the duplicate-inbound-request-id site (parity with v1/TS;
spec puts uniqueness on the sender).
Copy file name to clipboardExpand all lines: docs/migration.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1113,7 +1113,7 @@ In practice, replace direct `ServerSession` use with `Server.run(read_stream, wr
1113
1113
1114
1114
-`InitializationState` enum and `ServerSession._initialization_state` — initialization tracking is now on `Connection` (`connection.initialized` is an `anyio.Event`, `connection.client_params` holds the init params).
1115
1115
-`ServerRequestResponder` type alias.
1116
-
-`ServerSession.incoming_messages` stream — there is no longer a public stream of inbound messages to iterate. Register handlers via the `on_*` constructor params (or `add_request_handler`) and use `Server.middleware` to observe every request.
1116
+
-`ServerSession.incoming_messages` stream — there is no longer a public stream of inbound messages to iterate. Register handlers via the `on_*` constructor params (or `add_request_handler`) and use `Server.middleware` to observe every inbound request and notification (`initialize`, unknown methods, validation failures, and `notifications/initialized` included).
1117
1117
-`ServerSession.__aenter__` / `__aexit__` — `ServerSession` is no longer an async context manager.
1118
1118
- The private `_receive_loop`, `_received_request`, `_received_notification`, and `_handle_incoming` overrides — there is nothing to override on `ServerSession` anymore. To intercept inbound messages, use `Server.middleware` or `DispatchMiddleware` (see the `_handle_*` removal section above).
0 commit comments