phenoforge
This MCP server supports ICD-10-CM concept lookup, hierarchy expansion, hybrid free-text search, and curated OHDSI phenotype matching with provenance-tagged results.
Look up an exact ICD-10-CM code with
lookup_conceptto retrieve its name and OMOP metadata, ornullif not found.Expand an ICD-10-CM code with
expand_hierarchyto get all descendant codes, taggedgeneratedprovenance.Search by free-text clinical term with
search_conceptsusing fused BM25 + dense retrieval, returning up tokrelevant concepts taggedgenerated.Find a curated phenotype definition first with
find_curated_definition, matching against a bundled OHDSI Phenotype Library demo set and returningcuratedprovenance when found.Review provenance and unresolved terms: set-returning tools include per-concept trust tier/source and
unmappableentries explaining failed matches.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@phenoforge adults with type 2 diabetes and nephropathy"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
phenoforge
Semantic value set assembly for clinical cohort definitions, over MCP.
Status: early prototype. The vocabulary loader, hierarchy expansion, hybrid (BM25 + dense) search, curated OHDSI Phenotype Library matching, an eval harness scoring all of it against curated ground truth, a thin MCP server exposing them all, and a LangGraph agent that decomposes a population description, checks curated first, and pauses for human confirmation before including anything generated — all work end-to-end against a real Athena download. See Roadmap.
Try it now, no setup
git clone https://github.com/colbyw5/phenoforge && cd phenoforge
uv run python scripts/run_demo.py "diabetic nephropathy" # or: make demoRuns real hybrid search and hierarchy expansion against a small, bundled, redistributable
ICD-10-CM-only demo vocabulary (see demo/README.md) — no Athena account, no API key, no model
download. It only exercises the generated tier (BM25 + hierarchy expansion); the curated
tier, dense retrieval, and the full agent need the real Setup below.
Related MCP server: OMOP MCP Server
Setup
Published to PyPI as py-phenoforge (the bare phenoforge name is taken by an unrelated
package) — pip install py-phenoforge or uv add py-phenoforge gets you the library and the
phenoforge-mcp CLI, importable as phenoforge. That alone isn't runnable yet, though: every
tool needs the vocabulary database built below from your own Athena download, which can't be
redistributed on PyPI.
Requires your own OHDSI Athena bulk download — vocabulary content carries its own license terms, so it can't be bundled with this repo.
Create a free account at athena.ohdsi.org.
Under Search, select at least ICD10CM and SNOMED as vocabularies, then click Download. SNOMED is used locally only — to resolve curated-set matching (
find_curated_definition) — and is never shipped or exposed through any tool surface.Unzip the download into
data/athena/(this directory is gitignored — nothing underdata/is ever committed or shipped). It contains OMOP CDM vocabulary tables (CONCEPT.csv,CONCEPT_RELATIONSHIP.csv, etc.) — Athena ships vocabulary content pre-shaped as OMOP, so no separate mapping step is needed.
uv sync
python scripts/load_vocab.py data/athena --output data/vocab.duckdb
phenoforge-mcp # stdio MCP server; add to Claude Desktop's mcpServers config to try itOr, once the Athena download is in place, make setup chains install + every optional data-build
step below (vocab, phenotype library, dense index) in one call. make check runs lint, type
checks, and the full test suite — the same checks CI runs on every push. See the Makefile for
the full target list.
find_curated_definition needs a small local cache of OHDSI Phenotype Library cohort
definitions. Like the Athena download, this content carries its own terms — the OHDSI
PhenotypeLibrary GitHub repo has no confirmed LICENSE file (its R package DESCRIPTION claims
Apache, but that's a manifest claim, not a verified grant for the cohort content itself) — so
it's fetched into a gitignored local directory, never committed to this repo. Without this step,
find_curated_definition still runs and reports why nothing matched.
python scripts/fetch_phenotype_library.py # writes data/phenotype_library/Bundles 23 hand-picked cohorts (not the full ~1,100-cohort library), spanning: diabetes (type
2/type 1/gestational, ketoacidosis, retinopathy), chronic kidney disease, cardiovascular (MI,
atrial fibrillation, heart failure), respiratory (pneumonia, asthma), mental health (depression,
anxiety), rheumatoid arthritis, neurological (epilepsy, migraine), sepsis, inflammatory bowel
disease, cirrhosis, hyperlipidemia, and obesity. See scripts/fetch_phenotype_library.py for
exact cohort ids and selection rationale.
search_concepts fuses lexical and semantic matching when a dense index has been built;
without one, it falls back to lexical-only search automatically.
python scripts/build_index.py # writes data/concept_index.lance; downloads BioLORD-2023 on first runScores each retrieval method (BM25, dense, hybrid, hierarchy expansion) against the curated demo cohorts as ground truth — hierarchical distance-weighted scoring, set-level coverage, and an over-inclusion penalty (partial credit for near-misses under the same hierarchy parent, not exact-match recall). Requires the phenotype library fetch step above; dense/hybrid scoring also needs the built index.
python scripts/run_eval.py # bm25 + expand_descendants
python scripts/run_eval.py --index data/concept_index.lance # + dense + hybridSeparately, scripts/eval_decomposition.py scores the agent's decompose step itself (needs
ANTHROPIC_API_KEY and the agent extra — see Validation and limitations below):
python scripts/eval_decomposition.py --index data/concept_index.lanceThe LangGraph agent decomposes a plain-English population description into seed terms, checks
each against the curated phenotype library first, and pauses on the command line for you to
accept or reject any generated (unverified) candidates before they're included. Requires an
Anthropic API key (decomposition is a real Claude call) and the agent extra.
scripts/run_agent.py loads a local .env automatically (gitignored — never commit real keys),
or export the variable directly.
uv sync --extra agent
echo 'ANTHROPIC_API_KEY=...' > .env # or: export ANTHROPIC_API_KEY=...
python scripts/run_agent.py "adults with type 2 diabetes and diabetic nephropathy"
python scripts/run_agent.py "..." --index data/concept_index.lance # + dense retrieval for generated candidatesHosted at colbyw5.github.io/phenoforge, rebuilt on
every push to main. To build locally instead:
make docs # writes docs/_build/index.htmlBoth notebooks are exploration only, never pushed to production — reusable logic stays in
src/phenoforge/.
notebooks/explore.ipynbcalls the engine directly (no MCP transport) against your real builtdata/vocab.duckdb.notebooks/evaluate.ipynbruns the eval harness and walks through the metrics with explanatory text, a method-comparison chart, and a sortable per-cohort results table.
uv sync --extra dev
jupyter lab notebooks/explore.ipynbWhat it does
Turns a plain-English patient population description into a defensible set of ICD-10-CM codes, where every code carries provenance — whether it came from a peer-reviewed phenotype definition, from hierarchy expansion, or from semantic retrieval that a human should check.
"adults with type 2 diabetes and diabetic nephropathy"
→ decomposes into seed clinical terms
→ checks OHDSI Phenotype Library for a validated definition for each
→ falls back to hybrid retrieval for terms with no curated match,
pausing for human confirmation before including anything generated
→ returns a ConceptSet with per-code provenance and citationsRun it for real: python scripts/run_agent.py "adults with type 2 diabetes and diabetic nephropathy" (see Setup).
Why not an existing terminology server
Several good MCP terminology servers exist. They solve lookup — "what is code X", "map X to Y". This solves set assembly, which is the actual task in cohort definition. It also covers US ICD-10-CM, which the existing servers do not, and uses semantic retrieval rather than proxied keyword search, which fails when a population description and a code description share no vocabulary.
Architecture
Three layers — a retrieval engine, a thin MCP server, and a LangGraph agent. The MCP server and the agent are independent consumers of the same engine.
v0.1 — vocabulary layer. Athena loader, DuckDB schema, hierarchy queries
v0.2 — retrieval. BM25, BioLORD-2023 embeddings, LanceDB index, RRF hybrid scoring
v0.3 — expansion + provenance.
ConceptSetmodel, descendant expansion, and OHDSI PL curated matching (small hand-picked demo set — see Setup)v0.4 — MCP server. stdio transport, four tools (see below), Claude Desktop config
v0.5 — eval harness. Distance-weighted scoring, coverage, over-inclusion penalty; curated demo cohorts as ground truth. Decomposition accuracy deferred to
v0.7(seephenoforge.eval) — nothing decomposes a population description yetv0.7 — LangGraph agent. Decompose → check curated first → generate only for unresolved terms → human confirmation gate on anything generated → assemble. Real interactive CLI (
scripts/run_agent.py)v0.6 — encoder benchmark.
scripts/compare_encoders.pymeasured BioLORD-2023 against SapBERT and MedCPT on the same benchmark; BioLORD stays the default (see EVALUATION.md)v1.0 — packaging. One-command setup (
make setup), CI (lint/typecheck/test on every push), a PyPI release pipeline (tag-triggered, trusted publishing) aspy-phenoforge, a zero-setup demo (make demo, no account/key/download needed), hosted API docs (colbyw5.github.io/phenoforge, built from the same docstrings every function already carries), and a validation and limitations section (see below)
Deferred: literature-derived phenotype algorithms (published tier), RxNorm and LOINC domains
Watching: TypeSafe AI's Jev, a
schema-constrained "System One Model" that could fit the decompose node's structured-output
call. Early access/waitlist, proprietary, no independent benchmarks yet as of 2026-10 — not
adopted; revisit if it leaves early access and the latency/cost tradeoff is verified
independently.
Tool | Status | Purpose |
| done | Exact ICD-10-CM code → name and metadata |
| done | Seed code → full descendant expansion ( |
| done | Hybrid BM25 + dense search over ICD-10-CM names, RRF-fused ( |
| done | Search the bundled OHDSI Phenotype Library demo set before generating anything ( |
| done | Why a code would be included, via which path(s), with what evidence — re-derives rather than reading back state, since nothing persists server-side |
find_curated_definition is the only source of curated provenance today, and only for the 23
bundled demo cohorts. Everything from expand_hierarchy and search_concepts is generated
provenance — ungrounded, structural or lexical/semantic only, and meant to be confirmed by a
human before use in a cohort definition.
Full methodology, numbers, and investigation notes live in EVALUATION.md — this is a short summary, not the analysis itself.
The only quantitative evaluation that exists is scripts/run_eval.py scoring each retrieval
method against the 23 bundled OHDSI Phenotype Library demo cohorts (spanning diabetes/kidney,
cardiovascular, respiratory, mental health, and more — see Setup) as ground truth:
method | coverage | over-inclusion | hierarchical |
| 0.759 | 0.441 | 0.589 |
| 0.635 | 0.122 | 0.667 |
| 0.828 | 0.541 | 0.577 |
| 0.873 | 0.436 | 0.654 |
The headline caveats (see EVALUATION.md for the full writeup of each):
23 cohorts across several disease areas — still not a general benchmark. It says nothing about conditions outside the set, rare diseases, or codes with sparse/ambiguous natural-language descriptions.
Over-inclusion is the dominant error mode, not coverage. Every method pulls in more codes than curated ground truth; the
generatedtier should be expected to need rejection of a meaningful fraction of what it returns, not a rubber stamp.Decomposition helps on average (mean gap -0.125 to -0.165 across the 23 cohorts) but has distinct, documented failure modes — near-duplicate cohorts, a mislabeled cohort, and a vocabulary-coverage gap on umbrella clinical terms. See EVALUATION.md.
The encoder benchmark (
v0.6) confirmed BioLORD-2023 as the right default over SapBERT and MedCPT onhybrid(0.654 vs. 0.599/0.617) — though MedCPT is actually the stronger dense-only retriever standalone. See EVALUATION.md.Curated-tier coverage is still narrow by construction. 23 cohorts out of the library's ~1,100 are bundled; any population description outside them falls through entirely to the unverified
generatedtier.No scale or concurrency testing, English/ICD-10-CM only, no audit trail on the human-confirmation gate. See EVALUATION.md.
.github/workflows/publish.yml builds and publishes to PyPI on any v*.*.* tag push, via
PyPI trusted publishing (OIDC — no stored API
token). One-time setup, done outside this repo:
On PyPI: Account settings → Publishing → add a pending publisher for
py-phenoforge, repositorycolbyw5/phenoforge, workflowpublish.yml, environmentpypi.On GitHub: Settings → Environments → create an environment named
pypi(optionally with required reviewers, for a manual approval gate before each publish).
To cut a release: bump version in pyproject.toml, commit, then git tag v0.1.0 && git push origin v0.1.0.
.github/workflows/docs.yml builds and deploys the API docs to GitHub Pages on every push to
main. One-time setup: on GitHub, Settings → Pages → set "Source" to "GitHub Actions" (no
separate environment to create — deploy-pages manages the github-pages environment itself).
License
Apache 2.0. Vocabulary content (ICD-10-CM, SNOMED) carries its own license terms from OHDSI/
Athena, separate from this repo's license — nothing from data/ is redistributed.
Not a clinical decision tool
This produces code sets for research and analytics. It does not make clinical determinations and has not been validated for patient care.
Available Tools
4 toolsexpand_hierarchyA
Expand an ICD-10-CM code to every code beneath it in the billing hierarchy.
For example, expanding "E11" (Type 2 diabetes mellitus) returns all
of its more specific subtypes, such as "E11.21" (with diabetic
nephropathy). Every returned concept is tagged generated provenance:
it is a structural consequence of the vocabulary hierarchy, not a
clinically validated inclusion, and should be treated as ungrounded
until a human confirms it belongs in the target population.
:param seed_code: An exact ICD-10-CM code to expand from, e.g. "E11".
:returns: All descendant concepts, or an empty set if seed_code does
not exist or has no descendants.
:rtype: ConceptSet
Inputs: seed_code (required). Returns: A retrieval or expansion result. Deliberately not a bare list of codes (AGENTS.…
find_curated_definitionA
Search the OHDSI Phenotype Library for a validated cohort definition.
Use this FIRST for any population description that plausibly matches a
peer-reviewed phenotype (e.g. "type 2 diabetes", "diabetic ketoacidosis")
— a match here is curated provenance, safe to use as-is citing the
cohort id. Only fall back to search_concepts/expand_hierarchy if
nothing matches; those return generated provenance requiring human
confirmation. This demo bundles a small, hand-picked set of
diabetes/kidney-related cohorts, not the full library — a miss here
does not mean no curated definition exists.
:param query: Free-text population description.
:returns: The best-matching cohort's resolved ICD-10-CM concepts tagged
curated, or an empty set with an explanatory unmappable
entry if nothing in the bundled set matches or the library has not
been fetched yet.
:rtype: ConceptSet
Inputs: query (required). Returns: A retrieval or expansion result. Deliberately not a bare list of codes (AGENTS.…
lookup_conceptA
Look up a single ICD-10-CM concept by its exact billing code.
Use this when the caller already has a specific code, e.g. "E11.21",
and wants its name and OMOP metadata. Not a search tool — for free-text
clinical terms use search_concepts instead.
:param concept_code: An exact ICD-10-CM code, e.g. "E11.21".
:returns: The matching concept, or None if no ICD-10-CM concept has
that code.
:rtype: Concept | None
Inputs: concept_code (required). Returns: result
search_conceptsA
Search ICD-10-CM concept names for a free-text clinical term or phrase.
Combines lexical (BM25) and semantic (embedding) matching, fused by
reciprocal rank, so paraphrased or loosely-worded descriptions (e.g.
"sugar disease" for diabetes) are found even without shared exact
wording — always prefer this over guessing at exact terminology
yourself. Every returned concept is tagged generated provenance and
should be treated as ungrounded until a human confirms it.
:param query: Free-text search string, e.g. "diabetic nephropathy".
:param k: Maximum number of results to return.
:returns: Fused, deduplicated results ordered by combined relevance. If
nothing matches, concepts is empty and unmappable explains why.
:rtype: ConceptSet
Inputs: query (required), k. Returns: A retrieval or expansion result. Deliberately not a bare list of codes (AGENTS.…
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool occupies a distinct role: exact code lookup, hierarchy expansion, free-text concept search, and curated phenotype library lookup. Explicit cross-references such as 'not a search tool' and 'use this FIRST' make misselection unlikely.
All tool names follow a clear snake_case verb_noun pattern: lookup_concept, expand_hierarchy, search_concepts, find_curated_definition. The names are predictable and communicate their action on a target object.
Four tools is well-scoped for a narrow terminology and phenotype discovery server. Each tool maps to a distinct workflow step without redundancy or unnecessary bloat.
The core discovery workflows are covered: exact code lookup, free-text search, hierarchy expansion, and curated cohort lookup. Missing capabilities like ancestor navigation, batch lookup, or explicit concept set construction are workaround-able and do not severely undermine the stated purpose.
Related MCP Connectors
Semantic search across 5 US government healthcare databases.
NCI Thesaurus concepts and the other cancer-research vocabularies served by NCI Enterprise…
Open healthcare quality measures: CQL, SQL and FHIR with provenance and known issues
Expert-structured medical ontologies, relationships, and evidence for AI research and reasoning.
Related MCP Servers
- AlicenseAqualityDmaintenanceMedical terminology MCP server — ICD-10, MedDRA, RxNorm, CTCAE for AI agents6MIT
- AlicenseBqualityDmaintenanceMCP server for mapping clinical terminology to OMOP concepts using LLMs, with vocabulary search and batch processing capabilities.243Apache 2.0

snowstorm-mcp-serverofficial
AlicenseNot gradedqualityBmaintenanceEnables AI assistants to look up, search, validate, navigate hierarchies, and expand value sets for SNOMED CT clinical terminology through the Model Context Protocol.9Apache 2.0- AlicenseNot gradedqualityDmaintenanceEnables natural language exploration of OMOP CDM databases for concept discovery, patient count queries, and cohort SQL generation with support for multiple database backends.1MIT