Metadata-Version: 2.4
Name: fastmcp-dishka
Version: 0.1.0
Summary: Dishka dependency injection integration for FastMCP
Keywords: dependency-injection,dishka,fastmcp,mcp
Author: Faddey Valuev
Author-email: Faddey Valuev <vfaddey@yandex.ru>
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Dist: dishka>=1.10.1
Requires-Dist: fastmcp>=3.2.4
Requires-Python: >=3.13
Project-URL: Homepage, https://github.com/vfaddey/fastmcp-dishka
Project-URL: Source, https://github.com/vfaddey/fastmcp-dishka
Project-URL: Tracker, https://github.com/vfaddey/fastmcp-dishka/issues
Description-Content-Type: text/markdown

# FastMCP Dishka

[![PyPI](https://img.shields.io/pypi/v/fastmcp-dishka.svg)](https://pypi.org/project/fastmcp-dishka/)
[![Python](https://img.shields.io/pypi/pyversions/fastmcp-dishka.svg)](https://pypi.org/project/fastmcp-dishka/)
[![License](https://img.shields.io/pypi/l/fastmcp-dishka.svg)](https://github.com/vfaddey/fastmcp-dishka/blob/main/LICENSE)
[![Ruff](https://img.shields.io/badge/lint-ruff-46a3ff.svg)](https://github.com/astral-sh/ruff)
[![Coverage](https://img.shields.io/badge/coverage-90%25%2B-brightgreen.svg)](#development)

Integration package for using [dishka](https://dishka.readthedocs.io/) dependency
injection with [FastMCP](https://gofastmcp.com/) 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

```python
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.

```python
@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](examples/fastmcp_app.py) for a complete FastMCP
server with a tool, resource, prompt, and Dishka providers.

## Development

Install development dependencies:

```bash
uv sync --dev
```

Run tests with coverage:

```bash
make test
```

Run linting and formatting:

```bash
make lint
make format
```

Install pre-commit hooks:

```bash
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`
