mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-06-17 13:05:58 +00:00
fix: add MCP tools cache reset endpoint (#3602)
* fix: add MCP tools cache reset endpoint * docs: clarify MCP cache reset scope
This commit is contained in:
@@ -8,6 +8,7 @@ from fastapi import APIRouter, HTTPException, Request, status
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from deerflow.config.extensions_config import ExtensionsConfig, get_extensions_config, reload_extensions_config
|
||||
from deerflow.mcp.cache import reset_mcp_tools_cache
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter(prefix="/api", tags=["mcp"])
|
||||
@@ -69,6 +70,13 @@ class McpConfigUpdateRequest(BaseModel):
|
||||
)
|
||||
|
||||
|
||||
class McpCacheResetResponse(BaseModel):
|
||||
"""Response model for resetting the MCP tools cache."""
|
||||
|
||||
success: bool = Field(description="Whether the MCP tools cache was reset")
|
||||
message: str = Field(description="Human-readable reset status")
|
||||
|
||||
|
||||
_MASKED_VALUE = "***"
|
||||
|
||||
|
||||
@@ -269,6 +277,27 @@ async def get_mcp_configuration(request: Request) -> McpConfigResponse:
|
||||
return McpConfigResponse(mcp_servers=servers)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/mcp/cache/reset",
|
||||
response_model=McpCacheResetResponse,
|
||||
summary="Reset MCP Tools Cache",
|
||||
description=("Reset cached MCP tools and pooled sessions process-wide so tools are reloaded on next use. This affects all threads and users in the current Gateway process."),
|
||||
)
|
||||
async def reset_mcp_tools_cache_endpoint(request: Request) -> McpCacheResetResponse:
|
||||
"""Reset cached MCP tools and persistent sessions process-wide.
|
||||
|
||||
The next agent run or tool lookup will reload tools from the configured MCP
|
||||
servers. This affects all threads and users in the current Gateway process,
|
||||
and avoids relying on extensions_config.json mtime changes.
|
||||
"""
|
||||
await _require_admin_user(request)
|
||||
reset_mcp_tools_cache()
|
||||
return McpCacheResetResponse(
|
||||
success=True,
|
||||
message="MCP tools cache reset. Tools will reload on next use.",
|
||||
)
|
||||
|
||||
|
||||
@router.put(
|
||||
"/mcp/config",
|
||||
response_model=McpConfigResponse,
|
||||
@@ -363,6 +392,7 @@ async def update_mcp_configuration(request: Request, body: McpConfigUpdateReques
|
||||
# agent runtime lives in Gateway, so this keeps API reads and tool
|
||||
# execution aligned after extensions_config.json changes.
|
||||
reloaded_config = reload_extensions_config()
|
||||
reset_mcp_tools_cache()
|
||||
servers = {name: _mask_server_config(McpServerConfigResponse(**server.model_dump())) for name, server in reloaded_config.mcp_servers.items()}
|
||||
return McpConfigResponse(mcp_servers=servers)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user