Labsco
github logo

php-mcp-server-generator

✓ Official36,200

by github · part of github/awesome-copilot

Scaffold production-ready PHP MCP server projects with tools, resources, prompts, and tests. Generates complete project structure with composer.json, server.php, and PSR-4 autoloading configured for the official PHP SDK Supports three transport types (stdio, HTTP, or both) and includes attribute-based tool, resource, and prompt definitions with schema validation Provides templated examples for simple tools, validated parameters, enum-based operations, static resources, and dynamic resource...

🔥🔥🔥🔥✓ VerifiedFreeQuick setup
🧩 One of 7 skills in the github/awesome-copilot package — works on its own, and pairs well with its siblings.

Scaffold production-ready PHP MCP server projects with tools, resources, prompts, and tests. Generates complete project structure with composer.json, server.php, and PSR-4 autoloading configured for the official PHP SDK Supports three transport types (stdio, HTTP, or both) and includes attribute-based tool, resource, and prompt definitions with schema validation Provides templated examples for simple tools, validated parameters, enum-based operations, static resources, and dynamic resource...

Inspect the full instructions your agent will receiveExpand

This is the exact playbook injected into your agent when the skill activates — shown here so you can audit it before installing. You don't need to read it to use the skill.

by github

Scaffold production-ready PHP MCP server projects with tools, resources, prompts, and tests. Generates complete project structure with composer.json, server.php, and PSR-4 autoloading configured for the official PHP SDK Supports three transport types (stdio, HTTP, or both) and includes attribute-based tool, resource, and prompt definitions with schema validation Provides templated examples for simple tools, validated parameters, enum-based operations, static resources, and dynamic resource... npx skills add https://github.com/github/awesome-copilot --skill php-mcp-server-generator Download ZIPGitHub36.2k

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 Structure

Copy & paste — that's it
{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

Copy & paste — that's it
{
 "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

Copy & paste — that's it
/vendor
/cache
composer.lock
.phpunit.cache
phpstan.neon

README.md

Copy & paste — that's it
# {Project Name}

{Server description}

## Testing

vendor/bin/phpunit

Copy & paste — that's it

## Tools

- **{tool_name}**: {Tool description}

## Development

Test with MCP Inspector:

npx @modelcontextprotocol/inspector php server.php

Copy & paste — that's it

server.php

Copy & paste — that's it
#!/usr/bin/env php
 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

Copy & paste — that's it
 $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

Copy & paste — that's it
 '1.0.0',
 'environment' => 'production',
 'features' => [
 'logging' => true,
 'caching' => true
 ]
 ];
 }
}

src/Resources/DataProvider.php

Copy & paste — that's it
 $category,
 'id' => $id,
 'data' => "Sample data for {$category}/{$id}"
 ];
 }
}

src/Prompts/PromptGenerator.php

Copy & paste — that's it
 'assistant',
 'content' => 'You are an expert code reviewer specializing in best practices and optimization.'
 ],
 [
 'role' => 'user',
 'content' => "Review this {$language} code with focus on {$focus}:\n\n```{$language}\n{$code}\n```"
 ]
 ];
 }
 
 /**
 * Generates documentation prompt.
 */
 #[McpPrompt]
 public function generateDocs(string $code, string $style = 'detailed'): array
 {
 return [
 [
 'role' => 'user',
 'content' => "Generate {$style} documentation for:\n\n```\n{$code}\n```"
 ]
 ];
 }
}

tests/ToolsTest.php

Copy & paste — that's it
 tool = new ExampleTool();
 }
 
 public function testGreet(): void
 {
 $result = $this->tool->greet('World');
 $this->assertSame('Hello, World!', $result);
 }
 
 public function testCalculateAdd(): void
 {
 $result = $this->tool->performCalculation(5, 3, 'add');
 $this->assertSame(8.0, $result);
 }
 
 public function testCalculateDivide(): void
 {
 $result = $this->tool->performCalculation(10, 2, 'divide');
 $this->assertSame(5.0, $result);
 }
 
 public function testCalculateDivideByZero(): void
 {
 $this->expectException(\InvalidArgumentException::class);
 $this->expectExceptionMessage('Division by zero');
 
 $this->tool->performCalculation(10, 0, 'divide');
 }
 
 public function testCalculateInvalidOperation(): void
 {
 $this->expectException(\InvalidArgumentException::class);
 $this->expectExceptionMessage('Invalid operation');
 
 $this->tool->performCalculation(5, 3, 'modulo');
 }
}

phpunit.xml.dist

Copy & paste — that's it
 
 
 
 
 tests 
 
 
 
 
 src 
 
 
 

Implementation Guidelines

  • Use PHP Attributes: Leverage #[McpTool], #[McpResource], #[McpPrompt] for clean code

  • Type Declarations: Use strict types (declare(strict_types=1);) in all files

  • PSR-12 Coding Standard: Follow PHP-FIG standards

  • Schema Validation: Use #[Schema] attributes for parameter validation

  • Error Handling: Throw specific exceptions with clear messages

  • Testing: Write PHPUnit tests for all tools

  • Documentation: Use PHPDoc blocks for all methods

  • Caching: Always use PSR-16 cache for discovery in production

Tool Patterns

Simple Tool

Copy & paste — that's it
#[McpTool]
public function simpleAction(string $input): string
{
 return "Processed: {$input}";
}

Tool with Validation

Copy & paste — that's it
#[McpTool]
public function validateEmail(
 #[Schema(format: 'email')]
 string $email
): bool {
 return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}

Tool with Enum

Copy & paste — that's it
enum Status: string {
 case ACTIVE = 'active';
 case INACTIVE = 'inactive';
}

#[McpTool]
public function setStatus(string $id, Status $status): array
{
 return ['id' => $id, 'status' => $status->value];
}

Resource Patterns

Static Resource

Copy & paste — that's it
#[McpResource(uri: 'config://settings', mimeType: 'application/json')]
public function getSettings(): array
{
 return ['key' => 'value'];
}

Dynamic Resource

Copy & paste — that's it
#[McpResourceTemplate(uriTemplate: 'user://{id}')]
public function getUser(string $id): array
{
 return $this->users[$id] ?? throw new \RuntimeException('User not found');
}