README
¶
mcp-oauth-cli
mcp-oauth-cli is a Go CLI for acting as an MCP client against protected Streamable HTTP MCP servers, authenticating with OAuth, saving inspection state, and testing token refresh/rotation behavior.
It uses:
github.com/modelcontextprotocol/go-sdk/mcpfor the MCP client.github.com/modelcontextprotocol/go-sdk/authfor OAuth Authorization Code + PKCE handling.github.com/alecthomas/kongfor the CLI.- Standard library
log/slogfor structured logs.
Install
Install a prebuilt release binary (macOS arm64/amd64, Linux amd64/arm64) with install.sh. The script verifies SHA-256 checksums, plus GitHub Release attestations when gh is available and keyless SLSA v1 provenance when cosign is available:
curl -fsSL https://raw.githubusercontent.com/wolfeidau/mcp-oauth-cli/main/install.sh | sh
Or install a tagged release with Go 1.27+:
go install github.com/wolfeidau/mcp-oauth-cli/cmd/mcp-oauth-cli@<version>
Pin a release, build from source, or verify release assets manually
Pin a specific version or install prefix:
curl -fsSL https://raw.githubusercontent.com/wolfeidau/mcp-oauth-cli/main/install.sh | sh -s -- --version v0.1.0 --prefix ~/.local
Build from source:
git clone https://github.com/wolfeidau/mcp-oauth-cli.git
cd mcp-oauth-cli
go build -o mcp-oauth-cli ./cmd/mcp-oauth-cli
./mcp-oauth-cli --help
Or run directly from this repository:
go run ./cmd/mcp-oauth-cli --help
Verify a downloaded release archive manually (each release publishes .tar.gz, .sha256, .sbom.json, and .sigstore.json signed by https://buildkite.com/wolfeidauci/mcp-oauth-cli-release):
# 1. Verify SHA-256 checksum (use shasum -a 256 on macOS)
diff -u <(sha256sum mcp-oauth-cli_linux_amd64.tar.gz | cut -d' ' -f1) mcp-oauth-cli_linux_amd64.tar.gz.sha256
# 2. Verify immutable GitHub Release asset attestation
gh release verify-asset v0.1.0 mcp-oauth-cli_linux_amd64.tar.gz --repo wolfeidau/mcp-oauth-cli
# 3. Verify keyless SLSA v1 provenance via Sigstore/Cosign
cosign verify-blob-attestation \
--bundle mcp-oauth-cli_linux_amd64.tar.gz.sigstore.json \
--type slsaprovenance1 \
--certificate-oidc-issuer https://agent.buildkite.com \
--certificate-identity https://buildkite.com/wolfeidauci/mcp-oauth-cli-release \
mcp-oauth-cli_linux_amd64.tar.gz
State And Secrets
The CLI is designed as a step-by-step inspection tool. Commands read and write a JSON state bundle at:
.mcp-oauth-cli/state.json
Override it with --state:
mcp-oauth-cli --state .mcp-oauth-cli/custom.json show
By default (--secret-store keyring), OAuth access tokens, refresh tokens, and client secrets are stored in the OS keyring (macOS Keychain, Linux Secret Service via D-Bus, or Windows Credential Manager) under service mcp-oauth-cli, referenced by secret_id in the state file. The state file itself is written atomically with 0600 permissions and keeps only non-secret inspection metadata and SHA-256 fingerprints, so show and jq work without exposing raw tokens.
On headless Linux systems or CI environments without a keyring daemon, --secret-store keyring fails closed rather than silently writing plaintext tokens to disk. Opt into file-based secret storage explicitly with --secret-store file or MCP_OAUTH_CLI_SECRET_STORE=file.
Use logout to delete stored tokens and client secrets from the keyring and clear them from the state file:
mcp-oauth-cli logout
Human-readable and redacted JSON outputs replace secret values with SHA-256 fingerprints by default. Use --dump-sensitive only when you explicitly want raw token values.
.mcp-oauth-cli* is ignored by git.
Global Flags
These flags apply across commands:
--state Path to the saved inspection state. Default: .mcp-oauth-cli/state.json
--secret-store Where to store OAuth tokens and client secrets: keyring or file ($MCP_OAUTH_CLI_SECRET_STORE). Default: keyring
--format Output format: text or json. Default: text (rotate and check-old-refresh-tokens always output JSON)
--log-level Log level: debug, info, warn, error. Default: info
--log-format Log format: text or json. Default: text
Command results are written to stdout. Logs and interactive authorization prompts are written to stderr.
Typical Workflow
The normal flow is:
discover -> register -> authorize -> call -> token --refresh -> rotate
1. Discover OAuth Metadata
Discover protected resource metadata and authorization server metadata for a Streamable HTTP MCP endpoint:
mcp-oauth-cli discover --server https://example.com/mcp
This saves:
- MCP server URL.
- Protected resource metadata URL.
- Protected resource metadata.
- Authorization server metadata (including
code_challenge_methods_supported, whichdiscoverprints aspkce_s256).
Write to a different state file for this first step:
mcp-oauth-cli discover \
--server https://example.com/mcp \
--out .mcp-oauth-cli/example.json
Machine-readable output:
mcp-oauth-cli --format json discover --server https://example.com/mcp
2. Register A Client
If the authorization server supports Dynamic Client Registration:
mcp-oauth-cli register
Add scopes or override the dynamic registration client name (default: mcp-oauth-cli):
mcp-oauth-cli register --client-name my-mcp-tester --scope read --scope write
Set a redirect URL explicitly:
mcp-oauth-cli register --redirect-url http://localhost:3142
If the server requires pre-registered credentials:
mcp-oauth-cli register \
--client-id "$OAUTH_CLIENT_ID" \
--client-secret "$OAUTH_CLIENT_SECRET" \
--token-endpoint-auth-method client_secret_basic
The --client-id and --client-secret flags can also come from environment variables:
export OAUTH_CLIENT_ID=...
export OAUTH_CLIENT_SECRET=...
mcp-oauth-cli register --token-endpoint-auth-method client_secret_basic
Supported token endpoint auth methods:
client_secret_basicclient_secret_postnone
3. Authorize With PKCE
Start the Authorization Code + PKCE flow:
mcp-oauth-cli authorize
By default, this listens on localhost:3142, prints the authorization URL, waits for the callback, connects to the MCP server, calls tools/list, and saves the resulting token state, tool definitions, and server instructions.
Open the browser automatically:
mcp-oauth-cli authorize --open
Use a different callback port:
mcp-oauth-cli authorize --callback-port 8085
Print raw token values after authorization:
mcp-oauth-cli authorize --dump-sensitive
4. Inspect Tokens
Show a redacted token summary:
mcp-oauth-cli token
Export redacted token JSON:
mcp-oauth-cli --format json token
Export raw token JSON:
mcp-oauth-cli token --export --dump-sensitive
Refresh the saved token:
mcp-oauth-cli token --refresh
Refresh and print raw values:
mcp-oauth-cli token --refresh --dump-sensitive
If the server does not issue a refresh token, refresh and rotation commands will report that rotation cannot be exercised.
5. Call MCP Methods
Validate the saved token by making an MCP call:
mcp-oauth-cli call tools/list
Supported validation calls:
pingtools/listresources/listprompts/list
Examples:
mcp-oauth-cli call ping
mcp-oauth-cli call resources/list
Each call is appended to the state bundle with success/failure details.
Successful tools/list calls also replace the saved tools definitions and update tools_listed_at in the state bundle.
Every successful call also connects to the server and, if it advertises instructions during initialization, saves them as server_instructions and updates server_instructions_at.
6. Test Token Rotation
Run repeated MCP calls and refresh attempts:
mcp-oauth-cli rotate --iterations 3 --delay 1s
Use a different validation method:
mcp-oauth-cli rotate \
--iterations 5 \
--delay 2s \
--method tools/list
For each iteration the CLI records:
- Access token fingerprint before refresh.
- Access token fingerprint after refresh.
- Whether the access token changed.
- Any refresh or MCP validation error.
Rotation results are saved to the state bundle and printed as JSON.
7. Check Old Refresh Tokens
After you have refreshed or rotated at least once, the state bundle contains prior tokens in previous_tokens. Use check-old-refresh-tokens to test whether those historical refresh tokens are still accepted by the authorization server:
mcp-oauth-cli check-old-refresh-tokens
Limit how many historical refresh tokens are tested:
mcp-oauth-cli check-old-refresh-tokens --limit 1
Also test the current refresh token:
mcp-oauth-cli check-old-refresh-tokens --include-current
The command prints JSON and appends results to old_refresh_checks in the state bundle. Each result includes:
- Historical token index, where
-1means the current token. - Original refresh token fingerprint.
- Whether the token was usable.
- New access and refresh token fingerprints, if refresh succeeded.
- Whether the refresh token rotated or was reused.
- Any token endpoint error.
This command intentionally sends old refresh tokens to the real token endpoint. Some authorization servers revoke token families or rotate again when an old refresh token is reused, so run it against test tenants or disposable credentials when possible. Note that --include-current is read-only with respect to current_token in state: if the server rotates single-use refresh tokens on that check, the saved current refresh token may no longer be valid.
Inspect Saved State
Show a human-readable summary:
mcp-oauth-cli show
Show redacted JSON:
mcp-oauth-cli --format json show
Show raw JSON, including secrets:
mcp-oauth-cli --format json show --dump-sensitive
You can also inspect the state file directly:
jq . .mcp-oauth-cli/state.json
Discovery metadata is grouped under discovery, the active token is under current_token, and older tokens are under previous_tokens.
Full Example
SERVER_URL=https://example.com/mcp
go run ./cmd/mcp-oauth-cli discover --server "$SERVER_URL"
go run ./cmd/mcp-oauth-cli register --scope read
go run ./cmd/mcp-oauth-cli authorize --open
go run ./cmd/mcp-oauth-cli call tools/list
go run ./cmd/mcp-oauth-cli token --refresh
go run ./cmd/mcp-oauth-cli rotate --iterations 3 --delay 1s
go run ./cmd/mcp-oauth-cli --format json show
With a custom state path:
STATE=.mcp-oauth-cli/example-state.json
SERVER_URL=https://example.com/mcp
go run ./cmd/mcp-oauth-cli --state "$STATE" discover --server "$SERVER_URL"
go run ./cmd/mcp-oauth-cli --state "$STATE" register
go run ./cmd/mcp-oauth-cli --state "$STATE" authorize
go run ./cmd/mcp-oauth-cli --state "$STATE" rotate --iterations 3
Development
Toolchain versions (go, golangci-lint, goreleaser, cosign, gh, shellcheck, and syft) are pinned in mise.toml and mise.lock. Install them with:
mise install
Run tests (with the race detector and uncached execution):
make test
Format code with gofmt and gci:
make fmt
Run lint and module tidy checks:
make lint
make tidy
Or run the mise tasks directly:
mise run check:tidy
mise run check:lint
CI (.buildkite/pipeline.yml) runs mise run check:tidy, mise run check:lint (golangci-lint and shellcheck), make build, go test -race -count=1 with coverage artifacts, and a goreleaser release --snapshot --clean build on pushes and pull requests. Tagged v* releases are built, attested, and published by .buildkite/pipeline.release.yml.
Current Scope
This first version targets Streamable HTTP MCP servers. It focuses on Authorization Code + PKCE, dynamic or pre-registered clients, saved token inspection, refresh attempts, and MCP calls that validate whether the current token still works.
If an authorization server issues long-lived access tokens and does not issue refresh tokens, the tool can still authenticate and call the MCP server, but it cannot prove token rotation without server-side support for refresh or intentionally short token lifetimes.