Skip to main content

Dishka dependency injection integration for FastMCP

Project description

FastMCP Dishka

CI PyPI Python License Ruff Coverage

Integration package for using dishka dependency injection with FastMCP tools, resources, and prompts.

It provides:

  • FastMCPProvider with FastMCP request context objects for dishka.
  • setup_dishka() middleware that opens a Scope.REQUEST container per tool/resource/prompt call.
  • @inject support for parameters marked as FromDishka[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.

@mcp.prompt
@inject
async def welcome_prompt(
    name: str,
    service: FromDishka[GreetingService],
) -> str:
    return f"Write a short welcome message for: {service.greet(name)}"

See examples/fastmcp_app.py for a complete FastMCP server with a tool, resource, prompt, and Dishka providers.

Development

Install development dependencies:

uv sync --dev

Run tests with coverage:

make test

Run linting and formatting:

make lint
make format

Install pre-commit hooks:

make pre-commit-install

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastmcp_dishka-0.1.2.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastmcp_dishka-0.1.2-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file fastmcp_dishka-0.1.2.tar.gz.

File metadata

  • Download URL: fastmcp_dishka-0.1.2.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastmcp_dishka-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4261acd0dd734a45665fcf33bd9456268cd92470d03ca9772f5d6bec687d04ab
MD5 7d145e8d710922f674fc9bd4b430a2fa
BLAKE2b-256 80be5ea66e9fc4cc99537c5f725c5514e77fb80f4909a92f52fbff9f9ca0a3b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastmcp_dishka-0.1.2.tar.gz:

Publisher: ci.yml on vfaddey/fastmcp-dishka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastmcp_dishka-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: fastmcp_dishka-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastmcp_dishka-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7bb58aafbe0eff92866361bde9f902066db28749bc68f0035ef3e30266617217
MD5 bb51164901530785ab32dd151dfdb4c7
BLAKE2b-256 3485b9846f08826757f8a9781f7b59fe2ef7711a1359c1fcf56497184fc4acd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastmcp_dishka-0.1.2-py3-none-any.whl:

Publisher: ci.yml on vfaddey/fastmcp-dishka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page