Skip to content
Skillpedia
APIs & servers (backend)40k Β· #7323

php-mcp-server-generator

What it does

This generator creates a complete PHP server project for AI communication (using the MCP protocol). It includes the necessary tools, resources, and tests for the server to function.

When to use it

  • βœ“When you want to create a PHP server to interact with AIs.
  • βœ“When you need a server with specific functionalities, like reading files or performing calculations.
  • βœ“If you already have a PHP project and want to add the capability to communicate with AIs.

Skill link

https://github.com/github/awesome-copilot/blob/main/skills/php-mcp-server-generator/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/php-mcp-server-generator/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œGenerate a PHP MCP server named 'my-file-server' with the description 'Server for managing files', using http transport, with tools for 'file read' and 'file write', and include resources and prompts. Use PHP 8.2.”

5 new skills a week. 1 minute to read.

How it works

You provide the project name, description, how it will communicate (stdio or http), which tools it should have (like reading or writing files), if you want extra resources, and which PHP version to use. The AI then sets up the entire folder and file structure needed.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

PHP MCP Server Generator

You are a PHP MCP server generator. Create a complete, production-ready PHP MCP server project using the official PHP SDK.

Project Requirements

Ask the user for:

  1. Project name (e.g., "my-mcp-server")
  2. Server description (e.g., "A file management MCP server")
  3. Transport type (stdio, http, or both)
  4. Tools to include (e.g., "file read", "file write", "list directory")
  5. Whether to include resources and prompts
  6. PHP version (8.2+ required)

Project Structure

{project-name}/
β”œβ”€β”€ composer.json
β”œβ”€β”€ .gitignore
β”œβ”€β”€ README.md
β”œβ”€β”€ server.php
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ Tools/
β”‚   β”‚   └── {ToolClass}.php
β”‚   β”œβ”€β”€ Resources/
β”‚   β”‚   └── {ResourceClass}.php
β”‚   β”œβ”€β”€ Prompts/
β”‚   β”‚   └── {PromptClass}.php
β”‚   └── Providers/
β”‚       └── {CompletionProvider}.php
└── tests/
    └── ToolsTest.php

File Templates

composer.json

{
    "name": "your-org/{project-name}",
    "description": "{Server description}",
    "type": "project",
    "require": {
        "php": "^8.2",
        "mcp/sdk": "^0.1"
    },
    "require-dev": {
        "phpunit/phpunit": "^10.0",
        "symfony/cache": "^6.4"
    },
    "autoload": {
        "psr-4": {
            "App\\\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\\\": "tests/"
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    }
}

.gitignore

/vendor
/cache
composer.lock
.phpunit.cache
phpstan.neon

README.md

# {Project Name}

{Server description}

## Requirements

- PHP 8.2 or higher
- Composer

## Installation

```bash
composer install

Usage

Start Server (Stdio)

php server.php

Configure in Claude Desktop

{
  "mcpServers": {
    "{project-name}": {
      "command": "php",
      "args": ["/absolute/path/to/server.php"]
    }
  }
}

Testing

vendor/bin/phpunit

Tools

  • {tool_name}: {Tool description}

Development

Test with MCP Inspector:

npx @modelcontextprotocol/inspector php server.php

### server.php

```php
#!/usr/bin/env php
<?php

declare(strict_types=1);

require_once __DIR__ . '/vendor/autoload.php';

use Mcp\Server;
use Mcp\Server\Transport\StdioTransport;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;

// Setup cache for discovery
$cache = new Psr16Cache(new FilesystemAdapter('mcp-discovery', 3600, __DIR__ . '/cache'));

// Build server with discovery
$server = Server::builder()
    ->setServerInfo('{Project Name}', '1.0.0')
    ->setDiscovery(
        basePath: __DIR__,
        scanDirs: ['src'],
        excludeDirs: ['vendor', 'tests', 'cache'],
        cache: $cache
    )
    ->build();

// Run with stdio transport
$transport = new StdioTransport();

$server->run($transport);

src/Tools/ExampleTool.php

<?php

declare(strict_types=1);

namespace App\Tools;

use Mcp\Capability\Attribute\McpTool;
use Mcp\Capability\Attribute\Schema;

class ExampleTool
{
    /**
     * Performs a greeting with the provided name.
     * 
     * @param string $name The name to greet
     * @return string A greeting message
     */
    #[McpTool]
    public function greet(string $name): string
    {
        return "Hello, {$name}!";
    }
    
    /**
     * Performs arithmetic calculations.
     */
    #[McpTool(name: 'calculate')]
    public function performCalculation(
        float $a,
        float $b,
        #[Schema(pattern: '^(add|subtract|multiply|divide)$')]
        string $operation
    ): float {
        return match($operation) {
            'add' => $a + $b,
            'subtract' => $a - $b,
            'multiply' => $a * $b,
            'divide' => $b != 0 ? $a / $b : 
                throw new \InvalidArgumentException('Division by zero'),
            default => throw new \InvalidArgumentException('Invalid operation')
        };
    }
}

src/Resources/ConfigResource.php

<?php

declare(strict_types=1);

namespace App\Resources;

use Mcp\Capability\Attribute\McpResource;

class ConfigResource
{
    /**
     * Provides application configuration.
     */
    #[McpResource(
        uri: 'config://app/settings',
        name: 'app_config',
        mimeType: 'application/json'
    )]
    public function getConfiguration(): array
    {
        return [
            'version' => '1.0.0',

…
FAQ

What is the MCP protocol?

MCP (Model Context Protocol) is a standard for computer programs (servers) to communicate with artificial intelligence in an organized way.

What are 'tools', 'resources', and 'prompts' in this context?

Tools are actions the server can perform (e.g., calculate something). Resources are data the server can provide (e.g., configurations). Prompts are templates for questions the AI can use to interact with the server.

Do I need to know PHP programming to use this?

Yes, this generator creates a PHP project. Although it automates the creation, understanding PHP helps in customizing and using the generated server.

Details

Original description by the author

Generate a complete PHP Model Context Protocol server project with tools, resources, prompts, and tests using the official PHP SDK

repo: github/awesome-copilot

Popularity

GitHub stars
40k
Ranking position
#7323
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills