The official PHP SDK for Model Context Protocol servers and clients. Maintained in collaboration with The PHP Foundation.
# Add to your Claude Code skills
git clone https://github.com/modelcontextprotocol/php-sdkGuides for using mcp servers skills like php-sdk.
Last scanned: 8/4/2026
{
"issues": [],
"status": "PASSED",
"scannedAt": "2026-08-04T06:27:22.326Z",
"npmAuditRan": true,
"pipAuditRan": true,
"promptInjectionRan": true
}php-sdk is an open-source mcp servers skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by modelcontextprotocol. The official PHP SDK for Model Context Protocol servers and clients. Maintained in collaboration with The PHP Foundation. It has 1,572 GitHub stars.
Yes. php-sdk passed SkillsLLM's automated security scan — a dependency vulnerability audit plus prompt-injection heuristics — with no high-severity issues. You can read the full report in the Security Report section on this page.
Clone the repository with "git clone https://github.com/modelcontextprotocol/php-sdk" and add it to your Claude Code skills directory (see the Installation section above).
php-sdk is primarily written in PHP. It is open-source under modelcontextprotocol on GitHub, so you can review or fork the full source.
Yes. SkillsLLM lists many other MCP Servers skills you can browse and compare side by side. Open the MCP Servers category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh php-sdk against similar tools.
No comments yet. Be the first to share your thoughts!
Top skills in this category by stars
The official PHP SDK for Model Context Protocol (MCP). It provides a framework-agnostic API for implementing MCP servers and clients in PHP.
This project represents a collaboration between the PHP Foundation and the Symfony project. It adopts development practices and standards from the Symfony project, including Coding Standards and the Backward Compatibility Promise.
Until the first major release, this SDK is considered experimental, please see the roadmap for planned next steps and features.
composer require mcp/sdk
The MCP PHP SDK provides both server and client implementations for the Model Context Protocol, enabling you to:
Build MCP servers to expose your PHP application's capabilities to AI agents like Claude, Codex, and others.
use Mcp\Server;
use Mcp\Server\Transport\StdioTransport;
use Mcp\Capability\Attribute\McpTool;
use Mcp\Capability\Attribute\McpResource;
// Define capabilities using PHP attributes
class CalculatorCapabilities
{
#[McpTool]
public function add(int $a, int $b): int
{
return $a + $b;
}
#[McpResource(uri: 'config://calculator/settings')]
public function getSettings(): array
{
return ['precision' => 2];
}
}
// Build and run the server
$server = Server::builder()
->setServerInfo('Calculator Server', '1.0.0')
->setDiscovery(__DIR__, ['.']) // Auto-discover attributes
->build();
$transport = new StdioTransport();
$server->run($transport);
There are multiple ways to register your MCP capabilities—choose the approach that best fits your application's architecture:
1. Attribute-Based Discovery — Define capabilities using PHP attributes for automatic discovery:
#[McpTool]
public function generateReport(): string { /* ... */ }
#[McpResource(uri: 'config://app/settings')]
public function getConfig(): array { /* ... */ }
2. Manual Registration — Register capabilities programmatically without attributes:
$server = Server::builder()
->addTool([Calculator::class, 'add'], 'add_numbers')
->addResource([Config::class, 'get'], 'config://app')
->build();
3. Hybrid Approach — Combine both methods for maximum flexibility:
$server = Server::builder()
->setDiscovery(__DIR__, ['.'])
->addTool([ExternalService::class, 'process'], 'external')
->build();
Choose the transport that matches your deployment environment:
1. STDIO Transport — For command-line integration and local processes:
$transport = new StdioTransport();
$server->run($transport);
2. HTTP Transport — For web-based servers and distributed systems:
$transport = new StreamableHttpTransport($request, $responseFactory, $streamFactory);
$response = $server->run($transport);
Configure session storage to maintain state between requests. Choose the backend that fits your infrastructure:
In-Memory (default, suitable for STDIO):
$server = Server::builder()
->setSession(ttl: 7200) // 2 hours
->build();
File-Based (suitable for single-server HTTP deployments):
$server = Server::builder()
->setSession(new FileSessionStore(__DIR__ . '/sessions'))
->build();
PSR-16 Cache (for example with Redis for scaled deployments):
$server = Server::builder()
->setSession(new Psr16SessionStore(
cache: new Psr16Cache($redisAdapter),
prefix: 'mcp-',
ttl: 3600
))
->build();
Connect to MCP servers from your PHP applications to access their tools, resources, and prompts.
use Mcp\Client;
use Mcp\Client\Transport\StdioTransport;
// Build the client
$client = Client::builder()
->setClientInfo('My Application', '1.0.0')
->setInitTimeout(30)
->setRequestTimeout(120)
->build();
// Connect to a server
$transport = new StdioTransport(
command: 'php',
args: ['/path/to/server.php'],
);
$client->connect($transport);
// Discover and use capabilities
$tools = $client->listTools();
$result = $client->callTool('add', ['a' => 5, 'b' => 3]);
$resources = $client->listResources();
$content = $client->readResource('config://calculator/settings');
$client->disconnect();
$result = $client->callTool(
name: 'process_data',
arguments: ['dataset' => 'large_file.csv'],
onProgress: function (float $progress, ?float $total, ?string $message) {
echo "Progress: {$progress}/{$total} - {$message}\n";
}
);
$samplingHandler = new SamplingRequestHandler($myCallback);
$client = Client::builder()
->setCapabilities(new ClientCapabilities(sampling: true))
->addRequestHandler($samplingHandler)
->build();
$elicitationHandler = new ElicitationRequestHandler($myCallback);
$client = Client::builder()
->setCapabilities(new ClientCapabilities(elicitation: true))
->addRequestHandler($elicitationHandler)
->build();
$loggingHandler = new LoggingNotificationHandler($myCallback);
$client = Client::builder()
->addNotificationHandler($loggingHandler)
->build();
Connect to MCP servers using the transport that matches your setup:
1. STDIO Transport — Connect to local server processes:
$transport = new StdioTransport(
command: 'php',
args: ['/path/to/server.php'],
);
$client->connect($transport);
2. HTTP Transport — Connect to remote or web-based servers:
$transport = new HttpTransport('http://localhost:8000');
$client->connect($transport);