Skip to content

Authentication

Overview

swag2mcp supports 9 authentication methods for working with APIs that require authorization. You configure it once in the config file — after that, every API call through invoke automatically includes the right tokens and headers.

Where to configure

Authentication is set at the spec level in swag2mcp.yaml:

yaml
specs:
  - domain: jokes
    llm_title: Dad Joke API
    base_url: https://icanhazdadjoke.com
    collections:
      - llm_title: Jokes
        location: https://raw.githubusercontent.com/mmadfox/swag2mcp/main/specs/dadjoke.yaml
    auth:
      type: bearer
      config:
        token: "my-token"

How it works

  • You specify the auth type and parameters in the config
  • swag2mcp automatically applies them to every request when you call invoke
  • You don't need to request a token before calling an API — it happens automatically
  • If a token expires (OAuth2, Script), swag2mcp refreshes it on its own

Environment variables

Sensitive data (tokens, passwords, keys) can be stored in environment variables using $(VAR_NAME) syntax:

yaml
auth:
  type: bearer
  config:
    token: "$(MY_API_TOKEN)"

swag2mcp substitutes the value of MY_API_TOKEN at startup.

MCP auth tool

The LLM agent can retrieve a token or headers through the auth MCP tool — for example, to build a curl command or show the user.

In production, this tool should be disabled with --disable-llm-auth (enabled by default) so the LLM never has access to tokens.

Methods

MethodDescriptionBest for
noneNo authenticationPublic APIs
basicHTTP Basic (username + password)Legacy APIs, simple auth
bearerBearer Token (JWT, token)Modern REST APIs
api-keyAPI key in header or query parameterServices with API keys
digestHTTP Digest (username + password)Legacy APIs, more secure than Basic
hmacHMAC-SHA256 signature (Binance-style)Cryptocurrency exchanges
oauth2-ccOAuth2 Client CredentialsServer-to-server, microservices
oauth2-pwdOAuth2 Password GrantApps with user login
scriptExternal script to obtain a tokenAny custom auth scheme