Skip to content

Conversation

@ochafik
Copy link
Contributor

@ochafik ochafik commented Nov 11, 2025

Implement types from modelcontextprotocol/modelcontextprotocol#1577 (accepted)

Spec PR: modelcontextprotocol/modelcontextprotocol#1796 (under review)

cc/ @bhosmer-ant

Follow up PRs may include more code from #991:

  • Examples
  • ToolRegistry, runToolLoop helpers

Motivation and Context

Allows using tools in sampling.

How Has This Been Tested?

#991 has examples + backfill support

Breaking Changes

Yes: any code that uses the result of sampling will now need to check whether CreateMessageResult.content is an array or not (if the server is on a previous spec version, the content returned cannot be an array, but the static types now allow both)

const response = await options.server.server.createMessage({ messages, maxTokens: 4000 });

// BEFORE:
// const contentText = response.content.type === 'text' ? response.content.text : '';

// AFTER:
const contentArray = Array.isArray(response.content) ? response.content : [response.content];
const contentText = contentArray.filter(c => c.type === 'text').map(c => c.text).join('\n');

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

@ochafik ochafik changed the title Implement SEP 1577 (Sampling w/ Tools) Implement SEP-1577: Sampling With Tools) Nov 11, 2025
@ochafik ochafik changed the title Implement SEP-1577: Sampling With Tools) Implement SEP-1577 - Sampling With Tools) Nov 11, 2025
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.

2 participants