Skip to content

[MCP Bundle] Incompatibility of the MCPBundle with FrankenPHP #999

@gplanchat

Description

@gplanchat

Context

I am using McpBundle (commit a29a8df2d3af0442bae8efc4a5196ecb2f66635c) with APIPlatform 4.1.20 and Symfony 7.3.6. The project is based on the API Platform repository template. I am using the provided Docker stack with FrankenPHP.

On top of this base I have required the MCP Bundle with the default routes configuration :

# api/config/routes/mcp.yaml
mcp_bundle_routes:
    resource: .
    type: mcp

Issue

When I try to connect a MCP client, the first request on POST /mcp succeeds. However if there are some following request in the few seconds after the first one, there are HTTP 500 errors with the following trace. It seems to me it happens exclusively in the context of a Symfony application running with the FrankenPHP worker. In this context the server instance seems to be shared between several requests.

Image
{
	"type": "https://tools.ietf.org/html/rfc2616#section-10",
	"title": "An error occurred",
	"status": 500,
	"detail": "Protocol already connected to a transport",
	"class": "RuntimeException",
	"trace": [
		{
			"namespace": "",
			"short_class": "",
			"class": "",
			"type": "",
			"function": "",
			"file": "/app/vendor/mcp/sdk/src/Server/Protocol.php",
			"line": 93,
			"args": []
		},
		{
			"namespace": "Mcp\\Server",
			"short_class": "Protocol",
			"class": "Mcp\\Server\\Protocol",
			"type": "->",
			"function": "connect",
			"file": "/app/vendor/mcp/sdk/src/Server.php",
			"line": 48,
			"args": [
				[
					"object",
					"Mcp\\Server\\Transport\\StreamableHttpTransport"
				]
			]
		},
		{
			"namespace": "Mcp",
			"short_class": "Server",
			"class": "Mcp\\Server",
			"type": "->",
			"function": "run",
			"file": "/app/vendor/symfony/mcp-bundle/src/Controller/McpController.php",
			"line": 46,
			"args": [
				[
					"object",
					"Mcp\\Server\\Transport\\StreamableHttpTransport"
				]
			]
		},
		{
			"namespace": "Symfony\\AI\\McpBundle\\Controller",
			"short_class": "McpController",
			"class": "Symfony\\AI\\McpBundle\\Controller\\McpController",
			"type": "->",
			"function": "handle",
			"file": "/app/vendor/symfony/http-kernel/HttpKernel.php",
			"line": 183,
			"args": [
				[
					"object",
					"Symfony\\Component\\HttpFoundation\\Request"
				]
			]
		},
		{
			"namespace": "Symfony\\Component\\HttpKernel",
			"short_class": "HttpKernel",
			"class": "Symfony\\Component\\HttpKernel\\HttpKernel",
			"type": "->",
			"function": "handleRaw",
			"file": "/app/vendor/symfony/http-kernel/HttpKernel.php",
			"line": 76,
			"args": [
				[
					"object",
					"Symfony\\Component\\HttpFoundation\\Request"
				],
				[
					"integer",
					1
				]
			]
		},
		{
			"namespace": "Symfony\\Component\\HttpKernel",
			"short_class": "HttpKernel",
			"class": "Symfony\\Component\\HttpKernel\\HttpKernel",
			"type": "->",
			"function": "handle",
			"file": "/app/vendor/symfony/http-kernel/Kernel.php",
			"line": 182,
			"args": [
				[
					"object",
					"Symfony\\Component\\HttpFoundation\\Request"
				],
				[
					"integer",
					1
				],
				[
					"boolean",
					true
				]
			]
		},
		{
			"namespace": "Symfony\\Component\\HttpKernel",
			"short_class": "Kernel",
			"class": "Symfony\\Component\\HttpKernel\\Kernel",
			"type": "->",
			"function": "handle",
			"file": "/app/vendor/runtime/frankenphp-symfony/src/Runner.php",
			"line": 38,
			"args": [
				[
					"object",
					"Symfony\\Component\\HttpFoundation\\Request"
				]
			]
		},
		{
			"namespace": "Runtime\\FrankenPhpSymfony",
			"short_class": "Runner",
			"class": "Runtime\\FrankenPhpSymfony\\Runner",
			"type": "->",
			"function": "{closure:Runtime\\FrankenPhpSymfony\\Runner::run():33}",
			"file": null,
			"line": null,
			"args": []
		},
		{
			"namespace": "",
			"short_class": "",
			"class": "",
			"type": "",
			"function": "frankenphp_handle_request",
			"file": "/app/vendor/runtime/frankenphp-symfony/src/Runner.php",
			"line": 45,
			"args": [
				[
					"object",
					"Closure"
				]
			]
		},
		{
			"namespace": "Runtime\\FrankenPhpSymfony",
			"short_class": "Runner",
			"class": "Runtime\\FrankenPhpSymfony\\Runner",
			"type": "->",
			"function": "run",
			"file": "/app/vendor/autoload_runtime.php",
			"line": 29,
			"args": []
		},
		{
			"namespace": "",
			"short_class": "",
			"class": "",
			"type": "",
			"function": "require_once",
			"file": "/app/public/index.php",
			"line": 5,
			"args": [
				[
					"string",
					"/app/vendor/autoload_runtime.php"
				]
			]
		}
	]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions