refactor: remove request_ctx ContextVar, thread Context explicitly (#2203)

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
This commit is contained in:
Max Isbey 2026-03-04 13:23:02 +00:00 • committed by GitHub
commit cc22bf5464
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,7 +17,7 @@ from mcp.types import Icon, ToolAnnotations
if TYPE_CHECKING:
from mcp.server.context import LifespanContextT, RequestT
from mcp.server.mcpserver.server import Context
from mcp.server.mcpserver.context import Context
class Tool(BaseModel):
@ -92,10 +92,14 @@ class Tool(BaseModel):
async def run(
self,
arguments: dict[str, Any],
context: Context[LifespanContextT, RequestT] | None = None,
context: Context[LifespanContextT, RequestT],
convert_result: bool = False,
) -> Any:
"""Run the tool with arguments."""
"""Run the tool with arguments.
Raises:
ToolError: If the tool function raises during execution.
"""
try:
result = await self.fn_metadata.call_fn_with_arg_validation(
self.fn,