Skip to content

About

No description, website, or topics provided.

Resources

Stars

17 stars

Watchers

0 watching

Forks

Repository files navigation

cBioPortal MCP Server

WARNING ⚠️: This is still under construction

A wrapper around the mcp-clickhouse server adding a cBioPortal-specific system prompt.

Installation

# Navigate to the project directory
cd cbioportal-mcp

# Create a virtual environment
python -m venv venv

# Activate the virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate

# Upgrade pip
pip install --upgrade pip

# Install the package in development mode
pip install -e .

# Or install with development dependencies
pip install -e "."

Configuration

Set the same environment variables used by mcp-clickhouse:

export CLICKHOUSE_HOST=your-clickhouse-host
export CLICKHOUSE_PORT=9000
export CLICKHOUSE_USER=your-username
export CLICKHOUSE_PASSWORD=your-password
export CLICKHOUSE_DATABASE=your-cbioportal-database  # see "Preparing the database" below
export CLICKHOUSE_SECURE=true  # or false for insecure connections
# Access control: all four required, "off" for a public portal (see below).
export CBIOPORTAL_MCP_STUDY_FILTERING=off
export CBIOPORTAL_MCP_AUTH_ENFORCEMENT=off
export CBIOPORTAL_MCP_AUTH_TEST_USERS=
export CBIOPORTAL_MCP_PUBLIC_DB_CHECK=off
export CLICKHOUSE_MCP_SERVER_TRANSPORT=http # default; or sse
# Local stdio: set both of these.
# export CLICKHOUSE_MCP_SERVER_TRANSPORT=stdio
# export CBIOPORTAL_MCP_LOCAL_DEV=1
# Optional: mount the HTTP endpoint under a sub-path (default: /mcp).
# Set when reverse-proxied behind a prefix so trailing-slash redirects
# include it, e.g. /db/mcp when served at https://host/db/mcp.
# export CLICKHOUSE_MCP_HTTP_PATH=/db/mcp
# Optional: the http transport is stateless by default (no MCP session IDs, so a
# restart can't strand open client sessions). Set to false to keep sessions.
# export CLICKHOUSE_MCP_STATELESS_HTTP=false
# Optional: how long table lists, column descriptions, and generated study
# guides are cached in-process (default: 3600; 0 disables the cache).
# export CBIOPORTAL_MCP_METADATA_CACHE_TTL_SECONDS=3600
# Optional: most ClickHouse queries one server process runs at once, across
# concurrent tool calls (default: 4). Sets mcp-clickhouse's query pool
# (CLICKHOUSE_MCP_MAX_WORKERS, which it overrides); may also be set in the .env
# mcp-clickhouse loads. A query waiting for a free slot counts against
# CLICKHOUSE_MCP_QUERY_TIMEOUT, so a saturated pool yields a timeout error
# rather than a hung request. If mcp_clickhouse is imported before
# cbioportal_mcp with a different pool size, the server refuses to start.
# export CBIOPORTAL_MCP_MAX_CONCURRENT_QUERIES=4

Access control

The four CBIOPORTAL_MCP_* switches above choose between:

  • off: no extra checks. Every current deployment runs this way.
  • public-database check: refuse to serve study data if the database contains private studies.
  • study filtering: each user sees public studies plus those granted to their email, enforced by ClickHouse row policies. Needs login (Google OAuth and/or the LibreChat bridge).

They have no defaults over HTTP: a missing or misspelled value refuses startup. If a check fails at startup, the server keeps running but blocks study data; GET /health reports study_data_available and a reason.

Details: docs/access-control.md (switches, login, health), docs/study-filtering-setup.md (setting up filtering), docs/study-filtering-design.md (how the row policies work).

Datadog Tool Metrics

The server emits one OpenTelemetry span per MCP tool call and can also emit DogStatsD metrics for dashboard-level aggregates:

Metric Type Purpose
cbioportal_mcp.tool.calls counter Tool-call volume by tool, success, client_kind, and client_name
cbioportal_mcp.tool.duration_ms distribution Tool latency, including p50/p95/p99 by tool
cbioportal_mcp.tool.errors counter Tool-call failures by tool/client

