ClinicalTrials.gov MCP Server

2.3.4 · active · verified Wed Apr 22

The `clinicaltrialsgov-mcp-server` package offers a robust Model-Context-Protocol (MCP) server solution for interacting with the ClinicalTrials.gov v2 API. Its core functionalities include comprehensive search capabilities for clinical trials, detailed retrieval of study information and results, and advanced patient-to-trial matching based on specified eligibility criteria. The package is currently stable at version 2.3.4, with a release cadence likely driven by API updates or feature enhancements. As a TypeScript-first server, it provides strong type safety and is designed to serve as a backend component, particularly useful for AI agents or LLMs that require structured, real-time access to clinical trial data. Key differentiators include its specialized focus on the ClinicalTrials.gov ecosystem and its MCP adherence, abstracting away much of the API complexity for developers building patient matching and research applications, offering a higher-level interface than direct API interaction. The server can run locally via HTTP or stdio, and is deployable to platforms like Cloudflare Workers.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize and start the `clinicaltrialsgov-mcp-server` locally, handling port configuration and API key loading from environment variables. It also shows basic error and ready event handling.

import { ClinicalTrialsGovMcpServer } from 'clinicaltrialsgov-mcp-server';
import { ConsoleLogger } from '@cyanheads/logger'; // Assumed dependency for logging
import dotenv from 'dotenv';

dotenv.config();

async function main() {
  const port = parseInt(process.env.PORT ?? '3000', 10);
  const clinicalTrialsApiKey = process.env.CLINICALTRIALS_API_KEY ?? '';

  if (!clinicalTrialsApiKey) {
    console.warn("Warning: CLINICALTRIALS_API_KEY is not set. The server might not be able to access ClinicalTrials.gov API without proper authentication.");
  }

  try {
    // Initialize the MCP Server with configuration
    const server = new ClinicalTrialsGovMcpServer({
      port,
      logger: new ConsoleLogger(), // Inject a logger implementation
      clinicalTrialsGovApiKey: clinicalTrialsApiKey,
      // Other configurations like 'storageBackend' or 'authMechanism' might be needed
      // depending on specific deployment and security requirements.
    });

    server.on('ready', () => {
      console.log(`ClinicalTrials.gov MCP Server listening on http://localhost:${port}`);
      console.log('Available tools include search, study details retrieval, and patient matching.');
      console.log('Refer to the documentation for specific API endpoints (e.g., /search, /study/:nctId).');
    });

    server.on('error', (error) => {
      console.error('MCP Server encountered an error:', error);
      process.exit(1);
    });

    // Start the server instance
    await server.start();
    console.log('MCP Server started successfully.');

  } catch (error) {
    console.error('Failed to initialize or start the MCP Server:', error);
    process.exit(1);
  }
}

main();

view raw JSON →