[Agent] Enable remote MCP tools for agents #1129
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a proof-of-concept MCP client implementation allowing Symfony AI agents to connect to remote MCP servers and use their tools.
How it works
1. Transports
Three transport implementations for different MCP server types:
SseTransportHttpTransportStdioTransport2. McpToolbox
Adapts MCP tools to Symfony AI's
ToolboxInterface:ToolobjectsMcpClient::callTool()TextContentTextImageContentImage(base64 decoded)AudioContentAudio(base64 decoded)EmbeddedResourceText/Image/Audio/File3. ChainToolbox
Combines multiple
ToolboxInterfaceinto one, enabling agents to use tools from different sources (local + multiple MCPs).4. ToolCallMessage changes
ToolCallMessagenow supports multiple content types (not just string):This enables MCP tools to return images/audio that get displayed in chat.
5. Bundle Integration
Creates services:
ai.mcp.client.{name}- The MCP clientai.mcp.toolbox.{name}- The toolbox (use this in agent config)Use in agent:
Breaking Changes
This PR introduces breaking changes to enable multimodal tool results:
1.
ToolCallMessage::getContent()return type changedMigration: Use
$message->asText()to get the text content as a string.2.
ToolResultConverter::convert()return type changed3.
ToolCallMessageconstructor signature changedPassing a single string still works but internally converts to
Textcontent.Demo
Timelinebot combining two MCP servers:User asks about a city → Agent fetches news → Agent generates timeline → Image displayed in chat.