batch_annotate
Annotate multiple texts simultaneously with biological ontologies using comma-separated ontology acronyms, returning longest or whole-word matches as specified.
Instructions
Process multiple texts for annotation efficiently
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| longest_only | No | Return only longest matches (default: true) | |
| ontologies | No | Comma-separated ontology acronyms | |
| texts | Yes | Array of texts to annotate (max 10) | |
| whole_word_only | No | Match whole words only (default: true) |
Implementation Reference
- src/index.ts:995-1040 (handler)The handler function that implements the batch_annotate tool. It validates input, loops over each text, calls the BioOntology /annotator API with parameters, collects successes and errors per text, and returns batched results as JSON.private async handleBatchAnnotate(args: any) { if (!Array.isArray(args.texts) || args.texts.length === 0 || args.texts.length > 10) { throw new McpError(ErrorCode.InvalidParams, 'Invalid batch annotate arguments - texts must be array of 1-10 items'); } try { const results = []; for (const text of args.texts) { const params: any = { text: text, apikey: this.apiKey, }; if (args.ontologies) params.ontologies = args.ontologies; if (args.longest_only !== undefined) params.longest_only = args.longest_only; if (args.whole_word_only !== undefined) params.whole_word_only = args.whole_word_only; try { const response = await this.apiClient.get('/annotator', { params }); results.push({ text, annotations: response.data, success: true }); } catch (error: any) { results.push({ text, error: error.message, success: false }); } } return { content: [ { type: 'text', text: JSON.stringify({ batch_results: results }, null, 2), }, ], }; } catch (error: any) { return { content: [ { type: 'text', text: `Error in batch annotation: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], isError: true, }; } }
- src/index.ts:643-652 (schema)JSON Schema defining the input parameters for the batch_annotate tool, including required texts array and optional annotation options.inputSchema: { type: 'object', properties: { texts: { type: 'array', items: { type: 'string' }, description: 'Array of texts to annotate (max 10)', minItems: 1, maxItems: 10 }, ontologies: { type: 'string', description: 'Comma-separated ontology acronyms' }, longest_only: { type: 'boolean', description: 'Return only longest matches (default: true)' }, whole_word_only: { type: 'boolean', description: 'Match whole words only (default: true)' }, }, required: ['texts'], },
- src/index.ts:640-653 (registration)Tool registration entry in the list of available tools, specifying name, description, and input schema.{ name: 'batch_annotate', description: 'Process multiple texts for annotation efficiently', inputSchema: { type: 'object', properties: { texts: { type: 'array', items: { type: 'string' }, description: 'Array of texts to annotate (max 10)', minItems: 1, maxItems: 10 }, ontologies: { type: 'string', description: 'Comma-separated ontology acronyms' }, longest_only: { type: 'boolean', description: 'Return only longest matches (default: true)' }, whole_word_only: { type: 'boolean', description: 'Match whole words only (default: true)' }, }, required: ['texts'], }, },
- src/index.ts:714-715 (registration)Switch case in the CallToolRequestHandler that routes calls to batch_annotate to its handler function.case 'batch_annotate': return this.handleBatchAnnotate(args);