aiohttp-tiny-mcp
Documentation · Repository · Issues · PyPI
An MCP server and client library for aiohttp, designed for remote MCP over HTTP across multiple processes and servers.
Use it to expose your application's operations and data to assistants: search a catalog, read a document, or request a deployment. You declare async Python handlers and Pydantic argument models. The library publishes tool, resource, and prompt descriptions, validates calls, and handles MCP messages and streams. It supports five protocol revisions from the same handler declarations, and is optimized for low-overhead HTTP and stdio operation. See performance for reproducible measurements and methodology.
Shared state (optional)
Registry uses in-memory sessions and events by default, which is suitable for
tests and one process. For multiple workers, give every worker the same
SessionStore and Hub: SQLite for workers on one machine, Redis or
PostgreSQL across machines. The backend owns persistence; handlers use
Exchange (ex.session, ex.ask, progress) without knowing which backend is
in use.
For a local multi-process setup:
from aiohttp import web
from aiohttp_tiny_mcp import Registry
from aiohttp_tiny_mcp.sqlite import SqliteHub, SqliteSessionStore, SqliteStorage
storage = SqliteStorage("mcp.sqlite")
registry = Registry(
"service", "1.0", hub=SqliteHub(storage), session_store=SqliteSessionStore(storage)
)
app = web.Application()
# Open the file for the application's lifetime and sweep expired rows.
app.cleanup_ctx.append(storage.cleanup_ctx)
For Redis/PostgreSQL setup, backend parameters, cleanup, and deployment constraints, see stores and hubs.
Start a server
Python 3.10+ is required. Runtime dependencies are aiohttp and pydantic.
pip install aiohttp-tiny-mcp
For a first runnable server and client, follow the quickstart.
The example below adds a resource and a tool that asks for confirmation. Save
it as server.py. The deployment result is illustrative; replace it with your
application's operation.
from aiohttp import web
from pydantic import BaseModel
from aiohttp_tiny_mcp import (
Endpoint,
Exchange,
Registry,
elicit,
)
registry = Registry("demo", "0.1.0")
class Nothing(BaseModel):
pass
class Deploy(BaseModel):
service: str
@registry.resource("config://app", mime_type="application/json")
async def config(args: Nothing) -> dict:
"""Application configuration."""
return {"debug": False}
@registry.tool
async def deploy(args: Deploy, ex: Exchange) -> str:
"""Deploy a service, once somebody agrees to it."""
agreed = await ex.ask("confirm", elicit(f"Deploy {args.service}?"))
if not agreed.accepted:
return f"stopped at {agreed.action}"
return f"deployed {args.service}"
app = Endpoint(registry).app("/mcp")
if __name__ == "__main__":
web.run_app(app, host="127.0.0.1", port=8080)
Run it locally:
python server.py
To try it without a client, mount the console beside the endpoint:
from aiohttp_tiny_mcp.console import Console
Console("/mcp", title="Demo").setup(app, "/console")
Open http://127.0.0.1:8080/console. It speaks the protocol itself on any of
the five revisions, builds a form from each tool's schema, answers the
questions a handler asks, and shows every message either way. Three files from
this package, no build step and no second process.
An MCP host that supports Streamable HTTP can connect to
http://127.0.0.1:8080/mcp. In an existing aiohttp service, use
Endpoint(registry).setup(app, "/mcp"). For a local subprocess transport,
run_stdio(registry) serves the same declarations.
The Deploy model becomes the tool's input schema; the function name and
docstring become its name and description. ex: Exchange is supplied by the
library, so the caller only supplies service. ex.ask requests a decision
from the client. Put irreversible work after the final question: some revisions
restart the handler when the answer arrives. Python locals are not persisted
automatically. See Asking the user.
Call it from Python
The bundled Client is useful for integration tests or an application that
connects to MCP servers. The following runs inside an async function with url
set to your endpoint URL. Its callback automatically accepts the question;
in an interactive application, collect the user's answer there.
from aiohttp_tiny_mcp import Client, elicit_accept
from aiohttp_tiny_mcp.protocol.selection import AdapterSet
async def answer(request):
return elicit_accept({"ok": True})
adapter = AdapterSet.default().by_version["2025-06-18"]
async with Client(url, adapter, on_ask=answer, log_level="info") as client:
await client.initialize()
result = await client.call_tool("deploy", {"service": "web"})
async for change in client.listen(resources=["config://app"]):
print(change["params"]["uri"])
break
The subscription loop waits for a resource-change event. The server snippet
above does not publish changes; see Notifications
for that part, or omit the loop when testing only the tool call.
StdioClient provides the corresponding client over a subprocess's stdin/stdout.
Performance
The project includes reproducible HTTP and stdio benchmarks against the official SDK. Results depend on Python, hardware, and protocol revision; see the benchmark methodology and full results instead of treating a README number as a guarantee.
Documentation
Start with the documentation overview, then follow:
- Tools, resources, and prompts: what to expose and what the client sees.
- Quickstart: a complete server, launch command, and client call.
- How the server fits together: a conversation across two workers and each object's lifetime.
- Using Exchange: request context, progress, questions, and state.
- Authentication: bearer-token verification and OAuth resource metadata.
- Stores and hubs: shared backend contracts and deployment requirements.
The server supports 2026-07-28, 2025-11-25, 2025-06-18, 2025-03-26
and 2024-11-05.
Delivery mechanisms and client support differ; see the
compatibility table and
implementation coverage.
Documentation examples are checked by the test suite. From a source checkout:
uv run pytest docs README.md
uv run --group docs sphinx-build -W -b html docs docs/_build
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 aiohttp_tiny_mcp-0.2.2.tar.gz.
File metadata
- Download URL: aiohttp_tiny_mcp-0.2.2.tar.gz
- Upload date:
- Size: 84.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf95f6c344eaca3ccc311d316e368d52ee4e2bdbce25c3fbc87495e1dcdce2e4
|
|
| MD5 |
7c93e9888ac87be44058c40a133c71bd
|
|
| BLAKE2b-256 |
9f52d0ac26cf7b44666f9a516ee0bfc1e9a9b62e6f14cf5fb108df062fb49bb1
|
Provenance
The following attestation bundles were made for aiohttp_tiny_mcp-0.2.2.tar.gz:
Publisher:
publish.yml on mosquito/aiohttp-tiny-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiohttp_tiny_mcp-0.2.2.tar.gz -
Subject digest:
bf95f6c344eaca3ccc311d316e368d52ee4e2bdbce25c3fbc87495e1dcdce2e4 - Sigstore transparency entry: 2869314452
- Sigstore integration time:
-
Permalink:
mosquito/aiohttp-tiny-mcp@4941ba4c6dd48c0cda9c2c836cc529e3a1427d96 -
Branch / Tag:
refs/tags/0.2.2 - Owner: https://github.com/mosquito
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4941ba4c6dd48c0cda9c2c836cc529e3a1427d96 -
Trigger Event:
release
-
Statement type:
File details
Details for the file aiohttp_tiny_mcp-0.2.2-py3-none-any.whl.
File metadata
- Download URL: aiohttp_tiny_mcp-0.2.2-py3-none-any.whl
- Upload date:
- Size: 105.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0666d627cc3775636d6459983a22a964e1ec931a84720a0f97dee698907a1cf
|
|
| MD5 |
89bd3553fee724a19e98865b7b535ab4
|
|
| BLAKE2b-256 |
48a1e3d7af2cd11ae60684a4aa9958309e6265b9b20529e9b0d0fb9609e43321
|
Provenance
The following attestation bundles were made for aiohttp_tiny_mcp-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on mosquito/aiohttp-tiny-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiohttp_tiny_mcp-0.2.2-py3-none-any.whl -
Subject digest:
b0666d627cc3775636d6459983a22a964e1ec931a84720a0f97dee698907a1cf - Sigstore transparency entry: 2869314481
- Sigstore integration time:
-
Permalink:
mosquito/aiohttp-tiny-mcp@4941ba4c6dd48c0cda9c2c836cc529e3a1427d96 -
Branch / Tag:
refs/tags/0.2.2 - Owner: https://github.com/mosquito
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4941ba4c6dd48c0cda9c2c836cc529e3a1427d96 -
Trigger Event:
release
-
Statement type: