Skip to content

Conversation

keshav-k3
Copy link

Issue

Description

Resource Templates Implementation

Adds support for Resource Templates in the MCP server, enabling dynamic resources with URI patterns.

Changes

  • Core: New ResourceTemplate class extending Primitive with uriTemplate and mimeType support
  • Pattern Matching: UriTemplateMatcher utility for RFC 6570 URI template matching and variable extraction
  • Dynamic Reading: ReadResource enhanced to match URI patterns and inject extracted variables into template handlers
  • Method Handler: ListResourceTemplates for resources/templates/list endpoint
  • Generator: make:mcp-resource-template artisan command with stub file
  • Integration: Updated Server and ServerContext to support resource templates
  • Tests: Complete unit test coverage for new functionality

Usage
php artisan make:mcp-resource-template UserProfile

Generates a resource template with dynamic URI patterns like file://resources/user-profile/{id}

…eCommand and publish resource-template stub in service provider
…for ListPrompts, ListResources, and ListTools
… with RFC 6570 support and comprehensive tests
…ing with URI pattern matching and variable extraction in ReadResource
… implementations to support Resource|ResourceTemplate type union
…template-based resource reading with variable injection
Copy link

github-actions bot commented Oct 9, 2025

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

…P 8.1/8.4 compatibility and PHPStan compliance
…sourceTemplateCommand and pagination test for ListResourceTemplates
@keshav-k3 keshav-k3 marked this pull request as ready for review October 9, 2025 13:31
@taylorotwell taylorotwell marked this pull request as draft October 9, 2025 13:33
@alejojperez
Copy link

@keshav-k3 Hey, thank you for your contribution. I'm testing the code in your branch, and there is a small bug at \Laravel\Mcp\Server\Methods\ReadResource::55. You are binding the request to the container, but the arguments get overridden because of the logic that exists on \Laravel\Mcp\Server\McpServiceProvider::72. To make the path variables available on the request, you should change the implementation to something like this:

Container::getInstance()->afterResolving(Request::class, function (Request $mcpRequest) use ($variables): void {
    foreach ($variables as $key => $value) {
        $mcpRequest->merge([$key => $value]);
    }
});

CC: @taylorotwell

…f bind to prevent variable loss from McpServiceProvider callback
@keshav-k3
Copy link
Author

@alejojperez Hey, appreciate the spot! I’ve fixed it and tested the change — LGTM!

@alejojperez
Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@keshav-k3 Hey, remember to mark your PR as ready for review! 😊

@keshav-k3 keshav-k3 marked this pull request as ready for review October 11, 2025 12:56
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