You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50-16Lines changed: 50 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -94,27 +94,61 @@ PHP MCP Laravel provides two approaches to define your MCP elements: manual regi
94
94
95
95
### Manual Registration
96
96
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).
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 typefor resources resolved by this template.
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.
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.
120
154
@@ -124,7 +158,7 @@ Manually registered elements are always available regardless of cache status and
124
158
125
159
### Attribute-Based Discovery
126
160
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:
128
162
129
163
```php
130
164
namespace App\Mcp;
@@ -148,7 +182,7 @@ class DiscoveredElements
148
182
}
149
183
```
150
184
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:
0 commit comments