get_variation
Retrieve genetic variation details from WormBase, including molecular data, phenotypes, and associated strains for C. elegans research.
Instructions
Get information about a genetic variation/allele including molecular details, phenotypes, and strains.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Variation identifier - allele name (e.g., 'e1370') or WormBase variation ID | |
| widgets | No | Specific widgets to fetch: overview, molecular_details, phenotypes, references |
Implementation Reference
- src/index.ts:156-176 (registration)Registers the MCP tool 'get_variation' with name, description, input schema, and handler function.server.tool( "get_variation", "Get information about a genetic variation/allele including molecular details, phenotypes, and strains.", { id: z.string().describe("Variation identifier - allele name (e.g., 'e1370') or WormBase variation ID"), widgets: z.array(z.string()).optional().describe("Specific widgets to fetch: overview, molecular_details, phenotypes, references"), }, async ({ id, widgets }) => { try { const data = await client.getEntity("variation", id, widgets); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }], }; } catch (error) { return { content: [{ type: "text", text: `Error fetching variation: ${error}` }], isError: true, }; } } );
- src/index.ts:163-175 (handler)The handler function for the 'get_variation' tool. It calls WormBaseClient.getEntity with type 'variation' and returns formatted JSON response or error.async ({ id, widgets }) => { try { const data = await client.getEntity("variation", id, widgets); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }], }; } catch (error) { return { content: [{ type: "text", text: `Error fetching variation: ${error}` }], isError: true, }; } }
- src/index.ts:160-162 (schema)Zod input schema defining parameters for the 'get_variation' tool: id (required string) and optional widgets array.id: z.string().describe("Variation identifier - allele name (e.g., 'e1370') or WormBase variation ID"), widgets: z.array(z.string()).optional().describe("Specific widgets to fetch: overview, molecular_details, phenotypes, references"), },
- src/client.ts:111-132 (helper)Core helper method WormBaseClient.getEntity that fetches specified widgets from WormBase REST API for any entity type (used with 'variation' for get_variation tool).async getEntity( type: EntityType, id: string, widgets?: string[] ): Promise<Record<string, unknown>> { const defaultWidgets = ["overview"]; const requestedWidgets = widgets || defaultWidgets; const result: Record<string, unknown> = { id, type }; for (const widget of requestedWidgets) { try { const url = `${this.baseUrl}/rest/widget/${type}/${encodeURIComponent(id)}/${widget}`; const data = await this.fetch<any>(url); result[widget] = this.cleanWidgetData(data); } catch (error) { result[widget] = { error: `Failed to fetch ${widget}` }; } } return result; }
- src/client.ts:237-270 (helper)Helper method to clean and simplify raw data from WormBase API widgets, used in getEntity.private cleanWidgetData(data: any): Record<string, unknown> { if (!data) return {}; // The API typically wraps data in a "fields" object const fields = data.fields || data; // Clean and simplify the data structure const cleaned: Record<string, unknown> = {}; for (const [key, value] of Object.entries(fields)) { if (value === null || value === undefined) continue; // Handle nested data structures if (typeof value === "object" && value !== null) { const obj = value as Record<string, unknown>; if ("data" in obj) { cleaned[key] = obj.data; } else if ("id" in obj && "label" in obj) { // Entity reference cleaned[key] = { id: obj.id, label: obj.label, class: obj.class || obj.taxonomy, }; } else { cleaned[key] = this.simplifyValue(value); } } else { cleaned[key] = value; } } return cleaned; }