Skip to main content
Glama

ddd-info

Retrieve state and city information for any Brazilian area code (DDD) using this tool. Input a 2-digit DDD to instantly access accurate location data via the Brasil API MCP server.

Instructions

Get information about a Brazilian area code (DDD) including state and cities

Input Schema

NameRequiredDescriptionDefault
dddYesArea code (DDD) to be queried (only numbers, 2 digits)

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "ddd": { "description": "Area code (DDD) to be queried (only numbers, 2 digits)", "pattern": "^\\d{2}$", "type": "string" } }, "required": [ "ddd" ], "type": "object" }

Implementation Reference

  • Handler that fetches DDD data from BrasilAPI, handles errors, formats cities into a comma-separated list, and returns a formatted text response.
    async ({ ddd }) => { console.error(`Getting info for DDD: ${ddd}`); const result = await getBrasilApiData(`/ddd/v1/${ddd}`); if (!result.success) { return formatErrorResponse(`Error getting DDD information: ${result.message}`); } // Format the response data const dddInfo = result.data; const cities = dddInfo.cities.join(", "); return { content: [{ type: "text" as const, text: ` DDD ${ddd} Information: State: ${dddInfo.state} Cities: ${cities} ` }] }; }
  • Zod input schema for the 'ddd' parameter, enforcing exactly 2 digits.
    ddd: z.string() .regex(/^\d{2}$/, "DDD must contain exactly 2 digits") .describe("Area code (DDD) to be queried (only numbers, 2 digits)") },
  • Registers the 'ddd-info' tool on the MCP server, specifying name, description, input schema, and handler.
    server.tool( "ddd-info", "Get information about a Brazilian area code (DDD) including state and cities", { ddd: z.string() .regex(/^\d{2}$/, "DDD must contain exactly 2 digits") .describe("Area code (DDD) to be queried (only numbers, 2 digits)") }, async ({ ddd }) => { console.error(`Getting info for DDD: ${ddd}`); const result = await getBrasilApiData(`/ddd/v1/${ddd}`); if (!result.success) { return formatErrorResponse(`Error getting DDD information: ${result.message}`); } // Format the response data const dddInfo = result.data; const cities = dddInfo.cities.join(", "); return { content: [{ type: "text" as const, text: ` DDD ${ddd} Information: State: ${dddInfo.state} Cities: ${cities} ` }] }; } );
  • src/index.ts:28-28 (registration)
    Invokes the registration function to add the 'ddd-info' tool to the main MCP server instance.
    registerDddTools(server);
  • Utility function to make API requests to BrasilAPI, used by the ddd-info handler to fetch DDD data.
    export async function getBrasilApiData(endpoint: string, params: Record<string, any> = {}) { try { const url = `${BASE_URL}${endpoint}`; console.error(`Making request to: ${url}`); const response = await axios.get(url, { params }); return { data: response.data, success: true }; } catch (error: any) { console.error(`Error in API request: ${error.message}`); // Handle API errors in a structured format if (error.response) { return { success: false, statusCode: error.response.status, message: error.response.data?.message || error.message, error: error.response.data }; } return { success: false, message: error.message, error }; } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/guilhermelirio/brasil-api-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server