get_cnpj
Retrieve company information using a Brazilian CNPJ number. Query business details through the Brasil API MCP server for data integration.
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 main handler function that executes the tool logic: fetches company data for the given CNPJ using brasilApiClient and returns a 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 parameter 'CNPJ' as a string, along with its TypeScript type.const getCNPJToolParams = { CNPJ: z.string().describe("The CNPJ to query"), }; type GetCNPJToolParams = typeof getCNPJToolParams;
- src/index.ts:30-41 (registration)Registration of the getCNPJTool by including it in the tools array and calling registerTool on the MCP server for each tool.const tools = [ getCepTool, getCepV2Tool, getBookByISBNTool, getCNPJTool, getAllBanksTool, getBankByCodeTool, ]; tools.forEach((tool) => { registerTool(server, tool); });
- src/utils/index.ts:8-10 (helper)Helper function that registers a tool definition to the MCP server by calling server.tool with its properties.export const registerTool = (server: McpServer, tool: McpToolDefinition) => { server.tool(tool.name, tool.description, tool.params, tool.handler); };