search_by_taxonomy
Find UniProt entries by taxonomic classification using NCBI taxonomy IDs or names to retrieve relevant protein data.
Instructions
Search by detailed taxonomic classification
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "search_by_taxonomy"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| taxonomyId | No | NCBI taxonomy ID | |
| taxonomyName | No | Taxonomic name (e.g., Mammalia, Bacteria) | |
| size | No | Number of results to return (1-500, default: 25) |
Implementation Reference
- src/index.ts:1651-1693 (handler)The handler function that executes the tool's logic: validates input using isValidTaxonomySearchArgs, constructs a UniProt search query based on taxonomyId or taxonomyName, fetches results from the UniProt REST API, and returns formatted JSON or error.
private async handleSearchByTaxonomy(args: any) { if (!isValidTaxonomySearchArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid taxonomy search arguments'); } try { let query = 'reviewed:true'; if (args.taxonomyId) { query += ` AND taxonomy_id:"${args.taxonomyId}"`; } if (args.taxonomyName) { query += ` AND taxonomy_name:"${args.taxonomyName}"`; } const response = await this.apiClient.get('/uniprotkb/search', { params: { query: query, format: 'json', size: args.size || 25, }, }); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error searching by taxonomy: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], isError: true, }; } - src/index.ts:639-650 (schema)The input schema definition for the search_by_taxonomy tool, specifying properties for taxonomyId, taxonomyName, and size.
name: 'search_by_taxonomy', description: 'Search by detailed taxonomic classification', inputSchema: { type: 'object', properties: { taxonomyId: { type: 'number', description: 'NCBI taxonomy ID', minimum: 1 }, taxonomyName: { type: 'string', description: 'Taxonomic name (e.g., Mammalia, Bacteria)' }, size: { type: 'number', description: 'Number of results to return (1-500, default: 25)', minimum: 1, maximum: 500 }, }, required: [], }, }, - src/index.ts:770-771 (registration)Registration of the tool handler in the CallToolRequestSchema switch statement, mapping 'search_by_taxonomy' to handleSearchByTaxonomy.
case 'search_by_taxonomy': return this.handleSearchByTaxonomy(args); - src/index.ts:197-208 (helper)Helper validation function (type guard) that checks input arguments conform to the expected schema for search_by_taxonomy.
const isValidTaxonomySearchArgs = ( args: any ): args is { taxonomyId?: number; taxonomyName?: string; size?: number } => { return ( typeof args === 'object' && args !== null && (args.taxonomyId === undefined || (typeof args.taxonomyId === 'number' && args.taxonomyId > 0)) && (args.taxonomyName === undefined || typeof args.taxonomyName === 'string') && (args.size === undefined || (typeof args.size === 'number' && args.size > 0 && args.size <= 500)) && (args.taxonomyId !== undefined || args.taxonomyName !== undefined) ); };