get_protein
Retrieve protein details including sequence, domains, motifs, and structure from the WormBase database for C. elegans research.
Instructions
Get detailed information about a protein including sequence, domains, motifs, and structure.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Protein identifier - WormBase protein ID | |
| widgets | No | Specific widgets to fetch: overview, sequences, motif_details, external_links, references |
Implementation Reference
- src/index.ts:64-84 (registration)Registration of the 'get_protein' MCP tool, including description, Zod input schema, and handler function that delegates to WormBaseClient.getEntity.server.tool( "get_protein", "Get detailed information about a protein including sequence, domains, motifs, and structure.", { id: z.string().describe("Protein identifier - WormBase protein ID"), widgets: z.array(z.string()).optional().describe("Specific widgets to fetch: overview, sequences, motif_details, external_links, references"), }, async ({ id, widgets }) => { try { const data = await client.getEntity("protein", id, widgets); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }], }; } catch (error) { return { content: [{ type: "text", text: `Error fetching protein: ${error}` }], isError: true, }; } } );
- src/client.ts:111-132 (handler)Core handler logic in WormBaseClient.getEntity method, which fetches protein data from WormBase REST API widgets and cleans the response. Called by get_protein tool handler with type='protein'.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:15-32 (helper)Private fetch helper used by getEntity to make HTTP requests to WormBase REST API.private async fetch<T>(url: string): Promise<T> { const response = await fetch(url, { headers: { "Accept": "application/json", "Accept-Language": "en-US,en;q=0.9", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "cross-site", }, }); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } return response.json() as Promise<T>; }
- src/client.ts:237-270 (helper)Data cleaning helper used by getEntity to process and simplify WormBase API responses.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; }
- src/types.ts:69-75 (schema)Type definition for protein-specific widgets available for the get_protein tool.export const PROTEIN_WIDGETS = [ ...COMMON_WIDGETS, "sequences", "motif_details", "homology", "blast_details", ] as const;