Overview
MCP Blacksmith auto-detects authentication requirements from your OpenAPI specification’ssecuritySchemes and generates the appropriate handlers. You only need to provide credentials in the .env file.
Each operation is mapped to its required authentication scheme via the Security Requirement object. The server automatically injects the correct credentials into every request.
Supported authentication types
API Key
Used when the API requires a key passed as a header, query parameter, or cookie..env
X-API-Key header, the server automatically sends:
Bearer Token
Used for APIs that accept a static token in theAuthorization header.
.env
Authorization: Bearer your-bearer-token with each request.
HTTP Basic
Used for username/password authentication..env
Authorization: Basic <encoded>.
OAuth 2.0
Used for APIs requiring OAuth2 flows (Authorization Code, Client Credentials, Password)..env
- On first run, the server opens your browser for authorization
- You authorize the application on the API provider’s consent page
- The server receives the authorization code via a local callback server
- Tokens are exchanged and saved to
oauth2_tokens.json - On subsequent runs, saved tokens are reused
- Expired tokens are automatically refreshed
Delete
oauth2_tokens.json to force re-authorization if your tokens become invalid.8080 by default. Change OAUTH2_CALLBACK_PORT in .env if needed — make sure the matching redirect URI (http://localhost:<port>/callback) is registered in your OAuth provider’s developer console.
Flow selection
When an OpenAPI specification defines multiple OAuth2 flows on the same security scheme, the generator picks a single flow based on security strength:- Authorization Code — most secure; requires user authorization via browser redirect
- Client Credentials — server-to-server; no user interaction
- Device Authorization — for headless/CLI devices (OAS 3.2+)
- Password — legacy; sends credentials directly
- Implicit — deprecated in OAuth 2.1; least secure
.env and authentication class reflect only the selected flow. For example, a specification offering both authorizationCode and implicit flows will generate an Authorization Code handler — the implicit flow is discarded.
If you need a different flow than the one selected, you can override the authentication configuration in the generation dashboard before generating your server.
OpenID Connect (OIDC)
Extends OAuth2 with ID token validation and automatic discovery..env
- Automatic discovery from the OIDC Discovery endpoint
- ID token validation
- Tokens saved to
oidc_tokens.json
JWT Bearer
Used for APIs that require dynamically signed JSON Web Tokens — such as GitHub Apps, Google service accounts, and Apple APIs. Detected when the OpenAPI spec declaresbearerFormat: JWT on an HTTP Bearer scheme.
.env
JWT_PRIVATE_KEY accepts either a path to a .pem file (relative to the server directory or absolute) or an inline PEM key with newlines encoded as \n.
How it works:
- The server reads the private key and issuer ID from
.env - Before each API request, a short-lived JWT is signed locally (RS256 by default)
- The JWT is sent as
Authorization: Bearer <signed-jwt> - Tokens are cached in memory and regenerated when near expiry (30-second buffer)
Token exchange variant
Some APIs (e.g. Google) require an additional step: the signed JWT is exchanged at a token endpoint for an access token. SetJWT_TOKEN_URL to enable this:
.env
JWT_TOKEN_URL is set, the server POSTs the signed JWT to that endpoint and uses the returned access token instead.
Mutual TLS (mTLS)
Used for APIs requiring client certificate authentication. See mutualTLS in OAS 3.1 for specification details..env
Per-operation authentication
Not every operation uses the same authentication. The generated server maps each operation to its required schemes:- Outer list = OR — any one of these options works
- Inner list = AND — all schemes in this group are required together
Security best practices
- Store credentials in the
.envfile, not in code - Use the minimum required scopes for OAuth2/OIDC
- Replace API keys and tokens periodically
- For multi-tenant deployments, add proper isolation and credentials management — or let us handle it with MCP Armory