Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)40k · #7323

php-mcp-server-generator

Skill này làm gì

Bộ tạo này tạo một dự án máy chủ PHP hoàn chỉnh để giao tiếp với AI (dùng giao thức MCP). Dự án gồm các công cụ, tài nguyên và test cần thiết để máy chủ hoạt động.

Khi nào nên dùng

  • ✓Khi bạn muốn tạo một máy chủ PHP để tương tác với AI.
  • ✓Khi bạn cần một máy chủ có các chức năng cụ thể, như đọc file hoặc thực hiện phép tính.
  • ✓Khi bạn đã có dự án PHP và muốn thêm khả năng giao tiếp với AI.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/github/awesome-copilot/blob/main/skills/php-mcp-server-generator/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tạo một máy chủ PHP MCP tên là 'my-file-server', với mô tả 'Máy chủ quản lý file', dùng transport http, có các công cụ 'đọc file' và 'ghi file', kèm resources và prompts. Dùng PHP 8.2.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Bạn cung cấp tên dự án, mô tả, cách giao tiếp (stdio hoặc http), các công cụ cần có (như đọc hoặc ghi file), có muốn thêm tài nguyên không, và phiên bản PHP. Sau đó, AI thiết lập toàn bộ cấu trúc thư mục và file cần thiết.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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',

…
Câu hỏi thường gặp

MCP là gì?

MCP (Model Context Protocol) là chuẩn để các chương trình (máy chủ) giao tiếp với trí tuệ nhân tạo theo cách có tổ chức.

“Tools”, “resources” và “prompts” trong ngữ cảnh này là gì?

Tools là các hành động máy chủ có thể thực hiện (ví dụ tính toán). Resources là dữ liệu máy chủ có thể cung cấp (ví dụ cấu hình). Prompts là các mẫu câu hỏi để AI tương tác với máy chủ.

Tôi có cần biết lập trình PHP để dùng không?

Có, bộ tạo này tạo ra một dự án PHP. Dù quá trình tạo được tự động hóa, hiểu PHP sẽ giúp bạn tùy chỉnh và dùng máy chủ được tạo.

Chi tiết

Mô tả gốc của tác giả

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

repo: github/awesome-copilot

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7323
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự