Skip to content

[Server] Add outgoing (elicitation, sampling) request and client response events#386

Open
omouren wants to merge 5 commits into
modelcontextprotocol:mainfrom
FrenchFounders:feature/elicit-lifecycle-events
Open

[Server] Add outgoing (elicitation, sampling) request and client response events#386
omouren wants to merge 5 commits into
modelcontextprotocol:mainfrom
FrenchFounders:feature/elicit-lifecycle-events

Conversation

@omouren

@omouren omouren commented Jun 24, 2026

Copy link
Copy Markdown

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.

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

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 chr-hertel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @omouren - looks like a valuable addition to me, left some comments and didn't test yet.

Comment thread src/JsonRpc/MessageFactory.php Outdated
Comment thread src/Event/OutgoingRequestEvent.php Outdated
Comment thread src/Server/Protocol.php Outdated
Comment thread src/Server/Protocol.php Outdated
@chr-hertel chr-hertel changed the title Add outgoing (elicitation, sampling) request and client response events [Server] Add outgoing (elicitation, sampling) request and client response events Jul 5, 2026
@chr-hertel chr-hertel added Server Issues & PRs related to the Server component enhancement Request for a new feature that's not currently supported labels Jul 5, 2026
@chr-hertel chr-hertel added this to the 0.7.0 milestone Jul 5, 2026
@chr-hertel chr-hertel added the needs more work Not ready to be merged yet, needs additional follow-up from the author(s). label Jul 5, 2026
omouren and others added 4 commits July 21, 2026 15:20
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.
@omouren
omouren requested a review from chr-hertel July 21, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Request for a new feature that's not currently supported needs more work Not ready to be merged yet, needs additional follow-up from the author(s). Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants