What happened?
When mounting a FastMCP server, resource templates with wildcards do not work anymore. Static resources are fine, resources with a single parameter (not wildcard) are also fine. Only if there is a wildcards parameter, the substitution for e.g. resource://file/{path*} will only contain the value {path*} as path parameter instead of the provided value. This does not happen, when using the root FastMCP server, only in the mounted sub-server.
Example Code
from fastmcp import FastMCP
from fastmcp.server.transforms import ResourcesAsTools
mcp_sub = FastMCP("sub")
@mcp_sub.resource("resource://res")
def resource_single() -> str:
"""Resource.
Returns:
The resource
"""
return "ress"
@mcp_sub.resource("resource://single/{extra}")
def resource_single(extra: str) -> str:
"""Resource template with placeholder.
Args:
extra: a single value
Returns:
The provided value
"""
return extra
@mcp_sub.resource("resource://multi/{extra*}")
def resource_single(extra: str) -> str:
"""Resource template with wildcard
Args:
extra: the extra content
Returns:
The provided extra content.
"""
return extra
mcp = FastMCP("main")
@mcp.resource("resource2://multi2/{extra*}")
def resource_single2(extra: str) -> str:
"""Resource template with wildcard
Args:
extra: the extra content
Returns:
The provided extra content.
"""
return extra
mcp.mount(mcp_sub, namespace="sub")
# mcp.mount(mcp_sub) # also doesn't work
# mcp.add_transform(ResourcesAsTools(mcp)) # no change
Version Information
FastMCP version: 3.2.3
MCP version: 1.27.0
Python version: 3.10.12
Platform: Linux-6.6.87.2-microsoft-standard-WSL2-x86_64-with-glibc2.35
FastMCP root path: /<path>/.venv/lib/python3.10/site-packages
What happened?
When mounting a FastMCP server, resource templates with wildcards do not work anymore. Static resources are fine, resources with a single parameter (not wildcard) are also fine. Only if there is a wildcards parameter, the substitution for e.g.
resource://file/{path*}will only contain the value{path*}aspathparameter instead of the provided value. This does not happen, when using the root FastMCP server, only in the mounted sub-server.Example Code
Version Information