Skip to content

Add attribute alternatives for primitive and server configuration#154

Merged
taylorotwell merged 3 commits intomainfrom
attribute_refactor
Feb 16, 2026
Merged

Add attribute alternatives for primitive and server configuration#154
taylorotwell merged 3 commits intomainfrom
attribute_refactor

Conversation

@pushpak1300
Copy link
Member

@pushpak1300 pushpak1300 commented Feb 16, 2026

Following the Laravel ecosystem direction (framework PR #58578), this adds Attributes as a non-breaking alternative to class properties for configuring MCP primitives and servers.

Usage

// Before (properties — still works)
class SayHelloTool extends Tool
{
    protected string $name = 'say-hello';
    protected string $description = 'Greets the user';
}

// After (attributes)
#[Description('Greets the user')]
class SayHelloTool extends Tool
{
    // name auto-derived from class name
}

// Resources
#[Uri('file://logs/application')]
#[MimeType('text/plain')]
class ApplicationLog extends Resource {}

// Servers
#[Name('My App')]
#[Version('1.0.0')]
#[Instructions('Use this server to interact with the app')]
class AppServer extends Server {}

Approach

  • Seven new attribute classes: Name, Title, Description, Uri, MimeType, Version, Instructions
  • A shared ReadsAttributes trait resolves attribute values via reflection
  • Primitive, Resource, and Server accessor methods check attributes first, then fall back to properties, then to auto-generated defaults
  • Fully non-breaking — all existing tests pass unchanged

@pushpak1300 pushpak1300 changed the title Add PHP 8 attribute alternatives for primitive and server configuration Add attribute alternatives for primitive and server configuration Feb 16, 2026
@pushpak1300 pushpak1300 marked this pull request as ready for review February 16, 2026 18:34
@taylorotwell taylorotwell merged commit cf9b0cc into main Feb 16, 2026
22 checks passed
@taylorotwell taylorotwell deleted the attribute_refactor branch February 16, 2026 18:48
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.

2 participants