Metadata-Version: 2.5
Name: mcp-account-kit
Version: 0.1.0
Summary: Provider-neutral runtime kit for cookie-handover MCP account servers
Project-URL: Homepage, https://github.com/benjamin-di/mcp-account-kit
Project-URL: Issues, https://github.com/benjamin-di/mcp-account-kit/issues
Author: benjamin-di
License-Expression: MIT
License-File: LICENSE
Keywords: auth,fastmcp,mcp,model-context-protocol,sessions
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: cryptography>=44
Requires-Dist: fastmcp>=3
Provides-Extra: login
Requires-Dist: signin-window<0.18,>=0.17.1; extra == 'login'
Requires-Dist: uvicorn>=0.30; extra == 'login'
Provides-Extra: login-base
Requires-Dist: patchright==1.61.2; extra == 'login-base'
Requires-Dist: signin-window<0.18,>=0.17.1; extra == 'login-base'
Requires-Dist: uvicorn>=0.30; extra == 'login-base'
Provides-Extra: web
Requires-Dist: account-connections<2,>=1.7.2; extra == 'web'
Requires-Dist: signin-window[oidc]<0.18,>=0.17.1; extra == 'web'
Requires-Dist: starlette>=0.40; extra == 'web'
Description-Content-Type: text/markdown

# mcp-account-kit

Provider-neutral runtime kit for cookie-handover MCP account servers built on
[FastMCP](https://github.com/jlowin/fastmcp),
[signin-window](https://github.com/benjamin-di/signin-window), and
[account-connections](https://github.com/benjamin-di/account-connections).

## Installation

Base runtime (`cryptography`, `fastmcp`):

```bash
pip install mcp-account-kit
```

Optional extras:

- `mcp-account-kit[web]` — OIDC-guarded personal Connections UI and `BrowserRoutes` ASGI middleware (`signin-window[oidc]`, `account-connections`, `starlette`).
- `mcp-account-kit[login]` — Managed-policy hosted browser sign-in app (`signin-window`, `uvicorn`).
- `mcp-account-kit[login-base]` — Hosted browser sign-in runtime including pinned `patchright` (used to build `mcp-login-base`).

## Modules

| Module | Purpose |
| --- | --- |
| `mcp_account_kit.auth` | Comma-separated bearer token parsing, minimum length enforcement, and FastMCP `StaticTokenVerifier` construction. |
| `mcp_account_kit.fsio` | Crash-safe `0600` atomic file writes, `O_NOFOLLOW` private reads, cross-process file locks, and stat keys. |
| `mcp_account_kit.errors` | Closed public error taxonomy (`ErrorCatalog`, `PublicErrorAction`, `ServiceError`) that never leaks `log_detail` or raw exceptions. |
| `mcp_account_kit.state` | Persistent per-account UTC daily request budgets, pushback pause breaker with `Retry-After`, and unresolved error tracking. |
| `mcp_account_kit.session` | AES-256-GCM sealed per-person cookie storage bound to `person_id` via AAD, domain allowlists, monotonic generations, and disconnect barriers. |
| `mcp_account_kit.build_identity` | Embedded `build_identity.json` loader, fork-safe log context, and CLI embedder (`python -m mcp_account_kit.build_identity`). |
| `mcp_account_kit.logs` | Stderr JSONL formatter, `person_tag`, `SafeParser`, and FastMCP `ToolCallLog` middleware. |
| `mcp_account_kit.connections` | (`[web]`) OIDC-guarded personal-only Connections UI (`PersonalConnections`) and `BrowserRoutes` ASGI middleware with `Host` validation. |
| `mcp_account_kit.login` | (`[login]`) Managed Chrome policy check (`chrome_policy_installed`, `PolicyMissing`) and `serve_login_app`. |
| `mcp_account_kit.testing` | Reusable pytest assertions for self-describing error catalogs, root JSON Schema combinators, and MCP tool annotations. |

## Quick Example

```python
from pathlib import Path
from mcp_account_kit.errors import ErrorCatalog
from mcp_account_kit.session import LocalSession
from mcp_account_kit.state import StateStore

CATALOG = ErrorCatalog(
    next_step={
        "invalid_argument": "Fix the arguments and call again.",
        "rate_limited": "Wait until the pause reported by status ends.",
        "budget_exhausted": "Today's request budget is spent. It resets at 00:00 UTC.",
    },
    retryable=frozenset(),
    action={
        "invalid_argument": "none",
        "rate_limited": "retry_later",
        "budget_exhausted": "retry_later",
    },
)

store = StateStore(
    Path("/tmp/example-state"),
    budget=200,
    error_factory=CATALOG.error,
    valid_codes=CATALOG.codes,
    service_name="Example",
)

session = LocalSession(
    Path("/tmp/example-state/session.bin"),
    seal_magic=b"EXMP1",
    aad_prefix="example-mcp:session",
    allowed_domains=("example.com",),
    person_id="user-1",
    session_key=b"\x00" * 32,
)
```

## Hosted Login Base Image (`mcp-login-base`)

`Dockerfile.login-base` publishes `ghcr.io/benjamin-di/mcp-login-base` with pinned Google Chrome, noVNC (`/opt/novnc`), `Xvfb`, `x11vnc`, `dumb-init`, `patchright`, `signin-window` (with managed Chrome policy pre-installed), and `mcp-account-kit` running as non-root `USER 1000:1000`.

Downstream login services can build a thin `Dockerfile.login` on top:

```dockerfile
# syntax=docker/dockerfile:1.7
FROM ghcr.io/benjamin-di/mcp-login-base:<version>@sha256:<digest>

ENV EXAMPLE_LOGIN_NOVNC=/opt/novnc
USER root
WORKDIR /app
COPY pyproject.toml README.md LICENSE ./
COPY src ./src
RUN --mount=type=cache,target=/root/.cache/uv \
    UV_CACHE_DIR=/root/.cache/uv uv pip install --system --compile-bytecode --no-deps . && rm -rf /app/src
USER 1000:1000
CMD ["python", "-m", "example_login"]
```

## Development

```bash
make bootstrap
make check
```
