Client Integration (x402)

🧩 Clients

Connect Latch-enabled MCP servers to any compatible client — including ChatGPT, Cursor, Claude Desktop, Windsurf, or your own agent built on the SDK/CLI.

Each public server listed in the Latch Registry includes an Integration tab showing how to connect, test, and call its tools from multiple environments. You can integrate visually (predefined clients) or programmatically (via SDK or CLI).


⚙️ Programmatic Integration

Developers can connect to any Latch-powered MCP server using one of two transport methods:

Option
Description

Wallet (x402 payments)

Enables automatic 402 → pay → confirm → retry flow using an on-chain wallet.

HTTP + API Key

Simple authentication for direct API calls without wallet signing.

Find any MCP server URL from the Latch Registry.


Option 1 — Wallet-based Integration (x402)

This method automatically handles x402 responses: receives pricing metadata → completes the payment → retries the request seamlessly.

import { Client } from "@modelcontextprotocol/sdk/client/index";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/transport/streamable-http";
import { withLatchClient } from "latchmcp/client";
import { createSigner } from "x402/types";

const client = new Client({ name: "latch-example-client", version: "1.0.0" });

// Connect to your Latch MCP server
const MCP_SERVER_URL = "https://api.latchmcp.app/mcp?target-url=<ID>";
const transport = new StreamableHTTPClientTransport(new URL(MCP_SERVER_URL));
await client.connect(transport);

// Create signer (EVM example)
const evmSigner = await createSigner("base-sepolia", process.env.EVM_PRIVATE_KEY as `0x${string}`);

// Enable automatic x402 payments
const latchClient = withLatchClient(client, {
  wallet: { evm: evmSigner },
  confirmationCallback: async () => true, // optional: manual confirmation hook
});

const tools = await latchClient.listTools();
console.log("Available tools:", tools);

Option 2 — HTTP transport (API Key)

For environments without wallets or when wallet signing isn’t required, Latch servers also accept traditional auth via API keys.

Supported formats:

  • Query param: api_key (preferred)

  • Header: x-api-key (for server-to-server calls)

import { Client } from "@modelcontextprotocol/sdk/client/index";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/transport/streamable-http";

// 1) Query param example
const url1 = new URL("https://api.latchmcp.app/mcp?target-url=<ID>");
url1.searchParams.set("api_key", process.env.LATCH_API_KEY as string);
const t1 = new StreamableHTTPClientTransport(url1.toString());

// 2) Header example
const url2 = new URL("https://api.latchmcp.app/mcp?target-url=<ID>");
const t2 = new StreamableHTTPClientTransport(url2, {
  requestInit: {
    headers: { "x-api-key": process.env.LATCH_API_KEY as string },
  },
});

const client = new Client({ name: "latch-api-client", version: "1.0.0" });
await client.connect(t1); // or t2

🔑 API Keys

Developers can generate or manage API keys directly from the Developer tab in the Latch Console.

Each key defines scope and rate limits per registered MCP server.

Last updated