Skip to content

feat: add streaming methods for elicitation and sampling#1210

Open
LucaButBoring wants to merge 16 commits intomodelcontextprotocol:mainfrom
LucaButBoring:feat/elicitation-sampling-streaming
Open

feat: add streaming methods for elicitation and sampling#1210
LucaButBoring wants to merge 16 commits intomodelcontextprotocol:mainfrom
LucaButBoring:feat/elicitation-sampling-streaming

Conversation

@LucaButBoring
Copy link
Contributor

@LucaButBoring LucaButBoring commented Dec 1, 2025

Following #1041, this adds streaming methods for elicitation and sampling to simplify usage with Tasks.

Motivation and Context

Introduces a consistent way to use Tasks with elicitation and sampling just like we have with tool calls.

How Has This Been Tested?

New unit tests and example tool.

Breaking Changes

N/A

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

Additional context

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 1, 2025

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1210

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1210

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1210

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1210

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1210

commit: 79904ec

@LucaButBoring LucaButBoring force-pushed the feat/elicitation-sampling-streaming branch 3 times, most recently from f8755d8 to 7520307 Compare December 1, 2025 23:52
@LucaButBoring LucaButBoring force-pushed the feat/elicitation-sampling-streaming branch from 7520307 to 4ed61b6 Compare December 1, 2025 23:58
@LucaButBoring LucaButBoring marked this pull request as ready for review December 2, 2025 00:04
@LucaButBoring LucaButBoring requested a review from a team as a code owner December 2, 2025 00:04
@LucaButBoring LucaButBoring marked this pull request as draft December 2, 2025 00:20
@LucaButBoring
Copy link
Contributor Author

Doing some manual testing on this, converted back to draft temporarily

@LucaButBoring LucaButBoring marked this pull request as ready for review December 2, 2025 00:39
@LucaButBoring
Copy link
Contributor Author

Validated with new example tool.

@LucaButBoring LucaButBoring force-pushed the feat/elicitation-sampling-streaming branch from ba50e0a to 771f101 Compare December 8, 2025 23:21
@felixweinberger felixweinberger self-requested a review December 9, 2025 14:53
@changeset-bot
Copy link

changeset-bot bot commented Dec 22, 2025

⚠️ No Changeset found

Latest commit: 79904ec

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@cliffhall
Copy link
Member

@LucaButBoring could you resolve the conflicts on this PR? Hoping to get it merged soon.

- Replace schema-based setRequestHandler with string methods
- Update context API from extra.taskStore to extra.task?.store
- Add CreateTaskResult to ResultTypeMap for elicitation/create
  sampling/createMessage
@LucaButBoring
Copy link
Contributor Author

@cliffhall updated 👍

type ServerWithCapabilities = {
getClientCapabilities(): { elicitation?: { form?: boolean; url?: boolean } } | undefined;
};
const clientCapabilities = (this._server as unknown as ServerWithCapabilities).getClientCapabilities();
Copy link
Contributor

@KKonstantinov KKonstantinov Feb 8, 2026

Choose a reason for hiding this comment

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

Hi, could we achieve this without the as unknown? It's something we're actively trying to avoid. Is there something not matching on the ClientCapabilities.elicitation that we need to fix here? (them not being a boolean but an object | undefined)? Would rather fix that than have a proprietary casting here, basically forfeiting the type system fully for it

The checks bellow would pass even if elicitation.form or elicitation.url were objects and not boolean, so is that really needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I think that was due to other type inference failures around _server at the time this was originally written which are no longer applicable, I'm doing a scrub for this again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW the hard casts are needed around getTask and getTaskResult still either way, and that won't be addressed until #1449 is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, updated - this cast and the similar ones in sampling are no longer needed and have been removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants