### Direct example of stdio() transport Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/04-transport-factory.md Direct example of stdio() transport. Shows construction of the error with command, environment, and inheritance options. ```php $transport = TransportFactory::stdio( command: ['npx', '-y', '@modelcontextprotocol/server-filesystem', '/tmp'], cwd: null, env: ['FILESYSTEM_ROOT' => '/tmp'], inheritEnv: true, maxBufferSize: null, logger: $logger, ); ``` -------------------------------- ### debug:mcp command usage examples Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/06-commands.md Usage examples for the debug:mcp command. Shows how to list all servers, restrict to one server, show details for a tool, list clients without connecting, and connect to a client with a specific server. ```bash bin/console debug:mcp # list all servers' capabilities + unexposed elements bin/console debug:mcp --server=public # restrict the listing to one server bin/console debug:mcp get_forecast # details + input schema of one tool bin/console debug:mcp --clients # list configured clients, no connection bin/console debug:mcp --client=research --server=github # list what the remote server advertises ``` -------------------------------- ### Install MCP Bundle with Composer Source: https://github.com/symfony/mcp-bundle/blob/main/README.md Use this command to install the symfony/mcp-bundle package. Run it in your Symfony project root. The bundle is experimental and not covered by Symfony's Backward Compatibility Promise. ```bash composer require symfony/mcp-bundle ``` -------------------------------- ### mcp:server command usage Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/06-commands.md Usage examples for the mcp:server command. The first serves the single STDIO-configured server, the second serves the named server, and the third lists available servers via suggestServers(). ```bash bin/console mcp:server # serves the single STDIO-configured server bin/console mcp:server filesystem # serves the "filesystem" server bin/console mcp:server --help # lists servers via suggestServers() ``` -------------------------------- ### MCP client configuration for mcp:server Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/06-commands.md Example configuration for an MCP client that launches this server as a child process via the stdio transport. The command array specifies the console command and arguments to run. ```yaml # config/packages/mcp.yaml — a client reaching this server as a child process mcp: clients: fs: servers: local: transport: stdio command: ["bin/console", "mcp:server", "filesystem"] ``` -------------------------------- ### Direct usage of ServerLogForwarder Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/04-transport-factory.md Example of instantiating and directly invoking ServerLogForwarder. Shows the expected log call with context fields. The forwarder is normally invoked by the SDK as a notification handler, not directly by application code. ```php $forwarder = new ServerLogForwarder('research', 'github', $logger); // registered by the bundle as the LoggingNotificationHandler's delegate; a direct call: $forwarder->__invoke($notification); // => logger->log($notification->level->value, '', ['mcp_client' => 'research', 'mcp_server' => 'github', 'mcp_logger' => $notification->logger]) ``` -------------------------------- ### YAML typo protection example Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/10-compiler-passes.md Shows a typo in the 'prompts' pattern that causes a LogicException at compile time because the pattern does not match any registered service. ```yaml mcp: servers: default: registry: tools: ["App\\Mcp\\WeatherTool"] prompts: ["App\\Mem\\"] # typo — LogicException at compile time: # "The following MCP element patterns do not match any registered service: "App\Mem\" …" ``` -------------------------------- ### mcp:server Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/06-commands.md Starts an MCP server over STDIO. This command runs one configured MCP server, using the process's STDIN and STDOUT for transport. It accepts an optional server name argument and returns a command status code. ```APIDOC ## [CONSOLE] mcp:server ### Description Starts an MCP server over STDIO. Runs one configured MCP server, using the process's STDIN and STDOUT for transport. Accepts an optional server name argument. ### Method Console command ### Endpoint `bin/console mcp:server [name]` ### Parameters #### Arguments - **name** (?string) - Optional - Name of the server to run (`mcp.servers.`). If omitted, serves the single STDIO-enabled server. If multiple exist, an error is returned. ### Behavior - With no argument, serves the single STDIO-enabled server; if several exist, prints `Several MCP servers expose the STDIO transport, name the one to run: .` and returns `Command::INVALID`. - If the named server does not expose STDIO, prints `No MCP server named "" exposes the STDIO transport.` and returns `Command::INVALID`. - Otherwise calls `$this->servers->get($name)->run(new StdioTransport(logger: $this->logger))` and returns `Command::SUCCESS`. `run()` blocks serving the protocol for the life of the process. ### Returns - **int** - `Command::INVALID` (2) on a bad name, `Command::SUCCESS` (0) while serving. ### Usage Examples ```bash bin/console mcp:server # serves the single STDIO-configured server bin/console mcp:server filesystem # serves the "filesystem" server bin/console mcp:server --help # lists servers via suggestServers() ``` ### Configuration Example ```yaml # config/packages/mcp.yaml — a client reaching this server as a child process mcp: clients: fs: servers: local: transport: stdio command: ["bin/console", "mcp:server", "filesystem"] ``` ``` -------------------------------- ### Configure registry with list or map in YAML Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/configuration.md Defines the `registry` option for an MCP server named `default`. Use a single list to expose the same elements for every kind, or a map to narrow elements per kind (e.g., `tools`, `prompts`, `apps`). The example shows both forms; only one should be used at a time. ```yaml mcp: servers: default: registry: ["App\\Mcp\\"] # one list for every kind # or: registry: tools: ["App\\Mcp\\Tool\\"] prompts: ["*"] apps: ["App\\Mcp\\Apps\\"] ``` -------------------------------- ### PHP attribute example for MCP tool Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/10-compiler-passes.md Defines a WeatherTool class with the McpTool attribute. The input schema is derived from the method signature at container compile time. ```php namespace App\Mcp; use Mcp\Capability\Attribute\McpTool; final class WeatherTool { #[McpTool('get_forecast', title: 'Get the weather forecast')] public function getForecast(string $city, ?string $unit = 'celsius'): array { // input schema derived from this signature at container compile time return ['city' => $city, 'unit' => $unit, 'conditions' => 'sunny']; } } ``` -------------------------------- ### Inject McpClientInterface and call a tool Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/01-mcp-bundle.md Use this snippet to inject the McpClientInterface service by type and call a tool on a connection. The example shows a WeatherReportGenerator class that retrieves a connection named 'weather' and calls the 'get_forecast' tool with a city parameter. ```php use Symfony\AI\McpBundle\Client\McpClientInterface; final class WeatherReportGenerator { public function __construct( private readonly McpClientInterface $mcp, ) { } public function report(string $city): void { $connection = $mcp->get('weather'); $result = $connection->callTool('get_forecast', ['city' => $city]); // ... } } ``` -------------------------------- ### MiddlewareFactory class and create() method Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/07-http-transport.md The MiddlewareFactory class resolves the middleware stack for the streamable HTTP transport. Its constructor accepts an optional allowedHosts parameter: null keeps the SDK default (localhost only), an array restricts to those hosts, and false disables the protection entirely. The create() method returns null when allowedHosts is null, otherwise it starts from StreamableHttpTransport::defaultMiddleware() and re-instantiates each DnsRebindingProtectionMiddleware with the configured host list, dropping it when allowedHosts is false. ```php final class MiddlewareFactory { /** * @param list|false|null $allowedHosts Hostnames allowed by the DNS rebinding protection: null keeps the * SDK default (localhost only), an array restricts it to those hosts, * false disables the protection entirely */ public function __construct( private readonly array|false|null $allowedHosts = null, ) { } } ``` ```php /** * Returns null to keep the SDK secure defaults, or a tailored middleware stack when the DNS * rebinding protection needs to be disabled or restricted to custom hosts. * * @return list|null */ public function create(): ?array ``` -------------------------------- ### getInstructions() signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Returns the server's system-level instructions, or null. ```php public function getInstructions(): ?string ``` -------------------------------- ### getInstructions() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Returns the server's system-level instructions. ```APIDOC ## `getInstructions()` ### Description Returns the server's system-level instructions, or `null`. Opens the connection. ### Method `getInstructions()` ### Signature ```php public function getInstructions(): ?string ``` ### Returns - `?string` - The server's system-level instructions or `null`. ``` -------------------------------- ### McpClientInterface definition Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/02-mcp-client.md Defines the contract for an MCP client, extending IteratorAggregate and Countable. Methods include getName, has, get, getServerNames, and disconnect. ```php /** * @extends \IteratorAggregate */ interface McpClientInterface extends \IteratorAggregate, \Countable { public function getName(): string; public function has(string $server): bool; public function get(string $server): ServerConnectionInterface; public function getServerNames(): array; public function disconnect(): void; } ``` -------------------------------- ### Minimal server and client configuration Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/configuration.md Defines a server with HTTP and stdio transports, session file storage, and registries for tools, prompts, and resources. Also configures a client with two servers: one over HTTP with an Authorization header, and one over stdio using npx with environment inheritance. ```yaml mcp: servers: default: name: Weather MCP version: 1.0.0 transports: http: true stdio: true session: store: file # default registry: tools: ["App\\Mcp\\WeatherTool"] prompts: ["App\\Mcp\\WeatherPrompt"] resources: ["App\\Mcp\\WeatherResource"] clients: research: client_info: name: weather-researcher servers: github: transport: http url: https://api.githubcopilot.com/mcp headers: Authorization: "Bearer %GITHUB_TOKEN%" filesystem: transport: stdio command: ["npx", "-y", "@modelcontextprotocol/server-filesystem", "/tmp"] inherit_env: true ``` -------------------------------- ### McpCommand suggestServers method Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/06-commands.md Returns the names of all STDIO-enabled servers, used for shell completion. ```php public function suggestServers(): array ``` -------------------------------- ### suggestServers() and suggestClients() signatures Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/06-commands.md Completion suggestion methods for the --server and --client options. Used by shell completion to provide suggested values. ```php public function suggestServers(): array public function suggestClients(): array ``` -------------------------------- ### suggestServers() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/06-commands.md Returns the names of all STDIO-enabled servers, used for shell completion. ```APIDOC ## suggestServers() ### Description Returns the names of all STDIO-enabled servers, used for shell completion. ### Method Method on McpCommand ### Signature ```php public function suggestServers(): array ``` ### Returns - **array** - List of server names that expose the STDIO transport. ``` -------------------------------- ### McpClientInterface Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/02-mcp-client.md The contract application code depends on for a named MCP client. Provides methods to check, retrieve, and iterate over server connections, get the client name, list server names, and disconnect all connections. ```APIDOC ## McpClientInterface ### Description Interface for a named MCP client that owns a set of named remote server connections. Extends \IteratorAggregate and \Countable. ### Methods #### getName(): string Returns the name of the client. #### has(string $server): bool Checks if a server connection with the given name exists. #### get(string $server): ServerConnectionInterface Returns the server connection for the given server name. #### getServerNames(): array Returns an array of all server names. #### disconnect(): void Disconnects all server connections. ### IteratorAggregate Iterating the client yields ServerConnectionInterface instances keyed by server name. ### Countable count() returns the number of server connections. ``` -------------------------------- ### Create middleware with MiddlewareFactory Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/07-http-transport.md Shows the default secure settings (null), custom allowed hosts, or disabling DNS rebinding protection entirely. The create() call returns a list of MiddlewareInterface instances. ```php use Symfony\AI\McpBundle\Http\MiddlewareFactory; // null: SDK secure defaults — protection limited to localhost $factory = new MiddlewareFactory(); // restrict to custom hosts (public server behind a fixed hostname) $factory = new MiddlewareFactory(['mcp.example.com']); // disable the DNS rebinding protection entirely (public server, arbitrary hosts) $factory = new MiddlewareFactory(false); $middleware = $factory->create(); // ?list ``` -------------------------------- ### listPrompts() / getPrompts() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Lists prompts from the remote server. ```APIDOC ## `listPrompts(?string $cursor = null): ListPromptsResult` / `getPrompts(): array` ### Description Paged `prompts/list` and its fully-paginated `list` variant. ### Method `listPrompts()` / `getPrompts()` ### Signature ```php public function listPrompts(?string $cursor = null): ListPromptsResult public function getPrompts(): array ``` ### Parameters - `cursor` (string|null) - Optional - Pagination cursor for `listPrompts()`. ### Returns - `ListPromptsResult` - One page of prompts (`Mcp\Schema\Result\ListPromptsResult`). - `array` - List of `Prompt` objects (`Mcp\Schema\Prompt`). ``` -------------------------------- ### configure() method signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/01-mcp-bundle.md Signature of the configure() method that imports the bundle's options schema from config/options.php. ```php public function configure(DefinitionConfigurator $definition): void ``` -------------------------------- ### Error handling for RemoteCallException and ConnectionException Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Shows how to handle remote call failures with RemoteCallException and connection failures with ConnectionException. The code catches these exceptions separately, logging the message and returning a boolean. The comments are literal examples of the exception messages for the given client and server. ```php use Symfony\AI\McpBundle\Exception\ConnectionException; use Symfony\AI\McpBundle\Exception\RemoteCallException; final class ResilientClient { public function __construct(private readonly ServerConnectionInterface $connection) { } public function tryPing(): bool { try { $this->connection->ping(); return true; } catch (RemoteCallException $e) { // "The "ping" request of MCP client "ci" to server "runner" failed: …" error_log($e->getMessage()); return false; } catch (ConnectionException $e) { // "Failed to connect MCP client "ci" to server "runner": …" return false; } } } ``` -------------------------------- ### ServerLogForwarder::__construct() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/04-transport-factory.md Constructor for ServerLogForwarder. Initializes the client name, server name, and optional PSR-3 logger. ```APIDOC ## ServerLogForwarder::__construct() ### Description Initializes a new ServerLogForwarder instance with the owning client name, remote server name, and an optional PSR-3 logger. ### Method __construct ### Parameters #### Parameters - **clientName** (string) - Required - The owning client name, recorded as the `mcp_client` context field - **serverName** (string) - Required - The remote server name, recorded as the `mcp_server` context field - **logger** (LoggerInterface) - Optional - PSR-3 logger to write to. Default: `new NullLogger()` ### Request Example ```php new ServerLogForwarder('research', 'github', $logger); ``` ### Response #### Success Response No return value. ``` -------------------------------- ### Basic iteration and tool call with McpClientInterface Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/02-mcp-client.md Iterates over all configured MCP servers via the injected McpClientInterface, calling the 'search' tool on each connection and collecting the results. The client is injected by name and used as a single configured client. ```php use Symfony\AI\McpBundle\Client\McpClientInterface; final class SearchAggregator { public function __construct( private readonly McpClientInterface $mcp, // single configured client ) { } public function search(string $query): array { $results = []; foreach ($mcp as $serverName => $connection) { $result = $connection->callTool('search', ['q' => $query]); $results[] = ['server' => $serverName, 'text' => $result.content]; } return $results; } } ``` -------------------------------- ### getTools() signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Returns every tool the server advertises, following pagination to its end. ```php public function getTools(): array ``` -------------------------------- ### McpAppRenderer::renderFragment() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/05-mcp-apps.md Documentation for the McpAppRenderer::renderFragment() method, including parameters and return type. ```APIDOC ## McpAppRenderer::renderFragment() ### Description Renders a Twig template and returns the raw HTML fragment, for use as the `html` field of a tool result. ### Method `renderFragment` ### Parameters | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | `template` | `string` | yes | — | Twig template name | | `context` | `array` | no | `[]` | Twig rendering context | ### Returns `string` — the raw HTML fragment. ``` -------------------------------- ### McpClient::getServerNames() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/02-mcp-client.md Returns an array of all configured server names. ```APIDOC ## Method ### `getServerNames()` ```php public function getServerNames(): array ``` Returns an array (list of `string` server names) of every remote server configured for this client. ``` -------------------------------- ### FrameworkSessionStore constructor Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/08-framework-session-store.md Constructor signature for FrameworkSessionStore. The handler is required and must support read, write, open, and destroy. The prefix defaults to 'mcp-' and the TTL to 3600 seconds. ```php public function __construct( private readonly \SessionHandlerInterface $handler, private readonly string $prefix = 'mcp-', private readonly int $ttl = 3600, ) ``` -------------------------------- ### McpClient::__construct() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/02-mcp-client.md Constructor for the McpClient class. Initializes the client with a name and a service locator for server connections. ```APIDOC ## Constructor ### `McpClient::__construct()` ```php public function __construct( private readonly string $name, private readonly ServiceProviderInterface $connections, ) ``` | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | `name` | `string` | yes | — | The configured client name (`mcp.clients.`) | | `connections` | `ServiceProviderInterface` | yes | — | The per-server connection locator (service `mcp.client..locator`) | ``` -------------------------------- ### complete Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Asks the server to complete one argument of a prompt or resource template. ```APIDOC ## complete(PromptReference|ResourceReference $ref, array $argument): CompletionCompleteResult ### Description Asks the server to complete one argument of a prompt or resource template. Forwards the `completion/complete` MCP method. Returns a `CompletionCompleteResult` object. ### Method `completion/complete` ### Parameters - **ref** (PromptReference | ResourceReference) - Required - The prompt or resource template whose argument completion is requested - **argument** (array{name: string, value: string}) - Required - The argument to complete ### Returns `Mcp\Schema\Result\CompletionCompleteResult` ``` -------------------------------- ### Direct use of FrameworkSessionStore with custom handler Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/08-framework-session-store.md Instantiate FrameworkSessionStore directly with a custom handler, prefix, and TTL. Shows write, exists, read, and destroy operations. The read method returns a string. ```php use Symfony\AI\McpBundle\Session\FrameworkSessionStore; $store = new FrameworkSessionStore($handler, 'mcp-', 3600); $id = Uuid::v4(); $store->write($id, '{"state": {}}'); if ($store->exists($id)) { $data = $store->read($id); // string } $store->destroy($id); ``` -------------------------------- ### listResources() / getResources() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Lists resources from the remote server. ```APIDOC ## `listResources(?string $cursor = null): ListResourcesResult` / `getResources(): array` ### Description Paged `resources/list` and its fully-paginated `list` variant. ### Method `listResources()` / `getResources()` ### Signature ```php public function listResources(?string $cursor = null): ListResourcesResult public function getResources(): array ``` ### Parameters - `cursor` (string|null) - Optional - Pagination cursor for `listResources()`. ### Returns - `ListResourcesResult` - One page of resources (`Mcp\Schema\Result\ListResourcesResult`). - `array` - List of `ResourceDefinition` objects (`Mcp\Schema\ResourceDefinition`). ``` -------------------------------- ### McpAppRenderer::render() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/05-mcp-apps.md Documentation for the McpAppRenderer::render() method, including parameters and return type. ```APIDOC ## McpAppRenderer::render() ### Description Renders a Twig template into the `TextResourceContents` body of an MCP App UI resource. Returns a `TextResourceContents` object with MIME type `text/html;profile=mcp-app`. ### Method `render` ### Parameters | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | `uri` | `string` | yes | — | Resource URI for the result | | `template` | `string` | yes | — | Twig template name | | `context` | `array` | no | `[]` | Twig rendering context | | `contentMeta` | `?Mcp\Schema\Extension\Apps\UiResourceContentMeta` | no | `null` | Content-level `_meta.ui` metadata | ### Returns `Mcp\Schema\Content\TextResourceContents` with MIME type `McpApps::MIME_TYPE` (`text/html;profile=mcp-app`), the rendered template as text, and `meta: ['ui' => $contentMeta]` when metadata was given. ``` -------------------------------- ### listTools() signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Returns one page of the remote server's tools. Operation name on error: tools/list. ```php public function listTools(?string $cursor = null): ListToolsResult ``` -------------------------------- ### getServers() method with docblock Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/09-profiler-data-collector.md Public method signature for getServers() including its PHPDoc return type definition. Returns the 'servers' data or an empty array. ```php /** * @return array, handler: string}>, * prompts: array, handler: string}>, * resources: array, * resourceTemplates: array, * }> */ public function getServers(): array ``` -------------------------------- ### listPrompts() and getPrompts() signatures Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Paged prompts/list and its fully-paginated variant. ```php public function listPrompts(?string $cursor = null): ListPromptsResult ``` ```php public function getPrompts(): array ``` -------------------------------- ### Configure FrameworkSessionStore via YAML Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/08-framework-session-store.md Configure the framework session store in config/packages/mcp.yaml. The store is constructed by the bundle and the handler is injected. The prefix and ttl options are set here. ```yaml # config/packages/mcp.yaml mcp: servers: api: session: store: framework prefix: mcp-api- ttl: 1800 ``` -------------------------------- ### McpClient constructor Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/02-mcp-client.md Defines the constructor with a client name and a service provider for server connections. The name corresponds to the configured client key `mcp.clients.`, and the connections locator is the service `mcp.client..locator`. ```php public function __construct( private readonly string $name, private readonly ServiceProviderInterface $connections, ) ``` -------------------------------- ### listResourceTemplates() / getResourceTemplates() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Lists resource templates from the remote server. ```APIDOC ## `listResourceTemplates(?string $cursor = null): ListResourceTemplatesResult` / `getResourceTemplates(): array` ### Description Paged `resources/templates/list` and its fully-paginated `list` variant. ### Method `listResourceTemplates()` / `getResourceTemplates()` ### Signature ```php public function listResourceTemplates(?string $cursor = null): ListResourceTemplatesResult public function getResourceTemplates(): array ``` ### Parameters - `cursor` (string|null) - Optional - Pagination cursor for `listResourceTemplates()`. ### Returns - `ListResourceTemplatesResult` - One page of resource templates (`Mcp\Schema\Result\ListResourceTemplatesResult`). - `array` - List of `ResourceTemplate` objects. ``` -------------------------------- ### listResources() and getResources() signatures Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Paged resources/list and its fully-paginated variant. ```php public function listResources(?string $cursor = null): ListResourcesResult ``` ```php public function getResources(): array ``` -------------------------------- ### build() method signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/01-mcp-bundle.md Signature of the build() method that adds compiler passes. ```php public function build(ContainerBuilder $container): void ``` -------------------------------- ### McpClient::get() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/02-mcp-client.md Returns the ServerConnectionInterface for a given server name. Throws an exception if the server is not configured. ```APIDOC ## Method ### `get()` ```php /** * @throws InvalidArgumentException when this client has no such server configured */ public function get(string $server): ServerConnectionInterface ``` | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | `server` | `string` | yes | — | A remote server name | Returns the `ServerConnectionInterface` for the server. The connection is *not* opened by this call. - **Throws:** `Symfony\AI\McpBundle\Exception\InvalidArgumentException` when no server of that name is configured; the message lists the configured names: `The MCP client "research" has no server named "gitlab". Configured: "github"`. ``` -------------------------------- ### McpAppResourceRenderer::__invoke() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/05-mcp-apps.md Renders the resource content for a given URI using the registered template app. Throws a LogicException if the URI is not registered. ```APIDOC ## INVOKE /mcp/app/resource/{uri} ### Description Renders the resource content for a given URI using the registered template app. Throws a LogicException if the URI is not registered. ### Method __invoke ### Endpoint McpAppResourceRenderer::__invoke(string $uri): TextResourceContents ### Parameters #### Path Parameters - **uri** (string) - Required - The requested resource URI (filled by the SDK) ### Returns - **TextResourceContents** - Rendered by McpAppRenderer::render() with an empty context. ### Throws - **LogicException** - When $uri is not among the registered apps: `No MCP App is registered for resource URI "".` ``` -------------------------------- ### ServerLogForwarder constructor Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/04-transport-factory.md Constructor for ServerLogForwarder. Requires a client name and server name; the logger defaults to a NullLogger. The client and server names are recorded as context fields in log entries. ```php public function __construct( private readonly string $clientName, private readonly string $serverName, private readonly LoggerInterface $logger = new NullLogger(), ) ``` -------------------------------- ### Public HTTP server with relaxed DNS protection and modern tuning Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/configuration.md Configures a public HTTP server with allowed hosts, protocol version, request signing, caching with per-method TTL, cache-based subscriptions, session caching, and registry wildcard. Includes environment variable for signing key and modern-era tuning. ```yaml mcp: servers: api: http: path: /mcp allowed_hosts: ["mcp.example.com", "api.example.com"] protocol_versions: - "2026-07-28" request_state: key: "%MCP_REQUEST_SIGNING_KEY%" ttl: 900 cache: ttl_ms: 5000 scope: public methods: "tools/list": { ttl_ms: 30000 } subscriptions: bus: cache lifetime: 60.0 session: store: cache ttl: 7200 registry: ["*"] ``` -------------------------------- ### MCP App with Tool (OrderDashboard) Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/05-mcp-apps.md Defines an MCP app using the AsMcpApp attribute with a template and a tool method using AsMcpAppTool. The render method returns a context array for the template, and the refund tool is app-only with its own template. ```php namespace App\Mcp; use Symfony\AI\McpBundle\Attribute\AsMcpApp; use Symfony\AI\McpBundle\Attribute\AsMcpAppTool; #[AsMcpApp( title: 'Order Dashboard', name: 'render_order_dashboard', template: '@App/mcp/dashboard.html.twig', toolTemplate: '@App/mcp/dashboard_row.html.twig', cspConnect: ['https://api.example.com'], prefersBorder: true, )] final class OrderDashboard { public function __construct(private readonly Orders $orders) { } // Primary tool (HTML-over-the-wire): returns a context array, no Twig in the handler. public function render(string $customerId): array { return ['customer' => $this->orders->find($customerId)]; } #[AsMcpAppTool(name: 'refund_order', appOnly: true, template: '@App/mcp/refund_row.html.twig')] public function refund(string $orderId): array { return ['refund' => $this->orders->refund($orderId)]; } } ``` -------------------------------- ### ElementMatcher::match() method signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/10-compiler-passes.md Returns the names of servers exposing the given element. Parameters: kind (one of tools, prompts, resources, resource_templates, apps), serviceId, and class. Returns a list of server names, max one per server, first matching pattern wins. ```php /** * Returns the names of the servers exposing the given element. * * @param class-string $class * * @return list */ public function match(string $kind, string $serviceId, string $class): array ``` -------------------------------- ### getName() and getClientName() signatures Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Returns the configured remote server name and the owning client name. ```php public function getName(): string public function getClientName(): string ``` -------------------------------- ### destroy() method signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/08-framework-session-store.md Calls `$this->handler->open('', 'mcp')` to open the storage scope, then destroys the key `$prefix.$id`. Returns the handler's destroy result as bool. ```php public function destroy(Uuid $id): bool ``` -------------------------------- ### getTools() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Returns all tools advertised by the server. ```APIDOC ## `getTools(): array` ### Description Returns every tool the server advertises, following pagination to its end. ### Method `getTools()` ### Signature ```php public function getTools(): array ``` ### Returns - `array` - List of `Tool` objects (`Mcp\Schema\Tool`). ``` -------------------------------- ### readResource() signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Calls resources/read. Accepts a resource URI and an optional progress callback. ```php public function readResource(string $uri, ?callable $onProgress = null): ReadResourceResult ``` -------------------------------- ### listResourceTemplates() and getResourceTemplates() signatures Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Paged resources/templates/list and its fully-paginated variant. ```php public function listResourceTemplates(?string $cursor = null): ListResourceTemplatesResult ``` ```php public function getResourceTemplates(): array ``` -------------------------------- ### ElementMatcher class constructor Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/10-compiler-passes.md Defines the ElementMatcher class with a WILDCARD constant and a constructor that accepts a servers array mapping server names to kinds and patterns. ```php final class ElementMatcher { public const WILDCARD = '*'; /** * @param array>> $servers server => kind => patterns */ public function __construct( private readonly array $servers, ) { } } ``` -------------------------------- ### listTools() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Lists one page of the remote server's tools. ```APIDOC ## `listTools(?string $cursor = null): ListToolsResult` ### Description Returns one page of the remote server's tools. Operation name on error: `tools/list`. ### Method `listTools()` ### Signature ```php public function listTools(?string $cursor = null): ListToolsResult ``` ### Parameters - `cursor` (string|null) - Optional - Pagination cursor. ### Returns - `ListToolsResult` - One page of the remote server's tools (`Mcp\Schema\Result\ListToolsResult`). ``` -------------------------------- ### RouteLoader class constructor Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/07-http-transport.md Defines the RouteLoader class with a constructor that accepts a list of server configurations. Each server entry includes name, path, and controller. ```php final class RouteLoader extends Loader { /** * @param list $servers the MCP servers exposed over HTTP */ public function __construct( private array $servers, ) { parent::__construct(); } } ``` -------------------------------- ### TransportFactory::stdio() method signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/04-transport-factory.md Static method to build a StdioTransport. Throws LogicException when command is empty after serving parameters. ```php /** * @param list $command the program followed by its arguments * @param array $env */ public static function stdio(array $command, ?string $cwd, array $env, bool $inheritEnv, ?int $maxBufferSize, ?LoggerInterface $logger): StdioTransport ``` -------------------------------- ### McpClient implementation signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/02-mcp-client.md Shows the constructor and method signatures of the McpClient class. The constructor takes a client name and a ServiceProviderInterface for connections keyed by server name. ```php final class McpClient implements McpClientInterface { /** * @param ServiceProviderInterface $connections keyed by server name */ public function __construct( private readonly string $name, private readonly ServiceProviderInterface $connections, ) { } public function getName(): string; public function has(string $server): bool; public function get(string $server): ServerConnectionInterface; public function getServerNames(): array; public function getIterator(): \Traversable; public function count(): int; public function disconnect(): void; } ``` -------------------------------- ### McpCommand __invoke method Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/06-commands.md Invoke method for the McpCommand. It accepts a SymfonyStyle for console I/O and an optional server name. If no name is given, it serves the single STDIO-enabled server; if multiple exist, it prints an error and returns Command::INVALID. If the named server does not expose STDIO, it prints an error and returns Command::INVALID. Otherwise, it runs the server with a StdioTransport and returns Command::SUCCESS. ```php public function __invoke( SymfonyStyle $io, #[Argument(description: 'Name of the server to run (mcp.servers.)', suggestedValues: [self::class, 'suggestServers'])] ?string $name = null, ): int ``` -------------------------------- ### McpController constructor with injected dependencies Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/07-http-transport.md Constructor for the HTTP controller. It declares the required dependencies: the app server's server, a PSR-7 HttpMessageFactoryInterface, an HttpFoundationFactoryInterface, a PSR-17 ResponseFactoryInterface and StreamFactoryInterface, the MiddlewareFactory, and an optional PSR-3 logger. ```php final class McpController { public function __construct( private readonly Server $server, private readonly HttpMessageFactoryInterface $httpMessageFactory, private readonly HttpFoundationFactoryInterface $httpFoundationFactory, private readonly ResponseFactoryInterface $responseFactory, private readonly StreamFactoryInterface $streamFactory, private readonly MiddlewareFactory $middlewareFactory, private readonly ?LoggerInterface $logger = null, ) { } } ``` -------------------------------- ### McpClient::getIterator() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/02-mcp-client.md Yields `server name => ServerConnectionInterface` pairs. Does not open any connection. ```php public function getIterator(): \Traversable ``` -------------------------------- ### McpBundle class with element kinds and cache pool constants Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/01-mcp-bundle.md The McpBundle class extends AbstractBundle and defines element kind mapping and default cache pools. The class is used as the entry point and the configure(), loadExtension(), and build() methods are framework callbacks. ```php final class McpBundle extends AbstractBundle { public const ELEMENT_KINDS = [ 'tools' => 'mcp.tool', 'prompts' => 'mcp.prompt', 'resources' => 'mcp.resource', 'resource_templates' => 'mcp.resource_template', 'apps' => 'mcp.app', ]; public const DEFAULT_SESSION_CACHE_POOL = 'cache.mcp.sessions'; public const DEFAULT_NOTIFICATION_CACHE_POOL = 'cache.mcp.notifications'; public function configure(DefinitionConfigurator $definition): void public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void public function build(ContainerBuilder $container): void } ``` -------------------------------- ### Basic request with lazy connect using ServerConnectionInterface Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Uses ServerConnectionInterface to inject a filesystem server connection. The connection is opened lazily on the first callTool invocation, with lazy connect behavior. The service is the filesystem server configured under mcp.clients..servers.filesystem. ```php use Symfony\AI\McpBundle\Client\ServerConnectionInterface; final class FilesystemClient { public function __construct( private readonly ServerConnectionInterface $fs, // mcp.clients..servers.filesystem ) { } public function ls(string $path): array { $result = $this->fs->callTool('list_directory', ['path' => $path]); return $result.content; } } ``` -------------------------------- ### AsMcpAppTool Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/05-mcp-apps.md Documentation for the AsMcpAppTool attribute, including its properties and usage. ```APIDOC ## AsMcpAppTool (method-level attribute) ### Description Declares an additional tool on an `#[AsMcpApp]` class beyond the primary tool. The annotated method is registered as a tool linked to the enclosing app. ### Properties | Property | Type | Default | Description | |----------|------|---------|-------------| | `name` | `?string` | `null` | Tool name (model-facing); defaults to the method name converted to snake_case | | `title` | `?string` | `null` | Human-readable title shown by hosts | | `description` | `?string` | `null` | Tool description (model-facing) | | `template` | `?string` | `null` | Twig fragment rendered into the result's `html` field; when set the method must return a context array | | `appOnly` | `bool` | `false` | When `true` the tool is visible to the app only (`[app]`); otherwise to model and app (`[model, app]`) | ### Usage Apply this attribute to a method within a class that has the `#[AsMcpApp]` attribute. The method must not be the primary tool method. ### Example ```php #[AsMcpAppTool(name: 'my_tool', title: 'My Tool', description: 'Does something', template: 'tool.html.twig', appOnly: false)] public function myTool(array $context): array { return ['key' => 'value']; } ``` ``` -------------------------------- ### getKey() private method signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/08-framework-session-store.md Returns the session key as `$this->prefix.$id`. ```php private function getKey(Uuid $id): string ``` -------------------------------- ### McpCommand constructor Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/06-commands.md Constructor for the McpCommand class. It receives a ServiceProviderInterface of Server objects and an optional LoggerInterface. The servers are those with the STDIO transport enabled. ```php final class McpCommand { /** * @param ServiceProviderInterface $servers the servers with the STDIO transport enabled */ public function __construct( private readonly ServiceProviderInterface $servers, private readonly ?LoggerInterface $logger = null, ) { } } ``` -------------------------------- ### McpClient::getName() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/02-mcp-client.md Returns the configured client name. ```APIDOC ## Method ### `getName()` ```php public function getName(): string ``` Returns the configured client name (`mcp.clients.`). ``` -------------------------------- ### process() method signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/10-compiler-passes.md The process() method signature for the McpPass compiler pass, taking a ContainerBuilder instance. ```php public function process(ContainerBuilder $container): void ``` -------------------------------- ### DebugCommand constructor with service providers Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/06-commands.md Constructor of the debug:mcp command. Injects the service providers for builders, registries, and clients, plus an array of unassigned service ids grouped by kind. The unassigned parameter is used to render the "Not exposed by any server" section. ```php final class DebugCommand { /** * @param ServiceProviderInterface $builders * @param ServiceProviderInterface $registries * @param ServiceProviderInterface $clients * @param array> $unassigned kind => service ids no server exposes */ public function __construct( private readonly ServiceProviderInterface $builders, private readonly ServiceProviderInterface $registries, private readonly ServiceProviderInterface $clients, private readonly array $unassigned = [], ) { } } ``` -------------------------------- ### Adding compiler passes in build() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/01-mcp-bundle.md Adds the McpAppPass and McpPass compiler passes with priorities. ```php $container->addCompilerPass(new McpAppPass(), priority: 10); $container->addCompilerPass(new McpPass()); ``` -------------------------------- ### RouteLoader supports() method signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/07-http-transport.md Declares the supports() method that returns true only when the type is 'mcp'. ```php public function supports(mixed $resource, ?string $type = null): bool ``` -------------------------------- ### reset() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Resets the connection, ignoring any exceptions. ```APIDOC ## `reset()` ### Description `ResetInterface` implementation used by the kernel-reset tag. Calls `disconnect()` and ignores any `ExceptionInterface`. ### Method `reset()` ### Signature ```php public function reset(): void ``` ``` -------------------------------- ### getServerInfo() signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Returns the remote server's advertised identity after the initialize handshake, or null if none reported. ```php public function getServerInfo(): ?Implementation ``` -------------------------------- ### McpClient::getServerNames() Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/02-mcp-client.md Returns an array of server names (strings) for every remote server configured for this client. ```php public function getServerNames(): array ``` -------------------------------- ### loadExtension() method signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/01-mcp-bundle.md Signature of the loadExtension() method that processes the normalized MCP configuration. ```php /** * @param array{servers: array>, clients: array>} $config */ public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void ``` -------------------------------- ### getProtocolVersion() signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Returns the protocol revision negotiated with this server, or null before the first request. ```php public function getProtocolVersion(): ?ProtocolVersion ``` -------------------------------- ### callTool() signature Source: https://github.com/symfony/mcp-bundle/blob/main/_autodocs/api-reference/03-server-connection.md Calls tools/call. Accepts tool name, arguments, and an optional progress callback. ```php public function callTool(string $name, array $arguments = [], ?callable $onProgress = null): CallToolResult ```