@mseep/crunchbase-mcp-server
Version:
A Model Context Protocol (MCP) server that provides access to Crunchbase data for AI assistants
177 lines • 6.27 kB
JavaScript
import axios from 'axios';
export class CrunchbaseAPI {
constructor(apiKey) {
this.baseUrl = 'https://api.crunchbase.com/api/v4';
this.apiKey = apiKey;
this.client = axios.create({
baseURL: this.baseUrl,
headers: {
'Accept': 'application/json',
'X-cb-user-key': this.apiKey
}
});
}
/**
* Search for companies based on various criteria
*/
async searchCompanies(params) {
try {
// Build the query string based on the provided parameters
let query = params.query || '';
if (params.location) {
query += ` AND location:${params.location}`;
}
if (params.category) {
query += ` AND category:${params.category}`;
}
if (params.founded_after) {
query += ` AND founded_on:>=${params.founded_after}`;
}
if (params.founded_before) {
query += ` AND founded_on:<=${params.founded_before}`;
}
if (params.status) {
query += ` AND status:${params.status}`;
}
const response = await this.client.get('/searches/organizations', {
params: {
query,
limit: params.limit || 10,
order: 'rank DESC'
}
});
return response.data.data;
}
catch (error) {
console.error('Error searching companies:', error);
throw this.handleError(error);
}
}
/**
* Get detailed information about a specific company
*/
async getCompanyDetails(params) {
try {
// First, try to search for the company by name
const searchResponse = await this.client.get('/searches/organizations', {
params: {
query: params.name_or_id,
limit: 1
}
});
if (searchResponse.data.count === 0) {
throw new Error(`Company not found: ${params.name_or_id}`);
}
const companyId = searchResponse.data.data[0].uuid;
// Then, get the detailed information using the UUID
const detailsResponse = await this.client.get(`/entities/organizations/${companyId}`);
return detailsResponse.data;
}
catch (error) {
console.error('Error getting company details:', error);
throw this.handleError(error);
}
}
/**
* Get funding rounds for a specific company
*/
async getFundingRounds(params) {
try {
// First, get the company UUID
const company = await this.getCompanyDetails({ name_or_id: params.company_name_or_id });
// Then, get the funding rounds
const response = await this.client.get(`/entities/organizations/${company.uuid}/funding_rounds`, {
params: {
limit: params.limit || 10,
order: 'announced_on DESC'
}
});
return response.data.data;
}
catch (error) {
console.error('Error getting funding rounds:', error);
throw this.handleError(error);
}
}
/**
* Get acquisitions made by or of a specific company
*/
async getAcquisitions(params) {
try {
let companyId;
if (params.company_name_or_id) {
// Get the company UUID
const company = await this.getCompanyDetails({ name_or_id: params.company_name_or_id });
companyId = company.uuid;
}
// Build the query
let query = '';
if (companyId) {
query = `acquirer_identifier.uuid:${companyId} OR acquiree_identifier.uuid:${companyId}`;
}
// Get the acquisitions
const response = await this.client.get('/searches/acquisitions', {
params: {
query,
limit: params.limit || 10,
order: 'announced_on DESC'
}
});
return response.data.data;
}
catch (error) {
console.error('Error getting acquisitions:', error);
throw this.handleError(error);
}
}
/**
* Search for people based on various criteria
*/
async searchPeople(params) {
try {
// Build the query string based on the provided parameters
let query = params.query || '';
if (params.company) {
query += ` AND featured_job_organization_name:${params.company}`;
}
if (params.title) {
query += ` AND featured_job_title:${params.title}`;
}
const response = await this.client.get('/searches/people', {
params: {
query,
limit: params.limit || 10,
order: 'rank DESC'
}
});
return response.data.data;
}
catch (error) {
console.error('Error searching people:', error);
throw this.handleError(error);
}
}
/**
* Handle API errors
*/
handleError(error) {
if (axios.isAxiosError(error)) {
const status = error.response?.status;
const message = error.response?.data?.message || error.message;
if (status === 401) {
return new Error('Unauthorized: Invalid API key');
}
else if (status === 404) {
return new Error('Not found: The requested resource does not exist');
}
else if (status === 429) {
return new Error('Rate limit exceeded: Too many requests');
}
else {
return new Error(`Crunchbase API error (${status}): ${message}`);
}
}
return error instanceof Error ? error : new Error('Unknown error');
}
}
//# sourceMappingURL=crunchbase-api.js.map