lookup_rate
Check per-minute calling rates for phone numbers to calculate costs before dialing.
Instructions
Look up the calling rate for a specific phone number. Returns the per-minute cost.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| phone_number | Yes | Phone number in E.164 format (e.g. +442071234567) |
Implementation Reference
- src/tools/rates.ts:32-32 (handler)The handler function for lookup_rate tool - an async arrow function that calls client.post() to look up rates for a phone number via the /rates/lookup-number endpoint. Wrapped by callTool for error handling.
async (params) => callTool(() => client.post("/rates/lookup-number", { phone_number: params.phone_number })) - src/tools/rates.ts:25-31 (schema)The input schema definition for lookup_rate tool using Zod validation. Defines phone_number as a required string in E.164 format, along with tool annotations.
{ description: "Look up the calling rate for a specific phone number. Returns the per-minute cost.", inputSchema: { phone_number: z.string().describe("Phone number in E.164 format (e.g. +442071234567)"), }, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }, }, - src/tools/rates.ts:23-33 (registration)Registration of the lookup_rate tool with the MCP server. Associates the tool name with its schema definition and handler function.
server.registerTool( "lookup_rate", { description: "Look up the calling rate for a specific phone number. Returns the per-minute cost.", inputSchema: { phone_number: z.string().describe("Phone number in E.164 format (e.g. +442071234567)"), }, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }, }, async (params) => callTool(() => client.post("/rates/lookup-number", { phone_number: params.phone_number })) ); - src/tools/rates.ts:13-20 (helper)Helper function that wraps tool execution with try/catch error handling. Converts API errors to tool error responses and successful results to tool result responses.
async function callTool<T>(fn: () => Promise<T>) { try { return toolResult(await fn()); } catch (err) { const apiErr = err as ApiError; return toolError(`API error (${apiErr.status}): ${apiErr.message}`); } } - src/client.ts:33-39 (helper)The BubblyPhoneClient.post method used by the lookup_rate handler to make POST requests to the API. Handles JSON serialization and content-type headers.
async post<T = unknown>(path: string, body?: Record<string, unknown>): Promise<T> { return this.request<T>(`${this.baseUrl}${path}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: body ? JSON.stringify(body) : undefined, }); }