Skip to content

LocalProvider.get_tasks() skips provider transforms, so add_transform(Namespace(...)) breaks background-task registration #5114

Closed

Description

@BlueX888

What happened?

LocalProvider.get_tasks() never applies the provider's own transforms, so with a provider-level transform — including the documented provider.add_transform(Namespace("api")) example — the task-registration keys don't match the names the server actually dispatches.

Discovery uses the transformed name: mcp.get_tool("api_square").key is tool:api_square@, the key the callable is registered and dispatched under. But get_tasks() yields the untransformed tool:square@, so registering/enqueuing a background task for that tool fails with KeyError: 'tool:api_square@' instead of running.

Expected: get_tasks() returns the same transformed keys as discovery, as the base implementation and the sibling overrides (wrapped_provider.py, fastmcp_provider.py, server.py) do. The same namespace routed through mcp.add_provider(provider, namespace="api") works, so the add_transform path silently produces an unusable task registration.

Example Code

import asyncio

from fastmcp import FastMCP
from fastmcp.server.providers import LocalProvider
from fastmcp.server.transforms import Namespace


async def main():
    provider = LocalProvider()

    @provider.tool(task=True)
    async def square(n: int) -> int:
        return n * n

    provider.add_transform(Namespace("api"))
    mcp = FastMCP("demo", providers=[provider])

    tool = await mcp.get_tool("api_square")
    print("get_tool('api_square').key =", tool.key)
    print("get_tasks() keys           =", [c.key for c in await mcp.get_tasks()])


asyncio.run(main())

Actual output:

get_tool('api_square').key = tool:api_square@
get_tasks() keys           = ['tool:square@']

Submitting the task (repo task harness) then fails; the same namespace routed through the provider works:

[add_transform] dispatched_key='tool:api_square@' get_tasks_keys=['tool:square@']
[add_transform] run_task FAILED KeyError: 'tool:api_square@'
[add_provider ] dispatched_key='tool:api_square@' get_tasks_keys=['tool:api_square@']
[add_provider ] run_task status=completed

The non-obvious part: LocalProvider.get_tasks (fastmcp_slim/fastmcp/server/providers/local_provider/local_provider.py:456) builds its list straight from self._components and is the only get_tasks implementation that skips the for transform in self.transforms loop the others apply.

Version Information

FastMCP version: 4.0.4.dev12+58d903c8 (commit 58d903c84b0a3fe7596a15f9810ac138bda713dd)
MCP version:     2.0.0
Python version:  3.12.14
Platform:        macOS-26.6.2-arm64

Happy to open a PR if useful. Related: open PR #5062 also touches local_provider.py (unrelated MCP Apps property); merged PR #2729 last changed Provider.get_tasks().

Activity

  1. added
    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.
    serverRelated to FastMCP server implementation or server-side functionality.
    tasksRelated to background tasks, Docket, SEP-1686.
    on Sep 15, 2026
  2. added a commit that references this issue on Sep 15, 2026
    f044b9d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.serverRelated to FastMCP server implementation or server-side functionality.tasksRelated to background tasks, Docket, SEP-1686.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions