@cyanheads/pubmed-mcp-server 1.0.12

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.
Files changed (121) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +174 -0
  3. package/dist/config/index.d.ts +91 -0
  4. package/dist/config/index.js +324 -0
  5. package/dist/index.d.ts +24 -0
  6. package/dist/index.js +190 -0
  7. package/dist/mcp-server/resources/echoResource/echoResourceLogic.d.ts +79 -0
  8. package/dist/mcp-server/resources/echoResource/echoResourceLogic.js +82 -0
  9. package/dist/mcp-server/resources/echoResource/index.d.ts +13 -0
  10. package/dist/mcp-server/resources/echoResource/index.js +13 -0
  11. package/dist/mcp-server/resources/echoResource/registration.d.ts +30 -0
  12. package/dist/mcp-server/resources/echoResource/registration.js +168 -0
  13. package/dist/mcp-server/server.d.ts +28 -0
  14. package/dist/mcp-server/server.js +159 -0
  15. package/dist/mcp-server/tools/fetchPubMedContent/index.d.ts +6 -0
  16. package/dist/mcp-server/tools/fetchPubMedContent/index.js +6 -0
  17. package/dist/mcp-server/tools/fetchPubMedContent/logic.d.ts +63 -0
  18. package/dist/mcp-server/tools/fetchPubMedContent/logic.js +518 -0
  19. package/dist/mcp-server/tools/fetchPubMedContent/registration.d.ts +10 -0
  20. package/dist/mcp-server/tools/fetchPubMedContent/registration.js +37 -0
  21. package/dist/mcp-server/tools/getPubMedArticleConnections/index.d.ts +6 -0
  22. package/dist/mcp-server/tools/getPubMedArticleConnections/index.js +6 -0
  23. package/dist/mcp-server/tools/getPubMedArticleConnections/logic/citationFormatter.d.ts +9 -0
  24. package/dist/mcp-server/tools/getPubMedArticleConnections/logic/citationFormatter.js +288 -0
  25. package/dist/mcp-server/tools/getPubMedArticleConnections/logic/elinkHandler.d.ts +9 -0
  26. package/dist/mcp-server/tools/getPubMedArticleConnections/logic/elinkHandler.js +208 -0
  27. package/dist/mcp-server/tools/getPubMedArticleConnections/logic/index.d.ts +15 -0
  28. package/dist/mcp-server/tools/getPubMedArticleConnections/logic/index.js +82 -0
  29. package/dist/mcp-server/tools/getPubMedArticleConnections/logic/types.d.ts +27 -0
  30. package/dist/mcp-server/tools/getPubMedArticleConnections/logic/types.js +5 -0
  31. package/dist/mcp-server/tools/getPubMedArticleConnections/logic.d.ts +6 -0
  32. package/dist/mcp-server/tools/getPubMedArticleConnections/logic.js +6 -0
  33. package/dist/mcp-server/tools/getPubMedArticleConnections/registration.d.ts +36 -0
  34. package/dist/mcp-server/tools/getPubMedArticleConnections/registration.js +76 -0
  35. package/dist/mcp-server/tools/pubmedResearchAgent/index.d.ts +6 -0
  36. package/dist/mcp-server/tools/pubmedResearchAgent/index.js +6 -0
  37. package/dist/mcp-server/tools/pubmedResearchAgent/logic/index.d.ts +7 -0
  38. package/dist/mcp-server/tools/pubmedResearchAgent/logic/index.js +9 -0
  39. package/dist/mcp-server/tools/pubmedResearchAgent/logic/inputSchema.d.ts +111 -0
  40. package/dist/mcp-server/tools/pubmedResearchAgent/logic/inputSchema.js +149 -0
  41. package/dist/mcp-server/tools/pubmedResearchAgent/logic/outputTypes.d.ts +106 -0
  42. package/dist/mcp-server/tools/pubmedResearchAgent/logic/outputTypes.js +7 -0
  43. package/dist/mcp-server/tools/pubmedResearchAgent/logic/planOrchestrator.d.ts +10 -0
  44. package/dist/mcp-server/tools/pubmedResearchAgent/logic/planOrchestrator.js +251 -0
  45. package/dist/mcp-server/tools/pubmedResearchAgent/logic.d.ts +12 -0
  46. package/dist/mcp-server/tools/pubmedResearchAgent/logic.js +55 -0
  47. package/dist/mcp-server/tools/pubmedResearchAgent/registration.d.ts +10 -0
  48. package/dist/mcp-server/tools/pubmedResearchAgent/registration.js +36 -0
  49. package/dist/mcp-server/tools/searchPubMedArticles/index.d.ts +6 -0
  50. package/dist/mcp-server/tools/searchPubMedArticles/index.js +6 -0
  51. package/dist/mcp-server/tools/searchPubMedArticles/logic.d.ts +61 -0
  52. package/dist/mcp-server/tools/searchPubMedArticles/logic.js +229 -0
  53. package/dist/mcp-server/tools/searchPubMedArticles/registration.d.ts +10 -0
  54. package/dist/mcp-server/tools/searchPubMedArticles/registration.js +38 -0
  55. package/dist/mcp-server/transports/authentication/authMiddleware.d.ts +29 -0
  56. package/dist/mcp-server/transports/authentication/authMiddleware.js +174 -0
  57. package/dist/mcp-server/transports/httpTransport.d.ts +23 -0
  58. package/dist/mcp-server/transports/httpTransport.js +463 -0
  59. package/dist/mcp-server/transports/stdioTransport.d.ts +42 -0
  60. package/dist/mcp-server/transports/stdioTransport.js +63 -0
  61. package/dist/services/NCBI/ncbiConstants.d.ts +22 -0
  62. package/dist/services/NCBI/ncbiConstants.js +5 -0
  63. package/dist/services/NCBI/ncbiCoreApiClient.d.ts +24 -0
  64. package/dist/services/NCBI/ncbiCoreApiClient.js +118 -0
  65. package/dist/services/NCBI/ncbiRequestQueueManager.d.ts +36 -0
  66. package/dist/services/NCBI/ncbiRequestQueueManager.js +96 -0
  67. package/dist/services/NCBI/ncbiResponseHandler.d.ts +22 -0
  68. package/dist/services/NCBI/ncbiResponseHandler.js +192 -0
  69. package/dist/services/NCBI/ncbiService.d.ts +24 -0
  70. package/dist/services/NCBI/ncbiService.js +57 -0
  71. package/dist/services/index.d.ts +7 -0
  72. package/dist/services/index.js +7 -0
  73. package/dist/services/llm-providers/index.d.ts +7 -0
  74. package/dist/services/llm-providers/index.js +7 -0
  75. package/dist/services/llm-providers/llmFactory.d.ts +69 -0
  76. package/dist/services/llm-providers/llmFactory.js +132 -0
  77. package/dist/services/llm-providers/openRouter/index.d.ts +6 -0
  78. package/dist/services/llm-providers/openRouter/index.js +7 -0
  79. package/dist/services/llm-providers/openRouter/openRouterProvider.d.ts +99 -0
  80. package/dist/services/llm-providers/openRouter/openRouterProvider.js +329 -0
  81. package/dist/types-global/errors.d.ts +119 -0
  82. package/dist/types-global/errors.js +119 -0
  83. package/dist/types-global/pubmedXml.d.ts +350 -0
  84. package/dist/types-global/pubmedXml.js +7 -0
  85. package/dist/utils/index.d.ts +10 -0
  86. package/dist/utils/index.js +18 -0
  87. package/dist/utils/internal/errorHandler.d.ts +176 -0
  88. package/dist/utils/internal/errorHandler.js +335 -0
  89. package/dist/utils/internal/index.d.ts +9 -0
  90. package/dist/utils/internal/index.js +9 -0
  91. package/dist/utils/internal/logger.d.ts +141 -0
  92. package/dist/utils/internal/logger.js +426 -0
  93. package/dist/utils/internal/requestContext.d.ts +83 -0
  94. package/dist/utils/internal/requestContext.js +72 -0
  95. package/dist/utils/metrics/index.d.ts +7 -0
  96. package/dist/utils/metrics/index.js +7 -0
  97. package/dist/utils/metrics/tokenCounter.d.ts +35 -0
  98. package/dist/utils/metrics/tokenCounter.js +110 -0
  99. package/dist/utils/parsing/dateParser.d.ts +73 -0
  100. package/dist/utils/parsing/dateParser.js +107 -0
  101. package/dist/utils/parsing/index.d.ts +8 -0
  102. package/dist/utils/parsing/index.js +8 -0
  103. package/dist/utils/parsing/jsonParser.d.ts +82 -0
  104. package/dist/utils/parsing/jsonParser.js +126 -0
  105. package/dist/utils/parsing/ncbi-parsing/eSummaryResultParser.d.ts +32 -0
  106. package/dist/utils/parsing/ncbi-parsing/eSummaryResultParser.js +295 -0
  107. package/dist/utils/parsing/ncbi-parsing/index.d.ts +8 -0
  108. package/dist/utils/parsing/ncbi-parsing/index.js +8 -0
  109. package/dist/utils/parsing/ncbi-parsing/pubmedArticleStructureParser.d.ts +70 -0
  110. package/dist/utils/parsing/ncbi-parsing/pubmedArticleStructureParser.js +229 -0
  111. package/dist/utils/parsing/ncbi-parsing/xmlGenericHelpers.d.ts +31 -0
  112. package/dist/utils/parsing/ncbi-parsing/xmlGenericHelpers.js +76 -0
  113. package/dist/utils/security/idGenerator.d.ts +134 -0
  114. package/dist/utils/security/idGenerator.js +198 -0
  115. package/dist/utils/security/index.d.ts +9 -0
  116. package/dist/utils/security/index.js +9 -0
  117. package/dist/utils/security/rateLimiter.d.ts +108 -0
  118. package/dist/utils/security/rateLimiter.js +179 -0
  119. package/dist/utils/security/sanitization.d.ts +173 -0
  120. package/dist/utils/security/sanitization.js +439 -0
  121. package/package.json +97 -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,174 @@
