Skip to content

Commit 7f02775

Browse files
docs: Expand README.md with detailed explanations of MCP registration methods and their configurations
[skip ci]
1 parent 266df73 commit 7f02775

File tree

1 file changed

+50
-16
lines changed

1 file changed

+50
-16
lines changed

README.md

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,61 @@ PHP MCP Laravel provides two approaches to define your MCP elements: manual regi
9494
9595
### Manual Registration
9696
97-
The recommended approach is using the fluent `Mcp` facade to manually register your elements in `routes/mcp.php` (this path can be changed in config/mcp.php via the discovery.definitions_file key):
97+
The recommended approach is using the fluent `Mcp` facade to manually register your elements in `routes/mcp.php` (this path can be changed in config/mcp.php via the discovery.definitions_file key).
9898
9999
```php
100-
// routes/mcp.php
100+
Mcp::tool([MyHandlers::class, 'calculateSum']);
101101
102-
use App\Mcp\MyLaravelTools;
103-
use App\Mcp\TopicSummarizer;
104-
use PhpMcp\Laravel\Server\Facades\Mcp;
102+
Mcp::resource( 'status://app/health', [MyHandlers::class, 'getAppStatus']);
105103
106-
Mcp::tool('laravel_adder', [MyLaravelTools::class, 'add'])
107-
->description('Adds two numbers using Laravel.');
104+
Mcp::prompt(MyInvokableTool::class);
108105
109-
Mcp::resource('config://app/name', [MyLaravelTools::class, 'getAppName'])
110-
->name('laravel_app_name')
111-
->mimeType('text/plain');
106+
Mcp::resourceTemplate('user://{id}/data', [MyHandlers::class, 'getUserData']);
107+
```
112108
113-
Mcp::prompt('topic_summarizer', TopicSummarizer::class);
109+
The facade provides several registration methods, each with optional fluent configuration methods:
110+
111+
#### Tools (`Mcp::tool()`)
112+
113+
Defines an action or function the MCP client can invoke. Register a tool by providing either:
114+
- Just the handler: `Mcp::tool(MyTool::class)`
115+
- Name and handler: `Mcp::tool('my_tool', [MyClass::class, 'method'])`
116+
117+
Available configuration methods:
118+
- `name()`: Override the inferred name
119+
- `description()`: Set a custom description
120+
121+
#### Resources (`Mcp::resource()`)
122+
123+
Defines a specific, static piece of content or data identified by a URI. Register a resource by providing:
124+
- `$uri` (`required`): The unique URI for this resource instance (e.g., `config://app/settings`).
125+
- `$handler`: The handler that will return the resource's content.
126+
127+
Available configuration methods:
128+
- `name(string $name): self`: Sets a human-readable name. Inferred if omitted.
129+
- `description(string $description): self`: Sets a description. Inferred if omitted.
130+
- `mimeType(string $mimeType): self`: Specifies the resource's MIME type. Can sometimes be inferred from the handler's return type or content.
131+
- `size(?int $size): self`: Specifies the resource size in bytes, if known.
132+
- `annotations(array $annotations): self`: Adds MCP-standard annotations (e.g., ['audience' => ['user']]).
133+
134+
#### Resource Template (`Mcp::resourceTemplate()`)
135+
136+
Defines a handler for resource URIs that contain variable parts, allowing dynamic resource instance generation. Register a resource template by providing:
137+
- `$uriTemplate` (`required`): The URI template string (`RFC 6570`), e.g., `user://{userId}/profile`.
138+
- `$handler`: The handler method. Its parameters must match the variables in the `$uriTemplate`.
139+
140+
Available configuration methods:
141+
- `name(string $name): self`: Sets a human-readable name for the template type.
142+
- `description(string $description): self`: Sets a description for the template.
143+
- `mimeType(string $mimeType): self`: Sets a default MIME type for resources resolved by this template.
144+
- `annotations(array $annotations): self`: Adds MCP-standard annotations.
145+
146+
#### Prompts (`Mcp::prompt()`)
147+
148+
Defines a generator for MCP prompt messages, often used to construct conversations for an LLM. Register a prompt by providing just the handler, or the name and handler.
149+
- `$name` (`optional`): The MCP prompt name. Inferred if omitted.
150+
- `$handler`: The handler method. Its parameters become the prompt's input arguments.
114151
115-
Mcp::resourceTemplate('user://{userId}/profile', [MyLaravelTools::class, 'getUserProfile'])
116-
->mimeType('application/json');
117-
```
118152
119153
The package automatically resolves handlers through Laravel's service container, allowing you to inject dependencies through constructor injection. Each registration method accepts either an invokable class or a `[class, method]` array.
120154

@@ -124,7 +158,7 @@ Manually registered elements are always available regardless of cache status and
124158
125159
### Attribute-Based Discovery
126160
127-
As an alternative, you can use PHP 8 attributes to mark your methods or invokable classes as MCP elements:
161+
As an alternative, you can use PHP 8 attributes to mark your methods or invokable classes as MCP elements. That way, you don't have to manually register them in the definitions file:
128162
129163
```php
130164
namespace App\Mcp;
@@ -148,7 +182,7 @@ class DiscoveredElements
148182
}
149183
```
150184
151-
In development environments with `auto_discover` enabled in your config, these elements are automatically discovered when needed. For production or to manually trigger discovery, run:
185+
When `auto_discover` enabled in your config, these elements are automatically discovered when needed. For production or to manually trigger discovery, run:
152186
153187
```bash
154188
php artisan mcp:discover

0 commit comments

Comments
 (0)