Php-Mcp-Server
Php-Mcp-Server是一款code方向的AI技能,核心价值是Best practices for building Model Context Protocol servers in PHP using the official PHP SDK with attribute-based discovery and multiple transport options,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。
Best practices for building Model Context Protocol servers in PHP using the official PHP SDK with attribute-based discovery and multiple transport options
mkdir -p ./skills/php-mcp-server && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/php-mcp-server/SKILL.md -o ./skills/php-mcp-server/SKILL.md Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).
Skill Content
# PHP MCP Server Development Best Practices
This guide provides best practices for building Model Context Protocol (MCP) servers using the official PHP SDK maintained in collaboration with The PHP Foundation.
Installation and Setup
Install via Composer
composer require mcp/sdkProject Structure
Organize your PHP MCP server project:
my-mcp-server/
├── composer.json
├── src/
│ ├── Tools/
│ │ ├── Calculator.php
│ │ └── FileManager.php
│ ├── Resources/
│ │ ├── ConfigProvider.php
│ │ └── DataProvider.php
│ ├── Prompts/
│ │ └── PromptGenerator.php
│ └── Server.php
├── server.php # Server entry point
└── tests/
└── ToolsTest.phpComposer Configuration
{
"name": "your-org/mcp-server",
"description": "MCP Server for...",
"type": "project",
"require": {
"php": "^8.2",
"mcp/sdk": "^0.1"
},
"require-dev": {
"phpunit/phpunit": "^10.0"
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}Server Implementation
Basic Server with Attribute Discovery
Create your server entry point:
#!/usr/bin/env php
<?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Mcp\Server;
use Mcp\Server\Transport\StdioTransport;
$server = Server::builder()
->setServerInfo('My MCP Server', '1.0.0')
->setDiscovery(__DIR__, ['.'])
->build();
$transport = new StdioTransport();
$server->run($transport);Server with Caching
Use PSR-16 cache for better performance:
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;
$cache = new Psr16Cache(new FilesystemAdapter('mcp-discovery'));
$server = Server::builder()
->setServerInfo('My MCP Server', '1.0.0')
->setDiscovery(
basePath: __DIR__,
scanDirs: ['.', 'src'],
excludeDirs: ['vendor', 'tests'],
cache: $cache
)
->build();Manual Registration
Register capabilities programmatically:
use App\Tools\Calculator;
use App\Resources\Config;
$server = Server::builder()
->setServerInfo('My MCP Server', '1.0.0')
->addTool([Calculator::class, 'add'], 'add')
->addTool([Calculator::class, 'multiply'], 'multiply')
->addResource([Config::class, 'getSettings'], 'config://app/settings')
->build();Tool Development
Simple Tool with Attribute
<?php
namespace App\Tools;
use Mcp\Capability\Attribute\McpTool;
class Calculator
{
/**
* Adds two numbers together.
*
* @param int $a The first number
* @param int $b The second number
* @return int The sum of the two numbers
*/
#[McpTool]
public function add(int $a, int $b): int
{
return $a + $b;
}
}Tool with Custom Name
use Mcp\Capability\Attribute\McpTool;
class FileManager
{
/**
* Reads file content from the filesystem.
*/
#[McpTool(name: 'read_file')]
public function readFileContent(string $path): string
{
if (!file_exists($path)) {
throw new \InvalidArgumentException("File not found: {$path}");
}
return file_get_contents($path);
}
}Tool with Validation and Schema
use Mcp\Capability\Attribute\{McpTool, Schema};
class UserManager
{
#[McpTool(name: 'create_user')]
public function createUser(
#[Schema(format: 'email')]
string $email,
#[Schema(minimum: 18, maximum: 120)]
int $age,
#[Schema(
pattern: '^[A-Z][a-z]+$',
description: 'Capitalized first name'
)]
string $firstName
): array
{
return [
'id' => uniqid(),
'email' => $email,
'age' => $age,
'firstName' => $firstName
];
}
}Tool with Complex Return Types
use Mcp\Schema\Content\{Tex🎯 Best For
- UI designers
- Product designers
- Claude users
- GitHub Copilot users
- Software engineers
💡 Use Cases
- Generating component mockups
- Creating design system tokens
- Code quality improvement
- Best practice enforcement
📖 How to Use This Skill
- 1
Install the Skill
Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.
- 2
Load into Your AI Assistant
Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.
- 3
Apply Php-Mcp-Server to Your Work
Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.
- 4
Review and Refine
Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.
❓ Frequently Asked Questions
Does this work with Figma?
Some design skills integrate with Figma plugins. Check the Works With section for supported tools.
Is Php-Mcp-Server compatible with Cursor and VS Code?
Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.
Do I need specific dependencies for Php-Mcp-Server?
Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.
How do I install Php-Mcp-Server?
Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/php-mcp-server/SKILL.md, ready to use.
Can I customize this skill for my team?
Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.
⚠️ Common Mistakes to Avoid
Skipping usability testing
AI-generated designs should be validated with real users before development.
Skipping validation
Always test AI-generated code changes, even for simple refactors.
Missing dependency updates
Check if the skill requires updated dependencies or new packages.