cogstack-mcp-wrapper

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.

Category
访问服务器

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

  1. 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
  1. 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)
  2. 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 terms
  • limit (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 ID
    • include: Include (true) or exclude (false) patients
    • includeChildren: Include child concepts
    • operator: "AND" or "OR" for combining queries
  • filters (object, optional): Demographic filters:
    • ageMin, ageMax: Age range
    • gender: {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_cohort
  • analysisType (string, required): One of:
    • age_distribution: Age breakdown
    • top_conditions: Most common conditions
    • demographics: 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_PATH pointing to CogStackCohort directory

Architecture

┌─────────────────┐     ┌──────────────────┐     ┌──────────────────┐
│   MCP Client    │────►│  MCP Wrapper     │────►│ CogStack Server  │
│  (Any MCP App)  │◄────│  (Node.js)       │◄────│  (Express.js)    │
└─────────────────┘     └──────────────────┘     └──────────────────┘
         ↑                       │                            │
         └───────────────────────┴────────────────────────────┘
                    stdio (standard input/output)

The wrapper:

  1. Starts CogStack server as a subprocess
  2. Translates MCP tool calls to HTTP requests
  3. 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

  1. Missing data files: The server will automatically generate random test data if required files are missing.

  2. Port conflicts: Set PORT environment variable to use a different port.

  3. Memory issues: The CogStack server runs with --max-old-space-size=32768. Adjust in src/index.ts if needed.

  4. Server startup: The wrapper waits up to 30 seconds for CogStack to start. Check console output for errors.

Documentation

How It Works

The wrapper acts as a translation layer:

  1. Receives MCP commands from any MCP client
  2. Starts the CogStackCohort server (if not running)
  3. Translates commands to HTTP requests
  4. 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.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选