cogstack-mcp-wrapper
Enables querying and analyzing medical cohorts from CogStack via the Model Context Protocol, supporting SNOMED-CT search, cohort creation, and demographic analysis.
README
CogStack MCP Wrapper
An MCP (Model Context Protocol) server that provides programmatic access to CogStackCohort for querying and analyzing medical cohorts through a standardized interface.
What This Is
A bridge layer that:
- Makes CogStackCohort accessible via the Model Context Protocol (MCP)
- Automatically manages the CogStack server lifecycle
- Translates between user-friendly and internal data formats
- Provides a simplified API for complex medical queries
- Works with any MCP-compatible client (Claude Desktop, VS Code, custom clients)
What This Is NOT
- NOT a replacement for CogStackCohort
- NOT adding new medical logic or algorithms
- NOT modifying how cohorts are calculated
- NOT a visualization tool (returns data, not charts)
Key Features
The wrapper exposes CogStackCohort's functionality through MCP tools:
- Search SNOMED-CT concepts - Find medical conditions by keyword
- Create patient cohorts - Filter patients by conditions and demographics
- Temporal queries - Support for longitudinal studies (last 5/10 years, custom ranges)
- Analyze cohort statistics - Age distribution, top conditions, demographics
Prerequisites
- Node.js 14+
- npm or yarn
- CogStackCohort server
- An MCP-compatible client (e.g., Claude Desktop, VS Code with MCP extension, or custom implementation)
Installation
- Clone both repositories:
# Clone the MCP wrapper
git clone https://github.com/YOUR_USERNAME/cogstack-mcp-wrapper.git
cd cogstack-mcp-wrapper
# Clone CogStackCohort (in parent directory)
cd ..
git clone https://github.com/CogStack/CogStackCohort.git
cd cogstack-mcp-wrapper
# Install dependencies
npm install
-
Prepare data files in
../CogStackCohort/server/data/:- Extract SNOMED terms:
cd ../CogStackCohort/server/data && tar xzvf snomed_terms_data.tar.gz - Either provide real data files or generate random test data (automatic if files missing)
- Extract SNOMED terms:
-
Build the MCP server:
npm run build
Usage
Running the MCP Server
The server runs on stdio and automatically starts the CogStackCohort server:
node dist/index.js
Available Tools
1. cogstack_search_snomed
Search for SNOMED-CT concepts by keyword.
Parameters:
query(string, required): Search termslimit(number, optional): Maximum results (default: 20)
Example:
{
"tool": "cogstack_search_snomed",
"parameters": {
"query": "diabetes type 2",
"limit": 10
}
}
2. cogstack_create_cohort
Create a patient cohort based on SNOMED terms and filters.
Parameters:
queries(array, required): SNOMED queries with:cui: SNOMED concept IDinclude: Include (true) or exclude (false) patientsincludeChildren: Include child conceptsoperator: "AND" or "OR" for combining queries
filters(object, optional): Demographic filters:ageMin,ageMax: Age rangegender: {male, female, unknown}ethnicity: {asian, black, white, mixed, other, unknown}vitalStatus: {alive, deceased}timeFilter: Time-based filtering
Example:
{
"tool": "cogstack_create_cohort",
"parameters": {
"queries": [
{
"cui": "44054006",
"include": true,
"includeChildren": true,
"operator": "AND"
},
{
"cui": "38341003",
"include": false
}
],
"filters": {
"ageMin": 50,
"ageMax": 70,
"gender": {
"male": true,
"female": true
}
}
}
}
3. cogstack_analyze_cohort
Analyze a previously created cohort.
Parameters:
cohortId(string, required): ID from create_cohortanalysisType(string, required): One of:age_distribution: Age breakdowntop_conditions: Most common conditionsdemographics: Full demographic analysis
4. cogstack_get_stats
Get statistics about the loaded data.
Configuration
Environment variables:
COGSTACK_PATH: Path to CogStackCohort directory (default:../CogStackCohort)COGSTACK_DATA_PATH: Path to data files (default:../CogStackCohort/server/data)PORT: Port for CogStack server (default: 3000)
Integration with MCP Clients
Claude Desktop
Add to your Claude Desktop configuration:
{
"mcpServers": {
"cogstack": {
"command": "node",
"args": ["/path/to/cogstack-mcp-wrapper/dist/index.js"],
"env": {
"COGSTACK_PATH": "/path/to/CogStackCohort"
}
}
}
}
Other MCP Clients
For other MCP clients, configure with:
- Command:
node /path/to/cogstack-mcp-wrapper/dist/index.js - Transport: stdio
- Environment:
COGSTACK_PATHpointing to CogStackCohort directory
Architecture
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ MCP Client │────►│ MCP Wrapper │────►│ CogStack Server │
│ (Any MCP App) │◄────│ (Node.js) │◄────│ (Express.js) │
└─────────────────┘ └──────────────────┘ └──────────────────┘
↑ │ │
└───────────────────────┴────────────────────────────┘
stdio (standard input/output)
The wrapper:
- Starts CogStack server as a subprocess
- Translates MCP tool calls to HTTP requests
- Returns formatted results to the MCP client
Development
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build for production
npm run build
Troubleshooting
-
Missing data files: The server will automatically generate random test data if required files are missing.
-
Port conflicts: Set
PORTenvironment variable to use a different port. -
Memory issues: The CogStack server runs with
--max-old-space-size=32768. Adjust insrc/index.tsif needed. -
Server startup: The wrapper waits up to 30 seconds for CogStack to start. Check console output for errors.
Documentation
- COMPARISON.md - Detailed comparison between the MCP wrapper and original CogStackCohort
- CogStackCohort Documentation - Original project documentation
How It Works
The wrapper acts as a translation layer:
- Receives MCP commands from any MCP client
- Starts the CogStackCohort server (if not running)
- Translates commands to HTTP requests
- Formats responses for the MCP client
All medical logic, data processing, and cohort calculations remain in the original CogStackCohort server.
License
This wrapper follows the same license as CogStackCohort.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.