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

Publishing

The GitHub workflow publishes to PyPI when a GitHub Release is published. Configure PyPI Trusted Publishing with:

  • PyPI project name: fastmcp-dishka
  • Owner: vfaddey
  • Repository: fastmcp-dishka
  • Workflow filename: ci.yml
  • Environment: pypi

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.0.tar.gz (8.1 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.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastmcp_dishka-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 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.0.tar.gz
Algorithm Hash digest
SHA256 5c8766b6873760200a36318323a99229ebc50267328c7b50e846ea32163bd17b
MD5 72226d6f41a0eb76ab81d6fcf7f2bd99
BLAKE2b-256 f765fc42bb25ff2baa744c1c201e86e222dd886e538ae94ef71a90fe651d380f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: fastmcp_dishka-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc29b51c1f715e4c54af2dd13458373f0a37ffcc5ff0de1d3d37af09af369151
MD5 6c5ae1ac87d2b7adead68fcf73ebf750
BLAKE2b-256 30f9e8552d9ce4c6d52b39fcdedb0e484579323630a2d5b4cd19848dcfbabf18

See more details on using hashes here.

Provenance

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