Skip to main content

Dishka dependency injection integration for FastMCP

Project description

FastMCP Dishka

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.1.tar.gz (7.9 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.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastmcp_dishka-0.1.1.tar.gz
  • Upload date:
  • Size: 7.9 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.1.tar.gz
Algorithm Hash digest
SHA256 a69f0ccb46d8b132df0ebbeebec66c5e7992ba47a908860a8b33163541dd0805
MD5 8afd893b12bb525df9228760c2ea3994
BLAKE2b-256 e05429a29e1573d621ea4d5934d5714097b95473c18e4ed90fc6da79f01b085e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastmcp_dishka-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: fastmcp_dishka-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a4992213c691533f41a9dd0cf8ab21e48702abbda8f2c3e0aeff0cb46633680
MD5 7392b08068060937a871e9c78e841ad8
BLAKE2b-256 1000429a62164694835a7e6db7f59bbc0438ff765a7b271aa9a522bd6d28603e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastmcp_dishka-0.1.1-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