search_by_localization
Search and retrieve proteins based on their subcellular localization, such as nucleus or mitochondria, and filter by organism or result size using the UniProt MCP Server.
Instructions
Find proteins by subcellular localization
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| localization | Yes | Subcellular localization (e.g., nucleus, mitochondria) | |
| 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:1490-1529 (handler)The handler function that executes the 'search_by_localization' tool. It validates input arguments, constructs a UniProt search query using 'cc_subcellular_location' field for the specified localization and optional organism filter, queries the UniProt REST API, and returns the JSON results or an error.private async handleSearchByLocalization(args: any) { if (!isValidLocalizationSearchArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid localization search arguments'); } try { let query = `reviewed:true AND cc_subcellular_location:"${args.localization}"`; 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 localization: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], isError: true, }; } }
- src/index.ts:597-605 (schema)JSON Schema defining the input parameters for the 'search_by_localization' tool: required 'localization' string, optional 'organism' string and 'size' number.inputSchema: { type: 'object', properties: { localization: { type: 'string', description: 'Subcellular localization (e.g., nucleus, mitochondria)' }, 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: ['localization'], },
- src/index.ts:762-765 (registration)Registration of the tool handler in the CallToolRequestSchema switch statement, routing calls to 'search_by_localization' to its handler method.return this.handleSearchByFunction(args); case 'search_by_localization': return this.handleSearchByLocalization(args); // Batch Processing & Advanced Search
- src/index.ts:221-232 (helper)Type guard helper function that validates the input arguments for the 'search_by_localization' tool before execution.const isValidLocalizationSearchArgs = ( args: any ): args is { localization: string; organism?: string; size?: number } => { return ( typeof args === 'object' && args !== null && typeof args.localization === 'string' && args.localization.length > 0 && (args.organism === undefined || typeof args.organism === 'string') && (args.size === undefined || (typeof args.size === 'number' && args.size > 0 && args.size <= 500)) ); };