by cyanheads
Provides LLM tools that interface with the official ClinicalTrials.gov v2 REST API, enabling fast search, retrieval, and statistical trend analysis of clinical trial records.
ClinicalTrialsGov Mcp Server offers a production‑grade, multi‑tenant Model Context Protocol (MCP) server that exposes three high‑level tools for interacting with the ClinicalTrials.gov database: searching studies, fetching detailed study records, and performing aggregate trend analyses. The server is built for performance, scalability, and edge deployment (e.g., Cloudflare Workers), and includes robust error handling, authentication options, and pluggable storage back‑ends.
git clone https://github.com/cyanheads/clinicaltrialsgov-mcp-server.git
cd clinicaltrialsgov-mcp-server
bun install # or use your preferred package manager
.env file. See the src/config/index.ts table for all options.bun start:httpbun start:stdiobun build:worker then deploy with Wrangler.{
"mcpServers": {
"clinicaltrialsgov-mcp-server": {
"command": "bunx",
"args": ["clinicaltrialsgov-mcp-server"],
"env": { "MCP_LOG_LEVEL": "info" }
}
}
}
clinicaltrials_search_studies, clinicaltrials_get_study, clinicaltrials_analyze_trends).none, jwt, oauth).tsyringe for clean, testable code.Q: Do I need an API key for ClinicalTrials.gov? A: No. The official ClinicalTrials.gov v2 API is open and does not require authentication.
Q: How many studies can I retrieve in a single call?
A: The clinicaltrials_get_study tool accepts up to 5 NCT IDs per request; the search tool paginates up to 200 results per page.
Q: What is the maximum size for trend analysis?
A: Up to 5,000 studies can be aggregated in a single clinicaltrials_analyze_trends request.
Q: Can I run this server on the edge?
A: Yes. Build the Cloudflare Worker bundle with bun build:worker and deploy via Wrangler.
Q: How is authentication handled?
A: The server supports three modes—none (default), jwt (requires MCP_AUTH_SECRET_KEY), and oauth (requires OAUTH_ISSUER_URL). Choose the mode via the MCP_AUTH_MODE environment variable.
Q: What storage options are available?
A: Configure STORAGE_PROVIDER_TYPE to one of in-memory, filesystem, supabase, cloudflare-kv, or r2.
Q: How do I enable OpenTelemetry?
A: Set OTEL_ENABLED=true; the server will automatically emit traces and metrics.
This server provides three powerful tools for accessing and analyzing clinical trial data from ClinicalTrials.gov:
| Tool Name | Description |
|---|---|
clinicaltrials_search_studies |
Searches for clinical studies using a combination of query terms and filters. Supports pagination, sorting, and geographic filtering. |
clinicaltrials_get_study |
Fetches one or more clinical studies by their NCT IDs. Returns either complete study data or concise summaries for each. |
clinicaltrials_analyze_trends |
Performs statistical analysis on studies, aggregating data by status, country, sponsor, or phase. Handles up to 5000 studies per analysis. |
clinicaltrials_search_studiesSearch and discover clinical trials using free-text queries and advanced filters.
Key Features:
Example Use Cases:
clinicaltrials_get_studyRetrieve detailed information for specific clinical trials by their NCT ID.
Key Features:
Example Use Cases:
clinicaltrials_analyze_trendsPerform statistical analysis across thousands of clinical trials.
Key Features:
Example Use Cases:
This server is built on the mcp-ts-template and inherits its rich feature set:
McpError system ensures consistent, structured error responses.none, jwt, or oauth modes.in-memory, filesystem, Supabase, Cloudflare KV/R2) without changing business logic.tsyringe for a clean, decoupled, and testable architecture.Plus, specialized features for ClinicalTrials.gov:
Add the following to your MCP Client configuration file (e.g., cline_mcp_settings.json).
{
"mcpServers": {
"clinicaltrialsgov-mcp-server": {
"command": "bunx",
"args": ["clinicaltrialsgov-mcp-server"],
"env": {
"MCP_LOG_LEVEL": "info"
}
}
}
}
git clone https://github.com/cyanheads/clinicaltrialsgov-mcp-server.git
cd clinicaltrialsgov-mcp-server
bun install
This server equips AI agents with specialized tools to interact with the ClinicalTrials.gov database.
All configuration is centralized and validated at startup in src/config/index.ts. Key environment variables in your .env file include:
| Variable | Description | Default |
|---|---|---|
MCP_TRANSPORT_TYPE |
The transport to use: stdio or http. |
http |
MCP_HTTP_PORT |
The port for the HTTP server. | 3010 |
MCP_AUTH_MODE |
Authentication mode: none, jwt, or oauth. |
none |
STORAGE_PROVIDER_TYPE |
Storage backend: in-memory, filesystem, supabase, cloudflare-kv, r2. |
in-memory |
OTEL_ENABLED |
Set to true to enable OpenTelemetry. |
false |
LOG_LEVEL |
The minimum level for logging (debug, info, warn, error). |
info |
MCP_AUTH_SECRET_KEY |
Required for jwt auth. A 32+ character secret key. |
(none) |
OAUTH_ISSUER_URL |
Required for oauth auth. URL of the OIDC provider. |
(none) |
Build and run the production version:
# One-time build
bun rebuild
# Run the built server
bun start:http
# or
bun start:stdio
Run checks and tests:
bun devcheck # Lints, formats, type-checks, and more
bun test # Runs the test suite
bun build:worker
bun deploy:dev
bun deploy:prod
| Directory | Purpose & Contents |
|---|---|
src/mcp-server/tools |
Your tool definitions (*.tool.ts). This is where you add new capabilities. |
src/mcp-server/resources |
Your resource definitions (*.resource.ts). This is where you add data sources. |
src/mcp-server/transports |
Implementations for HTTP and STDIO transports, including auth middleware. |
src/storage |
StorageService abstraction and all storage provider implementations. |
src/services |
Integrations with external services (ClinicalTrials.gov, LLMs, Speech). |
src/container |
Dependency injection container registrations and tokens. |
src/utils |
Core utilities for logging, error handling, performance, and security. |
src/config |
Environment variable parsing and validation with Zod. |
tests/ |
Unit and integration tests, mirroring the src/ directory structure. |
For strict rules when using this server with an AI agent, refer to the .clinerules file in this repository. Key principles include:
try/catch in your tool logic. Throw an McpError instead.RequestContext object through your call stack for logging and tracing.index.ts barrel files within their respective definitions directories.Issues and pull requests are welcome! If you plan to contribute, please run the local checks and tests before submitting your PR.
bun run devcheck
bun test
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
Please log in to share your review and rating for this MCP.
Explore related MCPs that share similar capabilities and solve comparable challenges
by mindsdb
Enables humans, AI agents, and applications to retrieve highly accurate answers across large‑scale data sources, unifying heterogeneous databases, warehouses, and SaaS platforms.
by mckinsey
Build high-quality data visualization apps quickly using a low-code toolkit that leverages Plotly, Dash, and Pydantic.
by antvis
Offers over 25 AntV chart types for automated chart generation and data analysis, callable via MCP tools, CLI, HTTP, SSE, or streamable transports.
by reading-plus-ai
A versatile tool that enables interactive data exploration through prompts, CSV loading, and script execution.
by Canner
Provides a semantic engine that lets MCP clients and AI agents query enterprise data with contextual understanding, precise calculations, and built‑in governance.
by surendranb
Provides natural‑language access to Google Analytics 4 data via MCP, exposing over 200 dimensions and metrics for Claude, Cursor and other compatible clients.
by ergut
Provides secure, read‑only access to BigQuery datasets, allowing large language models to query and analyze data through a standardized interface.
by isaacwasserman
Provides an interface for LLMs to visualize data using Vega‑Lite syntax, supporting saving of data tables and rendering visualizations as either a full Vega‑Lite specification (text) or a base64‑encoded PNG image.
by vantage-sh
Fetch and explore cloud cost and usage data from a Vantage account using natural language through AI assistants and MCP clients.