From 96e13c0c3c1b15657d443020b16db1b95b37df2b Mon Sep 17 00:00:00 2001 From: Amashiro Date: Thu, 18 Sep 2025 17:31:02 +0800 Subject: [PATCH 1/2] fix(mcp): add meta field to MCPToolResult for MCP _meta support --- src/strands/tools/mcp/mcp_client.py | 10 ++++++++-- src/strands/types/tools.py | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/strands/tools/mcp/mcp_client.py b/src/strands/tools/mcp/mcp_client.py index f810fed06..3caa0b97f 100644 --- a/src/strands/tools/mcp/mcp_client.py +++ b/src/strands/tools/mcp/mcp_client.py @@ -443,15 +443,21 @@ def _map_mcp_content_to_tool_result_content( """ if isinstance(content, MCPTextContent): self._log_debug_with_thread("mapping MCP text content") - return {"text": content.text} + result = {"text": content.text} + if content.meta is not None: + result["_meta"] = content.meta + return result elif isinstance(content, MCPImageContent): self._log_debug_with_thread("mapping MCP image content with mime type: %s", content.mimeType) - return { + result = { "image": { "format": MIME_TO_FORMAT[content.mimeType], "source": {"bytes": base64.b64decode(content.data)}, } } + if content.meta is not None: + result["_meta"] = content.meta + return result else: self._log_debug_with_thread("unhandled content type: %s - dropping content", content.__class__.__name__) return None diff --git a/src/strands/types/tools.py b/src/strands/types/tools.py index e8d5531b2..e449a7601 100644 --- a/src/strands/types/tools.py +++ b/src/strands/types/tools.py @@ -7,7 +7,7 @@ from abc import ABC, abstractmethod from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, AsyncGenerator, Awaitable, Callable, Literal, Protocol, Union +from typing import TYPE_CHECKING, Any, AsyncGenerator, Awaitable, Callable, Literal, Protocol, Union, NotRequired, Dict from typing_extensions import TypedDict @@ -68,12 +68,14 @@ class ToolResultContent(TypedDict, total=False): document: Document content returned by the tool. image: Image content returned by the tool. json: JSON-serializable data returned by the tool. + meta: meta content returned by the tool. text: Text content returned by the tool. """ document: DocumentContent image: ImageContent json: Any + meta: NotRequired[Dict[str, Any]] text: str From d70dc90ed959f242bc6bcc39d7591a40204708c9 Mon Sep 17 00:00:00 2001 From: Amashiro Date: Thu, 18 Sep 2025 18:11:02 +0800 Subject: [PATCH 2/2] fix(mcp): Fixed the _meta field of ToolResultContent, which was previously incorrectly written as meta. This did not comply with the MCP specification. --- src/strands/types/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/strands/types/tools.py b/src/strands/types/tools.py index e449a7601..d714df8fc 100644 --- a/src/strands/types/tools.py +++ b/src/strands/types/tools.py @@ -68,14 +68,14 @@ class ToolResultContent(TypedDict, total=False): document: Document content returned by the tool. image: Image content returned by the tool. json: JSON-serializable data returned by the tool. - meta: meta content returned by the tool. + _meta: meta content returned by the tool. text: Text content returned by the tool. """ document: DocumentContent image: ImageContent json: Any - meta: NotRequired[Dict[str, Any]] + _meta: NotRequired[Dict[str, Any]] text: str