API keys & OAuth
Two mechanisms, one underlying token model. OAuth 2.1 through the gateway for AI assistants; the Bearer key for your code and for tools configured by file.
01The MCP key
Format: mia_ followed by 64 hex characters (256 bits of entropy).
It is stored hashed with SHA-256: the server cannot show it again. A token carries
the identity of a workspace user and a scope. Every call runs as that user.
The MCP key only works on the MCP server. The data API has its own key, created in the workspace preferences.
02Create a key
In the MADATA portal: Mia → MCP tab → Create a key. A key connects an external tool to MADATA without a password or two-factor authentication: treat it as a secret.
The owner and the MADATA administrators of the workspace. Linking an assistant over OAuth needs no key: any user with access to Mia can do it (see below).
- Name
- Free text: helps you find the key in the list.
- Duration
- 1 month, 3 months, 6 months, 1 year, or permanent.
- Scope
- Read-only (default) or Read + write.
- Act on behalf of
- The workspace user whose permissions the key carries (the workspace owner by default).
The key is shown only once, at creation. Copy it immediately; it will never be readable again.
03Use the key
curl -s https://<workspace>.madata.app/mia/mcp \
-H "Authorization: Bearer mia_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call",
"params":{"name":"get_kpi","arguments":{"period":"month"}}}'
A key is always used on the address of its workspace,
https://<workspace>.madata.app/mia/mcp, never on
mcp.madata.africa.
04Scopes
| Scope | Visible tools |
|---|---|
read_only | Only the tools that do not write. |
full_access | All tools, read and write. |
custom | Only the tools of an allow-list, defined on the workspace. Without a list, no tool. |
The scope is further clamped by the user's access mode:
a full_access connection held by a "Read only" user cannot write. It
can be changed at any time from the Connections and keys card of the
portal.
05Revoke / delete
From the Connections and keys card: revoke disables
the key without removing it (the history stays); delete erases it
for good. A revoked key returns 401 on the next call. For a connection
made through the gateway, either one cuts the link at once.
06OAuth 2.1 through the gateway
Claude, ChatGPT, Le Chat and Claude Code connect to
https://mcp.madata.africa/mcp over OAuth 2.1 with PKCE
S256. No client ID to prepare: they register themselves.
| Endpoint (on mcp.madata.africa) | Role |
|---|---|
GET /.well-known/oauth-protected-resource | RFC 9728: resource: "https://mcp.madata.africa/mcp", scopes_supported: ["mcp"]. |
GET /.well-known/oauth-authorization-server | RFC 8414: endpoints, authorization_code + refresh_token, S256, iss in the response (RFC 9207). |
POST /oauth/register | Dynamic client registration (RFC 7591). Public client, no secret. Client metadata documents (CIMD) are also accepted for ChatGPT and Claude. |
GET /oauth/authorize | Checks the request then redirects to the MADATA authorization page. A request is valid for 15 minutes. |
POST /oauth/token | Exchanges authorization_code (PKCE S256 mandatory, single-use code valid for 5 minutes) or refresh_token. |
On the MADATA page, the user signs in (email and password, Google or Microsoft, two-factor code if enabled), picks the workspace if they have several, then authorizes. Their password stays with MADATA: the assistant only receives a revocable access. Any user with access to Mia can link an assistant, with their own permissions.
The token handed over is an MCP key of the workspace: it shows up in Connections and keys under the assistant's name, for example "ChatGPT (mcp.madata.africa)", as read + write clamped by the user's access mode. The gateway only keeps its hash.
- Lifetime: the access token is valid for 30 days. Refreshing hands over a new key and deletes the old one, with no user action.
- Scope kept: each refresh rereads the state of the key in the workspace. A restriction is kept, a disabled key cuts the link.
- Replayed token: a refresh token already replaced and presented again more than 60 seconds later cuts the link.
- Verified name: the ChatGPT or Claude name and logo only show if the return address really is theirs. Otherwise the page says "(non vérifié)".
- Protected sign-in: 10 failures per address in 15 minutes lock the sign-in; a request allows at most 5 wrong two-factor codes.
07OAuth 2.1 on the workspace
Each workspace also keeps its own authorization server, for a client that targets
https://<workspace>.madata.app/mia/mcp directly:
| Endpoint (on the workspace) | Role |
|---|---|
GET /.well-known/oauth-protected-resource | RFC 9728: resource metadata. |
GET /.well-known/oauth-authorization-server | RFC 8414: endpoints, authorization_code + refresh_token, S256. |
POST /mia/mcp/oauth/register | Dynamic registration (RFC 7591): returns a client_id mcp_…. 64 KB and 30 requests per minute at most. |
GET /mia/mcp/oauth/authorize | Consent page. Workspace sign-in required. |
POST /mia/mcp/oauth/authorize/decision | Issues a single-use authorization code, CSRF-protected. |
POST /mia/mcp/oauth/token | Exchanges authorization_code (PKCE S256 mandatory, plain rejected) or refresh_token. |
The access token is valid for 30 days and a refresh_token
(mrt_…) renews it silently. Presented again more than 60 seconds after
its rotation, a refresh token disables the key. Reconnecting the same
client_id disables that client's previous key.
For claude.ai,
claude.com, console.anthropic.com,
chatgpt.com, chat.openai.com,
platform.openai.com, the client is re-registered on the fly if
its cached client_id no longer exists server-side (database
re-created). PKCE and consent still protect the flow.
08Lifecycle & security
- Every call runs with the permissions of the user holding the token, never more.
- The token is stored hashed: it is never shown again.
- Expiry is checked on every call; an expired token returns
401. - An OAuth token stops working if the user loses access to Mia.
- The
mrt_prefix of the refresh token makes it unusable as an access key. - Every
tools/callis logged (see Logging).