Skip to content

Conversation

@ochafik
Copy link

@ochafik ochafik commented Nov 7, 2025

Note: don't merge before the SEP is accepted (currently under review)

Add support for tool calling during sampling requests, enabling MCP servers to execute agentic workflows using client LLM capabilities.

modelcontextprotocol/modelcontextprotocol#1577

Key changes:

  • Add ToolUseContent type for assistant tool invocation requests
  • Add ToolResultContent type for tool execution results
  • Add ToolChoice type to control tool usage behavior
  • Add UserMessage and AssistantMessage types for role-specific messages
  • Extend SamplingMessage to support tool content (backward compatible)
  • Add SamplingToolsCapability & SamplingContextCapability
  • Update CreateMessageRequestParams with tools and toolChoice fields
  • Update CreateMessageResult to support tool use content
  • Update StopReason to include "toolUse" value
  • Add comprehensive unit tests for all new types

The implementation maintains backward compatibility by keeping SamplingMessage as a flexible BaseModel while adding more specific UserMessage and AssistantMessage types for type-safe tool interactions.

All new types follow existing patterns:

  • Use Pydantic V2 BaseModel
  • Allow extra fields with ConfigDict(extra="allow")
  • Include proper docstrings and field descriptions
  • Support optional fields where appropriate

Add support for tool calling during sampling requests, enabling MCP servers
to execute agentic workflows using client LLM capabilities.

Key changes:
- Add ToolUseContent type for assistant tool invocation requests
- Add ToolResultContent type for tool execution results
- Add ToolChoice type to control tool usage behavior
- Add UserMessage and AssistantMessage types for role-specific messages
- Extend SamplingMessage to support tool content (backward compatible)
- Add SamplingToolsCapability for capability negotiation
- Update CreateMessageRequestParams with tools and toolChoice fields
- Update CreateMessageResult to support tool use content
- Update StopReason to include "toolUse" value
- Add comprehensive unit tests for all new types

The implementation maintains backward compatibility by keeping SamplingMessage
as a flexible BaseModel while adding more specific UserMessage and
AssistantMessage types for type-safe tool interactions.

All new types follow existing patterns:
- Use Pydantic V2 BaseModel
- Allow extra fields with ConfigDict(extra="allow")
- Include proper docstrings and field descriptions
- Support optional fields where appropriate

Github-Issue: #1577
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