mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-26 23:44:17 +02:00
Expose local_provider property, deprecate FastMCP.remove_tool() (#3155)
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
This commit is contained in:
parent
fe57c3d689
commit
a307e9c3cc
7 changed files with 170 additions and 54 deletions
|
|
@ -81,9 +81,9 @@ mcp.add_prompt(my_prompt)
|
|||
Remove components by name or URI:
|
||||
|
||||
```python
|
||||
mcp.remove_tool("my_tool")
|
||||
mcp.remove_resource("data://info")
|
||||
mcp.remove_prompt("my_prompt")
|
||||
mcp.local_provider.remove_tool("my_tool")
|
||||
mcp.local_provider.remove_resource("data://info")
|
||||
mcp.local_provider.remove_prompt("my_prompt")
|
||||
```
|
||||
|
||||
## Duplicate Handling
|
||||
|
|
|
|||
|
|
@ -975,7 +975,7 @@ def example_tool() -> str:
|
|||
mcp.add_tool(example_tool) # Sends tools/list_changed notification
|
||||
mcp.disable(keys={"tool:example_tool"}) # Sends tools/list_changed notification
|
||||
mcp.enable(keys={"tool:example_tool"}) # Sends tools/list_changed notification
|
||||
mcp.remove_tool("example_tool") # Sends tools/list_changed notification
|
||||
mcp.local_provider.remove_tool("example_tool") # Sends tools/list_changed notification
|
||||
```
|
||||
|
||||
Notifications are only sent when these operations occur within an active MCP request context (e.g., when called from within a tool or other MCP operation). Operations performed during server initialization do not trigger notifications.
|
||||
|
|
@ -1060,7 +1060,7 @@ The duplicate behavior options are:
|
|||
|
||||
<VersionBadge version="2.3.4" />
|
||||
|
||||
You can dynamically remove tools from a server using the `remove_tool` method:
|
||||
You can dynamically remove tools from a server through its [local provider](/servers/providers/local):
|
||||
|
||||
```python
|
||||
from fastmcp import FastMCP
|
||||
|
|
@ -1072,7 +1072,7 @@ def calculate_sum(a: int, b: int) -> int:
|
|||
"""Add two numbers together."""
|
||||
return a + b
|
||||
|
||||
mcp.remove_tool("calculate_sum")
|
||||
mcp.local_provider.remove_tool("calculate_sum")
|
||||
```
|
||||
|
||||
## Versioning
|
||||
|
|
|
|||
|
|
@ -293,14 +293,14 @@ If the requested version doesn't exist, a `NotFoundError` is raised.
|
|||
|
||||
## Removing Versions
|
||||
|
||||
The `remove_tool`, `remove_resource`, and `remove_prompt` methods accept an optional `version` parameter that controls what gets removed.
|
||||
The `remove_tool`, `remove_resource`, and `remove_prompt` methods on the server's [local provider](/servers/providers/local) accept an optional `version` parameter that controls what gets removed.
|
||||
|
||||
```python
|
||||
# Remove ALL versions of a component
|
||||
mcp.remove_tool("calculate")
|
||||
mcp.local_provider.remove_tool("calculate")
|
||||
|
||||
# Remove only a specific version
|
||||
mcp.remove_tool("calculate", version="1.0")
|
||||
mcp.local_provider.remove_tool("calculate", version="1.0")
|
||||
```
|
||||
|
||||
When you remove a specific version, other versions remain registered. When you remove without specifying a version, all versions are removed.
|
||||
|
|
@ -332,5 +332,5 @@ Clients automatically see version 2.0 (the highest). During the transition, your
|
|||
Once the migration is complete, remove the old version.
|
||||
|
||||
```python
|
||||
mcp.remove_tool("process_data", version="1.0")
|
||||
mcp.local_provider.remove_tool("process_data", version="1.0")
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue