03. API Clients and MCP

What services/api/client.ts Shows

The client layer is not a trivial HTTP wrapper. It supports multiple provider paths and auth modes: direct API key access, subscriber OAuth flows, Bedrock, Foundry, Vertex, custom headers, proxy-aware fetch, session identifiers, and additional protection headers.

This is a useful lesson if you build local agents: provider abstraction gets messy quickly once you support enterprise auth, cloud variants, session analytics, and proxy routing.

What services/mcp/auth.ts Shows

MCP support here is treated as a serious protocol layer. The auth module covers metadata discovery, authorization server interaction, callback ports, token storage, secure storage, browser launch, lock files, error normalization, retries, and cross-app access support.

That means MCP is not bolted on. It is a platform-grade integration mechanism.

Practical Lesson

If you want to build your own local terminal agent, do not underestimate the adapter layer. The model adapter is where product ambition becomes operational complexity: auth refresh, proxies, provider quirks, session IDs, quota checks, and protocol differences all accumulate there.

Where To Read Next

  • source/services/api/claude.ts: request assembly and model query flow
  • source/services/api/filesApi.ts: file upload and download path
  • source/services/mcp/client.ts: MCP tool/resource plumbing
  • source/services/mcp/types.ts: shape of the MCP integration surface

Source Navigation

Recommended Source Files

  • source/services/api/client.ts
  • source/services/api/claude.ts
  • source/services/mcp/auth.ts
  • source/services/mcp/client.ts
  • source/services/oauth/client.ts

Next Files to Read

  • source/services/api/filesApi.ts
  • source/services/api/withRetry.ts
  • source/services/mcp/config.ts