TypeScript client
Read the REST API or connect with the official MCP TypeScript SDK.
Set M0_BASE_URL from the quickstart, and supply a sandbox developer key as M0_API_KEY through your secret manager or process environment. These examples run server-side on Node.js 22+ or Bun. They do not belong in a browser bundle.
HTTP client
No Mandate0-specific package is required for a REST request:
const baseUrl = process.env.M0_BASE_URL;
const apiKey = process.env.M0_API_KEY;
if (!baseUrl || !apiKey)
throw new Error("Configure M0_BASE_URL and M0_API_KEY");
const response = await fetch(new URL("/api/v1/wallets", baseUrl), {
headers: { Authorization: `Bearer ${apiKey}`, Accept: "application/json" },
signal: AbortSignal.timeout(30_000),
redirect: "error",
});
if (!response.ok)
throw new Error(`Wallet request failed: HTTP ${response.status}`);
const result: unknown = await response.json();
console.log(result);Validate the returned shape against the reviewed API schema before using it in a typed application. A TypeScript cast alone does not validate external data.
MCP client
This recipe uses the official MCP TypeScript SDK's 1.x client interface, matching the platform's existing SDK smoke test. Install an updated release within that major and commit your dependency lockfile:
npm install '@modelcontextprotocol/sdk@^1'
npm install --save-dev tsx typescript @types/nodeSave as client.ts in an ESM project and run with npx tsx client.ts:
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
const baseUrl = process.env.M0_BASE_URL;
const apiKey = process.env.M0_API_KEY;
if (!baseUrl || !apiKey)
throw new Error("Configure M0_BASE_URL and M0_API_KEY");
const client = new Client({ name: "my-mandate0-client", version: "1.0.0" });
try {
await client.connect(
new StreamableHTTPClientTransport(new URL("/api/mcp", baseUrl), {
requestInit: {
headers: { Authorization: `Bearer ${apiKey}` },
redirect: "error",
},
}),
);
const listing = await client.listTools();
console.log(listing.tools.map((tool) => tool.name));
const result = await client.callTool({
name: "m0_list_merchants",
arguments: { limit: 5 },
});
if (result.isError) throw new Error("Merchant listing was refused");
console.log(result.content);
} finally {
await client.close();
}The SDK handles the MCP handshake. This static-key example does not implement an OAuth browser flow or token refresh; assistant clients should use OAuth setup.
For writes, discover the input schema and permission requirements first. Financial operations require appropriate authority and idempotency; never automatically retry a payment with a new idempotency key.