The PHP version mirrors Python's FastMCP with a similar decorator-style API using method chaining:
$mcp = new FastMcp('My Server');
// Register tools
$mcp->tool('add')(function (int $a, int $b): int {
return $a + $b;
});
// Register resources
$mcp->resource('config://app')(function (): string {
return "App configuration";
});
// Register prompts
$mcp->prompt('greeting')(function (string $name): string {
return "Please greet $name warmly";
});- Full JSON-RPC 2.0 support
- All MCP methods (tools, resources, prompts, sampling)
- Proper error handling and protocol compliance
- STDIO transport (implemented)
- Framework for SSE and HTTP transports
- Extensible transport interface
- Promise-based async operations using ReactPHP
- Full client capabilities
- Clean API for consuming MCP servers
Similar to Python's mcp command:
# Install a server
mcp install server.php --name "My Server"
# Run in development mode
mcp dev server.php
# Run normally
mcp run server.php- PHP 8.1+ with strict types
- PSR-4 autoloading
- Composer package management
- Proper namespacing
- Interface-based design
- Decorators → Method Chaining: PHP doesn't have decorators, so we use method chaining
- Async/Await → Promises: Using ReactPHP promises for async operations
- Type System: Leveraging PHP's type declarations for safety
- Lifespan Management: Using constructor/destructor patterns instead of context managers
- Create a new project:
composer create-project mcp/php-sdk my-mcp-server- Create a server:
<?php
use Mcp\Server\FastMcp;
$mcp = new FastMcp('My Server');
$mcp->tool('hello')(function (string $name): string {
return "Hello, $name!";
});
$mcp->run();- Install in Claude Desktop:
php server.php installThe PHP SDK provides the same power and flexibility as the Python version while following PHP conventions and best practices. It's ready for building production MCP servers and integrating with LLM applications!