Skip to content

Contributing to PHP MCP SDK โ€‹

Thank you for your interest in contributing to the PHP MCP SDK! This guide will help you get started with contributing to the project.

๐Ÿค How to Contribute โ€‹

There are many ways to contribute to the PHP MCP SDK:

  • Report bugs and request features
  • Improve documentation and examples
  • Submit code improvements and new features
  • Help other users in discussions and issues
  • Share your projects built with the SDK

๐Ÿ“‹ Before You Start โ€‹

Code of Conduct โ€‹

This project follows a Code of Conduct to ensure a welcoming environment for all contributors. Please read and follow our community guidelines.

Getting Familiar โ€‹

Before contributing, please:

  1. Read the documentation
  2. Try the examples
  3. Understand the MCP protocol
  4. Review existing issues

๐Ÿ› Reporting Issues โ€‹

Bug Reports โ€‹

When reporting bugs, please include:

  • Clear description of the issue
  • Steps to reproduce the problem
  • Expected vs actual behavior
  • Environment details (PHP version, OS, etc.)
  • Code samples that demonstrate the issue

Feature Requests โ€‹

For new features, please describe:

  • Use case and problem it solves
  • Proposed solution or implementation approach
  • Alternative approaches considered
  • Impact on existing functionality

๐Ÿ› ๏ธ Development Setup โ€‹

Prerequisites โ€‹

  • PHP 8.1 or higher
  • Composer
  • Git

Setting Up Your Environment โ€‹

  1. Fork the repository on GitHub

  2. Clone your fork locally:

    bash
    git clone https://github.com/your-username/php-mcp-sdk.git
    cd php-mcp-sdk
  3. Install dependencies:

    bash
    composer install
  4. Run tests to ensure everything works:

    bash
    composer test

Development Workflow โ€‹

  1. Create a feature branch:

    bash
    git checkout -b feature/your-feature-name
  2. Make your changes following our coding standards

  3. Add tests for your changes

  4. Run the test suite:

    bash
    composer test
    composer test:coverage
  5. Check code quality:

    bash
    composer lint
    composer analyze
  6. Commit your changes:

    bash
    git add .
    git commit -m "Add: your descriptive commit message"
  7. Push to your fork:

    bash
    git push origin feature/your-feature-name
  8. Create a Pull Request on GitHub

๐Ÿ“ Coding Standards โ€‹

PHP Standards โ€‹

We follow these coding standards:

  • PSR-12 for code style
  • PSR-4 for autoloading
  • PHPDoc for documentation
  • Type declarations for all parameters and return types

Code Style โ€‹

php
<?php

declare(strict_types=1);

namespace MCP\Example;

use MCP\Server\McpServer;
use MCP\Types\Implementation;

/**
 * Example class demonstrating coding standards.
 */
class ExampleClass
{
    private string $property;

    public function __construct(string $property)
    {
        $this->property = $property;
    }

    /**
     * Example method with proper documentation.
     */
    public function exampleMethod(array $parameters): array
    {
        return [
            'property' => $this->property,
            'parameters' => $parameters,
        ];
    }
}

Naming Conventions โ€‹

  • Classes: PascalCase (McpServer, TransportInterface)
  • Methods: camelCase (executeTask, validateInput)
  • Properties: camelCase ($serverName, $connectionPool)
  • Constants: SCREAMING_SNAKE_CASE (MAX_CONNECTIONS, DEFAULT_TIMEOUT)

๐Ÿงช Testing Guidelines โ€‹

Test Structure โ€‹

php
<?php

declare(strict_types=1);

namespace MCP\Tests\Server;

use MCP\Server\McpServer;
use MCP\Types\Implementation;
use PHPUnit\Framework\TestCase;

class McpServerTest extends TestCase
{
    private McpServer $server;

    protected function setUp(): void
    {
        $this->server = new McpServer(
            new Implementation('test-server', '1.0.0')
        );
    }

    public function testServerCreation(): void
    {
        $this->assertInstanceOf(McpServer::class, $this->server);
    }

    public function testToolRegistration(): void
    {
        $this->server->tool(
            'test-tool',
            'Test tool description',
            ['type' => 'object'],
            fn($args) => ['result' => 'success']
        );

        $tools = $this->server->getTools();
        $this->assertCount(1, $tools);
        $this->assertEquals('test-tool', $tools[0]['name']);
    }
}

Test Categories โ€‹

  • Unit Tests: Test individual classes and methods
  • Integration Tests: Test component interactions
  • Feature Tests: Test complete features end-to-end
  • Performance Tests: Test performance characteristics

Running Tests โ€‹

bash
# Run all tests
composer test

# Run specific test suite
composer test -- --testsuite=Unit

# Run with coverage
composer test:coverage

# Run performance tests
composer test:performance

