Skip to content

Expose local_provider property, deprecate FastMCP.remove_tool()#3155

Merged
jlowin merged 2 commits intomainfrom
feat/local-provider-property
Feb 12, 2026
Merged

Expose local_provider property, deprecate FastMCP.remove_tool()#3155
jlowin merged 2 commits intomainfrom
feat/local-provider-property

Conversation

@jlowin
Copy link
Copy Markdown
Member

@jlowin jlowin commented Feb 11, 2026

FastMCP.remove_tool() only operated on the local provider but gave misleading errors if a tool existed on a different provider (e.g. a mounted subserver). Rather than adding parallel remove_resource()/remove_prompt()/remove_template() methods that all share this limitation, the server's LocalProvider is now accessible as a public property — making it explicit that removal is scoped to locally-registered components.

mcp = FastMCP()

@mcp.tool
def my_tool() -> str: ...

# Old (now deprecated):
mcp.remove_tool("my_tool")

# New — works for all component types:
mcp.local_provider.remove_tool("my_tool")
mcp.local_provider.remove_resource("data://info")
mcp.local_provider.remove_prompt("my_prompt")
mcp.local_provider.remove_template("resource://{id}/data")

FastMCP.remove_tool() still works but emits a DeprecationWarning.

Closes #2880

jlowin and others added 2 commits February 11, 2026 16:41
Component removal now goes through mcp.local_provider.remove_*()
which makes it clear you're operating on locally-registered components.
@marvin-context-protocol marvin-context-protocol Bot added enhancement Improvement to existing functionality. For issues and smaller PR improvements. server Related to FastMCP server implementation or server-side functionality. provider Related to the FastMCP Provider class labels Feb 11, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 11, 2026

Walkthrough

This PR exposes the FastMCP server's LocalProvider instance through a new public local_provider property, enabling direct access to the server's locally-registered components. The removal methods (remove_tool, remove_resource, remove_prompt) are repositioned from the top-level FastMCP interface to the LocalProvider interface. The remove_tool method is deprecated with a runtime warning directing users to mcp.local_provider.remove_tool() instead. Documentation is updated across multiple files to reflect the new API usage patterns and namespace boundaries without altering underlying behavior.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description lacks required contributors checklist items, missing issue closure confirmation and documentation update verification. Add completed contributors checklist items including closure of issue #2880, verification of development workflow, testing, and documentation updates.
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the two main changes: exposing the local_provider property and deprecating FastMCP.remove_tool(), which aligns with the changeset.
Linked Issues check ✅ Passed The PR successfully addresses issue #2880 by exposing LocalProvider as a public property, enabling removal of resources (and other components) at runtime alongside tools.
Out of Scope Changes check ✅ Passed All changes directly support the primary objective of exposing local_provider and deprecating FastMCP.remove_tool(), with documentation updates consistently reflecting the new API.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/local-provider-property

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/fastmcp/server/server.py (1)

371-381: Docstring omits remove_template.

The local_provider docstring shows examples for remove_tool, remove_resource, and remove_prompt, but LocalProvider also exposes remove_template(uri_template, version=None). For completeness and discoverability, add it.

Suggested fix
     `@property`
     def local_provider(self) -> LocalProvider:
         """The server's local provider, which stores directly-registered components.
 
         Use this to remove components:
 
             mcp.local_provider.remove_tool("my_tool")
             mcp.local_provider.remove_resource("data://info")
             mcp.local_provider.remove_prompt("my_prompt")
+            mcp.local_provider.remove_template("resource://{id}/data")
         """
         return self._local_provider

Based on learnings: "Changes affecting tool interactions must be adopted, applied, and tested on all major MCP object types: Tools, Resources, Resource Templates, and Prompts."

docs/servers/providers/local.mdx (1)

79-87: Consider adding remove_template to the removal examples.

LocalProvider also supports remove_template(uri_template) for removing resource templates. Including it here keeps the documentation aligned with the full API surface.

 mcp.local_provider.remove_tool("my_tool")
 mcp.local_provider.remove_resource("data://info")
 mcp.local_provider.remove_prompt("my_prompt")
+mcp.local_provider.remove_template("resource://{id}/data")

Based on learnings: "Changes affecting tool interactions must be adopted, applied, and tested on all major MCP object types: Tools, Resources, Resource Templates, and Prompts."


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@jlowin jlowin merged commit a307e9c into main Feb 12, 2026
14 checks passed
@jlowin jlowin deleted the feat/local-provider-property branch February 12, 2026 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement to existing functionality. For issues and smaller PR improvements. provider Related to the FastMCP Provider class server Related to FastMCP server implementation or server-side functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support remove_resource

1 participant