ClinicalTrials.gov
STDIO临床试验数据库访问查询MCP服务器
临床试验数据库访问查询MCP服务器
ClinicalTrials.gov Model Context Protocol (MCP) Server with tools to programmatically search, retrieve, compare, analyze, and find eligible clinical trials. Built for performance and scalability, with native support for serverless deployment (Cloudflare Workers).
This server provides five powerful tools for accessing and analyzing clinical trial data from ClinicalTrials.gov:
| Tool Name | Description | 
|---|---|
clinicaltrials_search_studies | Searches for clinical studies using query terms, filters, pagination, and sorting. Now includes geographic filtering. | 
clinicaltrials_get_study | Fetches one or more clinical studies by their NCT IDs, returning either full data or concise summaries. | 
clinicaltrials_analyze_trends | Performs statistical analysis on up to 5000 studies, with new time-series analysis by year and month. | 
clinicaltrials_compare_studies | Performs a detailed side-by-side comparison of 2-5 clinical studies, highlighting commonalities and differences. | 
clinicaltrials_find_eligible_studies | Matches patient profiles to eligible clinical trials, filtering by age, sex, conditions, and location. | 
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:
clinicaltrials_compare_studiesCompare and contrast multiple studies to identify key similarities and differences.
Key Features:
Example Use Cases:
clinicaltrials_find_eligible_studiesFind relevant clinical trials based on a patient's specific medical profile and demographics.
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": { "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=3015
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. | 3017 | 
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.