1
+ # PubMed MCP Server Pubmed
2
+
3
+ [![TypeScript](https://img.shields.io/badge/TypeScript-^5.8.3-blue.svg)](https://www.typescriptlang.org/)
4
+ [![Model Context Protocol SDK](https://img.shields.io/badge/MCP%20SDK-1.12.0-green.svg)](https://github.com/modelcontextprotocol/typescript-sdk)
5
+ [![MCP Spec Version](https://img.shields.io/badge/MCP%20Spec-2025--03--26-lightgrey.svg)](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/docs/specification/2025-03-26/changelog.mdx)
6
+ [![Version](https://img.shields.io/badge/Version-1.0.12-blue.svg)](./CHANGELOG.md)
7
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
8
+ [![Status](https://img.shields.io/badge/Status-Beta-orange.svg)](https://github.com/cyanheads/pubmed-mcp-server/issues)
9
+ [![GitHub](https://img.shields.io/github/stars/cyanheads/pubmed-mcp-server?style=social)](https://github.com/cyanheads/pubmed-mcp-server)
10
+
11
+ **Unlock the power of biomedical literature for your AI agents with the PubMed MCP Server!**
12
+
13
+ This server acts as a bridge, connecting your AI to NCBI's PubMed and E-utilities through the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/). It empowers language models to seamlessly search, retrieve, and analyze biomedical articles and data. Built with TypeScript and adhering to the **MCP 2025-03-26 specification**, it's designed for robustness and includes production-grade utilities.
14
+
15
+ ## 🚀 Core Capabilities: PubMed Tools 🛠️
16
+
17
+ This server equips your AI with specialized tools to interact with PubMed:
18
+
19
+ | Tool Name | Description | Key Features | Output Structure (JSON Example) |
20
+ | :------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
21
+ | `search_pubmed_articles` | Searches PubMed for articles based on your query. | - Filter by max results, sort order, date range, publication types.<br/>- Uses NCBI ESearch for PMIDs.<br/>- Optionally fetches brief summaries (title, authors, source, dates) via ESummary. | `{"searchParameters": {"queryTerm": "oncology", "maxResults": 5},"effectiveESearchTerm": "oncology","totalFound": 250,"retrievedPmidCount": 5,"pmids": ["12345", "67890"],"briefSummaries": [{"pmid": "12345", "title": "Example Title"}],"eSearchUrl": "https://ncbi...","eSummaryUrl": "https://ncbi..."}` |
22
+ | `fetch_pubmed_content` | Retrieves detailed information for PubMed articles. Can use a list of PMIDs or ESearch history (queryKey/webEnv) with pagination. | - Flexible `detailLevel`: `abstract_plus` (parsed details, optional MeSH/grant), `full_xml` (JSON representation of the PubMedArticle XML structure), `medline_text` (MEDLINE format), `citation_data` (minimal for citations).<br/>- Supports direct PMID list or `queryKey`/`webEnv` from ESearch history.<br/>- Supports `retstart`/`retmax` for pagination with history.<br/>- Uses NCBI EFetch. | `{"requestedPmids": ["12345"],"articles": [{"pmid": "12345", "title": "Example Title", "abstractText": "..."}],"notFoundPmids": [],"eFetchDetails": {"urls": ["https://ncbi..."], "requestMethod": "GET"}}` (Or raw string for`detailLevel: 'full_xml'/'medline_text'`with`outputFormat: 'raw_text'`) |
23
+ | `get_pubmed_article_connections` | Finds related articles (cited by, similar, references) or formats citations for a PMID. | - Uses NCBI ELink for relationships.<br/>- Uses NCBI EFetch for citation data (RIS, BibTeX, APA, MLA).<br/>- Filter by max related results. | `{"sourcePmid": "12345","relationshipType": "pubmed_similar_articles","relatedArticles": [{"pmid": "67890", "title": "Related Title"}],"citations": {"ris": "RIS formatted citation..." },"retrievedCount": 1,"eUtilityUrl": "https://ncbi...","message": "Success"}` |
24
+ | `pubmed_research_agent` | Generates a standardized JSON research plan outline from component details. | - Accepts granular inputs for all research phases.<br/>- Optionally embeds instructive prompts for agent execution.<br/>- Structures rough ideas into a formal, machine-readable plan for further processing. | `{"plan_title": "Comprehensive Research Plan on Topic X","input_summary": {"keywords_received": ["Topic X", "Gene Y"]},"phase_1_conception_and_planning": {"step_1_1_research_question_and_hypothesis": {"primary_research_question": "What is the role of Gene Y in Topic X?"}},"phase_2_data_collection_and_processing": {}}` |
25
+
26
+ ---
27
+
28
+ ## ✨ Key Features Beyond Tools
29
+
30
+ | Feature Category | Description |
31
+ | :----------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
32
+ | **🔌 MCP Compliant** | Fully functional server supporting `stdio` and `http` (SSE) transports. |
33
+ | **🚀 Production-Ready Utils** | Includes robust logging, error handling, ID generation, rate limiting, request context tracking, and input sanitization. |
34
+ | **🔒 Secure & Type-Safe** | Built with TypeScript & Zod for strong type checking and input validation. Manages NCBI API keys, implements rate limiting, and features JWT-based auth middleware for HTTP. |
35
+ | **⚙️ Advanced Error Handling** | Consistent error categorization, detailed logging, and centralized handling, including specific error types for NCBI interactions. |
36
+ | **📚 Well-Documented** | Comprehensive JSDoc comments, API references, and project specifications. |
37
+ | **🤖 Agent-Friendly** | Includes a `.clinerules` developer cheatsheet tailored for LLM coding agents using this server. |
38
+ | **🛠️ Developer Utilities** | Scripts for cleaning builds, setting executable permissions, generating directory trees, and fetching OpenAPI specifications. |
39
+
40
+ ## 🚀 Quick Start
41
+
42
+ Get the PubMed MCP server running in minutes:
43
+
44
+ 1. **Clone the repository:**
45
+
46
+ ```bash
47
+ git clone https://github.com/cyanheads/pubmed-mcp-server.git
48
+ cd pubmed-mcp-server
49
+ ```
50
+
51
+ 2. **Install dependencies:**
52
+
53
+ ```bash
54
+ npm install
55
+ ```
56
+
57
+ 3. **Configure Environment Variables (`.env` file):**
58
+ Create a `.env` file in the project root. Key variables:
59
+
60
+ ```env
61
+ # REQUIRED FOR HTTP TRANSPORT
62
+ MCP_AUTH_SECRET_KEY=generate_a_strong_random_32_plus_char_secret_key
63
+
64
+ # RECOMMENDED FOR NCBI E-UTILITIES (for higher rate limits)
65
+ # NCBI_API_KEY=your_ncbi_api_key_here
66
+ # NCBI_ADMIN_EMAIL=your_email@example.com # Recommended if using an API key
67
+ # NCBI_TOOL_IDENTIFIER=@cyanheads/pubmed-mcp-server/1.0.11 # Optional: Tool identifier for NCBI (defaults to current version)
68
+ ```
69
+
70
+ For all options, see the [Configuration](#⚙️-configuration) section below or the [Developer Cheatsheet (.clinerules)](./.clinerules).
71
+
72
+ 4. **Build the project:**
73
+
74
+ ```bash
75
+ npm run build
76
+ # Or use 'npm run rebuild' for a clean install (deletes node_modules, logs, dist)
77
+ ```
78
+
79
+ 5. **Format the code (Optional but Recommended):**
80
+
81
+ ```bash
82
+ npm run format
83
+ ```
84
+
85
+ 6. **Run the Server:**
86
+
87
+ - **Via Stdio (Default):** Many MCP host applications will run this automatically using `stdio`. To run manually for testing:
88
+ ```bash
89
+ npm start
90
+ # or 'npm run start:stdio'
91
+ ```
92
+ - **Via HTTP (SSE):** (Ensure `MCP_TRANSPORT_TYPE=http` and `MCP_AUTH_SECRET_KEY` are set in your `.env`)
93
+ ```bash
94
+ npm run start:http
95
+ ```
96
+ This starts an HTTP server (default: `http://127.0.0.1:3010`) using Server-Sent Events.
97
+
98
+ ## ⚙️ Configuration
99
+
100
+ ### Server Configuration (Environment Variables)
101
+
102
+ Configure the PubMed MCP server's behavior using environment variables (typically in a `.env` file).
103
+
104
+ | Variable | Description | Default |
105
+ | :---------------------- | :----------------------------------------------------------------------------------------------------- | :--------------------------------------- |
106
+ | `MCP_TRANSPORT_TYPE` | Server transport: `stdio` or `http`. | `stdio` |
107
+ | `MCP_HTTP_PORT` | Port for the HTTP server (if `MCP_TRANSPORT_TYPE=http`). | `3010` |
108
+ | `MCP_HTTP_HOST` | Host address for the HTTP server (if `MCP_TRANSPORT_TYPE=http`). | `127.0.0.1` |
109
+ | `MCP_ALLOWED_ORIGINS` | Comma-separated allowed origins for CORS (if `MCP_TRANSPORT_TYPE=http`). | (none) |
110
+ | `MCP_LOG_LEVEL` | Server logging level (`debug`, `info`, `warning`, `error`, etc.). | `debug` |
111
+ | `LOGS_DIR` | Directory for log files. | `logs/` (in project root) |
112
+ | `NODE_ENV` | Runtime environment (`development`, `production`). | `development` |
113
+ | `MCP_AUTH_SECRET_KEY` | **Required for HTTP transport.** Secret key (min 32 chars) for signing/verifying auth tokens (JWT). | (none - **MUST be set in production**) |
114
+ | `NCBI_API_KEY` | **Optional, but highly recommended.** Your NCBI API Key for higher rate limits (10/sec vs 3/sec). | (none) |
115
+ | `NCBI_ADMIN_EMAIL` | **Optional, but recommended if using an API key.** Your email for NCBI contact. | (none) |
116
+ | `NCBI_TOOL_IDENTIFIER` | Optional. Tool identifier sent to NCBI. | `@cyanheads/pubmed-mcp-server/<version>` |
117
+ | `NCBI_REQUEST_DELAY_MS` | Milliseconds to wait between NCBI requests. Dynamically set (e.g., 100ms with API key, 334ms without). | (see `src/config/index.ts`) |
118
+ | `NCBI_MAX_RETRIES` | Maximum number of retries for failed NCBI requests. | `3` |
119
+
120
+ **Note on HTTP Port Retries:** If the `MCP_HTTP_PORT` is busy, the server automatically tries the next port (up to 15 times).
121
+
122
+ **Security Note for HTTP Transport:** When using `MCP_TRANSPORT_TYPE=http`, authentication is **mandatory** as per the MCP specification. This server includes JWT-based authentication middleware. You **MUST** set a strong, unique `MCP_AUTH_SECRET_KEY` in your production environment.
123
+
124
+ For a **comprehensive list of all available environment variables**, their descriptions, and default values, please review the configuration loader at `src/config/index.ts`.
125
+
126
+ ## 🏗️ Project Structure Overview
127
+
128
+ The `src/` directory contains the core logic:
129
+
130
+ - `config/`: Environment variable loading and package information.
131
+ - `mcp-server/`: The heart of the PubMed MCP server.
132
+ - `server.ts`: Initializes the server instance and registers all tools and resources.
133
+ - `resources/`: Implementations for MCP resources (e.g., server status, PubMed statistics).
134
+ - `tools/`: Implementations for MCP tools (like `searchPubMedArticles`, `fetchPubMedContent`, `getPubMedArticleConnections`).
135
+ - `transports/`: Handles `stdio` and `http` (SSE) communication, including authentication for HTTP.
136
+ - `services/`: Integrations with external services.
137
+ - `NCBI/ncbiService.ts`: Manages all interactions with NCBI E-utilities, including API calls, rate limiting, and response parsing.
138
+ - `llm-providers/`: (Optional) For integrating LLM capabilities directly within the server.
139
+ - `types-global/`: Shared TypeScript definitions, especially for errors and MCP types.
140
+ - `utils/`: A comprehensive suite of reusable utilities for logging, error handling, security, parsing, metrics, and more.
141
+
142
+ For a detailed file tree, run: `npm run tree` or see [Directory Tree](./docs/tree.md).
143
+
144
+ ## 🧩 Extending with More PubMed Capabilities
145
+
146
+ Adding new tools or resources is straightforward:
147
+
148
+ 1. **Directory Setup**: Create a new directory under `src/mcp-server/tools/yourNewTool/` or `src/mcp-server/resources/yourNewResource/`.
149
+ 2. **Implement Core Logic (`logic.ts`)**:
150
+ - Define Zod schemas for input validation.
151
+ - Write the function that interacts with `src/services/NCBI/ncbiService.ts` (e.g., `ncbiService.eLink(...)`).
152
+ - Parse the NCBI response and format it according to MCP specifications (`CallToolResult` or `ReadResourceResult`).
153
+ 3. **Register the Capability (`registration.ts`)**:
154
+ - For tools: `server.tool(name, description, zodSchemaShape, handlerFunction)`
155
+ - For resources: `server.resource(registrationName, template, metadata, handlerFunction)`
156
+ - Always wrap your logic in `ErrorHandler.tryCatch` for robust error management.
157
+ 4. **Export and Integrate**: Export the registration function from your new directory's `index.ts` and call it within `src/mcp-server/server.ts`.
158
+
159
+ ## 🌍 Learn More
160
+
161
+ - **[Model Context Protocol Official Site](https://modelcontextprotocol.io/)**
162
+ - **[MCP Specification (2025-03-26)](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/docs/specification/2025-03-26/changelog.mdx)**
163
+ - **[TypeScript SDK for MCP](https://github.com/modelcontextprotocol/typescript-sdk)**
164
+ - **[NCBI E-utilities Documentation](https://www.ncbi.nlm.nih.gov/books/NBK25501/)**
165
+
166
+ ## 📜 License
167
+
168
+ This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details.
169
+
170
+ ---
171
+
172
+ <div align="center">
173
+ Empowering AI with PubMed | Built on the <a href="https://modelcontextprotocol.io/">Model Context Protocol</a>
174
+ </div>
@@ -0,0 +1,91 @@
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
+ /** MCP server name. Env `MCP_SERVER_NAME` > `package.json` name > "mcp-ts-template". */
23
+ mcpServerName: string;
24
+ /** MCP server version. Env `MCP_SERVER_VERSION` > `package.json` version > "0.0.0". */
25
+ mcpServerVersion: string;
26
+ /** Logging level. From `MCP_LOG_LEVEL` env var. Default: "debug". */
27
+ logLevel: string;
28
+ /** Absolute path to the logs directory. From `LOGS_DIR` env var. */
29
+ logsPath: string;
30
+ /** Runtime environment. From `NODE_ENV` env var. Default: "development". */
31
+ environment: string;
32
+ /** MCP transport type ('stdio' or 'http'). From `MCP_TRANSPORT_TYPE` env var. Default: "stdio". */
33
+ mcpTransportType: "stdio" | "http";
34
+ /** HTTP server port (if http transport). From `MCP_HTTP_PORT` env var. Default: 3010. */
35
+ mcpHttpPort: number;
36
+ /** HTTP server host (if http transport). From `MCP_HTTP_HOST` env var. Default: "127.0.0.1". */
37
+ mcpHttpHost: string;
38
+ /** Array of allowed CORS origins (http transport). From `MCP_ALLOWED_ORIGINS` (comma-separated). */
39
+ mcpAllowedOrigins: string[] | undefined;
40
+ /** Auth secret key (JWTs, http transport). From `MCP_AUTH_SECRET_KEY`. CRITICAL. */
41
+ mcpAuthSecretKey: string | undefined;
42
+ /** OpenRouter App URL. From `OPENROUTER_APP_URL`. Default: "http://localhost:3000". */
43
+ openrouterAppUrl: string;
44
+ /** OpenRouter App Name. From `OPENROUTER_APP_NAME`. Defaults to `mcpServerName`. */
45
+ openrouterAppName: string;
46
+ /** OpenRouter API Key. From `OPENROUTER_API_KEY`. */
47
+ openrouterApiKey: string | undefined;
48
+ /** Default LLM model. From `LLM_DEFAULT_MODEL`. */
49
+ llmDefaultModel: string;
50
+ /** Default LLM temperature. From `LLM_DEFAULT_TEMPERATURE`. */
51
+ llmDefaultTemperature: number | undefined;
52
+ /** Default LLM top_p. From `LLM_DEFAULT_TOP_P`. */
53
+ llmDefaultTopP: number | undefined;
54
+ /** Default LLM max tokens. From `LLM_DEFAULT_MAX_TOKENS`. */
55
+ llmDefaultMaxTokens: number | undefined;
56
+ /** Default LLM top_k. From `LLM_DEFAULT_TOP_K`. */
57
+ llmDefaultTopK: number | undefined;
58
+ /** Default LLM min_p. From `LLM_DEFAULT_MIN_P`. */
59
+ llmDefaultMinP: number | undefined;
60
+ /** Gemini API Key. From `GEMINI_API_KEY`. */
61
+ geminiApiKey: string | undefined;
62
+ /** NCBI API Key. From `NCBI_API_KEY`. */
63
+ ncbiApiKey: string | undefined;
64
+ /** NCBI Tool Identifier. From `NCBI_TOOL_IDENTIFIER`. Defaults to server name/version. */
65
+ ncbiToolIdentifier: string;
66
+ /** NCBI Admin Email. From `NCBI_ADMIN_EMAIL`. */
67
+ ncbiAdminEmail: string | undefined;
68
+ /** NCBI Request Delay in MS. From `NCBI_REQUEST_DELAY_MS`. Dynamically set based on API key presence. */
69
+ ncbiRequestDelayMs: number;
70
+ /** NCBI Max Retries. From `NCBI_MAX_RETRIES`. */
71
+ ncbiMaxRetries: number;
72
+ /** OAuth Proxy configurations. Undefined if no related env vars are set. */
73
+ oauthProxy: {
74
+ authorizationUrl: string | undefined;
75
+ tokenUrl: string | undefined;
76
+ revocationUrl: string | undefined;
77
+ issuerUrl: string | undefined;
78
+ serviceDocumentationUrl: string | undefined;
79
+ defaultClientRedirectUris: string[] | undefined;
80
+ } | undefined;
81
+ };
82
+ /**
83
+ * Configured logging level for the application.
84
+ * Exported for convenience.
85
+ */
86
+ export declare const logLevel: string;
87
+ /**
88
+ * Configured runtime environment ("development", "production", etc.).
89
+ * Exported for convenience.
90
+ */
91
+ export declare const environment: string;