Dishka dependency injection integration for FastMCP
Maintained. Last release 7 weeks ago, commits in 3 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install fastmcp-dishkaFastMCP Dishka
Integration package for using dishka dependency injection with FastMCP tools, resources, and prompts.
It provides:
FastMCPProviderwith FastMCP request context objects for dishka.setup_dishka()middleware that opens aScope.REQUESTcontainer per tool/resource/prompt call.@injectsupport for parameters marked asFromDishka[T].
Usage
from dishka import Provider, Scope, make_async_container, provide
from fastmcp import FastMCP
from fastmcp_dishka import FastMCPProvider, FromDishka, inject, setup_dishka
class GreetingService:
def greet(self, name: str) -> str:
return f"Hello, {name}!"
class AppProvider(Provider):
greeting = provide(GreetingService, scope=Scope.REQUEST)
mcp = FastMCP("GreetMCP")
container = make_async_container(AppProvider(), FastMCPProvider())
setup_dishka(container, mcp)
@mcp.tool
@inject
async def greet(name: str, service: FromDishka[GreetingService]) -> str:
return service.greet(name)
Place @inject below FastMCP decorators so FastMCP registers the wrapped
function signature.
@mcp.prompt defines a reusable prompt template exposed to MCP clients. A
prompt does not perform an action like a tool; it returns text or chat messages
that a client can insert into an LLM conversation.