[Server] Add outgoing (elicitation, sampling) request and client response events - #386
Conversation
Introduce `OutgoingRequestEvent` and `ClientResponseEvent` to provide full observability over the server's interaction with the client. This includes requests sent by the server (e.g., elicitation, sampling) and the client's replies to those requests. Additionally, update `ResponseEvent` and `ErrorEvent` to be dispatched when a suspended Fiber completes. This ensures that deferred responses from long-running, asynchronous operations are also observable via the existing event mechanisms.
chr-hertel
left a comment
There was a problem hiding this comment.
Thanks @omouren - looks like a valuable addition to me, left some comments and didn't test yet.
Co-authored-by: Christopher Hertel <mail@christopher-hertel.de>
…age factory The `OutgoingRequestEvent` is renamed to `ServerRequestEvent` to improve clarity, as it is dispatched when the server sends a request to the client. Additionally, the `MessageFactory` has been refactored. The `createMessage` and `createFromArray` methods are consolidated into a single public `createFromArray`, simplifying message creation and error handling logic.
|
Thanks for the review @chr-hertel 👍 |
|
Hey @omouren this needs a rebase - and more importantly, please double-check the handling in context of spec version 2026-07-28 with StatelessProtocol |
dbf4c37 to
a626b04
Compare
|
Hello @chr-hertel I haven’t looked at spec revision 2026-07-28 / StatelessProtocol yet, and I’m not entirely sure how to test the new spec for now. I retested with the previous spec and the events still work as expected there. |
|
Hello @chr-hertel Follow-up on 2026-07-28 / StatelessProtocol. I did not map elicitation onto ServerRequestEvent / ClientResponseEvent as there is no server-initiated JSON-RPC on that revision, so those events would lie about the wire. They stay for the handshake-era. I updated the StatelessProtocol to dispatch the same lifecycle events as the handshake path:
|
Introduces `RequestEvent`, `ResponseEvent`, and `ErrorEvent` for the stateless 2026-07-28 protocol revision. This provides extensibility points to observe and modify server operations during request processing. `RequestEvent` now includes `InputContext` for multi-round trip retries, and `ResponseEvent` dispatches `InputRequiredResult` for elicitation on the modern era. `ErrorEvent` is dispatched for all handler-related exceptions. Documentation is updated to clarify event behavior across protocol eras.
a0e32c9 to
7aa5c7c
Compare
Introduce
ServerRequestEventandClientResponseEventto provide full observability over the server's interaction with the client. This includes requests sent by the server (e.g., elicitation, sampling) and the client's replies to those requests.Additionally, update
ResponseEventandErrorEventto be dispatched when a suspended Fiber completes. This ensures that deferred responses from long-running, asynchronous operations are also observable via the existing event mechanisms.Motivation and Context
We wanted to be able to log every step of our MCP usage, including elicitation.
How Has This Been Tested?
Tested manualy
Breaking Changes
No breaking changes
Types of changes
Checklist