get_cnpj
Retrieve company details using a CNPJ number with the Brasil-API MCP Server. Streamline business verification and data integration for applications.
Instructions
Get information about a company given a CNPJ.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| CNPJ | Yes | The CNPJ to query |
Implementation Reference
- src/tools/cnpj.ts:20-34 (handler)The handler function that executes the tool logic: fetches company data for the given CNPJ using brasilApiClient and returns formatted text response.handler: async ({ CNPJ }): Promise<McpResponse> => { try { const result = await brasilApiClient.cnpj.getBy(CNPJ); const content: McpTextContent = { type: "text", text: `CNPJ ${CNPJ} found:\n${prettifyJson(result.data)}`, }; return { content: [content], }; } catch (error: any) { console.error(error); throw new Error(`Failed to fetch CNPJ ${CNPJ}`); } },
- src/tools/cnpj.ts:10-14 (schema)Zod schema defining the input parameters for the get_cnpj tool (CNPJ string).const getCNPJToolParams = { CNPJ: z.string().describe("The CNPJ to query"), }; type GetCNPJToolParams = typeof getCNPJToolParams;
- src/tools/cnpj.ts:16-35 (registration)Tool definition export including name, description, params, and handler.export const getCNPJTool: McpToolDefinition<GetCNPJToolParams> = { name: "get_cnpj", description: "Get information about a company given a CNPJ.", params: getCNPJToolParams, handler: async ({ CNPJ }): Promise<McpResponse> => { try { const result = await brasilApiClient.cnpj.getBy(CNPJ); const content: McpTextContent = { type: "text", text: `CNPJ ${CNPJ} found:\n${prettifyJson(result.data)}`, }; return { content: [content], }; } catch (error: any) { console.error(error); throw new Error(`Failed to fetch CNPJ ${CNPJ}`); } }, };
- src/index.ts:30-41 (registration)Registration of the getCNPJTool along with other tools to the MCP server using registerTool.const tools = [ getCepTool, getCepV2Tool, getBookByISBNTool, getCNPJTool, getAllBanksTool, getBankByCodeTool, ]; tools.forEach((tool) => { registerTool(server, tool); });