Skip to main content
Examples on this page use the MCP URL https://api.paywithlocus.com/api/credits/mcp. Locus Pro exposes a hosted Streamable HTTP MCP server. Interactive desktop and coding clients should use its OAuth discovery flow. The examples on this page target hosted model APIs, servers, and unattended framework runtimes, so they use an enterprise Agent Connection with a scoped lcac_… service credential. Examples below read the credential from LOCUS_AGENT_CONNECTION. Set it to the one-time lcac_… value returned when you create a connection; a tenant lcr_… secret key does not belong in any of these runtimes.
Connecting Codex, Claude Code, Cursor, Claude Desktop, VS Code, Gemini CLI, or another person-authorized client? Use the interactive OAuth setup instead. Personal accounts do not issue lcac_… service credentials.
mcp 2.0.0 on PyPI is a breaking release: it renamed the streamable HTTP client to streamable_http_client, its context manager now yields a 2-tuple instead of a 3-tuple, and tool results expose structured payloads as result.structured_content (snake_case). Much of the Python agent ecosystem still requires mcp>=1.24,<2, so use each Python section’s pip install line verbatim — the version pins are deliberate.

Choose an integration

Select an integration to jump directly to its setup guide.

OpenAI

Responses API and Agents SDK in Python or TypeScript.

Anthropic

Messages API remote MCP and Claude Agent SDK.

Vercel AI SDK

Load Locus tools through @ai-sdk/mcp.

Google

Gemini Interactions API and Google ADK.

LangChain

MultiServerMCPClient in Python or TypeScript.

LlamaIndex

Load MCP tools in Python or TypeScript.

CrewAI and AutoGen

Python multi-agent framework recipes.

Mastra

Configure Mastra’s native MCP client.

Raw MCP and custom frameworks

Official Python and TypeScript clients, plus the custom path.

Supported connections

“SDK preset” means @withlocus/credits 0.5.2 can turn a newly revealed agent connection into that framework’s exact MCP configuration shape. The framework remains responsible for loading tools and managing its MCP client lifecycle.
These are first-class MCP connection recipes, not native provider packages. The agent executes tools against Locus’s hosted server, so endpoint scope, pricing, account binding, expiry, and budgets remain enforced server-side.

Connection values

Create an agent connection in your trusted backend. Save these values when Locus reveals them:
Frameworks use one of two authorization shapes:
  • Hosted model APIs such as OpenAI Responses and Anthropic Messages receive the raw lcac_… token.
  • Runtime MCP clients receive Authorization: Bearer lcac_….
The 0.5.2 presets preserve that distinction. Do not strip or add Bearer yourself when you use a preset.

MCP versus a native provider

MCP is portable and keeps execution policy on the Locus server. It also means framework-local tool middleware does not wrap the HTTP call unless that framework explicitly supports MCP middleware. Use the direct Node SDK when your application needs to select every endpoint itself or wrap execution inside its own process. Pi is the only framework in the comparison list without a native MCP client. Its custom extension path remains experimental. Locus does not label that path stable until it has a maintained adapter and contract tests. See Connect an agent for coding-client configuration, connection lifecycle, and troubleshooting.

OpenAI

OpenAI can call Locus Pro as a hosted MCP tool. Send the raw lcac_… value on every request because OpenAI does not store MCP authorization.

Responses API

Agents SDK

Approval and scope

The presets default require_approval / requireApproval to never — whatever endpoint allowlist and spend limits the agent connection sets are the enforced boundary, so set them deliberately before relying on this default. Pass requireApproval: "always" to a preset when you also want the model provider to pause for approval before each tool call. If you narrow tools again with OpenAI’s allowed_tools, keep that list within the connection’s Locus scope. OpenAI-side filtering cannot expand the server-side allowlist.

Anthropic

Use Anthropic’s hosted MCP connector when the Messages API should call Locus directly. Use the Claude Agent SDK HTTP transport when MCP should run in your application.

Messages API

The hosted connector expects the raw lcac_… value in authorization_token.
Anthropic’s hosted connector supports tool calls over Streamable HTTP. Locus Pro does not require MCP resources or prompts for agent execution.

Claude Agent SDK

The runtime transport expects the complete Authorization header:
Use @anthropic-ai/claude-agent-sdk 0.2.70 or later for the corrected Streamable HTTP Accept header behavior.
Do not pass the tenant lcr_… key to Anthropic or the Claude Agent SDK. Use a scoped agent connection that can be expired, rotated, and revoked.

Vercel AI SDK

Use @ai-sdk/mcp when your Vercel AI SDK agent should discover and execute Locus tools through Streamable HTTP.

Create the MCP client

In production, create and store the connection in your control plane. Reconstruct the transport in the agent runtime from the saved MCP URL and credential:
Close the MCP client when the agent runtime shuts down. Do not create one client per model token or tool call.

Tool results

MCP tool failures can resolve with isError: true. If you call the MCP client directly, pass the result through parseMcpToolResult() before treating it as success. Follow Turn structured results into final answers to persist the result before answer generation and recover safely from interrupted turns.

Google Gen AI and ADK

