mcp-sdk
Model Context Protocol SDK for Client and Server applications in PHP
claude mcp add --transport stdio php-llm-mcp-sdk docker run -i php-llm/mcp-sdk
How to use
The PHP MCP SDK provides tools to expose LLM-driven tool execution as an MCP server. It focuses on enabling server-side tool calls via Server-Sent Events (SSE) and STDIO transport, making it suitable for Symfony-based applications. Through the SDK you can register tools with the LLM Chain toolbox and expose them to an MCP client, allowing the client to invoke tools through a streamed SSE channel or a standard input/output workflow. Typical usage involves wiring the Server class with a transport (for example, a SymfonyConsoleTransport for STDIO or a StreamTransport for SSE) and then starting the MCP server to listen for tool invocation requests from the client.
You can expose tools using the LLM Chain Toolbox annotations, such as AsTool, to declare available tools (e.g., a CompanyName tool that returns a string). The server will analyze the configured toolset and execute the appropriate tool when a request arrives. This enables seamless integration of PHP-based tooling into the MCP workflow, letting you compose complex agent capabilities from modular tools within your Symfony application.
How to install
Prerequisites:
- PHP 7.4 or newer
- Composer
- A PHP project (e.g., Symfony) where you want to expose MCP tools
Installation steps:
-
Install the MCP SDK package via Composer: composer require php-llm/mcp-sdk
-
(Optional) If using Symfony, install the relevant bundles and set up a transport (e.g., Symfony Console Transport for STDIO or SSE transport for HTTP streaming) as shown in the examples:
- For STDIO: configure PhpLlm\McpSdk\Server with a SymfonyConsoleTransport in a console command
- For SSE: configure the StreamTransport and expose an SSE endpoint in a controller as demonstrated in the README
-
Create and register your tools using the LLM Chain Toolbox annotations, for example: use PhpLlm\LlmChain\ToolBox\Attribute\AsTool; #[AsTool('company_name', 'Provides the name of your company')] final class CompanyName { public function __invoke(): string { return 'ACME Corp.'; } }
-
Run your Symfony application or PHP script that boots the MCP server, and ensure the transport endpoints are accessible to the MCP client.
Additional notes
Notes and tips:
- This SDK currently supports Tool Calls via Server-Sent Events (SSE) and STDIO transports. Validate which transport your client uses and configure the corresponding Transport in your Server setup.
- Tools are registered via the LLM Chain Toolbox; ensure your tools are annotated with AsTool and are discoverable by the Toolbox during server initialization.
- If using Docker as the execution method, ensure the container has PHP, Composer dependencies, and your application code available inside the image.
- Environment variables are typically not required for basic operation, but you may want to configure Symfony routing, SSE endpoints, or console transport settings depending on your deployment environment.
Related MCP Servers
drift
Codebase intelligence for AI. Detects patterns & conventions + remembers decisions across sessions. MCP server for any IDE. Offline CLI.
laravel
A Laravel package for implementing secure Model Context Protocol servers using Streamable HTTP and SSE transport, providing real-time communication and a scalable tool system for enterprise environments.
php
基于 PHP 实现的 MCP (Model Control Protocol) 服务器框架,通过注解优雅地定义 MCP 服务,支持 Tool、Prompt、Resource 三种处理器,支持Stdio、Sse 两种 transport。
mcp-profiler-bundle
The Symfony MCP Profiler Bundle mimics the WebProfiler Bundle. It bridges the gap between Profiler data and your favorite MCP-enabled AI-powered IDE.
elementor
Comprehensive Elementor MCP Server plugin.
mcp
Model Context Protocol for Hyperf