Remove stale catalog cache from CodeMode execute

This commit is contained in:
Jeremiah Lowin 2026-03-03 16:29:18 -05:00
commit f923b671ce
2 changed files with 28 additions and 9 deletions

View file

@ -5,7 +5,7 @@ from typing import Any
import pytest
from mcp.types import ImageContent, TextContent
from fastmcp import FastMCP
from fastmcp import Client, FastMCP
from fastmcp.exceptions import ToolError
from fastmcp.experimental.transforms.code_mode import (
CodeMode,
@ -507,6 +507,32 @@ async def test_code_mode_search_respects_disabled_tool_visibility() -> None:
assert "secret" not in text or "No tools" in text
async def test_code_mode_execute_sees_mid_run_visibility_changes() -> None:
"""Unlocking a tool mid-execution makes it callable in the same run."""
mcp = FastMCP("CodeMode Unlock")
@mcp.tool
async def unlock(ctx: Context) -> str:
await ctx.enable_components(names={"secret"}, components={"tool"})
return "unlocked"
@mcp.tool
async def secret() -> str:
return "secret-ok"
mcp.disable(names={"secret"}, components={"tool"})
mcp.add_transform(CodeMode(sandbox_provider=_UnsafeTestSandboxProvider()))
async with Client(mcp) as client:
result = await client.call_tool(
"execute",
{
"code": "await call_tool('unlock', {})\nreturn await call_tool('secret', {})"
},
)
assert result.data == {"result": "secret-ok"}
async def test_code_mode_execute_respects_tool_auth() -> None:
mcp = FastMCP("CodeMode Auth")