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
  1. At a glance
  2. 1. Discovery
  3. 2. Dynamic client registration
  4. 3. Authorize with PKCE
  5. 4. Exchange the code
  6. 5. Refresh

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

PropertyValue
Issuerhttps://api.formitai.com
Protected resourcehttps://api.formitai.com/api/v1/mcp
Scopemcp (the only scope)
Grant typesauthorization_code, refresh_token
PKCERequired, S256 only
Client authenticationnone (public clients, no client secret)
Access token lifetime1 hour
Refresh token lifetime30 days, rotated on every use
Authorization code lifetime10 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.

EndpointURL
Protected resource metadatahttps://api.formitai.com/.well-known/oauth-protected-resource (also served at /.well-known/oauth-protected-resource/api/v1/mcp)
Authorization server metadatahttps://api.formitai.com/.well-known/oauth-authorization-server
Registrationhttps://api.formitai.com/register
Authorizationhttps://api.formitai.com/authorize
Tokenhttps://api.formitai.com/token
GET /.well-known/oauth-authorization-server
{
  "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.

Node.js
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_VERIFIER

Send 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
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_ID

Ready?

Build your first AI form in minutes.

No credit card. Generate from a prompt, enable follow-ups, and publish a link or embed the same day.