-
-
Notifications
You must be signed in to change notification settings - Fork 106
[MCP Bundle] Migrate from symfony/mcp-sdk
to official mcp/sdk
#637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MCP Bundle] Migrate from symfony/mcp-sdk
to official mcp/sdk
#637
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for working on this - minor comment for now - on top I wonder about registering the capabilities correctly to the registry via DIC - but I'm only on my phone - could be a follow up anyways 👍
@chr-hertel What do you think of this approach: // Interface
interface McpToolInterface {}
// Autoconfiguration
$container->registerForAutoconfiguration(McpToolInterface::class)->addTag('mcp.tool');
// CompilerPass
$taggedServices = $container->findTaggedServiceIds('mcp.tool');
foreach ($taggedServices as $id => $tags) {
$container->getDefinition($id)->setPublic(true);
} In SDK's ReferenceHandler::getClassInstance() private function getClassInstance(string $className): object
{
if (null !== $this->container && $this->container->has($className)) {
return $this->container->get($className);
}
return new $className();
} Our CompilerPass makes services public so the SDK's ReferenceHandler can use Symfony's DIC. |
Goal would be to use the attributes, that are already around in the SDK - and we can use a service locator to skip making the public |
I'm not entirely sure we need to go through the Currently the flow is:
We could potentially scan for Pros
Pros of direct attribute scanning:
|
I started some work here #460 (mostly vibe coding, so maybe ignore the code changes), but check the docs and namespace changes, maybe it can help you. |
symfony/mcp-sdk
to official mcp/sdk
You should also remove the symfony/mcp-sdk completely here in this PR |
caea9d8
to
d916690
Compare
namespace Symfony\AI\McpBundle\Routing; | ||
|
||
use Symfony\AI\McpBundle\Exception\LogicException; | ||
use Symfony\Component\Config\Loader\Loader; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the right class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use maybe Symfony\Component\Routing\Exception\LogicException
?
In CLAUDE.MD :
Use project specific exceptions instead of global exception classes like \RuntimeException, \InvalidArgumentException etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please do a complete review? I've added in addition to the tool :
Feels like I'm going in all directions 😅 I'm not really sure what the bundle should handle vs what the SDK should handle. |
Two things, besides the rebase, make sense still:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @camilleislasse for kicking this off - will merge it now and we can iterate for leveling up 👍
8e8ede0
to
65402c5
Compare
Okay, we'll need to wait for modelcontextprotocol/php-sdk#79, but let's work with new PRs on top of this - instead of making this bigger. |
- Replace symfony/mcp-sdk dependency with official mcp/sdk - Refactor Server creation to use Server::make() builder pattern - Convert tool definitions from interfaces to #[McpTool] attributes - Implement automatic tool discovery in src/ directory - Update STDIO transport command to mcp:server - Simplify service configuration using native SDK patterns - Remove redundant ServerFactory and routes.php files - Add custom LogicException for bundle-specific errors - Update all documentation (README, CHANGELOG, index.rst) - Fix composer.json description - Add .idea/ to .gitignore Resolves symfony#526 Fabbot + php-cs-fixer DOCtor-RST Fix RouteLoader registration to always create when transports enabled Remove .idea - Add autoconfiguration for #[McpTool] attribute with mcp.tool tag - Create McpToolPass compiler pass using ServiceLocatorTagPass::register() - Inject Service Locator into ServerBuilder via setContainer() Fix PR review comments for MCP Bundle migration - Remove prefer-stable from root composer.json - Move CHANGELOG content to 0.1 section and remove BC BREAK labels - Use ServerBuilder::class and Server::class in services configuration - Fix "client vs server" comment in documentation - Use ServerBuilder::class in test instead of string Remove symfony/mcp-sdk Remove symfony/mcp-sdk ref in claude reamdde et phpstan Rewrite CHANGELOG.md Use [] === $taggedServices instead of empty($taggedServices) Use use Symfony\Component\Routing\Exception\LogicException; instead of custom Exception Add MCP capabilities support to Symfony bundle This commit implements Model Context Protocol (MCP) support by adding: - Prompts: System instructions for AI context using #[McpPrompt] - Resources: Static data access using #[McpResource] - Resource Templates: Dynamic resources with parameters using #[McpResourceTemplate] Implementation includes: - Auto-configuration for MCP attributes with proper tagging - Compiler passes extending AbstractMcpPass for service registration - Documentation updates with examples and usage patterns - Demo examples showcasing each capability type Technical details: - Refactored auto-configuration into registerMcpAttributes() method - Created AbstractMcpPass to eliminate code duplication - Added proper error handling for timezone validation - Resource Templates ready but await MCP SDK handler implementation Apply PHP CS Fixer to demo MCP examples - Add Symfony license headers to demo files - Fix code style and formatting - Add trailing commas where appropriate Add pagination_limit and instructions configuration options - Add pagination_limit option to control MCP list responses (default: 50) - Add instructions option for server description to help LLMs - Update services.php to pass both options to ServerBuilder - Add comprehensive tests for new configuration options - Update documentation with examples and usage - Update demo configuration with practical examples Both options map directly to ServerBuilder methods: - setPaginationLimit(int) - setInstructions(string) Add dedicated MCP logger with configurable Monolog integration - Create monolog.logger.mcp service with dedicated channel - Update ServerBuilder to use MCP-specific logger instead of generic logger - Add comprehensive logging documentation with configuration examples - Include examples for different environments (dev/prod) and handlers (file/Slack) - Add test coverage for MCP logger service creation and configuration The MCP logger uses Monolog's logger prototype pattern and can be customized by users through standard Monolog configuration in their applications. Add EventDispatcher support and event system documentation - Configure Symfony EventDispatcher for MCP SDK event handling - Add comprehensive event system documentation with examples - Add test coverage for EventDispatcher configuration - Fix PHPStan type assertion for ChildDefinition Migrate MCP Bundle from SSE to official StreamableHttpTransport - Replace custom SSE implementation with MCP SDK's StreamableHttpTransport - Change sse transport to http in configuration and code - Simplify DependencyInjection compiler passes - Add HTTP session management (file/memory store options) - Update documentation and tests for HTTP transport
65402c5
to
1382d4c
Compare
Thank you @camilleislasse. |
Summary
This PR migrates the MCP Bundle from the internal
symfony/mcp-sdk
to the officialmcp/sdk
package and completely removes the internal MCP SDK component.Changes
Remove Internal MCP SDK
src/mcp-sdk/
directorysymfony/mcp-sdk
tomcp/sdk
MCP Bundle Migration
symfony/mcp-sdk
→mcp/sdk
in composer.jsonServer::make()
builder patternNew MCP Capabilities Support
#[McpTool]
,#[McpPrompt]
,#[McpResource]
,#[McpResourceTemplate]
McpToolPass
,McpPromptPass
,McpResourcePass
,McpResourceTemplatePass
Bundle Enhancements
monolog.logger.mcp
servicepagination_limit
andinstructions
parametersDemo Application Updates
CurrentTimePrompt.php
- Prompt capabilityCurrentTimeResource.php
- Resource capabilityCurrentTimeResourceTemplate.php
- Resource template capabilityCurrentTimeTool.php
from interface to attributeDocumentation
doc/index.rst
with examples for all capability typesTesting
Breaking Changes
#[McpTool]
attribute instead of implementing interfacessymfony/mcp-sdk
withmcp/sdk
in composer.jsonCode Examples
Before (interface-based):