search_by_gene
Find proteins by entering a gene name or symbol. Filter results by organism and set the number of results returned for precise research on the UniProt MCP Server.
Instructions
Search for proteins by gene name or symbol
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| gene | Yes | Gene name or symbol (e.g., BRCA1, INS) | |
| organism | No | Organism name or taxonomy ID to filter results | |
| size | No | Number of results to return (1-500, default: 25) |
Implementation Reference
- src/index.ts:872-909 (handler)The main handler function for the 'search_by_gene' tool. It validates input, constructs a UniProt search query using the gene name (e.g., gene:"GENE") with optional organism filter, calls the UniProt API, and returns the JSON results or error.private async handleSearchByGene(args: any) { if (!isValidGeneSearchArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid gene search arguments'); } try { let query = `gene:"${args.gene}"`; if (args.organism) { query += ` AND organism_name:"${args.organism}"`; } 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 gene: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], isError: true, }; }
- src/index.ts:429-436 (schema)Input schema definition for the 'search_by_gene' tool, specifying parameters: gene (required string), organism (optional string), size (optional number 1-500).inputSchema: { type: 'object', properties: { gene: { type: 'string', description: 'Gene name or symbol (e.g., BRCA1, INS)' }, organism: { type: 'string', description: 'Organism name or taxonomy ID to filter results' }, size: { type: 'number', description: 'Number of results to return (1-500, default: 25)', minimum: 1, maximum: 500 }, }, required: ['gene'],
- src/index.ts:732-733 (registration)Registration of the 'search_by_gene' tool in the CallToolRequestSchema handler switch statement, dispatching to the handler function.case 'search_by_gene': return this.handleSearchByGene(args);
- src/index.ts:91-101 (helper)Type guard and validation function for input arguments of the 'search_by_gene' tool, used in the handler.const isValidGeneSearchArgs = ( args: any ): args is { gene: string; organism?: string; size?: number } => { return ( typeof args === 'object' && args !== null && typeof args.gene === 'string' && (args.organism === undefined || typeof args.organism === 'string') && (args.size === undefined || (typeof args.size === 'number' && args.size > 0 && args.size <= 500)) ); };
- src/index.ts:427-437 (registration)Tool metadata registration including name, description, and schema in the ListToolsRequestSchema response.name: 'search_by_gene', description: 'Search for proteins by gene name or symbol', inputSchema: { type: 'object', properties: { gene: { type: 'string', description: 'Gene name or symbol (e.g., BRCA1, INS)' }, organism: { type: 'string', description: 'Organism name or taxonomy ID to filter results' }, size: { type: 'number', description: 'Number of results to return (1-500, default: 25)', minimum: 1, maximum: 500 }, }, required: ['gene'], },