Documentation Index
Fetch the complete documentation index at: https://docs.alterauth.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Thealter-sdk[mcp] extra integrates with FastMCP to give MCP tools automatic OAuth credential injection. Decorate a function with @alter.tool(), and the SDK handles token retrieval, audit logging, and error recovery behind the scenes.
Quick Start
- Retrieves a valid OAuth token from Alter Vault (never exposed to the tool code)
- Injects it as a
Bearerheader on the provider API request - Logs the API call in the audit trail with tool name, caller, and execution context
- If no grant exists, returns a Connect URL so the user can authorize
How It Works
AlterMCP and @alter.tool()
AlterMCP is the integration entry point. Its .tool() method is a decorator that:
- Accepts a
providerparameter specifying which OAuth provider the tool uses - Injects an
AlterContextinstance as the first parameter of the tool function - Hides the
AlterContextparameter from the MCP tool schema (the LLM never sees it) - Sets an ambient audit context so any
vault.request()call inside the tool body is automatically tagged with the tool name
AlterContext
The AlterContext object injected into the tool has a .request() method that works like vault.request() but with the provider pre-configured:
| Parameter | Type | Description |
|---|---|---|
method | str | HTTP method ("GET", "POST", etc.) |
url | str | Provider API URL (supports {placeholder} templates) |
json | dict | Optional JSON request body |
query_params | dict | Optional URL query parameters |
path_params | dict | Optional URL path template substitutions |
extra_headers | dict | Optional additional headers |
reason | str | Optional audit reason |
account | str | Optional account identifier for multi-account providers |
provider and audit context are already set by the decorator — tool code only needs to specify the method and URL.
Error Recovery
The decorator automatically handles two common errors:GrantNotFoundError: No OAuth grant exists for this user/provider. The decorator creates a fresh Connect session and returns an MCP error containing the Connect URL, so the LLM can instruct the user to authorize.ScopeReauthRequiredError: The grant exists but its scopes are outdated. The decorator returns an MCP error asking the user to re-authorize with updated permissions.
Authentication with AlterAuthProvider
For MCP servers that need to authenticate end users via an identity provider (IDP), use AlterAuthProvider. It implements a full OAuth 2.0 Authorization Server — Claude Code and other spec-compliant MCP clients can discover, register, and authenticate automatically without any shim or proxy.
base_url parameter tells the OAuth server where it is hosted, so it can advertise correct endpoint URLs in the RFC 8414 discovery metadata. The providers dict declares which OAuth providers and scopes are available via Alter Connect.
Multi-Provider Scopes
All providers declared in theproviders dict have their scopes forwarded to the Connect session — non-primary providers are never silently dropped:
Nested Tools
When one@alter.tool() function calls another, the audit context preserves the call chain:
parent_tool key so the full call chain is recoverable from audit logs.
Registering with FastMCP
The@alter.tool() decorator produces a standard async function that FastMCP’s @mcp.tool() decorator can wrap. Stack the decorators with @mcp.tool() on the outside:
Complete Example
Requirements
- Python 3.11+
alter-sdk[mcp](installsfastmcp >= 3.0.0)- An Alter Vault API key with a configured OAuth provider in the Developer Portal