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
{{ message }}
This repository was archived by the owner on Nov 12, 2025. It is now read-only.
-[Parameter Type Casting](#parameter-type-casting)
30
+
-[Resource Results](#resource-results)
31
+
-[Resource Events](#resource-events)
32
+
-[JSON-RPC Integration](#json-rpc-integration-1)
24
33
-[Prompts](#prompts)
25
34
-[Creating Prompts](#creating-prompts)
26
35
-[Prompt Results](#prompt-results)
27
36
-[Prompt Events](#prompt-events)
28
-
-[JSON-RPC Integration](#json-rpc-integration-1)
37
+
-[JSON-RPC Integration](#json-rpc-integration-2)
29
38
-[JSON-RPC Methods](#json-rpc-methods)
30
39
-[Built-in Methods](#built-in-methods)
31
40
-[Custom Methods](#custom-methods)
@@ -273,6 +282,228 @@ This ensures that your tool handlers always receive properly validated and sanit
273
282
- **`tools/list`**: Lists all available tools and their definitions.
274
283
- **`tools/call`**: Executes a tool by name, with the provided input data.
275
284
285
+
## Resources
286
+
287
+
Resources are data sources that can be accessed by clients via their URI.
288
+
They can represent files, database records, or any other data that can be identified by a URI.
289
+
290
+
### Creating Resources
291
+
292
+
1. Create a new class that will handle your resource logic
293
+
2. Use the `#[AsResource]` attribute to register your resource
294
+
3. Define the URI pattern for your resource (static or templated)
295
+
4. Implement the `__invoke` method to handle the resource logic and return a `ResourceResult`
296
+
297
+
_As Resource classes are services within the Symfony application, any dependency can be injected in it, using the constructor, like any other service._
298
+
299
+
#### Static Resources
300
+
301
+
Static resources have a fixed URI that doesn't change. They are useful for resources that don't require parameters.
302
+
303
+
Example:
304
+
```php
305
+
<?php
306
+
307
+
use Ecourty\McpServerBundle\Attribute\AsResource;
308
+
use Ecourty\McpServerBundle\IO\Resource\ResourceResult;
309
+
use Ecourty\McpServerBundle\IO\Resource\TextResource;
310
+
311
+
#[AsResource(
312
+
uri: 'file://robots.txt',
313
+
name: 'robots_txt',
314
+
title: 'Get the Robots.txt file',
315
+
description: 'This resource returns the content of the robots.txt file.',
new BinaryResource('file://robots.txt', 'text/plain', $encodedFileContent),
329
+
]);
330
+
}
331
+
}
332
+
```
333
+
334
+
#### Templated Resources
335
+
336
+
Templated resources use URI templates with parameters enclosed in curly braces (e.g., `{id}`). These parameters are automatically extracted from the URI and passed to the `__invoke` method as arguments.
337
+
338
+
Example:
339
+
```php
340
+
<?php
341
+
342
+
use Ecourty\McpServerBundle\Attribute\AsResource;
343
+
use Ecourty\McpServerBundle\IO\Resource\ResourceResult;
344
+
use Ecourty\McpServerBundle\IO\Resource\TextResource;
345
+
346
+
#[AsResource(
347
+
uri: 'database://user/{id}',
348
+
name: 'user_data',
349
+
title: 'Get User Data',
350
+
description: 'Gathers the data of a user by their ID.',
The bundle automatically casts URI parameters to the appropriate types based on the method signature:
420
+
421
+
- `int`parameters are cast to integers
422
+
- `float`parameters are cast to floats
423
+
- `bool`parameters are cast to booleans
424
+
- `string`parameters remain as strings
425
+
- `array`parameters are JSON-decoded into arrays using `json_decode` if they are JSON strings
426
+
427
+
### Resource Results
428
+
429
+
The [MCP specification](https://modelcontextprotocol.io/specification/2025-06-18/server/resources#reading-resources) states that resource results should consist of an array of resource objects.
430
+
The bundle provides several result types that can be combined in a single `ResourceResult` object:
431
+
432
+
- `TextResource`: For text-based content (JSON, XML, plain text, etc.)
433
+
- `BinaryResource`: For binary content (images, audio, video, files, etc.), should be base-64 encoded
434
+
435
+
All resource results must be wrapped in a `ResourceResult` object, which can contain multiple resources.
436
+
437
+
Example:
438
+
```php
439
+
<?php
440
+
441
+
use Ecourty\McpServerBundle\IO\Resource\ResourceResult;
442
+
use Ecourty\McpServerBundle\IO\Resource\TextResource;
443
+
use Ecourty\McpServerBundle\IO\Resource\BinaryResource;
0 commit comments