Skip to content

AnthropicSamplingHandler reports stop_sequence as endTurn instead of stopSequence #5603

Closed

Description

@asasemahmed

What happened?

When Anthropic stops generation because a stop sequence was hit, the sampling result's stop_reason is endTurn, although MCP defines stopSequence for that case.

Example Code

from anthropic.types import Message, TextBlock, Usage

from fastmcp.client.sampling.handlers.anthropic import AnthropicSamplingHandler

message = Message(
    id="msg_1", type="message", role="assistant",
    content=[TextBlock(type="text", text="done")],
    model="claude-sonnet-4-5",
    stop_reason="stop_sequence", stop_sequence="END",
    usage=Usage(input_tokens=1, output_tokens=1),
)
result = AnthropicSamplingHandler._message_to_result_with_tools(message)
print(result.stop_reason)

Output: endTurn

Version Information

FastMCP version:                                     4.0.12.dev59+5baeacfe
MCP version:                                                         2.0.0
Python version:                                                    3.12.14
Platform:                                        Windows-11-10.0.26200-SP0

Activity

  1. added
    bug
    client
    on Oct 8, 2026
  2. added a commit that references this issue on Oct 8, 2026
    c41c388
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugclient

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions