Skip to main content

fastmcp.server.middleware.tool_injection

A middleware for injecting tools into the MCP server context.

Functions

list_prompts

list_prompts(context: Context) -> list[Prompt]
List prompts available on the server.

get_prompt

get_prompt(context: Context, name: Annotated[str, 'The name of the prompt to render.'], arguments: Annotated[dict[str, Any] | None, 'The arguments to pass to the prompt.'] = None) -> mcp.types.GetPromptResult
Render a prompt available on the server.

list_resources

list_resources(context: Context) -> list[mcp.types.Resource]
List resources available on the server.

read_resource

read_resource(context: Context, uri: Annotated[AnyUrl | str, 'The URI of the resource to read.']) -> list[ReadResourceContents]
Read a resource available on the server.

Classes

ToolInjectionMiddleware

A middleware for injecting tools into the context. Methods:

on_list_tools

on_list_tools(self, context: MiddlewareContext[mcp.types.ListToolsRequest], call_next: CallNext[mcp.types.ListToolsRequest, Sequence[Tool]]) -> Sequence[Tool]
Inject tools into the response.

on_call_tool

on_call_tool(self, context: MiddlewareContext[mcp.types.CallToolRequestParams], call_next: CallNext[mcp.types.CallToolRequestParams, ToolResult]) -> ToolResult
Intercept tool calls to injected tools.

PromptToolMiddleware

A middleware for injecting prompts as tools into the context.

ResourceToolMiddleware

A middleware for injecting resources as tools into the context.