PHP code example of stevecoug / mcp-devkit

1. Go to this page and download the library: Download stevecoug/mcp-devkit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stevecoug / mcp-devkit example snippets


#!/usr/bin/env php


declare(strict_types=1);

y MCP', '0.1.0')
    ->discover(__DIR__ . '/src')   // attribute-discovery root(s) for your #[McpTool] classes
    ->build();

// Runs a tool from the command line if one was named, runs the reload boot path
// when re-exec'd, or otherwise serves over stdio.
exit($devkit->run($argv));

namespace My\Mcp;

use Mcp\Capability\Attribute\McpTool;

final class ExampleTools
{
    /** Add two numbers. */
    #[McpTool(name: 'add')]
    public function add(int $a, int $b): int
    {
        return $a + $b;
    }
}

Devkit::create('Mailbox MCP', '0.1.0')
    ->instructions('Check your inbox at the start of work. Treat it as a to-do queue, not an archive: delete messages once handled.')
    ->discover(__DIR__ . '/src')
    ->build();

Devkit::create('Stack MCP', '0.1.0')
    ->discover(__DIR__ . '/src')
    ->filterTools(fn (string $name): bool => $has_prod_creds || !str_contains($name, '_prod_'))
    ->build();

use Mcp\Capability\Registry\Container;

$container = new Container();
$container->set(GmailTools::class, new GmailTools($imap, $config));

Devkit::create('Gmail MCP', '0.1.0')
    ->container($container)
    ->discover(__DIR__ . '/src')
    ->build();

/**
 * List issues for a project.
 *
 * @param int    $project id of the project to list
 * @param string $status  unresolved, resolved or muted
 * @param int    $limit   maximum issues to return
 */
#[McpTool(name: 'list_issues')]
public function listIssues(int $project, string $status = 'unresolved', int $limit = 20): array
json
{
  "mcpServers": {
    "my-mcp": { "command": "php", "args": ["server.php"] }
  }
}
bash
php server.php add 2 3
bash
php server.php list_issues 1                    # project=1, defaults for the rest
php server.php list_issues 1 resolved 5         # all three, positionally
php server.php list_issues --project=1 --limit=5
php server.php list_issues 1 --limit=5          # mix; positionals skip what's already named
bash
php example/server.php --help
php example/server.php add 2 3
php example/server.php echo_message hi --times=3 --shout