Commit Graph

1 Commits

Author SHA1 Message Date
Pietro Zullo 2ddad74dab fix(python): convert MCP tool results to LangChain content blocks (#1192)
* fix(python): convert MCP tool results to LangChain content blocks

Previously, tool results were converted using `str(tool_result.content)`,
which produced Python repr strings like
`[TextContent(type='text', text='...')]` instead of the actual content.

Now properly maps MCP content types to LangChain format:
- TextContent → plain string or {"type": "text", ...}
- ImageContent → {"type": "image", "source_type": "base64", ...}
- AudioContent → {"type": "audio", "source_type": "base64", ...}
- EmbeddedResource → text or file block depending on resource type

Single TextContent results (the most common case) are returned as
plain strings for backward compatibility.

* test(python): cover langchain tool content conversion

* style(python): format langchain adapter

* test(python): cover langchain block tool messages
2026-03-16 08:59:16 +01:00