search_mesh
Find MeSH descriptor codes and URIs for biomedical concepts by searching labels. Use this tool to identify medical terminology before retrieving detailed records or qualifiers.
Instructions
Search MeSH descriptors by label using the NLM Lookup autocomplete endpoint.
Use this to find the MeSH UI code and URI for a biomedical concept before calling get_mesh_record or get_mesh_qualifiers.
Parameters
query : str The label string to search for (e.g. "diabetes", "neoplasms"). match : str Matching strategy: "startsWith" — left-anchored (default, analogous to LCSH suggest2) "contains" — substring match anywhere in the label "exact" — exact match only limit : int Maximum number of results to return (default 10, max 50).
Returns
dict A 'results' list of {label, ui, uri} dicts, or an 'error' key. 'ui' is the MeSH unique identifier (e.g. "D003920"). 'uri' is the full RDF URI (e.g. "http://id.nlm.nih.gov/mesh/D003920").
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| match | No | startsWith | |
| limit | No |
Implementation Reference
- src/mesh_mcp/server.py:103-147 (handler)The search_mesh tool is defined as an MCP tool, querying the NLM descriptor lookup endpoint and formatting the results into a list of descriptors with labels, UI IDs, and URIs.
@mcp.tool() def search_mesh(query: str, match: str = "startsWith", limit: int = 10) -> dict: """ Search MeSH descriptors by label using the NLM Lookup autocomplete endpoint. Use this to find the MeSH UI code and URI for a biomedical concept before calling get_mesh_record or get_mesh_qualifiers. Parameters ---------- query : str The label string to search for (e.g. "diabetes", "neoplasms"). match : str Matching strategy: "startsWith" — left-anchored (default, analogous to LCSH suggest2) "contains" — substring match anywhere in the label "exact" — exact match only limit : int Maximum number of results to return (default 10, max 50). Returns ------- dict A 'results' list of {label, ui, uri} dicts, or an 'error' key. 'ui' is the MeSH unique identifier (e.g. "D003920"). 'uri' is the full RDF URI (e.g. "http://id.nlm.nih.gov/mesh/D003920"). """ result = _get( f"{_LOOKUP_BASE}/descriptor", params={"label": query, "match": match, "limit": min(limit, 50)}, ) if "error" in result: return result raw = result["data"] if not isinstance(raw, list): return {"error": "Unexpected response format from NLM lookup", "data": raw} results = [] for item in raw: uri = item.get("resource", "") label = item.get("label", "") ui = _uri_to_id(uri) if uri else "" results.append({"label": label, "ui": ui, "uri": uri}) return {"results": results}