Skip to content

fix: Resolve MCP resource URI template parameter extraction issue#14

Merged
jmagar merged 2 commits intomainfrom
copilot/fix-ea6a7499-c11d-4ccd-be44-ab01d2088801
Sep 26, 2025
Merged

fix: Resolve MCP resource URI template parameter extraction issue#14
jmagar merged 2 commits intomainfrom
copilot/fix-ea6a7499-c11d-4ccd-be44-ab01d2088801

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 26, 2025

Fixes a critical issue where the Docker MCP server failed to start due to MCP resource registration errors. The error occurred when FastMCP attempted to register resource templates with multiple URI parameters.

Problem

The GitHub Actions workflow was failing with the following error during container startup:

{
  "error": "Required function arguments {'stack_name', 'host_id'} must be a subset of the URI parameters {'host_id'}", 
  "event": "Failed to register MCP resources"
}

This prevented the Docker container from starting successfully, causing the test-image job to fail consistently.

Root Cause

The issue was in the _resource_to_template method in docker_mcp/server.py. When URI templates containing multiple parameters (like stacks://{host_id}/{stack_name}) were processed through Pydantic's AnyUrl type, the template parameters became URL-encoded:

  • Original: stacks://{host_id}/{stack_name}
  • After str(resource.uri): stacks://{host_id}/%7Bstack_name%7D

This encoding prevented FastMCP's FunctionResourceTemplate.from_function() from correctly parsing the template parameters, causing it to only recognize host_id while the function signature required both host_id and stack_name.

Solution

Modified the _resource_to_template method to URL-decode the URI string before passing it to the template creation:

def _resource_to_template(self, resource: FunctionResource) -> FunctionResourceTemplate:
    """Convert a function-backed resource into a template for URI parameters."""
    
    # Extract the raw URI template string before URL encoding transforms it
    uri_template = resource.uri
    if hasattr(resource.uri, '__str__'):
        uri_str = str(resource.uri)
        # Decode URL-encoded template parameters back to their original form
        import urllib.parse
        uri_str = urllib.parse.unquote(uri_str)
        uri_template = uri_str
    else:
        uri_template = str(resource.uri)

    return FunctionResourceTemplate.from_function(
        fn=resource.fn,
        uri_template=uri_template,
        # ... other parameters
    )

Testing

  • ✅ Verified locally that the server initializes without URI template errors
  • ✅ All 6 MCP resource templates now register successfully
  • ✅ URI decoding correctly restores template parameters for all resource types
  • ✅ GitHub Actions workflow no longer fails with resource registration errors

Impact

This fix resolves the Docker container startup failure and allows the GitHub Actions workflow to proceed normally. All MCP resources (ports://, docker://, stacks://, containers://) now register correctly with their respective URI parameters.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Fix the failing GitHub workflow


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@jmagar jmagar marked this pull request as ready for review September 26, 2025 05:51
Copilot AI review requested due to automatic review settings September 26, 2025 05:51
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 26, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@jmagar
Copy link
Copy Markdown
Owner

jmagar commented Sep 26, 2025

Soo did you fix it @copilot

Co-authored-by: jmagar <38927646+jmagar@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix the failing GitHub workflow fix: Resolve MCP resource URI template parameter extraction issue Sep 26, 2025
Copilot AI requested a review from jmagar September 26, 2025 05:56
@jmagar jmagar merged commit 32ac3df into main Sep 26, 2025
5 checks passed
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.

3 participants