get_top_inventors
Identify the top 10 inventors in a specific technology field using keywords or IPC codes. Filter results by patent application, publication date, or authority to evaluate top performers or find potential recruits.
Instructions
Shows the top inventors in the technology field. Evaluate top performers or identify potential recruits. Returns up to the top 10 inventors. Note: Search must contain either keywords or IPC. If both are provided, IPC is prioritized.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apply_end_time | No | Patent application end year (yyyy format). Filters by application filing date. | |
| apply_start_time | No | Patent application start year (yyyy format). Filters by application filing date. | |
| authority | No | Patent authority code (e.g., CN, US, EP, JP). Filters by patent office. Use OR for multiple, e.g., "US OR EP". | |
| ipc | No | Patent IPC classification code. Used to specify a particular technology field. | |
| keywords | No | Keywords to search within patent title and abstract/summary. Supports AND, OR, NOT logic. Example: "mobile phone AND (screen OR battery)" | |
| public_end_time | No | Patent publication end year (yyyy format). Filters by publication date. | |
| public_start_time | No | Patent publication start year (yyyy format). Filters by publication date. |
Implementation Reference
- src/index.ts:253-257 (handler)The main handler function for the 'get_top_inventors' tool. It builds URL search parameters from the input arguments and delegates to the shared callPatsnapApi helper to fetch data from the PatSnap 'inventor-ranking' endpoint.async function getTopInventors(args: BasePatentArgs): Promise<ServerResult> { const params = buildCommonSearchParams(args); // No 'lang' parameter for this endpoint return callPatsnapApi('inventor-ranking', params, 'get top inventors'); }
- src/index.ts:303-316 (schema)The input schema (basePatentInputSchema) used by the 'get_top_inventors' tool, defining the expected input properties for patent search parameters.const basePatentInputSchema = { type: 'object' as const, // Use 'as const' for stricter type checking properties: { keywords: { type: 'string', description: 'Keywords to search within patent title and abstract/summary. Supports AND, OR, NOT logic. Example: "mobile phone AND (screen OR battery)"' }, ipc: { type: 'string', description: 'Patent IPC classification code. Used to specify a particular technology field.' }, apply_start_time: { type: 'string', description: 'Patent application start year (yyyy format). Filters by application filing date.' }, apply_end_time: { type: 'string', description: 'Patent application end year (yyyy format). Filters by application filing date.' }, public_start_time: { type: 'string', description: 'Patent publication start year (yyyy format). Filters by publication date.' }, public_end_time: { type: 'string', description: 'Patent publication end year (yyyy format). Filters by publication date.' }, authority: { type: 'string', description: 'Patent authority code (e.g., CN, US, EP, JP). Filters by patent office. Use OR for multiple, e.g., "US OR EP".' } }, // Add a note about requiring keywords or IPC for most tools description: "Requires either 'keywords' or 'ipc' to be specified for a meaningful search. If both are provided, IPC is prioritized by the API." };
- src/index.ts:361-365 (registration)Tool registration in the ListTools handler, defining the name, description, and input schema for 'get_top_inventors'.{ name: 'get_top_inventors', description: 'Shows the top inventors in the technology field. Evaluate top performers or identify potential recruits. Returns up to the top 10 inventors. Note: Search must contain either keywords or IPC. If both are provided, IPC is prioritized.', inputSchema: basePatentInputSchema },
- src/index.ts:399-399 (registration)Mapping of tool name to handler function in the dispatch toolImplementations object.'get_top_inventors': getTopInventors,
- src/index.ts:146-210 (helper)Shared helper function callPatsnapApi that performs the actual API request to PatSnap, handles authentication, errors, and formats the response. Called by the getTopInventors handler with endpoint 'inventor-ranking'.async function callPatsnapApi(endpoint: string, params: URLSearchParams, errorContext: string): Promise<ServerResult> { const token = await getAccessToken(); // Will use cached token if available and valid const url = `${PATSNAP_API_BASE_URL}/insights/${endpoint}?${params.toString()}`; console.log(`Calling PatSnap API: ${url}`); // Log the request URL (consider using a proper logger) let response: Response; try { response = await fetch(url, { method: 'GET', headers: { // 'Content-Type': 'application/json', // Typically not needed for GET 'Authorization': `Bearer ${token}` } // Consider adding a timeout // signal: AbortSignal.timeout(15000) // e.g., 15 seconds timeout }); } catch (error) { console.error(`Network error calling PatSnap API endpoint ${endpoint}:`, error); throw new McpError(503, `Network error connecting to PatSnap API (${endpoint}): ${error instanceof Error ? error.message : String(error)}`); } if (!response.ok) { let errorText = `Status code ${response.status}`; try { errorText = await response.text(); } catch (e) { console.error("Failed to read error response body:", e); } console.error(`API Error (${response.status}) for ${endpoint}: ${errorText}`); // Log error details // Invalidate cache on auth errors (401 Unauthorized, 403 Forbidden) if (response.status === 401 || response.status === 403) { cachedToken = null; console.log('Authentication error detected, clearing token cache.'); } // Map common PatSnap error codes to potentially more user-friendly messages if desired // Example: if (errorText.includes("67200002")) { throw new McpError(429, "PatSnap API quota exceeded."); } throw new McpError(response.status, `Failed to ${errorContext}: ${errorText}`); } let json: PatsnapApiResponse; // Use interface type try { json = await response.json() as PatsnapApiResponse; // Type assertion } catch (error) { console.error(`Error parsing JSON response from ${endpoint}:`, error); throw new McpError(500, `Failed to parse JSON response from PatSnap API (${endpoint}): ${error instanceof Error ? error.message : String(error)}`); } // Basic check for PatSnap's own error structure within a 200 OK response if (json && typeof json.status === 'boolean' && json.status === false && json.error_code !== 0) { console.error(`PatSnap API returned error within successful response for ${endpoint}: Code ${json.error_code}, Msg: ${json.error_msg}`); // You might want to map these internal errors to McpError as well throw new McpError(400, `PatSnap API Error (${json.error_code || 'N/A'}): ${json.error_msg || 'Unknown error'}`); } return { content: [ { type: 'text', // Return the raw JSON response as text, formatted for readability text: JSON.stringify(json, null, 2) } ] }; }