๐Ÿ“š Documentation โ€‹

Documentation Standards โ€‹

  • Clear and concise explanations
  • Code examples for all features
  • Real-world use cases when possible
  • API documentation for all public methods

Documentation Structure โ€‹

markdown
# Feature Name

Brief description of the feature.

## Overview

Detailed explanation of what the feature does and why it's useful.

## Basic Usage

```php
// Simple example
$example = new ExampleClass();
$result = $example->doSomething();
```

Advanced Usage โ€‹

php
// More complex example with configuration
$example = new ExampleClass([
    'option1' => 'value1',
    'option2' => 'value2',
]);

API Reference โ€‹

Methods โ€‹

doSomething(array $parameters): array โ€‹

Description of what the method does.

Parameters:

  • $parameters (array): Description of parameters

Returns:

  • array: Description of return value

Example:

php
$result = $example->doSomething(['key' => 'value']);

## ๐Ÿ”„ Pull Request Process

### Before Submitting

- [ ] Tests pass locally
- [ ] Code follows style guidelines
- [ ] Documentation is updated
- [ ] CHANGELOG.md is updated
- [ ] No merge conflicts with main branch

### Pull Request Template

When creating a pull request, please include:

```markdown
## Description

Brief description of changes and motivation.

## Type of Change

- [ ] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that causes existing functionality to change)
- [ ] Documentation update

## Testing

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing completed

## Checklist

- [ ] Code follows project style guidelines
- [ ] Self-review completed
- [ ] Documentation updated
- [ ] CHANGELOG.md updated

Review Process โ€‹

  1. Automated checks must pass (tests, linting, etc.)
  2. Code review by maintainers
  3. Discussion and feedback incorporation
  4. Final approval and merge

๐Ÿ—๏ธ Architecture Guidelines โ€‹

Design Principles โ€‹

  • Single Responsibility: Each class should have one reason to change
  • Open/Closed: Open for extension, closed for modification
  • Dependency Injection: Use constructor injection for dependencies
  • Interface Segregation: Prefer small, focused interfaces
  • Type Safety: Use strict types throughout

Project Structure โ€‹

src/
โ”œโ”€โ”€ Client/          # MCP client implementations
โ”œโ”€โ”€ Server/          # MCP server implementations
โ”œโ”€โ”€ Shared/          # Shared components
โ”œโ”€โ”€ Types/           # Type definitions and schemas
โ”œโ”€โ”€ Transport/       # Transport layer implementations
โ”œโ”€โ”€ Validation/      # Input validation and schemas
โ””โ”€โ”€ Utils/           # Utility classes

tests/
โ”œโ”€โ”€ Unit/            # Unit tests
โ”œโ”€โ”€ Integration/     # Integration tests
โ”œโ”€โ”€ Feature/         # Feature tests
โ””โ”€โ”€ Performance/     # Performance tests

examples/
โ”œโ”€โ”€ server/          # Server examples
โ”œโ”€โ”€ client/          # Client examples
โ””โ”€โ”€ real-world/      # Real-world applications

๐ŸŽฏ Contribution Areas โ€‹

High Priority โ€‹

  • Performance optimizations
  • Additional transport implementations
  • Enhanced error handling
  • More comprehensive examples
  • Documentation improvements

Medium Priority โ€‹

  • Framework integrations (Symfony, CakePHP, etc.)
  • Additional validation schemas
  • Monitoring and observability tools
  • Development utilities

Ideas Welcome โ€‹

  • Creative examples and use cases
  • Performance benchmarks
  • Security enhancements
  • Developer experience improvements

๐Ÿ† Recognition โ€‹

Contributors are recognized in:

  • README.md contributors section
  • CHANGELOG.md for significant contributions
  • GitHub releases for major features
  • Documentation for examples and guides

๐Ÿ“ž Getting Help โ€‹

Community Support โ€‹

  • GitHub Discussions: General questions and ideas
  • GitHub Issues: Bug reports and feature requests
  • Discord/Slack: Real-time community chat (if available)

Direct Contact โ€‹

For sensitive issues or private discussions:

Licensing โ€‹

By contributing to this project, you agree that your contributions will be licensed under the same license as the project (MIT License).

Please ensure you have the right to contribute any code or content you submit.

๐Ÿš€ Release Process โ€‹

Versioning โ€‹

We follow Semantic Versioning:

  • MAJOR: Breaking changes
  • MINOR: New features (backward compatible)
  • PATCH: Bug fixes (backward compatible)

Release Cycle โ€‹

  • Regular releases every 2-4 weeks
  • Hotfix releases for critical bugs
  • Major releases for significant changes

Thank you for contributing to PHP MCP SDK! Your contributions help make AI development more accessible and powerful for the PHP community. ๐ŸŽ‰

Released under the MIT License.