create_wallet
Create a new CardZero wallet to receive a wallet address and one-time claim key for the human owner. No authentication required.
Instructions
Create a new CardZero wallet. Returns a wallet address and one-time claim key for the human owner. No authentication required.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | Optional display name for the wallet |
Implementation Reference
- src/index.ts:103-114 (handler)The handler function for the create_wallet tool. It accepts an optional 'name' parameter, calls POST /wallets (without auth), and returns the wallet info (address + claim key).
async ({ name }) => { try { const body: Record<string, unknown> = {}; if (name) body.name = name; const res = await callApi("POST", "/wallets", body, false); if (!res.ok) return errorResponse("Create wallet failed", res); return successResponse(res.json); } catch (e) { return { content: [{ type: "text" as const, text: `Create wallet error: ${e}` }], isError: true }; } }, ); - src/index.ts:102-102 (schema)Zod schema for the create_wallet tool input: an optional 'name' string describing the display name for the wallet.
{ name: z.string().optional().describe("Optional display name for the wallet") }, - src/index.ts:99-114 (registration)Registration of the 'create_wallet' tool on the McpServer via server.tool(), with a description and the handler.
server.tool( "create_wallet", "Create a new CardZero wallet. Returns a wallet address and one-time claim key for the human owner. No authentication required.", { name: z.string().optional().describe("Optional display name for the wallet") }, async ({ name }) => { try { const body: Record<string, unknown> = {}; if (name) body.name = name; const res = await callApi("POST", "/wallets", body, false); if (!res.ok) return errorResponse("Create wallet failed", res); return successResponse(res.json); } catch (e) { return { content: [{ type: "text" as const, text: `Create wallet error: ${e}` }], isError: true }; } }, ); - src/index.ts:33-62 (helper)The callApi helper used by the handler to make HTTP POST /wallets requests. The 'auth=false' parameter skips the API key header, allowing unauthenticated wallet creation.
async function callApi( method: "GET" | "POST", path: string, body?: Record<string, unknown>, auth = true, ): Promise<ApiResult> { if (auth && !API_KEY) { return { ok: false, status: 401, json: { error: "config_missing", message: "CARDZERO_API_KEY is not set. Get one at https://cardzero.ai", }, }; } const headers: Record<string, string> = {}; if (auth) headers["Authorization"] = `Bearer ${API_KEY}`; if (body) headers["Content-Type"] = "application/json"; const res = await fetch(`${API_URL}${path}`, { method, headers, body: body ? JSON.stringify(body) : undefined, }); const json = await res.json() as Record<string, unknown>; return { ok: res.ok, status: res.status, json }; }