search_targets
Discover therapeutic targets by searching gene symbols, names, or descriptions using this tool. Specify query, result size, and output format for precise research insights.
Instructions
Search for therapeutic targets by gene symbol, name, or description
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Output format (default: json) | |
| query | Yes | Search query (gene symbol, name, description) | |
| size | No | Number of results to return (1-500, default: 25) |
Implementation Reference
- src/index.ts:313-371 (handler)The primary handler function for the 'search_targets' tool. It validates the input arguments using isValidTargetSearchArgs, constructs and executes a GraphQL query to search for targets in the Open Targets API, limits the results based on the 'size' parameter, formats the response as JSON, and returns it as tool content. Handles errors by returning an error message.private async handleSearchTargets(args: any) { if (!isValidTargetSearchArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid target search arguments'); } try { const query = ` query SearchTargets($queryString: String!) { search(queryString: $queryString, entityNames: ["target"]) { hits { id name description entity } } } `; const response = await this.graphqlClient.post('', { query, variables: { queryString: args.query } }); // Limit results on client side const hits = response.data.data?.search?.hits || []; const limitedHits = hits.slice(0, args.size || 25); const result = { ...response.data, data: { search: { hits: limitedHits, total: hits.length } } }; return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error searching targets: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], isError: true, }; } }
- src/index.ts:213-221 (schema)The input schema definition for the 'search_targets' tool, specifying the expected parameters: required 'query' string, optional 'size' number (1-500), and optional 'format' enum ['json', 'tsv']. Used in tool registration.inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query (gene symbol, name, description)' }, size: { type: 'number', description: 'Number of results to return (1-500, default: 25)', minimum: 1, maximum: 500 }, format: { type: 'string', enum: ['json', 'tsv'], description: 'Output format (default: json)' }, }, required: ['query'], },
- src/index.ts:210-222 (registration)Tool registration entry in the ListToolsRequestSchema handler, defining the 'search_targets' tool with its name, description, and input schema.{ name: 'search_targets', description: 'Search for therapeutic targets by gene symbol, name, or description', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query (gene symbol, name, description)' }, size: { type: 'number', description: 'Number of results to return (1-500, default: 25)', minimum: 1, maximum: 500 }, format: { type: 'string', enum: ['json', 'tsv'], description: 'Output format (default: json)' }, }, required: ['query'], }, },
- src/index.ts:292-293 (registration)Dispatch logic in the CallToolRequestSchema handler's switch statement, routing calls to 'search_targets' to the handleSearchTargets method.case 'search_targets': return this.handleSearchTargets(args);
- src/index.ts:16-25 (helper)Helper validation function (type guard) used by the handler to validate input arguments for the 'search_targets' tool, checking query is non-empty string, size is valid number, and format is json or tsv.const isValidTargetSearchArgs = (args: any): args is { query: string; size?: number; format?: string } => { return ( typeof args === 'object' && args !== null && typeof args.query === 'string' && args.query.length > 0 && (args.size === undefined || (typeof args.size === 'number' && args.size > 0 && args.size <= 500)) && (args.format === undefined || ['json', 'tsv'].includes(args.format)) ); };