clinicaltrialsgov-mcp-server 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +235 -0
- package/dist/config/index.d.ts +100 -0
- package/dist/config/index.js +339 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +214 -0
- package/dist/mcp-server/server.d.ts +21 -0
- package/dist/mcp-server/server.js +108 -0
- package/dist/mcp-server/tools/getStudy/index.d.ts +7 -0
- package/dist/mcp-server/tools/getStudy/index.js +7 -0
- package/dist/mcp-server/tools/getStudy/logic.d.ts +35 -0
- package/dist/mcp-server/tools/getStudy/logic.js +56 -0
- package/dist/mcp-server/tools/getStudy/registration.d.ts +10 -0
- package/dist/mcp-server/tools/getStudy/registration.js +94 -0
- package/dist/mcp-server/tools/listStudies/index.d.ts +7 -0
- package/dist/mcp-server/tools/listStudies/index.js +7 -0
- package/dist/mcp-server/tools/listStudies/logic.d.ts +117 -0
- package/dist/mcp-server/tools/listStudies/logic.js +107 -0
- package/dist/mcp-server/tools/listStudies/registration.d.ts +10 -0
- package/dist/mcp-server/tools/listStudies/registration.js +86 -0
- package/dist/mcp-server/transports/authentication/authContext.d.ts +33 -0
- package/dist/mcp-server/transports/authentication/authContext.js +24 -0
- package/dist/mcp-server/transports/authentication/authMiddleware.d.ts +30 -0
- package/dist/mcp-server/transports/authentication/authMiddleware.js +145 -0
- package/dist/mcp-server/transports/authentication/authUtils.d.ts +18 -0
- package/dist/mcp-server/transports/authentication/authUtils.js +45 -0
- package/dist/mcp-server/transports/authentication/oauthMiddleware.d.ts +24 -0
- package/dist/mcp-server/transports/authentication/oauthMiddleware.js +109 -0
- package/dist/mcp-server/transports/authentication/types.d.ts +17 -0
- package/dist/mcp-server/transports/authentication/types.js +5 -0
- package/dist/mcp-server/transports/httpTransport.d.ts +16 -0
- package/dist/mcp-server/transports/httpTransport.js +258 -0
- package/dist/mcp-server/transports/stdioTransport.d.ts +42 -0
- package/dist/mcp-server/transports/stdioTransport.js +63 -0
- package/dist/services/clinical-trials-gov/ClinicalTrialsGovService.d.ts +59 -0
- package/dist/services/clinical-trials-gov/ClinicalTrialsGovService.js +175 -0
- package/dist/services/clinical-trials-gov/index.d.ts +8 -0
- package/dist/services/clinical-trials-gov/index.js +8 -0
- package/dist/services/clinical-trials-gov/types.d.ts +58 -0
- package/dist/services/clinical-trials-gov/types.js +21 -0
- package/dist/services/supabase/supabaseClient.d.ts +24 -0
- package/dist/services/supabase/supabaseClient.js +67 -0
- package/dist/types-global/errors.d.ts +119 -0
- package/dist/types-global/errors.js +118 -0
- package/dist/utils/clinicaltrials/jsonCleaner.d.ts +12 -0
- package/dist/utils/clinicaltrials/jsonCleaner.js +57 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/internal/errorHandler.d.ts +176 -0
- package/dist/utils/internal/errorHandler.js +335 -0
- package/dist/utils/internal/index.d.ts +9 -0
- package/dist/utils/internal/index.js +9 -0
- package/dist/utils/internal/logger.d.ts +141 -0
- package/dist/utils/internal/logger.js +406 -0
- package/dist/utils/internal/requestContext.d.ts +83 -0
- package/dist/utils/internal/requestContext.js +72 -0
- package/dist/utils/metrics/index.d.ts +7 -0
- package/dist/utils/metrics/index.js +7 -0
- package/dist/utils/metrics/tokenCounter.d.ts +35 -0
- package/dist/utils/metrics/tokenCounter.js +110 -0
- package/dist/utils/network/fetchWithTimeout.d.ts +21 -0
- package/dist/utils/network/fetchWithTimeout.js +59 -0
- package/dist/utils/network/index.d.ts +6 -0
- package/dist/utils/network/index.js +5 -0
- package/dist/utils/parsing/dateParser.d.ts +73 -0
- package/dist/utils/parsing/dateParser.js +107 -0
- package/dist/utils/parsing/index.d.ts +8 -0
- package/dist/utils/parsing/index.js +8 -0
- package/dist/utils/parsing/jsonParser.d.ts +82 -0
- package/dist/utils/parsing/jsonParser.js +126 -0
- package/dist/utils/security/idGenerator.d.ts +137 -0
- package/dist/utils/security/idGenerator.js +215 -0
- package/dist/utils/security/index.d.ts +9 -0
- package/dist/utils/security/index.js +9 -0
- package/dist/utils/security/rateLimiter.d.ts +108 -0
- package/dist/utils/security/rateLimiter.js +179 -0
- package/dist/utils/security/sanitization.d.ts +184 -0
- package/dist/utils/security/sanitization.js +453 -0
- package/package.json +98 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Casey Hand @cyanheads
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# ClinicalTrials.gov MCP Server
|
|
2
|
+
|
|
3
|
+
[](https://www.typescriptlang.org/)
|
|
4
|
+
[](https://modelcontextprotocol.io/)
|
|
5
|
+
[](./CHANGELOG.md)
|
|
6
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
7
|
+
[](https://github.com/cyanheads/clinicaltrialsgov-mcp-server/issues)
|
|
8
|
+
[](https://github.com/cyanheads/clinicaltrialsgov-mcp-server)
|
|
9
|
+
|
|
10
|
+
**Empower your AI agents with direct access to the official ClinicalTrials.gov database!**
|
|
11
|
+
|
|
12
|
+
An MCP (Model Context Protocol) server providing a robust, developer-friendly interface to the official [ClinicalTrials.gov v2 API](https://clinicaltrials.gov/api/v2/docs). Enables LLMs and AI agents to search, retrieve, and analyze clinical study data programmatically.
|
|
13
|
+
|
|
14
|
+
Built on the [`cyanheads/mcp-ts-template`](https://github.com/cyanheads/mcp-ts-template), this server follows a modular architecture with robust error handling, logging, and security features.
|
|
15
|
+
|
|
16
|
+
## 🚀 Core Capabilities: ClinicalTrials.gov Tools 🛠️
|
|
17
|
+
|
|
18
|
+
This server equips your AI with specialized tools to interact with the ClinicalTrials.gov database:
|
|
19
|
+
|
|
20
|
+
| Tool Name | Description | Key Features |
|
|
21
|
+
| :------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
22
|
+
| [`clinicaltrials_list_studies`](./src/mcp-server/tools/listStudies/) | Searches for clinical studies using a combination of query terms and filters. (See [Example](./examples/studies_2025-06-17T11-15-33-773Z.json)) | - `query`: Search by condition, term, location, title, intervention, outcomes, sponsor, or ID.<br/>- `filter`: Refine results by NCT IDs, study status, geographic distance, or advanced Essie expressions.<br/>- `pagination`: Control result sets with `pageSize` and `pageToken`.<br/>- `fields`: Specify which data fields to return for efficiency. |
|
|
23
|
+
| [`clinicaltrials_get_study`](./src/mcp-server/tools/getStudy/) | Retrieves detailed information for a single clinical study by its NCT number. (See [Example](./examples/study_NCT03934567_2025-06-17T11-17-59-791Z.json)) | - `nctId`: Fetches a study using its unique identifier (e.g., "NCT03934567").<br/>- `fields`: Select specific fields to retrieve.<br/>- `markupFormat`: Choose between `markdown` or `legacy` for formatted content.<br/>- Uses ClinicalTrials.gov REST API v2. |
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Table of Contents
|
|
28
|
+
|
|
29
|
+
| [Overview](#overview) | [Features](#features) | [Installation](#installation) |
|
|
30
|
+
|
|
31
|
+
| [Configuration](#configuration) | [Project Structure](#project-structure) |
|
|
32
|
+
|
|
33
|
+
| [Tools](#tools) | [Resources](#resources) | [Development](#development) | [License](#license) |
|
|
34
|
+
|
|
35
|
+
## Overview
|
|
36
|
+
|
|
37
|
+
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.
|
|
38
|
+
|
|
39
|
+
Instead of complex API integration or manual searches, your tools can leverage this server to:
|
|
40
|
+
|
|
41
|
+
- **Automate clinical research workflows**: Search for clinical trials, fetch detailed study metadata, and analyze trial characteristics programmatically.
|
|
42
|
+
- **Gain research insights**: Access comprehensive trial data including study protocols, eligibility criteria, outcomes, sponsors, and locations without leaving the host application.
|
|
43
|
+
- **Integrate clinical trial data into AI-driven research**: Enable LLMs to conduct clinical trial reviews, analyze research trends, and support evidence-based decision making.
|
|
44
|
+
- **Support regulatory and compliance workflows**: Retrieve structured data for regulatory submissions, competitive intelligence, and market research.
|
|
45
|
+
|
|
46
|
+
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.
|
|
47
|
+
|
|
48
|
+
> **Developer Note**: This repository includes a [.clinerules](.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.
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
### Core Utilities
|
|
53
|
+
|
|
54
|
+
Leverages the robust utilities provided by the `mcp-ts-template`:
|
|
55
|
+
|
|
56
|
+
- **Logging**: Structured, configurable logging (file rotation, stdout JSON, MCP notifications) with sensitive data redaction.
|
|
57
|
+
- **Error Handling**: Centralized error processing, standardized error types (`McpError`), and automatic logging.
|
|
58
|
+
- **Configuration**: Environment variable loading (`dotenv`) with comprehensive validation.
|
|
59
|
+
- **Input Validation/Sanitization**: Uses `zod` for schema validation and custom sanitization logic.
|
|
60
|
+
- **Request Context**: Tracking and correlation of operations via unique request IDs using `AsyncLocalStorage`.
|
|
61
|
+
- **Type Safety**: Strong typing enforced by TypeScript and Zod schemas.
|
|
62
|
+
- **HTTP Transport**: High-performance HTTP server using **Hono**, featuring session management with garbage collection, CORS, and IP-based rate limiting.
|
|
63
|
+
- **Authentication**: Robust authentication layer supporting JWT and OAuth 2.1, with fine-grained scope enforcement.
|
|
64
|
+
- **Deployment**: Multi-stage `Dockerfile` for creating small, secure production images with native dependency support.
|
|
65
|
+
|
|
66
|
+
### ClinicalTrials.gov Integration
|
|
67
|
+
|
|
68
|
+
- **Official API Integration**: Comprehensive access to ClinicalTrials.gov v2 API endpoints with automatic JSON parsing.
|
|
69
|
+
- **Advanced Search Capabilities**: Complex query construction with filters for study status, geographic location, conditions, interventions, and sponsors.
|
|
70
|
+
- **Full Study Metadata**: Retrieve complete trial data including protocols, eligibility criteria, study design, outcomes, sponsors, and contact information.
|
|
71
|
+
- **Flexible Field Selection**: Choose specific data fields to retrieve for efficient API usage and reduced response sizes.
|
|
72
|
+
- **Pagination Support**: Handle large result sets with built-in pagination using `pageSize` and `pageToken` parameters.
|
|
73
|
+
- **Multiple Query Types**: Support for condition-based, intervention-based, location-based, and sponsor-based searches.
|
|
74
|
+
- **Data Format Options**: Choose between `markdown` and `legacy` markup formats for study descriptions.
|
|
75
|
+
- **Rate Limiting Compliance**: Built-in request throttling to comply with ClinicalTrials.gov API guidelines.
|
|
76
|
+
|
|
77
|
+
## Installation
|
|
78
|
+
|
|
79
|
+
### Prerequisites
|
|
80
|
+
|
|
81
|
+
- [Node.js (>=18.0.0)](https://nodejs.org/)
|
|
82
|
+
- [npm](https://www.npmjs.com/) (comes with Node.js)
|
|
83
|
+
- [Docker](https://www.docker.com/) (optional, for containerized deployment)
|
|
84
|
+
|
|
85
|
+
### Install via npm (recommended)
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm install @cyanheads/clinicaltrialsgov-mcp-server
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Alternatively Install from Source
|
|
92
|
+
|
|
93
|
+
1. Clone the repository:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
git clone https://github.com/cyanheads/clinicaltrialsgov-mcp-server.git
|
|
97
|
+
cd clinicaltrialsgov-mcp-server
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
2. Install dependencies:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
npm install
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
3. Build the project:
|
|
107
|
+
```bash
|
|
108
|
+
npm run build
|
|
109
|
+
*or npm run rebuild*
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Configuration
|
|
113
|
+
|
|
114
|
+
### Environment Variables
|
|
115
|
+
|
|
116
|
+
Configure the server using environment variables. These environmental variables are set within your MCP client config/settings (e.g. `claude_desktop_config.json` for Claude Desktop)
|
|
117
|
+
|
|
118
|
+
| Variable | Description | Default |
|
|
119
|
+
| -------------------------- | ---------------------------------------------------------------------------------------- | ------------------------- |
|
|
120
|
+
| `MCP_TRANSPORT_TYPE` | Transport mechanism: `stdio` or `http`. | `stdio` |
|
|
121
|
+
| `MCP_HTTP_PORT` | Port for the HTTP server (if `MCP_TRANSPORT_TYPE=http`). | `3010` |
|
|
122
|
+
| `MCP_HTTP_HOST` | Host address for the HTTP server (if `MCP_TRANSPORT_TYPE=http`). | `127.0.0.1` |
|
|
123
|
+
| `MCP_ALLOWED_ORIGINS` | Comma-separated list of allowed origins for CORS (if `MCP_TRANSPORT_TYPE=http`). | (none) |
|
|
124
|
+
| `MCP_LOG_LEVEL` | Logging level (`debug`, `info`, `notice`, `warning`, `error`, `crit`, `alert`, `emerg`). | `debug` |
|
|
125
|
+
| `LOG_OUTPUT_MODE` | Logging output mode: `file` or `stdout`. | `file` |
|
|
126
|
+
| `MCP_AUTH_MODE` | Authentication mode for HTTP: `jwt` or `oauth`. | `jwt` |
|
|
127
|
+
| `MCP_AUTH_SECRET_KEY` | **Required for `jwt` auth.** Minimum 32-character secret key for JWT authentication. | (none) |
|
|
128
|
+
| `CLINICALTRIALS_DATA_PATH` | Directory for caching ClinicalTrials.gov API data. | `data/` (in project root) |
|
|
129
|
+
| `LOGS_DIR` | Directory for log file storage (if `LOG_OUTPUT_MODE=file`). | `logs/` |
|
|
130
|
+
| `NODE_ENV` | Runtime environment (`development`, `production`). | `development` |
|
|
131
|
+
|
|
132
|
+
### MCP Client Settings
|
|
133
|
+
|
|
134
|
+
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:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"mcpServers": {
|
|
139
|
+
"clinicaltrialsgov-mcp-server": {
|
|
140
|
+
"command": "npx",
|
|
141
|
+
"args": ["@cyanheads/clinicaltrialsgov-mcp-server"],
|
|
142
|
+
"env": {
|
|
143
|
+
"MCP_LOG_LEVEL": "info"
|
|
144
|
+
},
|
|
145
|
+
"disabled": false,
|
|
146
|
+
"autoApprove": []
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Project Structure
|
|
153
|
+
|
|
154
|
+
The codebase follows a modular structure within the `src/` directory:
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
src/
|
|
158
|
+
├── index.ts # Entry point: Initializes and starts the server
|
|
159
|
+
├── config/ # Configuration loading (env vars, package info)
|
|
160
|
+
│ └── index.ts
|
|
161
|
+
├── mcp-server/ # Core MCP server logic and capability registration
|
|
162
|
+
│ ├── server.ts # Server setup, capability registration
|
|
163
|
+
│ ├── transports/ # Transport handling (stdio, http)
|
|
164
|
+
│ ├── resources/ # MCP Resource implementations
|
|
165
|
+
│ └── tools/ # MCP Tool implementations (subdirs per tool)
|
|
166
|
+
├── services/ # External service integrations
|
|
167
|
+
│ └── clinical-trials-gov/ # ClinicalTrials.gov API client and parsing
|
|
168
|
+
├── types-global/ # Shared TypeScript type definitions
|
|
169
|
+
└── utils/ # Common utility functions (logger, error handler, etc.)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
For a detailed file tree, run `npm run tree` or see [docs/tree.md](docs/tree.md).
|
|
173
|
+
|
|
174
|
+
## Tools
|
|
175
|
+
|
|
176
|
+
The ClinicalTrials.gov MCP Server provides a comprehensive suite of tools for clinical trial research, callable via the Model Context Protocol.
|
|
177
|
+
|
|
178
|
+
| Tool Name | Description | Key Arguments |
|
|
179
|
+
| :---------------------------- | :-------------------------------------------------------------------- | :-------------------------------------------------------------------------------- |
|
|
180
|
+
| `clinicaltrials_list_studies` | Searches for clinical studies using queries, filters, and pagination. | `query?`, `filter?`, `fields?`, `sort?`, `pageSize?`, `pageToken?`, `countTotal?` |
|
|
181
|
+
| `clinicaltrials_get_study` | Fetches detailed information for a single study by NCT number. | `nctId`, `markupFormat?`, `fields?` |
|
|
182
|
+
|
|
183
|
+
_Note: All tools support comprehensive error handling and return structured JSON responses._
|
|
184
|
+
|
|
185
|
+
## Examples
|
|
186
|
+
|
|
187
|
+
Comprehensive usage examples are available in the [`examples/`](examples/) directory:
|
|
188
|
+
|
|
189
|
+
- [List Studies](examples/studies_2025-06-17T11-15-33-773Z.json)
|
|
190
|
+
- [Get Study Details](examples/study_NCT03934567_2025-06-17T11-17-59-791Z.json)
|
|
191
|
+
|
|
192
|
+
## Development
|
|
193
|
+
|
|
194
|
+
### Build and Test
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# Build the project (compile TS to JS in dist/ and make executable)
|
|
198
|
+
npm run build
|
|
199
|
+
|
|
200
|
+
# Test the server locally using the MCP inspector tool (stdio transport)
|
|
201
|
+
npm run inspector
|
|
202
|
+
|
|
203
|
+
# Test the server locally using the MCP inspector tool (http transport)
|
|
204
|
+
npm run inspector:http
|
|
205
|
+
|
|
206
|
+
# Clean build artifacts
|
|
207
|
+
npm run clean
|
|
208
|
+
|
|
209
|
+
# Generate a file tree representation for documentation
|
|
210
|
+
npm run tree
|
|
211
|
+
|
|
212
|
+
# Clean build artifacts and then rebuild the project
|
|
213
|
+
npm run rebuild
|
|
214
|
+
|
|
215
|
+
# Format code with Prettier
|
|
216
|
+
npm run format
|
|
217
|
+
|
|
218
|
+
# Start the server using stdio (default)
|
|
219
|
+
npm start
|
|
220
|
+
# Or explicitly:
|
|
221
|
+
npm run start:stdio
|
|
222
|
+
|
|
223
|
+
# Start the server using HTTP transport
|
|
224
|
+
npm run start:http
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## License
|
|
228
|
+
|
|
229
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
<div align="center">
|
|
234
|
+
Built with the <a href="https://modelcontextprotocol.io/">Model Context Protocol</a>
|
|
235
|
+
</div>
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Loads, validates, and exports application configuration.
|
|
3
|
+
* This module centralizes configuration management, sourcing values from
|
|
4
|
+
* environment variables and `package.json`. It uses Zod for schema validation
|
|
5
|
+
* to ensure type safety and correctness of configuration parameters.
|
|
6
|
+
*
|
|
7
|
+
* Key responsibilities:
|
|
8
|
+
* - Load environment variables from a `.env` file.
|
|
9
|
+
* - Read `package.json` for default server name and version.
|
|
10
|
+
* - Define a Zod schema for all expected environment variables.
|
|
11
|
+
* - Validate environment variables against the schema.
|
|
12
|
+
* - Construct and export a comprehensive `config` object.
|
|
13
|
+
* - Export individual configuration values like `logLevel` and `environment` for convenience.
|
|
14
|
+
*
|
|
15
|
+
* @module src/config/index
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Main application configuration object.
|
|
19
|
+
* Aggregates settings from validated environment variables and `package.json`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const config: {
|
|
22
|
+
/** Information from package.json. */
|
|
23
|
+
pkg: {
|
|
24
|
+
name: string;
|
|
25
|
+
version: string;
|
|
26
|
+
};
|
|
27
|
+
/** MCP server name. Env `MCP_SERVER_NAME` > `package.json` name > "mcp-ts-template". */
|
|
28
|
+
mcpServerName: string;
|
|
29
|
+
/** MCP server version. Env `MCP_SERVER_VERSION` > `package.json` version > "0.0.0". */
|
|
30
|
+
mcpServerVersion: string;
|
|
31
|
+
/** Logging level. From `MCP_LOG_LEVEL` env var. Default: "debug". */
|
|
32
|
+
logLevel: string;
|
|
33
|
+
/** Absolute path to the logs directory. From `LOGS_DIR` env var. */
|
|
34
|
+
logsPath: string;
|
|
35
|
+
/** Runtime environment. From `NODE_ENV` env var. Default: "development". */
|
|
36
|
+
environment: string;
|
|
37
|
+
/** MCP transport type ('stdio' or 'http'). From `MCP_TRANSPORT_TYPE` env var. Default: "stdio". */
|
|
38
|
+
mcpTransportType: "stdio" | "http";
|
|
39
|
+
/** HTTP server port (if http transport). From `MCP_HTTP_PORT` env var. Default: 3010. */
|
|
40
|
+
mcpHttpPort: number;
|
|
41
|
+
/** HTTP server host (if http transport). From `MCP_HTTP_HOST` env var. Default: "127.0.0.1". */
|
|
42
|
+
mcpHttpHost: string;
|
|
43
|
+
/** Array of allowed CORS origins (http transport). From `MCP_ALLOWED_ORIGINS` (comma-separated). */
|
|
44
|
+
mcpAllowedOrigins: string[] | undefined;
|
|
45
|
+
/** Auth secret key (JWTs, http transport). From `MCP_AUTH_SECRET_KEY`. CRITICAL. */
|
|
46
|
+
mcpAuthSecretKey: string | undefined;
|
|
47
|
+
/** The authentication mode ('jwt' or 'oauth'). From `MCP_AUTH_MODE`. */
|
|
48
|
+
mcpAuthMode: "jwt" | "oauth";
|
|
49
|
+
/** OAuth 2.1 Issuer URL. From `OAUTH_ISSUER_URL`. */
|
|
50
|
+
oauthIssuerUrl: string | undefined;
|
|
51
|
+
/** OAuth 2.1 JWKS URI. From `OAUTH_JWKS_URI`. */
|
|
52
|
+
oauthJwksUri: string | undefined;
|
|
53
|
+
/** OAuth 2.1 Audience. From `OAUTH_AUDIENCE`. */
|
|
54
|
+
oauthAudience: string | undefined;
|
|
55
|
+
/** OpenRouter App URL. From `OPENROUTER_APP_URL`. Default: "http://localhost:3000". */
|
|
56
|
+
openrouterAppUrl: string;
|
|
57
|
+
/** OpenRouter App Name. From `OPENROUTER_APP_NAME`. Defaults to `mcpServerName`. */
|
|
58
|
+
openrouterAppName: string;
|
|
59
|
+
/** OpenRouter API Key. From `OPENROUTER_API_KEY`. */
|
|
60
|
+
openrouterApiKey: string | undefined;
|
|
61
|
+
/** Default LLM model. From `LLM_DEFAULT_MODEL`. */
|
|
62
|
+
llmDefaultModel: string;
|
|
63
|
+
/** Default LLM temperature. From `LLM_DEFAULT_TEMPERATURE`. */
|
|
64
|
+
llmDefaultTemperature: number | undefined;
|
|
65
|
+
/** Default LLM top_p. From `LLM_DEFAULT_TOP_P`. */
|
|
66
|
+
llmDefaultTopP: number | undefined;
|
|
67
|
+
/** Default LLM max tokens. From `LLM_DEFAULT_MAX_TOKENS`. */
|
|
68
|
+
llmDefaultMaxTokens: number | undefined;
|
|
69
|
+
/** Default LLM top_k. From `LLM_DEFAULT_TOP_K`. */
|
|
70
|
+
llmDefaultTopK: number | undefined;
|
|
71
|
+
/** Default LLM min_p. From `LLM_DEFAULT_MIN_P`. */
|
|
72
|
+
llmDefaultMinP: number | undefined;
|
|
73
|
+
/** OAuth Proxy configurations. Undefined if no related env vars are set. */
|
|
74
|
+
oauthProxy: {
|
|
75
|
+
authorizationUrl: string | undefined;
|
|
76
|
+
tokenUrl: string | undefined;
|
|
77
|
+
revocationUrl: string | undefined;
|
|
78
|
+
issuerUrl: string | undefined;
|
|
79
|
+
serviceDocumentationUrl: string | undefined;
|
|
80
|
+
defaultClientRedirectUris: string[] | undefined;
|
|
81
|
+
} | undefined;
|
|
82
|
+
/** Supabase configuration. Undefined if no related env vars are set. */
|
|
83
|
+
supabase: {
|
|
84
|
+
url: string;
|
|
85
|
+
anonKey: string;
|
|
86
|
+
serviceRoleKey: string | undefined;
|
|
87
|
+
} | undefined;
|
|
88
|
+
/** Absolute path to the ClinicalTrials.gov data directory. From `CLINICALTRIALS_DATA_PATH` env var. */
|
|
89
|
+
clinicalTrialsDataPath: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Configured logging level for the application.
|
|
93
|
+
* Exported for convenience.
|
|
94
|
+
*/
|
|
95
|
+
export declare const logLevel: string;
|
|
96
|
+
/**
|
|
97
|
+
* Configured runtime environment ("development", "production", etc.).
|
|
98
|
+
* Exported for convenience.
|
|
99
|
+
*/
|
|
100
|
+
export declare const environment: string;
|