Langsung ke konten
Skillpedia
API & server (backend)40k Β· #7323

php-mcp-server-generator

Fungsinya

Generator ini membuat project server PHP yang lengkap untuk komunikasi AI (menggunakan protokol MCP). Project ini mencakup tools, resources, dan tes yang dibutuhkan agar server dapat berfungsi.

Kapan dipakai

  • βœ“Ketika Anda ingin membuat server PHP untuk berinteraksi dengan AI.
  • βœ“Ketika Anda membutuhkan server dengan fungsi tertentu, seperti membaca file atau melakukan perhitungan.
  • βœ“Ketika Anda sudah punya project PHP dan ingin menambahkan kemampuan berkomunikasi dengan AI.

Link skill

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

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/github/awesome-copilot/blob/main/skills/php-mcp-server-generator/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œBuatkan server MCP PHP bernama 'my-file-server' dengan deskripsi 'Server untuk mengelola file', menggunakan transport http, dengan tools 'file read' dan 'file write', serta sertakan resources dan prompts. Gunakan PHP 8.2.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Anda memberikan nama project, deskripsi, cara komunikasinya (stdio atau http), tools yang dibutuhkan (misalnya membaca atau menulis file), resources tambahan jika diinginkan, dan versi PHP yang akan digunakan. AI kemudian menyiapkan seluruh struktur folder dan file yang diperlukan.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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',

…
Pertanyaan umum

Apa itu protokol MCP?

MCP (Model Context Protocol) adalah standar agar program komputer (server) dapat berkomunikasi dengan kecerdasan buatan secara terstruktur.

Apa itu 'tools', 'resources', dan 'prompts' dalam konteks ini?

Tools adalah aksi yang dapat dilakukan server, misalnya menghitung sesuatu. Resources adalah data yang dapat disediakan server, misalnya konfigurasi. Prompts adalah template pertanyaan yang dapat digunakan AI untuk berinteraksi dengan server.

Apakah saya harus memahami pemrograman PHP untuk menggunakan ini?

Ya, generator ini membuat project PHP. Meski pembuatannya otomatis, memahami PHP akan membantu Anda menyesuaikan dan menggunakan server yang dihasilkan.

Detail

Deskripsi asli dari pembuat

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

repo: github/awesome-copilot

Popularitas

Bintang GitHub
40k
Peringkat
#7323
Lisensi
MIT
Diperbarui
15/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa