Tools for building Model Context Protocol (MCP) servers on top of aiohttp
Project description
aiohttp-mcp
Tools for building Model Context Protocol (MCP) servers on top of aiohttp.
Features
- Easy integration with aiohttp web applications
- Support for Model Context Protocol (MCP) tools
- Async-first design
- Type hints support
- Debug mode for development
- Flexible routing options
Installation
With uv package manager:
uv add aiohttp-mcp
Or with pip:
pip install aiohttp-mcp
Quick Start
Basic Server Setup
Create a simple MCP server with a custom tool:
import datetime
from zoneinfo import ZoneInfo
from aiohttp import web
from aiohttp_mcp import AiohttpMCP, build_mcp_app
# Initialize MCP
mcp = AiohttpMCP(debug=False)
# Define a tool
@mcp.tool()
def get_time(timezone: str) -> str:
"""Get the current time in the specified timezone."""
tz = ZoneInfo(timezone)
return datetime.datetime.now(tz).isoformat()
# Create and run the application
app = build_mcp_app(mcp, path="/mcp")
web.run_app(app)
Using as a Sub-Application
You can also use aiohttp-mcp as a sub-application in your existing aiohttp server:
from aiohttp import web
from aiohttp_mcp import AiohttpMCP, setup_mcp_subapp
mcp = AiohttpMCP(debug=False)
# Define your tools here
@mcp.tool()
def example_tool(param: str) -> str:
return f"Processed: {param}"
# Create your main application
app = web.Application()
# Add MCP as a sub-application
setup_mcp_subapp(app, mcp, prefix="/mcp")
web.run_app(app)
More Examples
For more examples, check the examples directory.
Development
Setup Development Environment
- Clone the repository:
git clone https://github.com/kulapard/aiohttp-mcp.git
cd aiohttp-mcp
- Create and activate a virtual environment:
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install development dependencies:
uv sync --all-extras
Running Tests
uv run pytest
Requirements
- Python 3.10 or higher
- aiohttp >= 3.9.0, < 4.0.0
- aiohttp-sse >= 2.2.0, < 3.0.0
- anyio >= 4.9.0, < 5.0.0
- mcp >= 1.6.0, < 2.0.0
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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 aiohttp_mcp-0.1.0.tar.gz.
File metadata
- Download URL: aiohttp_mcp-0.1.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
948733717ccd58e669c2948e044119def75e6015b7213e6a55acc1b5c86ea648
|
|
| MD5 |
4602536fe09cc7d8e03c36053c0ca9ca
|
|
| BLAKE2b-256 |
b91d0e3329e5fc39b0d425a9054b27f491705a991c4fe25ab299ca4d00932e14
|
Provenance
The following attestation bundles were made for aiohttp_mcp-0.1.0.tar.gz:
Publisher:
publish.yml on kulapard/aiohttp-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiohttp_mcp-0.1.0.tar.gz -
Subject digest:
948733717ccd58e669c2948e044119def75e6015b7213e6a55acc1b5c86ea648 - Sigstore transparency entry: 195635949
- Sigstore integration time:
-
Permalink:
kulapard/aiohttp-mcp@60cc3208b5ae2222a2e2f5cf6db2db9ca4caa32c -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/kulapard
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@60cc3208b5ae2222a2e2f5cf6db2db9ca4caa32c -
Trigger Event:
release
-
Statement type:
File details
Details for the file aiohttp_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aiohttp_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27388b42d1ed13d8a8f74a5cb89585471a96c6a84ec606e6c181ba6786e3ea3d
|
|
| MD5 |
410be2de7c562459ee97a7e04b5b1a3d
|
|
| BLAKE2b-256 |
1f674044f1e6cd0e44d4e3448ae9eb91034bc7549e88d34f807884fe4262fe91
|
Provenance
The following attestation bundles were made for aiohttp_mcp-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on kulapard/aiohttp-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiohttp_mcp-0.1.0-py3-none-any.whl -
Subject digest:
27388b42d1ed13d8a8f74a5cb89585471a96c6a84ec606e6c181ba6786e3ea3d - Sigstore transparency entry: 195635951
- Sigstore integration time:
-
Permalink:
kulapard/aiohttp-mcp@60cc3208b5ae2222a2e2f5cf6db2db9ca4caa32c -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/kulapard
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@60cc3208b5ae2222a2e2f5cf6db2db9ca4caa32c -
Trigger Event:
release
-
Statement type: