The Opportunity Zone MCP server uses OAuth 2.0 Authorization Code flow with PKCE (Proof Key for Code Exchange) for secure authentication. This flow is designed to work with both confidential and public clients.
First, you need to register your application in the developer dashboard.
POST https://oz-mcp.vercel.app/api/oauth/register
Content-Type: application/json
{
"client_name": "My Application",
"redirect_uris": [
"https://yourapp.com/callback",
"http://localhost:3000/callback"
]
}For enhanced security, especially for public clients, generate PKCE parameters.
import crypto from 'crypto';
// Generate code verifier
const codeVerifier = crypto.randomBytes(32).toString('base64url');
// Generate code challenge
const codeChallenge = crypto
.createHash('sha256')
.update(codeVerifier)
.digest('base64url');
// Store codeVerifier for later use
localStorage.setItem('code_verifier', codeVerifier);Redirect the user to the authorization endpoint with the required parameters.
https://oz-mcp.vercel.app/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=https%3A%2F%2Fyourapp.com%2Fcallback&response_type=code&scope=api%3Aread&state=random_state_value&code_challenge=CODE_CHALLENGE&code_challenge_method=S256
After the user authorizes your application, they'll be redirected back to your redirect URI.
https://yourapp.com/callback?code=AUTHORIZATION_CODE&state=random_state_value
https://yourapp.com/callback?error=access_denied&error_description=User+denied+authorization&state=random_state_value
Exchange the authorization code for an access token.
POST https://oz-mcp.vercel.app/api/oauth/token Content-Type: application/x-www-form-urlencoded grant_type=authorization_code &code=AUTHORIZATION_CODE &redirect_uri=https%3A%2F%2Fyourapp.com%2Fcallback &client_id=YOUR_CLIENT_ID &client_secret=YOUR_CLIENT_SECRET &code_verifier=CODE_VERIFIER
{
"access_token": "your_access_token_here",
"token_type": "Bearer",
"expires_in": 31536000
}Use the access token to make authenticated requests to the MCP server.
POST https://oz-mcp.vercel.app/api/mcp
Authorization: Bearer your_access_token_here
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "check_opportunity_zone",
"arguments": {
"latitude": "38.8977",
"longitude": "-77.0365"
}
}
}