Get the FREE Ultimate OpenClaw Setup Guide →

mcp-sdk

Model Context Protocol SDK for Client and Server applications in PHP

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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:

  1. Install the MCP SDK package via Composer: composer require php-llm/mcp-sdk

  2. (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
  3. 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.'; } }

  4. 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

Sponsor this space

Reach thousands of developers