Google supports Locus Pro through two paths: hosted remote MCP in the Gen AI Interactions API, or a runtime McpToolset in Google ADK.

Gen AI Interactions API

Remote MCP supports Streamable HTTP. Use a server name without hyphens; the Locus preset defaults to locus_pro.

Google ADK

Plain google-adk does not install mcp at all, and mcp 2.0.0 breaks its toolset imports; the [mcp] extra pins a compatible mcp>=1.24,<2.
googleAdkMcpServer(connection) returns the url and headers constructor values when a Node control plane prepares configuration for a Python worker. The Gemini or ADK layer can narrow tools, but it cannot widen the connection’s immutable Locus endpoint scope.

LangChain

LangChain’s MCP adapters discover Locus tools and expose them as normal LangChain tools. Use the same scoped connection in Python or TypeScript.
@langchain/mcp-adapters 1.1.3 and earlier mis-flatten estimate_cost’s oneOf input schema, so the TypeScript adapter rejects the {slug, body} form client-side before any request is sent. Call estimate_cost with the equivalent {provider, endpoint, body} form instead — it works on every adapter version.
MultiServerMCPClient can combine Locus with other MCP servers. Keep the Locus connection under its own server name so logs and tool prefixes stay attributable. The default client is stateless. It creates and cleans up a fresh MCP session for each tool call.
A LangChain callback or middleware does not automatically replace Locus’s server-side approval and budget policy. Keep least-privilege endpoint and credit limits on the agent connection itself.

LlamaIndex

Both LlamaIndex Python and LlamaIndexTS include MCP tool adapters. They convert Locus tool schemas into framework-native callable tools.

Python

llama-index-tools-mcp 0.5.0 breaks list_tools() against every streamable HTTP server on mcp 2.x; these pins hold the last working pairing.
BasicMCPClient selects Streamable HTTP for the Locus /mcp URL. Do not set the deprecated SSE transport.

TypeScript

The TypeScript adapter forwards requestInit.headers to the official MCP transport. Version 0.5.2’s preset builds that shape and clones the one-time authorization header.

Restrict tools

Use allowed_tools in McpToolSpec only as a local narrowing layer. Create the Locus connection with tools.enable so an accidental local configuration change cannot widen access. See Connect an agent for immutable scope and rotation.

CrewAI and AutoGen

CrewAI and AutoGen both accept authenticated Streamable HTTP MCP servers. Give each deployment its own Locus agent connection.

CrewAI

cache_tools_list=True avoids repeated discovery inside one worker. Restart or refresh the worker after changing the tenant catalog. The Locus server recomputes the authenticated catalog on every request, but the CrewAI client can retain its last tool list. If a Node control plane creates connections for Python workers, crewAIMcpServer(connection) returns these keyword values.

AutoGen

autogen-ext 0.7.5 imports break on mcp 2.0.0; keep the mcp pin until AutoGen supports the 2.x line. Use McpWorkbench as an async context manager so AutoGen closes the MCP session:
autoGenMcpServer(connection) returns the url and headers values when a Node control plane prepares worker configuration.
Reuse one Locus loop_id across paid calls in the same autonomous run when the connection has a per-loop budget. Dedicated tools accept a nested _locus: { "loop_id": "…" } object; execute accepts loop_id.

Mastra

Mastra’s MCPClient supports authenticated Streamable HTTP and converts MCP tools into Mastra tools.
The preset returns a URL and requestInit.headers, matching Mastra’s HTTP server definition. Set a stable id when several runtime components share the same connection configuration. For a runtime that does not have the Locus management client, build the same entry from stored secrets:
Mastra middleware can add application logging around agent activity. Locus still applies authorization, endpoint scope, reservations, capture/refund, and credit limits on the hosted server.

Raw MCP and custom frameworks

Use the official MCP clients when your runtime has no framework adapter. Locus uses Streamable HTTP and standard bearer authorization.

TypeScript MCP SDK

This example uses the stable @modelcontextprotocol/sdk package:
The current 2.x client is also available as @modelcontextprotocol/client. Follow its migration guide when you adopt the newer protocol package; the Locus URL and authorization header do not change.

Python MCP SDK

On mcp 2.x the Python SDK exposes structured tool payloads as result.structured_content (snake_case), not structuredContent. Locus is stateless and does not issue an MCP-Session-Id. Reconnect with the same agent connection after a transport interruption. Reuse the same idempotency key when retrying a paid call whose outcome is uncertain.

Custom frameworks

A custom adapter needs four operations:
  1. Connect with the MCP URL and authorization header.
  2. Call tools/list and map each JSON Schema into the framework’s tool type.
  3. Route tool calls back to MCP tools/call without changing arguments.
  4. Treat a resolved result with isError: true as a failed tool call.
Use parseMcpToolResult() when the adapter is written in TypeScript. It preserves Locus billing metadata, artifacts, retry guidance, and application errors.

Pi

Pi does not ship a native MCP client. You can build a TypeScript extension that registers tools from the official MCP SDK, but this path is experimental and is not part of Locus’s stable compatibility promise. Use raw REST from an extension when you need Pi today, and keep the connection’s endpoint and credit scope narrow. See Connect an agent for transport failures, stale client catalogs, and isError handling.