Skip to content

CaptureClub-LLC/PHP_MCP_SDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Key Features

1. FastMCP High-Level API

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";
});

2. Complete Protocol Implementation

  • Full JSON-RPC 2.0 support
  • All MCP methods (tools, resources, prompts, sampling)
  • Proper error handling and protocol compliance

3. Transport Layers

  • STDIO transport (implemented)
  • Framework for SSE and HTTP transports
  • Extensible transport interface

4. Client Implementation

  • Promise-based async operations using ReactPHP
  • Full client capabilities
  • Clean API for consuming MCP servers

5. CLI Tooling

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

6. Modern PHP Practices

  • PHP 8.1+ with strict types
  • PSR-4 autoloading
  • Composer package management
  • Proper namespacing
  • Interface-based design

Key Differences from Python

  1. Decorators → Method Chaining: PHP doesn't have decorators, so we use method chaining
  2. Async/Await → Promises: Using ReactPHP promises for async operations
  3. Type System: Leveraging PHP's type declarations for safety
  4. Lifespan Management: Using constructor/destructor patterns instead of context managers

Installation & Usage

  1. Create a new project:
composer create-project mcp/php-sdk my-mcp-server
  1. 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();
  1. Install in Claude Desktop:
php server.php install

The 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!

About

A PHP SDK for the Model Context Protocol (MCP)

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages