Skip to main content

MCP (Model Context Protocol) server for HawkAPI — auto-exports routes as agent tools

Project description

hawkapi-mcp

MCP (Model Context Protocol) server for HawkAPI. Auto-exports every route as an agent tool — any MCP-compatible client can call your API.

Install

pip install hawkapi-mcp

Quickstart

from hawkapi import HawkAPI
from hawkapi.responses import JSONResponse
from hawkapi_mcp import mount_mcp

app = HawkAPI()

@app.get("/users/{user_id:int}")
async def get_user(user_id: int) -> JSONResponse:
    return JSONResponse({"id": user_id, "name": "Alice"})

@app.post("/items")
async def create_item(body: dict) -> JSONResponse:
    return JSONResponse({"created": body})

mount_mcp(app)  # serves POST /mcp

Point any MCP-compatible client at http://your-host/mcp. Every HawkAPI route becomes a tool — its operationId is the tool name, the OpenAPI schema becomes the input schema.

Tool naming

Route definition Generated tool name
@app.get("/users/{id}", operation_id="get_user") get_user
@app.get("/users/{id}") (no operation_id) get_users_id

Tool input schema

The decorator combines path / query / header parameters and the JSON request body into a single object schema. Parameter names are namespaced so they cannot collide:

Source Schema key
Path parameter path.<name>
Query parameter query.<name>
Header parameter header.<name>
Cookie parameter cookie.<name>
JSON body body

tools/call example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "get_user",
    "arguments": {"path.user_id": "42"}
  }
}

The tool result has the response body in content[0].text and the raw HTTP status / headers in structuredContent. isError is true for any 4xx/5xx response.

Filtering tools

mount_mcp(app, include_only={"get_user", "create_item"})
mount_mcp(app, exclude={"internal_admin_route"})

Supported JSON-RPC methods

  • initialize — handshake. Returns the MCP protocol version, server info, and tool capability.
  • ping — keepalive.
  • tools/list — return the tool catalog.
  • tools/call — invoke a tool. Returns response body + HTTP status.
  • notifications/initialized — accepted, no response.

The endpoint accepts both single JSON-RPC objects and batches.

Auth

hawkapi-mcp does not define its own auth layer — wire your HawkAPI middleware (HTTPBearer, OAuth2, API key) on the MCP route just like any other path. Header arguments forwarded by the client land in the request before middleware runs.

Development

git clone https://github.com/ashimov/hawkapi-mcp.git
cd hawkapi-mcp
uv sync --extra dev
uv run pytest -q
uv run ruff check . && uv run ruff format --check .
uv run pyright src/

Specification

Implements a subset of the Model Context Protocol sufficient to advertise and invoke tools. Streamable HTTP transport only — stdio is out of scope (deploy your app behind any ASGI server and the agent connects to the /mcp URL).

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

hawkapi_mcp-0.2.0.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

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

hawkapi_mcp-0.2.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file hawkapi_mcp-0.2.0.tar.gz.

File metadata

  • Download URL: hawkapi_mcp-0.2.0.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hawkapi_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 148fc4390e8cb0ddfd381bd873a0695f634b488dd45b1b61ecbbbe27eba86ab8
MD5 2f53c88d4d3e986fa769109adcd29d89
BLAKE2b-256 6c914c7a0d0ebf9a3d42828f1429d588f18fa3e4558d7bbb373ce9735469ec80

See more details on using hashes here.

Provenance

The following attestation bundles were made for hawkapi_mcp-0.2.0.tar.gz:

Publisher: release.yml on ashimov/hawkapi-mcp

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

File details

Details for the file hawkapi_mcp-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: hawkapi_mcp-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hawkapi_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 79743f72ab9c1b11aab7ecf7b0f4133be7dd5d96c007e3e697d3996c388d64e5
MD5 52ecc6975389b19dc8fa7da554a151d2
BLAKE2b-256 3b192d5c60730b9d9b553a2817e401a46dbf253e309a4fc7490a592722cc90ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for hawkapi_mcp-0.2.0-py3-none-any.whl:

Publisher: release.yml on ashimov/hawkapi-mcp

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