Metadata-Version: 2.5
Name: agentbouncer-signer
Version: 1.0.0
Summary: Official Python SDK for signing AI agent and MCP requests verified by AgentBouncer (RFC 9421 / Web Bot Auth)
Project-URL: Homepage, https://agentbouncer.io
Project-URL: Repository, https://github.com/agentbouncer/agentbouncer-python
Project-URL: Issues, https://github.com/agentbouncer/agentbouncer-python/issues
Author-email: AgentBouncer <support@agentbouncer.io>
License-Expression: MIT
License-File: LICENSE
Keywords: agentbouncer,ai-agent,http-message-signatures,mcp,rfc9421,rfc9530,web-bot-auth
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security :: Cryptography
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: cryptography>=42.0.0
Provides-Extra: dev
Requires-Dist: httpx>=0.27.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: requests>=2.31.0; extra == 'dev'
Provides-Extra: httpx
Requires-Dist: httpx>=0.25.0; extra == 'httpx'
Provides-Extra: requests
Requires-Dist: requests>=2.31.0; extra == 'requests'
Description-Content-Type: text/markdown

# agentbouncer-signer

Official Python request signer for signing AI agent and MCP HTTP requests protected by [AgentBouncer](https://agentbouncer.io).

Implements **RFC 9421** (HTTP Message Signatures with the `web-bot-auth` profile) and **RFC 9530** (`Content-Digest`), fully compatible with `@agentbouncer/sdk` on the server side.

## Installation

```bash
pip install agentbouncer-signer
```

Optional HTTP client extras:

```bash
pip install "agentbouncer-signer[httpx]"
pip install "agentbouncer-signer[requests]"
```

## Quick Start

### 1. With the Official Python MCP SDK (`httpx`)

```python
import json
import os
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
from agentbouncer_signer import AgentBouncerSigner

signer = AgentBouncerSigner(
    private_jwk=json.loads(os.environ["AGENT_PRIVATE_JWK"]),
    signature_agent="https://agent.example.com",
)

async def main():
    async with streamablehttp_client(
        "https://mcp.example.com/mcp",
        auth=signer.httpx_auth(access_token=os.environ.get("USER_OAUTH_TOKEN")),
    ) as (read_stream, write_stream, _):
        async with ClientSession(read_stream, write_stream) as session:
            await session.initialize()
            tools = await session.list_tools()
            print(tools)
```

### 2. With `httpx` (Async or Sync)

```python
import httpx
from agentbouncer_signer import AgentBouncerSigner

signer = AgentBouncerSigner(
    private_jwk=PRIVATE_JWK,
    signature_agent="https://agent.example.com",
)

async with httpx.AsyncClient(auth=signer.httpx_auth()) as client:
    res = await client.post("https://api.example.com/v1/orders", json={"sku": "pro-plan"})
    res.raise_for_status()
```

### 3. With `requests`

```python
import requests
from agentbouncer_signer import AgentBouncerSigner

signer = AgentBouncerSigner(
    private_jwk=PRIVATE_JWK,
    signature_agent="https://agent.example.com",
)

res = requests.post(
    "https://api.example.com/v1/orders",
    json={"sku": "pro-plan"},
    auth=signer.requests_auth(),
)
```

### 4. Framework-agnostic (`sign` / `sign_json`)

```python
from agentbouncer_signer import AgentBouncerSigner

signer = AgentBouncerSigner(
    private_jwk=PRIVATE_JWK,
    key_id="proj-key-1",  # optional if "kid" is inside private_jwk
    signature_agent="https://agent.example.com",
    expires_in_ms=60_000,
)

signed = signer.sign_json(
    url="https://mcp.example.com/mcp",
    method="POST",
    json_data={"jsonrpc": "2.0", "id": 1, "method": "tools/list"},
    access_token="optional-user-oauth-jwt",
)

# signed.headers -> dict with Signature, Signature-Input, Signature-Agent, Content-Digest, Content-Type
# signed.body    -> exact UTF-8 bytes matching Content-Digest
```

## Generating an Ed25519 Keypair (for local testing)

```python
from agentbouncer_signer import generate_ed25519_jwk_pair

private_jwk, public_jwk = generate_ed25519_jwk_pair(kid="my-agent-key-1")
```

## License

MIT