Browse and search developers
MCP server
MCP OAuth 2.1 flow
How FormitAI’s MCP authorization server works: discovery metadata, dynamic client registration, PKCE S256, the mcp scope, and token refresh.
On this page
FormitAI runs an OAuth 2.1 authorization server for the MCP endpoint, following the MCP authorization specification (2025-06-18). Off-the-shelf clients like Claude and Cursor handle all of this for you. Read this page if you are building your own MCP client or debugging a connection.
At a glance
| Property | Value |
|---|---|
| Issuer | https://api.formitai.com |
| Protected resource | https://api.formitai.com/api/v1/mcp |
| Scope | mcp (the only scope) |
| Grant types | authorization_code, refresh_token |
| PKCE | Required, S256 only |
| Client authentication | none (public clients, no client secret) |
| Access token lifetime | 1 hour |
| Refresh token lifetime | 30 days, rotated on every use |
| Authorization code lifetime | 10 minutes, single use |
1. Discovery
An unauthenticated request to the MCP endpoint returns 401 with WWW-Authenticate: Bearer realm="mcp", resource_metadata="https://api.formitai.com/.well-known/oauth-protected-resource". Fetch that document, then the authorization server metadata.
| Endpoint | URL |
|---|---|
| Protected resource metadata | https://api.formitai.com/.well-known/oauth-protected-resource (also served at /.well-known/oauth-protected-resource/api/v1/mcp) |
| Authorization server metadata | https://api.formitai.com/.well-known/oauth-authorization-server |
| Registration | https://api.formitai.com/register |
| Authorization | https://api.formitai.com/authorize |
| Token | https://api.formitai.com/token |
{
"issuer": "https://api.formitai.com",
"authorization_endpoint": "https://api.formitai.com/authorize",
"token_endpoint": "https://api.formitai.com/token",
"registration_endpoint": "https://api.formitai.com/register",
"scopes_supported": ["mcp"],
"response_types_supported": ["code"],
"grant_types_supported": ["authorization_code", "refresh_token"],
"code_challenge_methods_supported": ["S256"],
"token_endpoint_auth_methods_supported": ["none"],
"resource_indicators_supported": true,
"authorization_response_iss_parameter_supported": true
}2. Dynamic client registration
Register with POST /register and a JSON body. redirect_uris is required (1 to 16 entries). Each must be https, a loopback http URL (localhost, 127.0.0.1 or ::1, any port), or a native-app private-use scheme such as cursor://…. URIs with fragments or credentials are rejected. If any URI is rejected, the whole registration fails with invalid_redirect_uri. A successful registration returns 201 with a client_id and no secret.
curl -sS -X POST https://api.formitai.com/register \
-H "Content-Type: application/json" \
-d '{"client_name":"My MCP client","redirect_uris":["http://127.0.0.1:8787/callback"]}'3. Authorize with PKCE
Generate a code_verifier of 43 to 128 characters from A-Z a-z 0-9 . _ ~ - and send its S256 challenge, BASE64URL(SHA256(verifier)). Send the user’s browser to /authorize with response_type=code, client_id, the exact registered redirect_uri, code_challenge, code_challenge_method=S256, state, and optionally resource (the MCP URL). FormitAI sends the user to its Connect MCP screen, where they sign in, pick a workspace and select Allow. The browser then returns to your redirect_uri with code, state and iss.
import { createHash, randomBytes } from 'node:crypto';
const verifier = randomBytes(32).toString('base64url'); // 43 chars
const challenge = createHash('sha256').update(verifier, 'ascii').digest('base64url');
const url = new URL('https://api.formitai.com/authorize');
url.search = new URLSearchParams({
response_type: 'code',
client_id,
redirect_uri: 'http://127.0.0.1:8787/callback',
code_challenge: challenge,
code_challenge_method: 'S256',
state: randomBytes(16).toString('hex'),
resource: 'https://api.formitai.com/api/v1/mcp',
}).toString();
// Open url in the user's browser, then read ?code=…&state=…&iss=… on your callback.The pending authorization and the code each expire after 10 minutes. If the request is invalid after the redirect URI has been checked, the error goes back to your redirect_uri as error and error_description query parameters.
4. Exchange the code
curl -sS -X POST https://api.formitai.com/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d grant_type=authorization_code \
-d code=AUTHORIZATION_CODE \
-d redirect_uri=http://127.0.0.1:8787/callback \
-d client_id=YOUR_CLIENT_ID \
-d code_verifier=YOUR_CODE_VERIFIERSend the access token as Authorization: Bearer <access_token> to the MCP endpoint. The token is bound to the workspace the user picked. Sending an x-formit-workspace header for a different workspace returns 401.
5. Refresh
Before the hour is up, call /token with grant_type=refresh_token, refresh_token and client_id. You get a new access token and a new refresh token, and the old refresh token is revoked. Store the new one every time. Using a revoked refresh token is treated as theft: FormitAI revokes every active refresh token for that client and user, and returns invalid_grant with "Refresh token reuse detected". The user has to authorize again.
curl -sS -X POST https://api.formitai.com/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d grant_type=refresh_token \
-d refresh_token=YOUR_REFRESH_TOKEN \
-d client_id=YOUR_CLIENT_IDRelated
Can't find what you need?