Dishka dependency injection integration for FastMCP
Project description
FastMCP 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.
@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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c8766b6873760200a36318323a99229ebc50267328c7b50e846ea32163bd17b
|
|
| MD5 |
72226d6f41a0eb76ab81d6fcf7f2bd99
|
|
| BLAKE2b-256 |
f765fc42bb25ff2baa744c1c201e86e222dd886e538ae94ef71a90fe651d380f
|
Provenance
The following attestation bundles were made for fastmcp_dishka-0.1.0.tar.gz:
Publisher:
ci.yml on vfaddey/fastmcp-dishka
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastmcp_dishka-0.1.0.tar.gz -
Subject digest:
5c8766b6873760200a36318323a99229ebc50267328c7b50e846ea32163bd17b - Sigstore transparency entry: 1474324263
- Sigstore integration time:
-
Permalink:
vfaddey/fastmcp-dishka@98178b5501044f06b4f81a82c136dabed898a3a6 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/vfaddey
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@98178b5501044f06b4f81a82c136dabed898a3a6 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc29b51c1f715e4c54af2dd13458373f0a37ffcc5ff0de1d3d37af09af369151
|
|
| MD5 |
6c5ae1ac87d2b7adead68fcf73ebf750
|
|
| BLAKE2b-256 |
30f9e8552d9ce4c6d52b39fcdedb0e484579323630a2d5b4cd19848dcfbabf18
|
Provenance
The following attestation bundles were made for fastmcp_dishka-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on vfaddey/fastmcp-dishka
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastmcp_dishka-0.1.0-py3-none-any.whl -
Subject digest:
fc29b51c1f715e4c54af2dd13458373f0a37ffcc5ff0de1d3d37af09af369151 - Sigstore transparency entry: 1474324396
- Sigstore integration time:
-
Permalink:
vfaddey/fastmcp-dishka@98178b5501044f06b4f81a82c136dabed898a3a6 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/vfaddey
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@98178b5501044f06b4f81a82c136dabed898a3a6 -
Trigger Event:
release
-
Statement type: