search_mesh
Find standardized biomedical terms, tree numbers, and scope notes in the Medical Subject Headings (MeSH) vocabulary for precise literature searches.
Instructions
Search the Medical Subject Headings (MeSH) vocabulary. Useful for finding standardized biomedical terms, tree numbers, and scope notes.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | MeSH term search query | |
| max_results | No | Maximum results |
Implementation Reference
- src/tools.ts:132-171 (handler)The main handler function searchMesh that implements the search_mesh tool logic. It searches the MeSH database using esearch.fcgi, fetches summaries with esummary.fcgi, and returns formatted results including term names, scope notes, and tree numbers.
export async function searchMesh(args: z.infer<typeof searchMeshSchema>): Promise<string> { const searchResult = await client.fetchJson("esearch.fcgi", { db: "mesh", term: args.query, retmax: String(args.max_results), }) as { esearchresult: { idlist: string[]; count: string } }; const ids = searchResult.esearchresult.idlist; if (ids.length === 0) { return JSON.stringify({ total_count: 0, terms: [] }, null, 2); } // Fetch MeSH summaries const summaryResult = await client.fetchJson("esummary.fcgi", { db: "mesh", id: ids.join(","), version: "2.0", }) as { result?: Record<string, unknown> }; const terms: Array<Record<string, unknown>> = []; if (summaryResult.result) { for (const id of ids) { const entry = summaryResult.result[id] as Record<string, unknown> | undefined; if (entry) { terms.push({ uid: id, name: entry.ds_meshterms || entry.ds_meshui || id, scope_note: entry.ds_scopenote || "", tree_numbers: entry.ds_treenumberlist || [], }); } } } return JSON.stringify({ total_count: parseInt(searchResult.esearchresult.count), showing: terms.length, terms, }, null, 2); } - src/tools.ts:30-33 (schema)The searchMeshSchema Zod schema defining the input validation for search_mesh tool, with query (string) and max_results (number 1-50, default 10) parameters.
export const searchMeshSchema = z.object({ query: z.string().describe("MeSH term search query"), max_results: z.number().min(1).max(50).default(10).describe("Maximum results"), }); - src/index.ts:61-68 (registration)Tool registration where search_mesh is registered with the MCP server, including its description and the handler binding to searchMesh function.
server.tool( "search_mesh", "Search the Medical Subject Headings (MeSH) vocabulary. Useful for finding standardized biomedical terms, tree numbers, and scope notes.", searchMeshSchema.shape, async (args) => ({ content: [{ type: "text", text: await searchMesh(searchMeshSchema.parse(args)) }], }) );