Skip to main content
Glama
ews-gate

ews-gate

README.md
# ews-gate

One MCP URL for every Wick denizen's Exchange mailbox. Each caller reaches only their own.

Built on [viartemev/outlook-ews-mcp](https://github.com/viartemev/outlook-ews-mcp) (MIT), pinned by commit
in the Dockerfile and used as a library, not forked:

- **Identity:** the caller's bearer token is hashed and matched to one `[[denizen]]` in `gate.toml`.
  The config holds only sha256 hashes, never tokens or passwords.
- **Isolation:** one upstream MCP server object per denizen in one process: their own Exchange client
  and NTLM login, their own concurrency gate, MCP sessions and attachment root. No impersonation role;
  Exchange itself enforces what each login may see. A session id from one denizen 404s for another.
- **Attachments as bytes:** upstream's tools take server-side paths, which a remote caller can't use and
  which would let one denizen attach another's files. Every path argument becomes
  `{filename, content_base64}` (send, reply, forward, drafts, add_attachment), and `get_attachment` returns
  bytes. The gate refuses to start if any tool still takes a path.
- **Lockout guard:** one rejected login closes the gate for that denizen until restart, so a stale password
  costs AD one failed attempt, not one per tool call. Other denizens are unaffected.
- **Cost:** ~80 MiB for the whole gate (measured with 2 denizens), not ~80 MiB per denizen.

## Run
    ews-gate token            # prints {"token": ..., "token_sha256": ...}; token to the denizen, hash to gate.toml
    EWS_GATE_CONFIG=/etc/ews-gate/gate.toml ews-gate    # serves /mcp and /healthz on :8080

Config format: see `ews_gate/config.py`. Passwords come from `password_file` (a mounted secret).

## Test
`tests/e2e_client.py` covers: bad/missing token → 401; tool list and bytes-only schema; mailbox info and folders;
attachment round trip through a draft (byte-identical, filename stripped of `../`); a ghost denizen gets
an auth error and none of the real data; a session hijack across tokens → 404.

## Later
Authelia OIDC: accept Authelia-issued access tokens next to static ones, mapping a claim to a denizen,
and serve OAuth protected-resource metadata so claude.ai and mobile clients can sign in.