clinicaltrialsgov-mcp-server
Version:
ClinicalTrials.gov Model Context Protocol (MCP) Server that provides a suite of tools for interacting with the official ClinicalTrials.gov v2 API. Enables AI agents and LLMs to programmatically search, retrieve, and analyze clinical trial data.
76 lines (75 loc) • 3.37 kB
TypeScript
/**
* @fileoverview Service for interacting with the ClinicalTrials.gov API.
* This module provides a singleton class `ClinicalTrialsGovService` that encapsulates
* all network requests to the ClinicalTrials.gov API, handles response validation,
* and implements backing up of API responses to the local filesystem.
* @module src/services/clinical-trials-gov/ClinicalTrialsGovService
*/
import { type RequestContext } from "../../utils/index.js";
import type { FieldNode, PagedStudies, Study } from "./types.js";
/**
* A service class to interact with the ClinicalTrials.gov API.
* It handles request construction, API communication, and response backup.
*/
export declare class ClinicalTrialsGovService {
private static instance;
/**
* Private constructor to prevent direct instantiation.
*/
private constructor();
/**
* Returns the singleton instance of the ClinicalTrialsGovService.
* @returns The singleton instance.
*/
static getInstance(): ClinicalTrialsGovService;
/**
* Fetches a single study by its NCT ID, with optional parameters.
* @param nctId - The NCT ID of the study.
* @param context - The request context for logging.
* @param options - Optional parameters for the fetch request.
* @param options.fields - A list of specific top-level fields to return.
* @param options.markupFormat - The format for rich text fields ('markdown' or 'legacy').
* @returns A promise that resolves with the study data.
*/
fetchStudy(nctId: string, context: RequestContext, options?: {
fields?: string[];
markupFormat?: "markdown" | "legacy";
}): Promise<Study>;
/**
* Searches for studies based on a set of query parameters.
* @param params - The query parameters for the search.
* @param context - The request context for logging.
* @returns A promise that resolves with a paged list of studies.
*/
listStudies(params: Record<string, unknown>, context: RequestContext): Promise<PagedStudies>;
/**
* Fetches the study metadata.
* @param params - Parameters for filtering metadata.
* @param context - The request context for logging.
* @returns A promise that resolves with the field node data.
*/
getStudyMetadata(params: {
includeIndexedOnly?: boolean;
includeHistoricOnly?: boolean;
}, context: RequestContext): Promise<FieldNode[]>;
/**
* Fetches API statistics.
* @param statType - The type of statistics to retrieve.
* @param params - Additional parameters for the statistics request.
* @param context - The request context for logging.
* @returns A promise that resolves with the statistical data.
*/
getApiStats(statType: "studySize" | "fieldValues" | "listFieldSizes", params: {
fields?: string[];
types?: string[];
}, context: RequestContext): Promise<unknown>;
/**
* A generic fetch method that handles backing up the response.
* It always fetches live data and writes it to a backup file if the data path is configured.
* @param url - The URL to fetch.
* @param fileName - The file name to use for the backup.
* @param context - The request context for logging.
* @returns A promise that resolves with the fetched data.
*/
private fetchAndBackup;
}