agentleFS
dalehurleydalehurley/php-mcp-sdk/.cursor/rules/php-mcp-sdk-main.mdc

php-mcp-sdk / rules

Cursor rule27 starsChanged 15 months agoMITView on GitHub

This is the PHP implementation of the Model Context Protocol (MCP) SDK, following the patterns established by the TypeScript SDK.

The file

We split this php-mcp-sdk-main.mdc into the rules it gives an agent

6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Type Safety: Use PHP 8+ type declarations, union types, and attributes extensively

    line 12
  2. Distinctive:

    PSR Standards: Follow PSR-4 for autoloading, PSR-12 for coding standards, PSR-7 for HTTP messages

    line 14
  3. Very specific:

    Use respect/validation or symfony/validator for schema validation

    line 63
  4. Distinctive:

    Create dedicated validator classes for each schema type

    line 64
  5. Very specific:

    Use custom exceptions extending McpError

    line 128
  6. Distinctive:

    Use PHPUnit for testing framework

    line 137

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
php-mcp-sdk-main.mdc
---
alwaysApply: true
---

# PHP MCP SDK Architecture Guide

This is the PHP implementation of the Model Context Protocol (MCP) SDK, following the patterns established by the TypeScript SDK.

## Core Architecture Principles

1. **Follow TypeScript SDK Patterns**: The PHP SDK should mirror the TypeScript SDK's architecture while using PHP idioms
2. **Type Safety**: Use PHP 8+ type declarations, union types, and attributes extensively
3. **Async Support**: Utilize ReactPHP or similar for async operations where the TypeScript SDK uses Promises
4. **PSR Standards**: Follow PSR-4 for autoloading, PSR-12 for coding standards, PSR-7 for HTTP messages

## Project Structure

```
php-mcp-sdk/
├── src/
│   ├── Server/                  # Server implementations
│   │   ├── McpServer.php       # High-level server API
│   │   ├── Server.php          # Low-level server implementation
│   │   ├── Auth/               # Authentication providers
│   │   │   ├── Provider.php
│   │   │   └── Providers/
│   │   └── Transport/          # Server transport implementations
│   │       ├── StdioServerTransport.php
│   │       ├── StreamableHttpServerTransport.php
│   │       └── SseServerTransport.php (deprecated)
│   ├── Client/                  # Client implementations
│   │   ├── Client.php          # MCP client
│   │   └── Transport/          # Client transport implementations
│   │       ├── StdioClientTransport.php
│   │       ├── StreamableHttpClientTransport.php
│   │       └── SseClientTransport.php (deprecated)
│   ├── Shared/                  # Shared components
│   │   ├── Protocol.php        # Protocol base class
│   │   ├── Transport.php       # Transport interface
│   │   ├── UriTemplate.php     # URI template handling
│   │   └── AuthUtils.php       # Authentication utilities
│   ├── Types/                   # Type definitions
│   │   ├── Types.php           # Core type definitions
│   │   ├── Schemas.php         # Validation schemas
│   │   └── Exceptions.php      # MCP exceptions
│   └── Utils/                   # Utility classes
│       ├── JsonSchema.php      # JSON Schema validation
│       └── Completable.php     # Completion support
├── tests/                       # Test files mirroring src structure
├── examples/                    # Example implementations
│   ├── server/
│   └── client/
├── composer.json
└── README.md
```

## Key Components Mapping

### TypeScript → PHP

1. **Zod Schemas → PHP Validation**

   - Use `respect/validation` or `symfony/validator` for schema validation
   - Create dedicated validator classes for each schema type

2. **Promises → ReactPHP Promises**

   ```php
   // TypeScript: async/await
   // PHP: ReactPHP promises
   use React\Promise\Promise;
   ```

3. **EventEmitter → Evenement**

   ```php
   use Evenement\EventEmitter;
   ```

4. **Type Definitions**
   ```php
   // Use PHP 8 union types and enums
   enum ErrorCode: int {
       case ConnectionClosed = -32000;
       case RequestTimeout = -32001;
       case ParseError = -32700;
       // ...
   }
   ```

## Core Interfaces

### Transport Interface

```php
interface Transport {
    public function start(): Promise;
    public function send(array $message): Promise;
    public function close(): Promise;
    public function setMessageHandler(callable $handler): void;
    public function setCloseHandler(callable $handler): void;
    public function setErrorHandler(callable $handler): void;
}
```

### Protocol Base Class

```php
abstract class Protocol {
    protected function assertCapability(string $capability): void;
    public function setRequestHandler(string $schema, callable $handler): void;
    public function sendNotification(array $notification): Promise;
    // ...
}
```

## Namespace Structure

- `MCP\Server` - Server implementations
- `MCP\Client` - Client implementations
- `MCP\Shared` - Shared components
- `MCP\Types` - Type definitions
- `MCP\Transport` - Transport implementations
- `MCP\Auth` - Authentication components

## Error Handling

1. Use custom exceptions extending `McpError`
2. Implement proper error codes from the protocol
3. Provide detailed error messages with context

## Testing Strategy

1. Unit tests for all components
2. Integration tests for transport layers
3. Example servers and clients for manual testing
4. Use PHPUnit for testing framework

## Dependencies

Core dependencies to use:

- `react/promise` - Async operations
- `react/event-loop` - Event loop for async
- `evenement/evenement` - Event emitter
- `respect/validation` or `symfony/validator` - Schema validation
- `guzzlehttp/psr7` - PSR-7 HTTP messages
- `monolog/monolog` - Logging

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.