Skip to main content

Complete MCP OAuth Flow

Used to complete OAuth 2.1 Authorization Code flow for an MCP (Model Context Protocol) server. Call this endpoint with the authorization code received from the OAuth callback to exchange it for access and refresh tokens.

API Endpoint

PropertyValue
Request MethodPOST
Request URLhttps://api.seliseblocks.com/tools/{tool_id}/complete-oauth

Request

Request Example

curl -X POST 'https://api.seliseblocks.com/tools/{tool_id}/complete-oauth' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"code": "authorization_code_from_callback",
"state": "state_value_from_initiate",
"project_key": "YOUR_PROJECT_KEY"
}'

Path Parameters

FieldTypeRequiredDescription
tool_idstringYesThe unique identifier of the MCP server tool.

Request Headers

FieldTypeRequiredDescription
acceptstringYesAccepted response format. Use application/json
Content-Typeapplication/jsonYesData type, must be application/json.

Request Body

Request Body Schema

{
"code": "string",
"state": "string",
"project_key": "string"
}

Request Body Parameters

FieldTypeRequiredDescription
codestringYesAuthorization code received from the OAuth callback redirect.
statestringYesState parameter used for CSRF validation (must match the value from initiate-oauth).
project_keystringYesThe project key for your project.
note

OAuth Completion Requirements

  • The authorization code is single-use and expires quickly (typically 5-10 minutes)
  • The state parameter must match the value generated during the initiate-oauth call
  • PKCE code verifier will be automatically used if PKCE was enabled during initiation
  • Both access tokens and refresh tokens will be securely stored after successful exchange
tip

OAuth Flow Completion Process:

  1. User is redirected to your redirect_uri with code and state parameters
  2. Extract the code and state from the URL query parameters
  3. Call this endpoint with the code, state, and project_key
  4. System validates the state parameter for CSRF protection
  5. System exchanges the authorization code for tokens at the OAuth provider
  6. Access token and refresh token are securely stored
  7. MCP server is now fully authenticated and ready for use

The system will:

  • Validate the state parameter matches the stored value
  • Exchange the authorization code for access and refresh tokens
  • Store tokens securely in the MCP server configuration
  • Set token expiration times based on OAuth provider response
  • Enable automatic token refresh when access tokens expire
  • Return success confirmation once authentication is complete

Response

Success Response (200 OK)

Returns an object containing the completion status.

{
"is_success": true,
"item_id": "mcp_server_123",
"detail": "OAuth authentication completed successfully. Access token obtained and stored.",
"error": {}
}

Response Fields

FieldTypeDescription
is_successbooleanIndicates whether the OAuth flow was completed successfully.
item_idstringThe identifier of the MCP server tool.
detailstringSuccess or failure message with additional context.
errorobjectError details if the operation failed (empty if successful).

Error Response (422 Unprocessable Entity)

Returns validation error details when the request body is invalid.

{
"detail": [
{
"loc": [
"body",
"state"
],
"msg": "State parameter does not match. Possible CSRF attack.",
"type": "value_error.csrf"
}
]
}

Error Response Fields

FieldTypeDescription
detailarrayArray of validation error objects.
locarrayLocation of the error in the request (e.g., body field).
msgstringHuman-readable error message.
typestringError type identifier.

Common Error Scenarios

Error TypeDescriptionResolution
Invalid StateState parameter doesn't match stored valueRestart OAuth flow from initiate-oauth endpoint
Expired CodeAuthorization code has expiredRestart OAuth flow to get a new authorization code
Invalid CodeAuthorization code is invalid or already usedEnsure code is correctly extracted from callback URL
Token Exchange FailedOAuth provider rejected the token requestVerify OAuth configuration and client credentials

Error Codes

Status CodeDescriptionResponse Type
200Successful ResponseSuccess
400Bad Request - Invalid OAuth parametersBad Request
401Unauthorized - OAuth provider rejected requestUnauthorized
404Not Found - MCP server tool does not existNot Found
422Validation Error - Invalid request parameters or CSRF validation failedUnprocessable Entity