The ClinicalTrials.gov MCP Server enables AI agents to programmatically access and analyze the ClinicalTrials.gov database through three core tools:
Search Studies (clinicaltrials_search_studies) - Find clinical trials using query terms (conditions, interventions, locations, sponsors) and filters, with support for pagination, sorting, geographic filtering, and advanced Essie expression syntax.
Retrieve Study Details (clinicaltrials_get_study) - Fetch comprehensive or summary information for specific studies by NCT ID, including protocols, eligibility criteria, outcomes, sponsors, and locations, with flexible field selection and markup format options.
Analyze Trends (clinicaltrials_analyze_trends) - Perform statistical analysis on up to 5000 studies, aggregating data by status, country, sponsor type, or phase to identify research patterns and trends.
Key Applications:
Automate clinical research workflows and integrate trial data into AI-driven applications
Support regulatory submissions, compliance workflows, and competitive intelligence
Enable evidence-based decision making through comprehensive trial analysis
Streamline clinical trial reviews and market research
Technical Features: Built on the official ClinicalTrials.gov v2 API with robust error handling, rate limiting, data cleaning, input validation, and TypeScript type safety for reliable programmatic access.
Provides the project repository on GitHub for access to source code and documentation.
Uses Hono as a high-performance HTTP server featuring session management, CORS, and IP-based rate limiting.
Supports returning clinical trial data in markdown format for improved readability in AI responses.
Requires Node.js (>=18.0.0) as the runtime environment for the MCP server.
Distributes the server via npm package management system, allowing for easy installation.
Uses Prettier for consistent code formatting during development.
Built with TypeScript for type safety and robust error handling when interacting with the ClinicalTrials.gov database.
Implements input validation and sanitization using Zod schema validation for secure API interactions.
Click on "Install 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., "@ClinicalTrials.gov MCP Serverfind Phase 3 diabetes studies currently recruiting"
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.
Tools
Seven tools for working with ClinicalTrials.gov data:
Tool Name | Description |
| Searches for clinical studies using query terms, filters, pagination, and sorting. Includes geographic and enum-based filtering. |
| Fetches one or more clinical studies by their NCT IDs, returning either full data or concise summaries. |
| Fetches trial results data for completed studies — outcomes, adverse events, participant flow, and baseline characteristics. |
| Discovers valid enum values for any API field with study counts, enabling informed query construction. |
| Performs statistical analysis on up to 5000 studies by status, country, sponsor, phase, year, month, study type, or intervention type. |
| Side-by-side comparison of 2-5 clinical studies across eligibility, design, interventions, outcomes, and sponsors. |
| Matches patient profiles to eligible clinical trials, filtering by age, sex, conditions, and location. Returns studies sorted by proximity. |
clinicaltrials_search_studies
Search for clinical trials using free-text queries and filters.
Full-text search plus specialized condition, intervention, and sponsor queries targeting specific API indexes
Typed enum filters for study status and phase (single value or array)
Geographic proximity filtering by coordinates and distance
Advanced filtering with ClinicalTrials.gov's AREA[] syntax
Pagination (up to 200 per page), sorting, and field selection
clinicaltrials_get_study
Fetch one or more clinical trials by NCT ID, with full data or concise summaries.
Batch fetch up to 5 studies at once
Full data includes protocol sections, results, adverse events, outcome measures, eligibility, and locations
Partial success reporting when some studies in a batch fail
clinicaltrials_analyze_trends
Aggregate statistics across up to 5,000 studies by status, country, sponsor, phase, year, month, study type, or intervention type.
Combine multiple analysis types in a single request
Filter to focus on specific subsets
Returns counts and top categories (percentages omitted for phase breakdowns, where multi-phase studies make the denominator ambiguous)
clinicaltrials_compare_studies
Compare 2-5 studies side-by-side across eligibility, design, interventions, outcomes, sponsors, and locations.
Configurable comparison fields — compare everything or focus on specific aspects
Handles partial failures if some studies can't be fetched
clinicaltrials_find_eligible_studies
Match a patient profile (age, sex, conditions, location) to eligible clinical trials.
Hard filters on age, sex, healthy volunteer status, and country — ineligible studies are excluded entirely
Condition token overlap used as a false-positive gate (studies with zero relevance to the patient's conditions are excluded)
Results sorted by location proximity: city match → state match → country-only, then by number of nearby sites
Returns a summary of why each study is a potential match
clinicaltrials_get_study_results
Fetch results data (outcomes, adverse events, participant flow, baseline characteristics) for completed studies.
Section-level filtering — request only the sections you need
Batch up to 5 studies per request
Reports which studies lack results or failed to fetch
Includes statistical analyses (p-values, methods) with outcome data
clinicaltrials_get_field_values
Look up valid enum values for any ClinicalTrials.gov API field, with study counts per value.
Sorted by frequency
Useful for exploring OverallStatus, Phase, InterventionType, StudyType, and other fields before constructing filters
Related MCP server: Healthcare MCP Server
Features
Built on mcp-ts-template:
Declarative tool definitions — single file per tool, framework handles registration and validation
Unified
McpErrorerror handling across all toolsPluggable auth (
none,jwt,oauth)Swappable storage backends:
in-memory,filesystem,Supabase,Cloudflare KV/R2Structured logging (Pino) with optional OpenTelemetry tracing
Typed DI container with
Token<T>phantom brandingRuns locally (stdio/HTTP) or on Cloudflare Workers from the same codebase
ClinicalTrials.gov-specific:
Type-safe client for the ClinicalTrials.gov v2 API
Tools for search, filtering, statistical aggregation, and patient matching
Automatic cleaning and simplification of API responses for agent consumption
Getting started
Public Hosted Instance
A public instance is available at https://clinicaltrials.caseyjhand.com/mcp — no installation required. Point any MCP client at it via Streamable HTTP:
{
"mcpServers": {
"clinicaltrialsgov": {
"type": "streamable-http",
"url": "https://clinicaltrials.caseyjhand.com/mcp"
}
}
}Self-Hosted / Local
Add the following to your MCP Client configuration file (e.g., cline_mcp_settings.json).
{
"mcpServers": {
"clinicaltrialsgov-mcp-server": {
"type": "stdio",
"command": "bunx",
"args": ["clinicaltrialsgov-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info"
}
}
}
}Or for Streamable HTTP:
MCP_TRANSPORT_TYPE=http
MCP_HTTP_PORT=3017Prerequisites
Bun v1.2.0 or higher.
Installation
Clone the repository:
git clone https://github.com/cyanheads/clinicaltrialsgov-mcp-server.gitNavigate into the directory:
cd clinicaltrialsgov-mcp-serverInstall dependencies:
bun installConfiguration
All configuration is centralized and validated at startup in src/config/index.ts. Key environment variables in your .env file include:
Variable | Description | Default |
| The transport to use: |
|
| The port for the HTTP server. |
|
| Authentication mode: |
|
| Storage backend: |
|
| Set to |
|
| The minimum level for logging (RFC 5424: |
|
| Required for A 32+ character secret key. |
|
| Required for URL of the OIDC provider. |
|
Running the server
Local Development
Build and run the production version:
# One-time build bun rebuild # Run the built server bun start:http # or bun start:stdioRun checks and tests:
bun devcheck # Lints, formats, type-checks, and more bun test # Runs the test suite
Cloudflare Workers
Build the Worker bundle:
bun build:workerRun locally with Wrangler:
bun deploy:devDeploy to Cloudflare:
bun deploy:prod
Project structure
Directory | Purpose & Contents |
| Your tool definitions ( |
| Your resource definitions ( |
| Implementations for HTTP and STDIO transports, including auth middleware. |
|
|
| Integrations with external services (ClinicalTrials.gov). |
| Dependency injection container registrations and tokens. |
| Core utilities for logging, error handling, performance, and security. |
| Environment variable parsing and validation with Zod. |
| Unit and integration tests, mirroring the |
Development guide
See CLAUDE.md for development guidelines and architectural rules. The short version:
Logic throws
McpError, handlers catch — notry/catchin tool logicPass
RequestContextthrough the call stack for logging and tracingRegister new tools and resources in the
index.tsbarrel files
Contributing
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 testLicense
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.