DogStatsD metrics are enabled by default when DD_AGENT_HOST or DD_DOGSTATSD_HOST is configured:

export DD_AGENT_HOST=<datadog-agent-host>
# Optional overrides:
export DD_DOGSTATSD_HOST=<dogstatsd-host>
export DD_DOGSTATSD_PORT=8125
export DD_SERVICE=cbioportal-mcp
export DD_ENV=prod
export CBIOPORTAL_MCP_DD_METRICS_ENABLED=true
export CBIOPORTAL_MCP_DD_METRIC_PREFIX=cbioportal_mcp

Set CBIOPORTAL_MCP_DD_METRICS_ENABLED=false to disable DogStatsD metrics. The checked-in dashboard definition at datadog/cbioagent-tool-metrics-dashboard.json can be imported into Datadog or used as the source for updating the existing cBioAgent dashboard.

Preparing the database

We strongly recommend pointing the MCP at a separate ClickHouse database, not your production cBioPortal database directly. Two reasons:

  1. LLM-friendly fixes are destructive. The agent works much better against a schema that's been cleaned up (misleading columns dropped, column comments added, OncoTree fields denormalized, named cohorts materialized). Applying those changes to your production database would interfere with the cBioPortal application.
  2. Isolation. A separate database with a read-only user (SELECT-only) means agent traffic — including pathological queries — can't degrade production performance or accidentally expose data your portal users shouldn't see.

The recommended pattern is a periodic clone job: copy your production cBioPortal database into a separate ClickHouse database, then apply the SQL files in sql/ — these add column comments, drop misleading columns, denormalize OncoTree, and materialize the cancer_study_query_preferences table the agent uses for cohort lookups. Point the MCP at this cloned-and-prepped database. See sql/README.md for the full schema-prep contract and how to add deployment-specific preferences.

To apply the SQL files manually (e.g. for ad-hoc testing), use the helper script:

export CLICKHOUSE_HOST=... CLICKHOUSE_DATABASE=your-prepped-db
export CLICKHOUSE_ADMIN_USER=...  CLICKHOUSE_ADMIN_PASSWORD=...
./scripts/apply_sql.sh

Note the deliberately separate CLICKHOUSE_ADMIN_* env vars — admin credentials with DDL rights are kept out of the MCP server's runtime environment (which only ever needs SELECT).

For an end-to-end reference deployment (Kubernetes CronJob that handles the clone + SQL apply + atomic pointer-flip), see the cBioPortal team's daily clone CronJob in knowledgesystems-k8s-deployment.

Development

Inspecting the Server with MCP Inspector

To connect to the MCP server and see requests and replies, use MCP Inspector. You can run it with:

CBIOPORTAL_MCP_STUDY_FILTERING=off CBIOPORTAL_MCP_LOCAL_DEV=1 \
  CLICKHOUSE_MCP_SERVER_TRANSPORT=stdio fastmcp dev inspector src/cbioportal_mcp/server.py

Running the Server

# For development
python -m cbioportal_mcp.server

# Or using the installed script
cbioportal-mcp

Running in Docker

# Build the image
docker build -t cbioportal-mcp -f docker/Dockerfile .
docker run -p 8000:8000 -e CBIOPORTAL_MCP_STUDY_FILTERING=off \
  -e CBIOPORTAL_MCP_AUTH_ENFORCEMENT=off -e CBIOPORTAL_MCP_AUTH_TEST_USERS= \
  -e CBIOPORTAL_MCP_PUBLIC_DB_CHECK=off cbioportal-mcp

Chat eval (CI)

PRs that change the server also run a behavioral eval: an LLM agent answers a fixed question set through this PR's image and through cbioportal/mcp:latest, and the check fails if the answers got worse. See docs/chat-eval.md for what it measures and the repository secrets it needs (CLICKHOUSE_*, and ANTHROPIC_API_KEY or an AWS role for Bedrock via OIDC).

License

Apache License 2.0 - see LICENSE for details.

Related Projects

About

No description, website, or topics provided.

Resources

Stars

17 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages