Skip to main content

MCP client built on top of aiohttp

Project description

aiohttp-mcp-client

CI PyPI Python License: MIT

MCP (Model Context Protocol) client built on top of aiohttp. Supports the Streamable HTTP transport.

Features

  • Async context manager with automatic initialize/terminate lifecycle
  • Supports both JSON and SSE response modes
  • Accepts an external aiohttp.ClientSession for integration into existing apps
  • Typed result objects (frozen dataclasses)
  • Only 1 runtime dependency: aiohttp

Installation

pip install aiohttp-mcp-client

Or with uv:

uv add aiohttp-mcp-client

Quick Start

import asyncio
from aiohttp_mcp_client import MCPClient

async def main():
    async with MCPClient("http://localhost:8080/mcp") as client:
        # List available tools
        tools = await client.list_tools()
        for tool in tools:
            print(f"  {tool.name}: {tool.description}")

        # Call a tool
        result = await client.call_tool("my_tool", {"arg": "value"})
        for block in result.content:
            print(block.text)

asyncio.run(main())

Notification callbacks

The server can send log messages and progress updates during tool calls. You can handle these with async callbacks — set defaults at client level, or override per call:

from aiohttp_mcp_client import MCPClient, LogMessage, Progress

async def on_log(msg: LogMessage) -> None:
    print(f"[{msg.level}] {msg.data}")

async def on_progress(msg: Progress) -> None:
    pct = f"{msg.progress}/{msg.total}" if msg.total else f"{msg.progress}"
    print(f"Progress: {pct}")

async def main():
    # Client-level defaults
    async with MCPClient(url, on_log=on_log, on_progress=on_progress) as client:
        result = await client.call_tool("slow_task", {"steps": 10})

        # Per-call override
        result = await client.call_tool("other_task", on_log=my_other_handler)

Using an existing aiohttp session

import aiohttp
from aiohttp_mcp_client import MCPClient

async def main():
    async with aiohttp.ClientSession() as session:
        async with MCPClient("http://localhost:8080/mcp", session=session) as client:
            tools = await client.list_tools()

API

MCPClient(url, *, session=None, client_info=None, on_log=None, on_progress=None)

  • url — MCP server endpoint URL
  • session — Optional aiohttp.ClientSession (one is created if not provided)
  • client_info — Optional {"name": "...", "version": "..."} dict
  • on_log — Default async callback for LogMessage notifications
  • on_progress — Default async callback for Progress notifications

Methods

Method Description
list_tools() List available tools
call_tool(name, arguments) Call a tool
list_resources() List available resources
read_resource(uri) Read a resource by URI
list_resource_templates() List resource templates
list_prompts() List available prompts
get_prompt(name, arguments) Get a prompt by name
ping() Send a ping

All methods except ping() accept optional on_log and on_progress keyword arguments to override the client-level defaults for that call.

Future Plans

  • Automatic pagination helpers (fetch all pages)

Requirements

  • Python 3.11+
  • aiohttp >= 3.9.0

Development

uv venv && source .venv/bin/activate
uv sync --all-extras
make test
make lint

License

MIT

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

aiohttp_mcp_client-0.0.3.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_mcp_client-0.0.3-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp_mcp_client-0.0.3.tar.gz.

File metadata

  • Download URL: aiohttp_mcp_client-0.0.3.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiohttp_mcp_client-0.0.3.tar.gz
Algorithm Hash digest
SHA256 aebd706a624d8326ecba2909e69c4b11e5eb94b6d508ad3d8202bb101f6dddb5
MD5 e9170db159cd06452299a8cfab4e8820
BLAKE2b-256 ac04f983a0e7587fd55851330f7386a2f725a3c7d84061a6cd5dbbc00b7dd1a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiohttp_mcp_client-0.0.3.tar.gz:

Publisher: publish.yml on kulapard/aiohttp-mcp-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiohttp_mcp_client-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp_mcp_client-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d706bbd9335aa8d74fbc02e71c61867328f9c44dae8be6bfddab46332800e12c
MD5 7dce226d0778e10984f5df0587105b51
BLAKE2b-256 3ae5978870f9f6a6fffa9c924ac328df013711fb3514bf54960ab2b781309487

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiohttp_mcp_client-0.0.3-py3-none-any.whl:

Publisher: publish.yml on kulapard/aiohttp-mcp-client

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