Configuration & Authentication
Managing auth headers, base URLs, tool filtering, and security best practices.
This guide covers advanced runtime options for apibear, including authentication precedence, base URL resolution, and context window optimization.
Injecting Authentication Headers
Most REST APIs require authorization headers (such as bearer tokens or API keys). Because stdio MCP servers execute as local processes, you inject credentials using the --header CLI option.
--header "Authorization: Bearer YOUR_API_TOKEN" \
--header "X-Workspace-Id: ws_7718"
Precedence Rules
When a request is built, headers are merged in the following order:
- Default Headers:
Accept: application/jsonis sent by default. - Spec-Declared Parameter Headers: Any header parameters defined in the OpenAPI spec and supplied as tool arguments.
- CLI Injected Headers: Any
--headerprovided on the command line.
CLI headers always win. If an OpenAPI document defines an Authorization header parameter and the model supplies an argument for it, the CLI’s --header "Authorization: ..." overrides it. This guarantees your verified credentials cannot be accidentally overridden by model hallucinations.
Base URL Resolution
Every tool call needs an absolute URL to execute HTTP requests against. API Bear determines the base URL using these steps:
- CLI Flag (
--base-url): If--base-url https://api.mycorp.comis provided, it always takes precedence. - Spec
serversObject: If no CLI flag is provided, API Bear examines the OpenAPI document’sserversarray.- It selects the first server URL with an absolute
https://orhttp://scheme. - Server variables (e.g.
{env}) with defaults are resolved.
- It selects the first server URL with an absolute
- Missing or Relative URL: If the spec defines only relative paths (like
/v1) or noserversarray at all,baseUrlresolves tonull.- Requirement: When
baseUrlisnull, you must supply--base-url. If not provided, tool execution will fail with an error instructing you to specify--base-url.
- Requirement: When
npx -y apibear --spec ./internal-api.json --base-url https://staging.internal.net
Filtering Tools with --only
Large OpenAPI specifications containing dozens or hundreds of endpoints can degrade model performance and waste context tokens.
The --only option filters the exposed tools to a specific list of operationIds:
--only "listUsers,getUserById,updateUser"
Best Practices for --only:
- Keep it under 20 tools: LLM reasoning is sharpest when given a focused set of related tools rather than an entire company-wide API.
- Compound workflows: Create separate MCP server entries in your client configuration for different tasks (e.g.
github-issueswith issue tools, andgithub-prswith pull request tools). - Diagnostics: If you specify an unknown
operationIdin--only, API Bear outputs a warning onstderrlisting the unknown ID, but continues serving the valid operations.
Security Considerations
Plaintext Headers in Local Client Configs
Today, MCP clients store runner arguments — including
--header "Authorization: Bearer ..."— as unencrypted plaintext JSON on your local filesystem (e.g. inclaude_desktop_config.json).
Protections in API Bear:
- No stdout leakage: Header values are never printed to stdout.
- Redacted stderr logs: When the runner boots, it outputs configured header names (e.g.
[apibear] injecting headers: Authorization, X-Workspace-Id), but never prints secret values. - Direct requests: Requests go directly from your machine to the destination API over HTTPS. No intermediate proxies or third-party servers see your tokens.
Future: API Bear Gateway
If you need secret vaulting to ensure tokens are never saved to developer laptops, see the upcoming API Bear Gateway.