# Auth.md

MapBulk REST API: `https://api.mapbulk.com`. Remote MCP: `https://api.mapbulk.com/mcp`, using Streamable HTTP. The MapBulk CLI uses the same REST API from your terminal.

## Obtain a credential

The account owner signs in at [MapBulk](https://app.mapbulk.com/) and creates a key in API, MCP & CLI. Scale or Max access is required. Free bonus credits do not grant API, MCP or CLI access. Choose a read-only key for inspecting lists, results and usage; choose read and write for creating, enriching, cancelling, retrying or exporting a list.

For the CLI, download the [verified Python 3.11 wheel](https://mapbulk.com/downloads/mapbulk_mvp-0.1.0-py3-none-any.whl), install it with `python -m pip install "./mapbulk_mvp-0.1.0-py3-none-any.whl[cli]"`, and run `mapbulk --help`. Authenticated commands ask for the key without displaying it; for scripts, inject `MAPBULK_API_KEY` from your secret manager. Installation does not register a new key or grant credits.

For an agent acting for an existing account owner, authorized account software can use the same provisioning endpoint after the owner approves that action. Use its securely stored authenticated account-session access token. A MapBulk API key or connector OAuth token cannot provision other keys.

```http
POST /v1/api-keys HTTP/1.1
Host: api.mapbulk.com
Authorization: Bearer <OWNER_ACCOUNT_SESSION_ACCESS_TOKEN>
Content-Type: application/json

{"name":"Agent read-only","scopes":["read"]}
```

Success is HTTP201 with `id`, `name`, `prefix`, `scopes`, `created_at` and `secret`. Store `secret` immediately in the agent client's secret storage; it is returned once. These API-key permissions are separate from OAuth scopes. Request read and write only with the owner's explicit approval for writes.

If the creation response is lost, do not retry blindly. The owner reviews the existing keys through the account interface or `GET /v1/api-keys` using the same account session; this returns key metadata, not secrets. Revoke an uncertain key before deliberately creating a replacement.

The owner can revoke a key in the account interface or through `DELETE /v1/api-keys/{key_id}` using the authenticated account-session token. Stop using the revoked credential and remove it from the agent's secret storage.

Configure the key in the client's secret storage as an HTTP header:

```text
Authorization: Bearer <MAPBULK_API_KEY>
```

Send the header on each MCP or REST request. Keep credentials out of prompts, shared configuration, logs, URLs, screenshots and exported data. MapBulk API keys cannot create or administer other keys; use the authenticated account interface to manage or revoke them.

## Connection and failures

Use the client's Streamable HTTP implementation and discover the current tools through `tools/list`. The public [server card](https://api.mapbulk.com/mcp/server-card) describes connection settings; it grants no access to account data.

A REST `401` means authentication is missing or invalid, including a revoked key. Stop using that credential and let the owner check or replace it. A REST `403` can mean that plan access or write permission is missing. Do not buy a plan, grant credits or escalate permissions automatically. MCP tool errors expose the upstream API status; a missing bearer header is rejected by the adapter.

## Owner-approved agent registration

Registration is available only when the live [authorization-server metadata](https://api.mapbulk.com/.well-known/oauth-authorization-server/agent-auth) returns an `agent_auth` block advertising `service_auth`. If it returns `404`, registration is disabled: use an owner-issued API key instead. Do not guess other endpoints or treat dashboard login as agent authorization.

The service-auth profile links an agent to an existing human-owned account. It does not create a MapBulk account, grant credits, purchase a plan or accept legal terms. Scale or Max access is required to approve and use the delegation. It is read-only: the agent can inspect lists, results, existing exports and usage, but cannot start, enrich, retry or export a search, change billing or administer keys.

1. Read the [protected-resource metadata](https://api.mapbulk.com/.well-known/oauth-protected-resource/mcp). Use its advertised issuer and the issuer's `identity_endpoint`, `claim_endpoint`, `token_endpoint` and `jwks_uri`; do not send MapBulk credentials to another origin.
2. With the owner's permission, POST JSON to `identity_endpoint` with `type: "service_auth"` and `login_hint` set to the email address of their existing MapBulk account. Store the returned `claim_token` privately. Registration expires after ten minutes. The same flow also accepts `type: "identity_assertion"` with `assertion_type: "verified_email"` and `email`; either way the email counts as verified only after the owner signs in and approves.
3. Present `claim.verification_uri` and the six-digit `claim.user_code` to the human owner. The owner signs in, reviews read-only access and explicitly approves or declines. Never enter the code or approve access on their behalf. The approval page does not return credentials to the browser.
4. POST an URL-encoded request to `token_endpoint` with `grant_type=urn:workos:agent-auth:grant-type:claim` and the private `claim_token`. Respect the returned polling interval (five seconds). `authorization_pending` means wait; `slow_down` means increase the interval. Stop on `access_denied`, `expired_token` or `invalid_grant`.
5. After approval, store the returned `access_token` and `identity_assertion` in client secret storage. Use `Authorization: Bearer <access_token>` for the protected resource. Access tokens last at most five minutes. The assertion lasts thirty days; check its `assertion_expires`, signature, issuer, audience, resource and scope before use.
6. While the assertion is valid, exchange it using `grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer`, `assertion=<identity_assertion>`, `resource=https://api.mapbulk.com/mcp` and `scope=read`. No refresh tokens are issued. Each exchange returns a fresh `identity_assertion` and moves its thirty days forward; store it and discard the old one, which stops working. An agent in regular use therefore keeps read-only access until the owner disconnects it. After assertion expiry, request a fresh human-approved registration.

If a pending ceremony needs to restart, POST JSON to the advertised `claim_endpoint` with the same private `claim_token` and `email`. Use the new `claim_attempt.verification_uri` and code; the old link becomes invalid and the original deadline does not extend.

The owner can revoke a delegation from Account → Agent access, including after a plan downgrade. Signing out of the approving session, deleting the account, losing eligible plan access, revoking the delegation or token expiry prevents further use. A held token must not be treated as offline authority. On `401` stop and ask the owner to reconnect; on `403` do not escalate permissions or purchase access automatically.

To invalidate an individual held token, POST `token=<access_token>` as URL-encoded data to the advertised `revocation_endpoint`. Whole-delegation revocation also invalidates its assertions and other tokens. Do not place tokens, assertions, claim links or codes in prompts, shared logs, screenshots or public URLs.

This profile does not support anonymous provisioning, automatic signup, external identity-provider assertions, IDP trust federation or arbitrary third-party OAuth connector linking. An agent-registration document is not a connector-directory listing or proof that a particular AI client supports this profile.

## Dashboard sign-in

Dashboard sign-in uses the Supabase issuer `https://srgbttgmwljfbncboblu.supabase.co/auth/v1`. Its public [OpenID Connect configuration](https://srgbttgmwljfbncboblu.supabase.co/auth/v1/.well-known/openid-configuration) and [OAuth authorization-server metadata](https://srgbttgmwljfbncboblu.supabase.co/.well-known/oauth-authorization-server/auth/v1) describe that issuer. Dashboard sign-in is separate from the owner-approved agent delegation above.

For bounded search, retry and export instructions, read the [MapBulk skill](https://mapbulk.com/.well-known/agent-skills/mapbulk/SKILL.md). Requests and response schemas are in the [REST OpenAPI document](https://api.mapbulk.com/openapi.json).
