
ClinicalTrials.gov
STDIOMCP server for accessing and querying ClinicalTrials.gov database via API
MCP server for accessing and querying ClinicalTrials.gov database via API
Empower your AI agents with direct access to the ClinicalTrials.gov database!
Model Context Protocol (MCP) Server providing a robust, developer-friendly interface to the official ClinicalTrials.gov v2 API. Enables LLMs and AI agents to search, retrieve, and analyze clinical study data programmatically.
Built on the cyanheads/mcp-ts-template
, this server follows a modular architecture with robust error handling, logging, and security features.
This server equips your AI with specialized tools to interact with the ClinicalTrials.gov database:
Tool Name | Description | Example |
---|---|---|
clinicaltrials_search_studies | Searches for clinical studies using a combination of query terms and filters. Supports pagination, sorting, and geographic filtering. | View Example |
clinicaltrials_get_study | Fetches one or more clinical studies from ClinicalTrials.gov by their NCT IDs. Returns either complete study data or concise summaries for each. | View Example |
clinicaltrials_analyze_trends | Performs a statistical analysis on a set of clinical trials, aggregating data by status, country, sponsor, or phase. Use specific query parameters to refine the analysis and filter the studies included in the analysis. The tool can handle up to 5000 studies per analysis. | View Example |
| Overview | Features | Installation | Configuration | Project Structure | Tools | Development & Testing | License
The ClinicalTrials.gov MCP Server acts as a bridge, allowing applications (MCP Clients) that understand the Model Context Protocol (MCP) – like advanced AI assistants (LLMs), IDE extensions, or custom research tools – to interact directly and efficiently with the official ClinicalTrials.gov database.
Instead of complex API integration or manual searches, your tools can leverage this server to:
Built on the robust mcp-ts-template
, this server provides a standardized, secure, and efficient way to expose ClinicalTrials.gov functionality via the MCP standard. It achieves this by integrating with the official ClinicalTrials.gov v2 API, ensuring compliance with rate limits and providing comprehensive error handling.
Developer Note: This repository includes a .clinerules file that serves as a developer cheat sheet for your LLM coding agent with quick reference for the codebase patterns, file locations, and code snippets.
Leverages the robust utilities provided by the mcp-ts-template
:
McpError
), and automatic logging.dotenv
) with comprehensive validation using Zod.zod
for schema validation and custom sanitization logic.AsyncLocalStorage
.Dockerfile
for creating small, secure production images with native dependency support.pageSize
and pageToken
parameters.Add the following to your MCP client's configuration file (e.g., cline_mcp_settings.json
). This configuration uses npx
to run the server, which will automatically install the package if not already present:
{ "mcpServers": { "clinicaltrialsgov-mcp-server": { "command": "npx", "args": ["clinicaltrialsgov-mcp-server"], "env": { "MCP_LOG_LEVEL": "info" } } } }
npm install clinicaltrialsgov-mcp-server
git clone https://github.com/cyanheads/clinicaltrialsgov-mcp-server.git cd clinicaltrialsgov-mcp-server
npm install
npm run build
Configure the server using environment variables. For local development, these can be set in a .env
file at the project root or directly in your environment. Otherwise, you can set them in your MCP client configuration as shown above.
Variable | Description | Default |
---|---|---|
MCP_TRANSPORT_TYPE | Transport mechanism: stdio or http . | stdio |
MCP_HTTP_PORT | Port for the HTTP server (if MCP_TRANSPORT_TYPE=http ). | 3010 |
MCP_HTTP_HOST | Host address for the HTTP server (if MCP_TRANSPORT_TYPE=http ). | 127.0.0.1 |
MCP_ALLOWED_ORIGINS | Comma-separated list of allowed origins for CORS (if MCP_TRANSPORT_TYPE=http ). | (none) |
MCP_LOG_LEVEL | Logging level (debug , info , notice , warning , error , crit , alert , emerg ). | debug |
MCP_AUTH_MODE | Authentication mode for HTTP: jwt or oauth . | jwt |
MCP_AUTH_SECRET_KEY | Required for jwt auth. Minimum 32-character secret key for JWT authentication. | (none) |
CLINICALTRIALS_DATA_PATH | Directory for caching ClinicalTrials.gov API data. | data/ |
LOGS_DIR | Directory for log file storage. | logs/ |
NODE_ENV | Runtime environment (development , production ). | development |
The codebase follows a modular structure within the src/
directory:
src/
├── index.ts # Entry point: Initializes and starts the server
├── config/ # Configuration loading (env vars, package info)
│ └── index.ts
├── mcp-server/ # Core MCP server logic and capability registration
│ ├── server.ts # Server setup, capability registration
│ ├── transports/ # Transport handling (stdio, http)
│ └── tools/ # MCP Tool implementations (subdirs per tool)
├── services/ # External service integrations
│ └── clinical-trials-gov/ # ClinicalTrials.gov API client and types
├── types-global/ # Shared TypeScript type definitions
└── utils/ # Common utility functions (logger, error handler, etc.)
For a detailed file tree, run npm run tree
or see docs/tree.md.
The ClinicalTrials.gov MCP Server provides a comprehensive suite of tools for clinical trial research, callable via the Model Context Protocol.
Tool Name | Description | Key Arguments |
---|---|---|
clinicaltrials_search_studies | Searches for clinical studies using queries, filters, and pagination. | query? , filter? , fields? , sort? , pageSize? , pageToken? , countTotal? |
clinicaltrials_get_study | Fetches detailed information for one or more studies by NCT ID. | nctIds , summaryOnly? , markupFormat? , fields? |
clinicaltrials_analyze_trends | Performs statistical analysis on a set of studies. | analysisType , query? , filter? |
Note: All tools support comprehensive error handling and return structured JSON responses.
Comprehensive usage examples for each tool are available in the examples/
directory.
clinicaltrials_search_studies
: View Exampleclinicaltrials_get_study
: View Exampleclinicaltrials_analyze_trends
: View Example# Build the project (compile TS to JS in dist/ and make executable) npm run build # Clean build artifacts npm run clean # Clean build artifacts and then rebuild the project npm run rebuild # Format code with Prettier npm run format # Generate a file tree representation for documentation npm run tree
This project uses Vitest for unit and integration testing.
# Run all tests once npm test # Run tests in watch mode npm run test:watch # Run tests and generate a coverage report npm run test:coverage
# Start the server using stdio (default) npm start # Or explicitly: npm run start:stdio # Start the server using HTTP transport npm run start:http # Test the server locally using the MCP inspector tool (stdio transport) npm run inspector # Test the server locally using the MCP inspector tool (http transport) npm run inspector:http
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.