company_research_exa
Research companies to gain insights into operations, financial data, and industry trends. This tool retrieves comprehensive business information and news for informed decision-making.
Instructions
Research companies using Exa AI - finds comprehensive information about businesses, organizations, and corporations. Provides insights into company operations, news, financial information, and industry analysis.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| companyName | Yes | Name of the company to research | |
| numResults | No | Number of search results to return (default: 5) |
Implementation Reference
- src/tools/companyResearch.ts:16-106 (handler)The core handler function for the 'company_research_exa' tool. It logs the request, constructs a search query for the Exa API focused on company information, sends the request, processes the response, and returns JSON-formatted results or appropriate error messages.async ({ companyName, numResults }) => { const requestId = `company_research_exa-${Date.now()}-${Math.random().toString(36).substring(2, 7)}`; const logger = createRequestLogger(requestId, 'company_research_exa'); logger.start(companyName); try { // Create a fresh axios instance for each request const axiosInstance = axios.create({ baseURL: API_CONFIG.BASE_URL, headers: { 'accept': 'application/json', 'content-type': 'application/json', 'x-api-key': config?.exaApiKey || process.env.EXA_API_KEY || '' }, timeout: 25000 }); const searchRequest: ExaSearchRequest = { query: `${companyName} company business corporation information news financial`, type: "auto", numResults: numResults || API_CONFIG.DEFAULT_NUM_RESULTS, contents: { text: { maxCharacters: API_CONFIG.DEFAULT_MAX_CHARACTERS }, livecrawl: 'preferred' }, includeDomains: ["bloomberg.com", "reuters.com", "crunchbase.com", "sec.gov", "linkedin.com", "forbes.com", "businesswire.com", "prnewswire.com"] }; logger.log("Sending request to Exa API for company research"); const response = await axiosInstance.post<ExaSearchResponse>( API_CONFIG.ENDPOINTS.SEARCH, searchRequest, { timeout: 25000 } ); logger.log("Received response from Exa API"); if (!response.data || !response.data.results) { logger.log("Warning: Empty or invalid response from Exa API"); return { content: [{ type: "text" as const, text: "No company information found. Please try a different company name." }] }; } logger.log(`Found ${response.data.results.length} company research results`); const result = { content: [{ type: "text" as const, text: JSON.stringify(response.data, null, 2) }] }; logger.complete(); return result; } catch (error) { logger.error(error); if (axios.isAxiosError(error)) { // Handle Axios errors specifically const statusCode = error.response?.status || 'unknown'; const errorMessage = error.response?.data?.message || error.message; logger.log(`Axios error (${statusCode}): ${errorMessage}`); return { content: [{ type: "text" as const, text: `Company research error (${statusCode}): ${errorMessage}` }], isError: true, }; } // Handle generic errors return { content: [{ type: "text" as const, text: `Company research error: ${error instanceof Error ? error.message : String(error)}` }], isError: true, }; } } );
- src/tools/companyResearch.ts:12-15 (schema)Input schema using Zod for validating the tool parameters: required companyName (string) and optional numResults (number).{ companyName: z.string().describe("Name of the company to research"), numResults: z.number().optional().describe("Number of search results to return (default: 5)") },
- src/tools/companyResearch.ts:8-107 (registration)The exported registration function that defines the tool name, description, input schema, and handler, then registers it with the MCP server using server.tool().export function registerCompanyResearchTool(server: McpServer, config?: { exaApiKey?: string }): void { server.tool( "company_research_exa", "Research companies using Exa AI - finds comprehensive information about businesses, organizations, and corporations. Provides insights into company operations, news, financial information, and industry analysis.", { companyName: z.string().describe("Name of the company to research"), numResults: z.number().optional().describe("Number of search results to return (default: 5)") }, async ({ companyName, numResults }) => { const requestId = `company_research_exa-${Date.now()}-${Math.random().toString(36).substring(2, 7)}`; const logger = createRequestLogger(requestId, 'company_research_exa'); logger.start(companyName); try { // Create a fresh axios instance for each request const axiosInstance = axios.create({ baseURL: API_CONFIG.BASE_URL, headers: { 'accept': 'application/json', 'content-type': 'application/json', 'x-api-key': config?.exaApiKey || process.env.EXA_API_KEY || '' }, timeout: 25000 }); const searchRequest: ExaSearchRequest = { query: `${companyName} company business corporation information news financial`, type: "auto", numResults: numResults || API_CONFIG.DEFAULT_NUM_RESULTS, contents: { text: { maxCharacters: API_CONFIG.DEFAULT_MAX_CHARACTERS }, livecrawl: 'preferred' }, includeDomains: ["bloomberg.com", "reuters.com", "crunchbase.com", "sec.gov", "linkedin.com", "forbes.com", "businesswire.com", "prnewswire.com"] }; logger.log("Sending request to Exa API for company research"); const response = await axiosInstance.post<ExaSearchResponse>( API_CONFIG.ENDPOINTS.SEARCH, searchRequest, { timeout: 25000 } ); logger.log("Received response from Exa API"); if (!response.data || !response.data.results) { logger.log("Warning: Empty or invalid response from Exa API"); return { content: [{ type: "text" as const, text: "No company information found. Please try a different company name." }] }; } logger.log(`Found ${response.data.results.length} company research results`); const result = { content: [{ type: "text" as const, text: JSON.stringify(response.data, null, 2) }] }; logger.complete(); return result; } catch (error) { logger.error(error); if (axios.isAxiosError(error)) { // Handle Axios errors specifically const statusCode = error.response?.status || 'unknown'; const errorMessage = error.response?.data?.message || error.message; logger.log(`Axios error (${statusCode}): ${errorMessage}`); return { content: [{ type: "text" as const, text: `Company research error (${statusCode}): ${errorMessage}` }], isError: true, }; } // Handle generic errors return { content: [{ type: "text" as const, text: `Company research error: ${error instanceof Error ? error.message : String(error)}` }], isError: true, }; } } ); }
- src/index.ts:91-93 (registration)Conditional registration of the company_research_exa tool in the main server setup by calling the register function if enabled in config.if (shouldRegisterTool('company_research_exa')) { registerCompanyResearchTool(server, config); registeredTools.push('company_research_exa');