Skip to content

Apply MCPClient prefix and carry tool annotations in TemporalMCPClient - #148

Merged
brianstrauch merged 1 commit into
temporalio:mainfrom
avanish-garg:fix/strands-mcp-prefix-annotations
Oct 23, 2026
Merged

brianstrauch merged 1 commit into
temporalio:mainfrom
avanish-garg:fix/strands-mcp-prefix-annotations

Conversation

@avanish-garg

Copy link
Copy Markdown
Contributor

What was changed

  • _MCPToolInfo gains agent_name and annotations, both defaulting to None. _tool_infos fills them from the MCPAgentTool it already builds to evaluate the tool filters: agent_name is its prefixed tool_name, annotations is the annotations entry of its tool_spec, so the shape matches plain Strands.
  • TemporalMCPTool.tool_name and tool_spec["name"] use agent_name (falling back to name), and tool_spec includes annotations when there are any. The tool still sends info.name, the server-side name, to the {server}-call-tool activity.
  • No change to activity names, the public API or the connection handling. Tool filters still match the server-side name, as in Strands.
  • New tests/test_mcp_prefix.py and a small tests/labeled_mcp_server.py (an annotated echo tool that tags its reply with the server's label).

Why?

The README says a worker-side factory can pass prefix to its MCPClient, but TemporalMCPClient listed the tools under their server-side names. The model saw echo instead of gh_echo, calling gh_echo failed with "Unknown tool", and two servers exposing the same tool name collided so one server's tool was lost. The annotations Strands puts in the tool spec were also dropped. Both fields are optional, so a list-tools result recorded before this change still decodes and keeps the old name.

Checklist

  1. Closes [Bug] strands_agents: TemporalMCPClient ignores MCPClient(prefix=...) and drops MCP tool annotations #147

  2. How was this tested:
    New tests in tests/test_mcp_prefix.py: unit tests for _tool_infos / TemporalMCPTool with a prefix, without one (name and spec unchanged, no annotations key), with annotations, with a filter plus a prefix (filter matches the server-side name), and decoding a list-tools payload that has none of the new fields; and one workflow test with two real stdio MCP servers that both expose echo (prefixes gh and gl): the model is offered gh_echo and gl_echo with their annotations, each call reaches its own server (which only knows echo), and the history replays with the Replayer. On main (install rebuilt with make sync and checked against the source) all 6 new tests fail; with the change make lint is clean and make test passes (58, 6 of them new). The repro in the issue now prints gh_echo / gl_echo with the annotations and success: hi. A trial merge with fix(strands): close a failed Python MCP connection only after in-flight calls finish #137 (git merge-tree) is clean.

  3. Any docs updates needed?
    No. The README already says prefix can be passed to the worker-side MCPClient; it now holds.

TemporalMCPClient listed tools under their server-side names, so the
MCPClient(prefix=...) a worker factory configures was ignored: the model saw
`echo` instead of `gh_echo`, a call to `gh_echo` failed with "Unknown tool",
and same-named tools from two servers collided. The list-tools activity now
records the agent-facing name next to the server-side one, and the call-tool
activity still receives the server-side name. Tool annotations (readOnlyHint
and friends) are carried into the tool spec as plain Strands does. Both new
fields default to None, so list-tools results recorded earlier still decode.
@avanish-garg
avanish-garg requested a review from a team as a code owner October 23, 2026 09:55

@brianstrauch brianstrauch 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.

Thank you!

@brianstrauch
brianstrauch merged commit b59c3af into temporalio:main Oct 23, 2026
15 checks passed
campoy added a commit that referenced this pull request Oct 26, 2026
Since #148, _tool_infos hands each tool to Strands' MCPAgentTool, which
reads the schema field names of the installed mcp line. Build the unit
test's tools as real mcp Tool objects, and keep mcp 2's next_cursor on
its pages. The prefix tests' server imports MCPServer on mcp 2, like the
echo server, so test_mcp_prefix.py also runs with mcp 2.
campoy added a commit that referenced this pull request Oct 28, 2026
Since #148, _tool_infos hands each tool to Strands' MCPAgentTool, which
reads the schema field names of the installed mcp line. Build the unit
test's tools as real mcp Tool objects, and keep mcp 2's next_cursor on
its pages. The prefix tests' server imports MCPServer on mcp 2, like the
echo server, so test_mcp_prefix.py also runs with mcp 2.
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.

[Bug] strands_agents: TemporalMCPClient ignores MCPClient(prefix=...) and drops MCP tool annotations

2 participants