Skip to content

feat: Add Closure Handler Support and Custom Input Schema for Tools #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025

Conversation

CodeWithKyrian
Copy link
Contributor

What's New

  • Closure Handler Support - All MCP element types now accept closures/callables as handlers:

    // Tools
    Mcp::tool(function(float $x, float $y): float {
        return $x * $y;
    })->name('multiply');
    
    // Resources  
    Mcp::resource('system://time', function(): string {
        return now()->toISOString();
    });
    
    // Resource Templates
    Mcp::resourceTemplate('file://{path}', function(string $path): string {
        return file_get_contents($path);
    });
    
    // Prompts
    Mcp::prompt(function(string $topic): array {
        return [['role' => 'user', 'content' => "Write about {$topic}"]];
    });
  • Custom Input Schema for Tools - Tools can now define custom JSON schemas for parameter validation:

    Mcp::tool([CalculatorService::class, 'calculate'])
        ->inputSchema([
            'type' => 'object',
            'properties' => [
                'operation' => ['type' => 'string', 'enum' => ['add', 'subtract']],
                'numbers' => ['type' => 'array', 'items' => ['type' => 'number']]
            ],
            'required' => ['operation', 'numbers']
        ]);

- Bump php-mcp/server dependency to ^3.2
- Add support for callable/closure handlers in all MCP element types (tools, resources, resource templates, prompts)
- Introduce inputSchema() method for tools to define custom JSON validation schemas

Breaking: None - all existing v3.0 code remains compatible
@CodeWithKyrian CodeWithKyrian merged commit a6a04f9 into main Jul 1, 2025
8 checks passed
@CodeWithKyrian CodeWithKyrian deleted the feature/closure-handlers-and-custom-schema branch July 1, 2025 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant