@cyanheads/pubmed-mcp-server 2.10.18 → 2.10.20

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/AGENTS.md +16 -15
  2. package/CLAUDE.md +16 -15
  3. package/Dockerfile +86 -36
  4. package/README.md +86 -109
  5. package/changelog/2.10.x/2.10.19.md +42 -0
  6. package/changelog/2.10.x/2.10.20.md +63 -0
  7. package/dist/mcp-server/resources/definitions/database-info.resource.d.ts +43 -1
  8. package/dist/mcp-server/resources/definitions/database-info.resource.d.ts.map +1 -1
  9. package/dist/mcp-server/resources/definitions/database-info.resource.js +2 -0
  10. package/dist/mcp-server/resources/definitions/database-info.resource.js.map +1 -1
  11. package/dist/mcp-server/tools/definitions/_text.d.ts.map +1 -1
  12. package/dist/mcp-server/tools/definitions/_text.js +10 -5
  13. package/dist/mcp-server/tools/definitions/_text.js.map +1 -1
  14. package/dist/mcp-server/tools/definitions/_visible-text.d.ts +19 -0
  15. package/dist/mcp-server/tools/definitions/_visible-text.d.ts.map +1 -0
  16. package/dist/mcp-server/tools/definitions/_visible-text.js +22 -0
  17. package/dist/mcp-server/tools/definitions/_visible-text.js.map +1 -0
  18. package/dist/mcp-server/tools/definitions/convert-ids.tool.d.ts +11 -4
  19. package/dist/mcp-server/tools/definitions/convert-ids.tool.d.ts.map +1 -1
  20. package/dist/mcp-server/tools/definitions/convert-ids.tool.js +1 -1
  21. package/dist/mcp-server/tools/definitions/convert-ids.tool.js.map +1 -1
  22. package/dist/mcp-server/tools/definitions/fetch-articles.tool.d.ts +20 -7
  23. package/dist/mcp-server/tools/definitions/fetch-articles.tool.d.ts.map +1 -1
  24. package/dist/mcp-server/tools/definitions/fetch-articles.tool.js +68 -15
  25. package/dist/mcp-server/tools/definitions/fetch-articles.tool.js.map +1 -1
  26. package/dist/mcp-server/tools/definitions/fetch-fulltext.tool.d.ts +37 -12
  27. package/dist/mcp-server/tools/definitions/fetch-fulltext.tool.d.ts.map +1 -1
  28. package/dist/mcp-server/tools/definitions/fetch-fulltext.tool.js +590 -481
  29. package/dist/mcp-server/tools/definitions/fetch-fulltext.tool.js.map +1 -1
  30. package/dist/mcp-server/tools/definitions/find-related.tool.d.ts +5 -5
  31. package/dist/mcp-server/tools/definitions/find-related.tool.d.ts.map +1 -1
  32. package/dist/mcp-server/tools/definitions/find-related.tool.js +31 -13
  33. package/dist/mcp-server/tools/definitions/find-related.tool.js.map +1 -1
  34. package/dist/mcp-server/tools/definitions/format-citations.tool.d.ts +11 -4
  35. package/dist/mcp-server/tools/definitions/format-citations.tool.d.ts.map +1 -1
  36. package/dist/mcp-server/tools/definitions/lookup-citation.tool.d.ts +26 -21
  37. package/dist/mcp-server/tools/definitions/lookup-citation.tool.d.ts.map +1 -1
  38. package/dist/mcp-server/tools/definitions/lookup-citation.tool.js +109 -55
  39. package/dist/mcp-server/tools/definitions/lookup-citation.tool.js.map +1 -1
  40. package/dist/mcp-server/tools/definitions/lookup-mesh.tool.d.ts +15 -7
  41. package/dist/mcp-server/tools/definitions/lookup-mesh.tool.d.ts.map +1 -1
  42. package/dist/mcp-server/tools/definitions/lookup-mesh.tool.js +19 -11
  43. package/dist/mcp-server/tools/definitions/lookup-mesh.tool.js.map +1 -1
  44. package/dist/mcp-server/tools/definitions/pubmed-europepmc-fetch.tool.d.ts +20 -2
  45. package/dist/mcp-server/tools/definitions/pubmed-europepmc-fetch.tool.d.ts.map +1 -1
  46. package/dist/mcp-server/tools/definitions/pubmed-europepmc-fetch.tool.js +98 -14
  47. package/dist/mcp-server/tools/definitions/pubmed-europepmc-fetch.tool.js.map +1 -1
  48. package/dist/mcp-server/tools/definitions/pubmed-europepmc-search.tool.d.ts +21 -6
  49. package/dist/mcp-server/tools/definitions/pubmed-europepmc-search.tool.d.ts.map +1 -1
  50. package/dist/mcp-server/tools/definitions/pubmed-europepmc-search.tool.js +42 -10
  51. package/dist/mcp-server/tools/definitions/pubmed-europepmc-search.tool.js.map +1 -1
  52. package/dist/mcp-server/tools/definitions/search-articles.tool.d.ts +42 -18
  53. package/dist/mcp-server/tools/definitions/search-articles.tool.d.ts.map +1 -1
  54. package/dist/mcp-server/tools/definitions/search-articles.tool.js +220 -48
  55. package/dist/mcp-server/tools/definitions/search-articles.tool.js.map +1 -1
  56. package/dist/mcp-server/tools/definitions/spell-check.tool.d.ts +15 -7
  57. package/dist/mcp-server/tools/definitions/spell-check.tool.d.ts.map +1 -1
  58. package/dist/mcp-server/tools/definitions/spell-check.tool.js +13 -9
  59. package/dist/mcp-server/tools/definitions/spell-check.tool.js.map +1 -1
  60. package/dist/services/error-contracts.d.ts +43 -72
  61. package/dist/services/error-contracts.d.ts.map +1 -1
  62. package/dist/services/error-contracts.js +44 -76
  63. package/dist/services/error-contracts.js.map +1 -1
  64. package/dist/services/europe-pmc/api-client.d.ts +8 -2
  65. package/dist/services/europe-pmc/api-client.d.ts.map +1 -1
  66. package/dist/services/europe-pmc/api-client.js +13 -8
  67. package/dist/services/europe-pmc/api-client.js.map +1 -1
  68. package/dist/services/europe-pmc/europe-pmc-service.d.ts +25 -2
  69. package/dist/services/europe-pmc/europe-pmc-service.d.ts.map +1 -1
  70. package/dist/services/europe-pmc/europe-pmc-service.js +90 -25
  71. package/dist/services/europe-pmc/europe-pmc-service.js.map +1 -1
  72. package/dist/services/europe-pmc/types.d.ts +6 -1
  73. package/dist/services/europe-pmc/types.d.ts.map +1 -1
  74. package/dist/services/ncbi/api-client.d.ts.map +1 -1
  75. package/dist/services/ncbi/api-client.js +2 -3
  76. package/dist/services/ncbi/api-client.js.map +1 -1
  77. package/dist/services/ncbi/formatting/citation-formatter.d.ts +24 -0
  78. package/dist/services/ncbi/formatting/citation-formatter.d.ts.map +1 -1
  79. package/dist/services/ncbi/formatting/citation-formatter.js +147 -46
  80. package/dist/services/ncbi/formatting/citation-formatter.js.map +1 -1
  81. package/dist/services/ncbi/ncbi-service.d.ts +18 -2
  82. package/dist/services/ncbi/ncbi-service.d.ts.map +1 -1
  83. package/dist/services/ncbi/ncbi-service.js +182 -90
  84. package/dist/services/ncbi/ncbi-service.js.map +1 -1
  85. package/dist/services/ncbi/parsing/article-parser.d.ts +15 -1
  86. package/dist/services/ncbi/parsing/article-parser.d.ts.map +1 -1
  87. package/dist/services/ncbi/parsing/article-parser.js +67 -29
  88. package/dist/services/ncbi/parsing/article-parser.js.map +1 -1
  89. package/dist/services/ncbi/parsing/esummary-parser.d.ts +9 -0
  90. package/dist/services/ncbi/parsing/esummary-parser.d.ts.map +1 -1
  91. package/dist/services/ncbi/parsing/esummary-parser.js +26 -2
  92. package/dist/services/ncbi/parsing/esummary-parser.js.map +1 -1
  93. package/dist/services/ncbi/parsing/pmc-article-parser.d.ts.map +1 -1
  94. package/dist/services/ncbi/parsing/pmc-article-parser.js +395 -147
  95. package/dist/services/ncbi/parsing/pmc-article-parser.js.map +1 -1
  96. package/dist/services/ncbi/parsing/pmc-xml-helpers.d.ts +73 -5
  97. package/dist/services/ncbi/parsing/pmc-xml-helpers.d.ts.map +1 -1
  98. package/dist/services/ncbi/parsing/pmc-xml-helpers.js +223 -27
  99. package/dist/services/ncbi/parsing/pmc-xml-helpers.js.map +1 -1
  100. package/dist/services/ncbi/parsing/text-helpers.d.ts +8 -6
  101. package/dist/services/ncbi/parsing/text-helpers.d.ts.map +1 -1
  102. package/dist/services/ncbi/parsing/text-helpers.js +95 -19
  103. package/dist/services/ncbi/parsing/text-helpers.js.map +1 -1
  104. package/dist/services/ncbi/response-handler.d.ts +20 -12
  105. package/dist/services/ncbi/response-handler.d.ts.map +1 -1
  106. package/dist/services/ncbi/response-handler.js +134 -38
  107. package/dist/services/ncbi/response-handler.js.map +1 -1
  108. package/dist/services/ncbi/types.d.ts +35 -2
  109. package/dist/services/ncbi/types.d.ts.map +1 -1
  110. package/dist/services/openalex/api-client.d.ts.map +1 -1
  111. package/dist/services/openalex/api-client.js +6 -7
  112. package/dist/services/openalex/api-client.js.map +1 -1
  113. package/dist/services/openalex/openalex-service.d.ts +10 -6
  114. package/dist/services/openalex/openalex-service.d.ts.map +1 -1
  115. package/dist/services/openalex/openalex-service.js +14 -12
  116. package/dist/services/openalex/openalex-service.js.map +1 -1
  117. package/dist/services/unpaywall/unpaywall-service.d.ts.map +1 -1
  118. package/dist/services/unpaywall/unpaywall-service.js +1 -3
  119. package/dist/services/unpaywall/unpaywall-service.js.map +1 -1
  120. package/package.json +16 -13
  121. package/server.json +10 -24
package/AGENTS.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Agent Protocol
2
2
 
3
3
  **Server:** @cyanheads/pubmed-mcp-server
4
- **Version:** 2.10.18
5
- **Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.6`
4
+ **Version:** 2.10.20
5
+ **Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.11`
6
6
  **Engines:** Bun ≥1.4.0, Node ≥24.0.0
7
7
 
8
8
  > **Read the framework docs first:** `node_modules/@cyanheads/mcp-ts-core/CLAUDE.md` contains the full API reference — builders, Context, error codes, exports, patterns. This file covers server-specific conventions only.
@@ -182,15 +182,15 @@ Handlers receive a unified `ctx` object. Key properties:
182
182
  | Property | Description |
183
183
  |:---------|:------------|
184
184
  | `ctx.log` | Request-scoped logger — `.debug()`, `.info()`, `.notice()`, `.warning()`, `.error()`. Auto-correlates requestId, traceId, tenantId. Dual-sink: Pino **and** `notifications/message` to the client, so treat it as client-visible. |
185
- | `ctx.state` | Tenant-scoped KV — `.get(key)`, `.set(key, value, { ttl? })`, `.delete(key)`, `.getMany(keys)`, `.list(prefix, { cursor, limit })`. Accepts any serializable value. |
185
+ | `ctx.state` | Tenant-scoped KV — `.get(key)`, `.set(key, value, { ttl? })`, `.delete(key)`, `.getMany(keys)`, `.list(prefix, { cursor, limit })`. Accepts any JSON-serializable value; reads return its JSON form (a `Date` comes back as an ISO string). |
186
186
  | `ctx.requestInput` | Suspend and ask the caller for more input — `return ctx.requestInput({ inputRequests: { key: inputRequired.elicit({ message, requestedSchema }) } })`. Never returns; the handler is re-entered with the answers. Always present. |
187
- | `ctx.inputs` | Reader over a retried request's responses — `.accepted(key, schema)`, `.view(key)`, `.state()`, `.dropped`. Empty on the first round. |
187
+ | `ctx.inputs` | The request's responses — `.accepted(key, schema)`, `.view(key)`, `.state()`, `.dropped` — limited to what the client declared (`elicitation` and its form/url modes, `sampling`, `roots`). Client-supplied: a consent gate trusts only a `ctx.state` record it stored when it asked, bound to the operation, caller, and target (see the `api-context` skill). |
188
+ | `ctx.clientCapabilities` | What the client declared for this request, `undefined` when no view exists. Decides whether to ask for optional context (e.g. roots); never a reason to skip a consent prompt. |
188
189
  | `ctx.enrich` | Success-path agent context (empty-result notices, query echo, pagination totals) — `ctx.enrich(...)` or `.notice()` / `.total()` / `.echo()` / `.truncated()`. Reaches `structuredContent` and `content[]`; lands only when the definition declares an `enrichment` block (no-op otherwise). |
189
190
  | `ctx.content` | Non-text content blocks — `.image(data, mimeType)`, `.audio(data, mimeType)`, or `ctx.content(block)` for a raw block. Prepended to `content[]` after `format()`; never enters `structuredContent`. |
190
- | `ctx.recoveryFor(reason)` | Typed lookup of the contract `recovery` for a declared reason. Returns `{ recovery: { hint } }` for known reasons, `{}` otherwise. Spread into `ctx.fail` data to mirror the contract hint into `content[]`. |
191
191
  | `ctx.signal` | `AbortSignal` for cancellation. |
192
- | `ctx.requestId` | Unique request ID. |
193
- | `ctx.tenantId` | Tenant ID from JWT, `'default'` for stdio or HTTP+`MCP_AUTH_MODE=none`. |
192
+ | `ctx.requestId` | Request ID — the one every log record of the call carries and its error envelope returns as `data.requestId`. |
193
+ | `ctx.tenantId` | Tenant ID from JWT; `'default'` for stdio or HTTP with auth off. |
194
194
 
195
195
  ---
196
196
 
@@ -198,7 +198,7 @@ Handlers receive a unified `ctx` object. Key properties:
198
198
 
199
199
  Handlers throw — the framework catches, classifies, and formats.
200
200
 
201
- **Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable?, severity?, thrownBy? }]` on `tool()` / `resource()` to receive a typed `ctx.fail(reason, …)` keyed by the declared reason union. TypeScript catches `ctx.fail('typo')` at compile time, `data.reason` is auto-populated for observability, and the linter enforces conformance against the handler body. The `recovery` field is required (≥ 5 words, lint-validated) — it's the single source of truth for the recovery hint. Spread `ctx.recoveryFor('reason')` into `data` to mirror the contract recovery onto the wire (the framework mirrors `data.recovery.hint` into `content[]` text unless the message already contains it verbatim, then closes the text with `(reason <reason> · not retryable)`); pass an explicit `recovery: { hint: '...' }` when runtime context matters. Forwarding is lint-enforced per throw site (`error-contract-recovery-unforwarded`). A declared reason the handler never names warns as `error-contract-unthrown` — entries the service layer throws carry `thrownBy: 'service'` (lint-only metadata; every entry in `src/services/error-contracts.ts`'s service arrays has it), and a tool whose handler catches a service's failures doesn't spread that service's array at all. Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`, `RequestCancelled`) bubble freely and don't need declaring.
201
+ **Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable?, severity?, thrownBy? }]` on `tool()` / `resource()` to receive `ctx.fail(reason, …)` typed against the reason union. TypeScript catches typos at compile time, `data.reason` is auto-populated for observability, and the linter enforces conformance against the handler body. `recovery` is required (≥ 5 words, lint-validated) — the single source of truth for the agent's next move. The framework puts it on the wire whenever a failure carrying that `reason` arrives without a hint — a bare `ctx.fail('reason')` or a service throw with `data: { reason }` — as `data.recovery.hint`, mirrored into `content[]` text unless the message already contains it verbatim; override with an explicit `{ recovery: { hint: '...' } }` when dynamic runtime context matters. Every error envelope also carries `data.requestId`, the id the server's log records for that call carry, and `content[]` closes with `(reason … · request <id>)`. A declared reason the handler never names warns as `error-contract-unthrown` — entries the service layer throws carry `thrownBy: 'service'` (lint-only metadata; every entry in `src/services/error-contracts.ts`'s service arrays has it), and a tool whose handler catches a service's failures doesn't spread that service's array at all. Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`, `RequestCancelled`) bubble freely and don't need declaring.
202
202
 
203
203
  ```ts
204
204
  errors: [
@@ -209,10 +209,8 @@ errors: [
209
209
  async handler(input, ctx) {
210
210
  const articles = await ncbi.fetch(input.pmids);
211
211
  if (articles.length === 0) {
212
- // Static contract recovery
213
- throw ctx.fail('no_match', `None of ${input.pmids.length} PMIDs returned data`, {
214
- ...ctx.recoveryFor('no_match'),
215
- });
212
+ // The framework fills the contract's recovery hint onto the wire
213
+ throw ctx.fail('no_match', `None of ${input.pmids.length} PMIDs returned data`);
216
214
  }
217
215
  return { articles };
218
216
  }
@@ -240,7 +238,7 @@ throw new McpError(JsonRpcErrorCode.DatabaseError, 'Connection failed', { pool:
240
238
 
241
239
  For HTTP responses, prefer `httpErrorFromResponse(response, { service, data })` from `/utils` over hand-rolled status ladders — covers the full 4xx/5xx → `JsonRpcErrorCode` table and captures body + `Retry-After`.
242
240
 
243
- **Service-layer:** services don't have `ctx.fail`. To carry a contract `reason` from a service throw, pass `data: { reason: 'X' }` to the factory — the auto-classifier preserves `data` on the wire so clients see the same `error.data.reason` they'd see from `ctx.fail`.
241
+ **Service-layer:** services don't have `ctx.fail`. To carry a contract `reason` from a service throw, pass `data: { reason: 'X' }` to the factory — the auto-classifier preserves `data` on the wire so clients see the same `error.data.reason` they'd see from `ctx.fail`, and a tool or resource that declares `X` gets its `recovery` filled in. Spread the service's array from `src/services/error-contracts.ts` into every definition that lets those failures propagate, or the hint never reaches the caller.
244
242
 
245
243
  See framework CLAUDE.md and the `api-errors` skill for the full auto-classification table, all factories, and the contract reference.
246
244
 
@@ -261,7 +259,7 @@ src/
261
259
  response-handler.ts # XML response parsing
262
260
  types.ts # NCBI/PubMed domain types
263
261
  parsing/ # XML parsers (article, esummary, PMC)
264
- formatting/ # Citation formatter (APA, MLA, BibTeX, RIS)
262
+ formatting/ # Citation formatter (APA, MLA, BibTeX, RIS, Vancouver)
265
263
  mcp-server/
266
264
  tools/definitions/ # 11 tool definitions (*.tool.ts)
267
265
  resources/definitions/ # database-info.resource.ts
@@ -345,10 +343,13 @@ When you complete a skill's checklist, check the boxes and add a completion time
345
343
  | `bun run format` | Auto-fix formatting (safe fixes only) |
346
344
  | `bun run format:unsafe` | Also apply Biome's unsafe autofixes — review the diff; they can change behavior |
347
345
  | `bun run test` | Run tests (Vitest — use `bun run test`, not `bun test`) |
346
+ | `bun run test:corpus` | Run only the real-article corpus suite in `tests/corpus/` (`bun run test` includes it) |
347
+ | `bun run corpus:snapshot` | Rewrite each corpus fixture's `expected.md` after an intended output change — review every rewritten snapshot against its `source.xml` before keeping it |
348
+ | `bun run scripts/corpus-add.ts <PMCID>` | Add an openly licensed PMC article (`--kind pubmed <PMID>` for a PubMed record) to the corpus; refuses any license but CC BY, CC BY-SA, CC0, or public domain, and regenerates `tests/corpus/ATTRIBUTION.md` |
348
349
  | `bun run changelog:build` | Regenerate `CHANGELOG.md` from `changelog/*.md` |
349
350
  | `bun run changelog:check` | Verify `CHANGELOG.md` is in sync (used by devcheck) |
350
351
  | `bun run lint:mcp` | Validate MCP definitions against spec |
351
- | `bun run lint:packaging` | Validate env var alignment between `manifest.json` and `server.json` (skipped cleanly when `manifest.json` is absent) |
352
+ | `bun run lint:packaging` | Packaging surface checks — `server.json`/`manifest.json` env-var parity, `server.json` npm launch shape, plugin manifests (run by devcheck) |
352
353
  | `bun run list-skills` | List skills in `framework-skills/` with name + description |
353
354
  | `bun run bundle` | Build, pack, and clean a `.mcpb` for one-click Claude Desktop install |
354
355
  | `bun run release:github` | Create GitHub Release from an annotated tag — enforces `v<VERSION>: <subject>` title, attaches `.mcpb` bundle |
package/CLAUDE.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Agent Protocol
2
2
 
3
3
  **Server:** @cyanheads/pubmed-mcp-server
4
- **Version:** 2.10.18
5
- **Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.6`
4
+ **Version:** 2.10.20
5
+ **Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.11`
6
6
  **Engines:** Bun ≥1.4.0, Node ≥24.0.0
7
7
 
8
8
  > **Read the framework docs first:** `node_modules/@cyanheads/mcp-ts-core/CLAUDE.md` contains the full API reference — builders, Context, error codes, exports, patterns. This file covers server-specific conventions only.
@@ -182,15 +182,15 @@ Handlers receive a unified `ctx` object. Key properties:
182
182
  | Property | Description |
183
183
  |:---------|:------------|
184
184
  | `ctx.log` | Request-scoped logger — `.debug()`, `.info()`, `.notice()`, `.warning()`, `.error()`. Auto-correlates requestId, traceId, tenantId. Dual-sink: Pino **and** `notifications/message` to the client, so treat it as client-visible. |
185
- | `ctx.state` | Tenant-scoped KV — `.get(key)`, `.set(key, value, { ttl? })`, `.delete(key)`, `.getMany(keys)`, `.list(prefix, { cursor, limit })`. Accepts any serializable value. |
185
+ | `ctx.state` | Tenant-scoped KV — `.get(key)`, `.set(key, value, { ttl? })`, `.delete(key)`, `.getMany(keys)`, `.list(prefix, { cursor, limit })`. Accepts any JSON-serializable value; reads return its JSON form (a `Date` comes back as an ISO string). |
186
186
  | `ctx.requestInput` | Suspend and ask the caller for more input — `return ctx.requestInput({ inputRequests: { key: inputRequired.elicit({ message, requestedSchema }) } })`. Never returns; the handler is re-entered with the answers. Always present. |
187
- | `ctx.inputs` | Reader over a retried request's responses — `.accepted(key, schema)`, `.view(key)`, `.state()`, `.dropped`. Empty on the first round. |
187
+ | `ctx.inputs` | The request's responses — `.accepted(key, schema)`, `.view(key)`, `.state()`, `.dropped` — limited to what the client declared (`elicitation` and its form/url modes, `sampling`, `roots`). Client-supplied: a consent gate trusts only a `ctx.state` record it stored when it asked, bound to the operation, caller, and target (see the `api-context` skill). |
188
+ | `ctx.clientCapabilities` | What the client declared for this request, `undefined` when no view exists. Decides whether to ask for optional context (e.g. roots); never a reason to skip a consent prompt. |
188
189
  | `ctx.enrich` | Success-path agent context (empty-result notices, query echo, pagination totals) — `ctx.enrich(...)` or `.notice()` / `.total()` / `.echo()` / `.truncated()`. Reaches `structuredContent` and `content[]`; lands only when the definition declares an `enrichment` block (no-op otherwise). |
189
190
  | `ctx.content` | Non-text content blocks — `.image(data, mimeType)`, `.audio(data, mimeType)`, or `ctx.content(block)` for a raw block. Prepended to `content[]` after `format()`; never enters `structuredContent`. |
190
- | `ctx.recoveryFor(reason)` | Typed lookup of the contract `recovery` for a declared reason. Returns `{ recovery: { hint } }` for known reasons, `{}` otherwise. Spread into `ctx.fail` data to mirror the contract hint into `content[]`. |
191
191
  | `ctx.signal` | `AbortSignal` for cancellation. |
192
- | `ctx.requestId` | Unique request ID. |
193
- | `ctx.tenantId` | Tenant ID from JWT, `'default'` for stdio or HTTP+`MCP_AUTH_MODE=none`. |
192
+ | `ctx.requestId` | Request ID — the one every log record of the call carries and its error envelope returns as `data.requestId`. |
193
+ | `ctx.tenantId` | Tenant ID from JWT; `'default'` for stdio or HTTP with auth off. |
194
194
 
195
195
  ---
196
196
 
@@ -198,7 +198,7 @@ Handlers receive a unified `ctx` object. Key properties:
198
198
 
199
199
  Handlers throw — the framework catches, classifies, and formats.
200
200
 
201
- **Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable?, severity?, thrownBy? }]` on `tool()` / `resource()` to receive a typed `ctx.fail(reason, …)` keyed by the declared reason union. TypeScript catches `ctx.fail('typo')` at compile time, `data.reason` is auto-populated for observability, and the linter enforces conformance against the handler body. The `recovery` field is required (≥ 5 words, lint-validated) — it's the single source of truth for the recovery hint. Spread `ctx.recoveryFor('reason')` into `data` to mirror the contract recovery onto the wire (the framework mirrors `data.recovery.hint` into `content[]` text unless the message already contains it verbatim, then closes the text with `(reason <reason> · not retryable)`); pass an explicit `recovery: { hint: '...' }` when runtime context matters. Forwarding is lint-enforced per throw site (`error-contract-recovery-unforwarded`). A declared reason the handler never names warns as `error-contract-unthrown` — entries the service layer throws carry `thrownBy: 'service'` (lint-only metadata; every entry in `src/services/error-contracts.ts`'s service arrays has it), and a tool whose handler catches a service's failures doesn't spread that service's array at all. Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`, `RequestCancelled`) bubble freely and don't need declaring.
201
+ **Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable?, severity?, thrownBy? }]` on `tool()` / `resource()` to receive `ctx.fail(reason, …)` typed against the reason union. TypeScript catches typos at compile time, `data.reason` is auto-populated for observability, and the linter enforces conformance against the handler body. `recovery` is required (≥ 5 words, lint-validated) — the single source of truth for the agent's next move. The framework puts it on the wire whenever a failure carrying that `reason` arrives without a hint — a bare `ctx.fail('reason')` or a service throw with `data: { reason }` — as `data.recovery.hint`, mirrored into `content[]` text unless the message already contains it verbatim; override with an explicit `{ recovery: { hint: '...' } }` when dynamic runtime context matters. Every error envelope also carries `data.requestId`, the id the server's log records for that call carry, and `content[]` closes with `(reason … · request <id>)`. A declared reason the handler never names warns as `error-contract-unthrown` — entries the service layer throws carry `thrownBy: 'service'` (lint-only metadata; every entry in `src/services/error-contracts.ts`'s service arrays has it), and a tool whose handler catches a service's failures doesn't spread that service's array at all. Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`, `RequestCancelled`) bubble freely and don't need declaring.
202
202
 
203
203
  ```ts
204
204
  errors: [
@@ -209,10 +209,8 @@ errors: [
209
209
  async handler(input, ctx) {
210
210
  const articles = await ncbi.fetch(input.pmids);
211
211
  if (articles.length === 0) {
212
- // Static contract recovery
213
- throw ctx.fail('no_match', `None of ${input.pmids.length} PMIDs returned data`, {
214
- ...ctx.recoveryFor('no_match'),
215
- });
212
+ // The framework fills the contract's recovery hint onto the wire
213
+ throw ctx.fail('no_match', `None of ${input.pmids.length} PMIDs returned data`);
216
214
  }
217
215
  return { articles };
218
216
  }
@@ -240,7 +238,7 @@ throw new McpError(JsonRpcErrorCode.DatabaseError, 'Connection failed', { pool:
240
238
 
241
239
  For HTTP responses, prefer `httpErrorFromResponse(response, { service, data })` from `/utils` over hand-rolled status ladders — covers the full 4xx/5xx → `JsonRpcErrorCode` table and captures body + `Retry-After`.
242
240
 
243
- **Service-layer:** services don't have `ctx.fail`. To carry a contract `reason` from a service throw, pass `data: { reason: 'X' }` to the factory — the auto-classifier preserves `data` on the wire so clients see the same `error.data.reason` they'd see from `ctx.fail`.
241
+ **Service-layer:** services don't have `ctx.fail`. To carry a contract `reason` from a service throw, pass `data: { reason: 'X' }` to the factory — the auto-classifier preserves `data` on the wire so clients see the same `error.data.reason` they'd see from `ctx.fail`, and a tool or resource that declares `X` gets its `recovery` filled in. Spread the service's array from `src/services/error-contracts.ts` into every definition that lets those failures propagate, or the hint never reaches the caller.
244
242
 
245
243
  See framework CLAUDE.md and the `api-errors` skill for the full auto-classification table, all factories, and the contract reference.
246
244
 
@@ -261,7 +259,7 @@ src/
261
259
  response-handler.ts # XML response parsing
262
260
  types.ts # NCBI/PubMed domain types
263
261
  parsing/ # XML parsers (article, esummary, PMC)
264
- formatting/ # Citation formatter (APA, MLA, BibTeX, RIS)
262
+ formatting/ # Citation formatter (APA, MLA, BibTeX, RIS, Vancouver)
265
263
  mcp-server/
266
264
  tools/definitions/ # 11 tool definitions (*.tool.ts)
267
265
  resources/definitions/ # database-info.resource.ts
@@ -345,10 +343,13 @@ When you complete a skill's checklist, check the boxes and add a completion time
345
343
  | `bun run format` | Auto-fix formatting (safe fixes only) |
346
344
  | `bun run format:unsafe` | Also apply Biome's unsafe autofixes — review the diff; they can change behavior |
347
345
  | `bun run test` | Run tests (Vitest — use `bun run test`, not `bun test`) |
346
+ | `bun run test:corpus` | Run only the real-article corpus suite in `tests/corpus/` (`bun run test` includes it) |
347
+ | `bun run corpus:snapshot` | Rewrite each corpus fixture's `expected.md` after an intended output change — review every rewritten snapshot against its `source.xml` before keeping it |
348
+ | `bun run scripts/corpus-add.ts <PMCID>` | Add an openly licensed PMC article (`--kind pubmed <PMID>` for a PubMed record) to the corpus; refuses any license but CC BY, CC BY-SA, CC0, or public domain, and regenerates `tests/corpus/ATTRIBUTION.md` |
348
349
  | `bun run changelog:build` | Regenerate `CHANGELOG.md` from `changelog/*.md` |
349
350
  | `bun run changelog:check` | Verify `CHANGELOG.md` is in sync (used by devcheck) |
350
351
  | `bun run lint:mcp` | Validate MCP definitions against spec |
351
- | `bun run lint:packaging` | Validate env var alignment between `manifest.json` and `server.json` (skipped cleanly when `manifest.json` is absent) |
352
+ | `bun run lint:packaging` | Packaging surface checks — `server.json`/`manifest.json` env-var parity, `server.json` npm launch shape, plugin manifests (run by devcheck) |
352
353
  | `bun run list-skills` | List skills in `framework-skills/` with name + description |
353
354
  | `bun run bundle` | Build, pack, and clean a `.mcpb` for one-click Claude Desktop install |
354
355
  | `bun run release:github` | Create GitHub Release from an annotated tag — enforces `v<VERSION>: <subject>` title, attaches `.mcpb` bundle |
package/Dockerfile CHANGED
@@ -7,10 +7,10 @@
7
7
  # Pinned to $BUILDPLATFORM so this stage runs natively on the builder instead of
8
8
  # under emulation. `dist/` is pure JavaScript — tsc output plus tsc-alias path
9
9
  # rewriting, with no native artifacts — so it is identical across targets, and
10
- # the production stage installs its own runtime dependencies per target.
11
- # Emulating this stage aborts `tsc` on a source tree this size.
10
+ # the deps stage cross-installs the runtime dependencies per target. Emulating
11
+ # this stage aborts `tsc` on a source tree this size.
12
12
  # ==============================================================================
13
- FROM --platform=$BUILDPLATFORM oven/bun:1.4.0 AS build
13
+ FROM --platform=$BUILDPLATFORM oven/bun:1.4.2 AS build
14
14
 
15
15
  WORKDIR /usr/src/app
16
16
 
@@ -32,57 +32,105 @@ RUN bun run build
32
32
 
33
33
 
34
34
  # ==============================================================================
35
- # Production Stage
35
+ # Production Dependencies Stage
36
36
  #
37
- # This stage creates a minimal, optimized, and secure image for running the
38
- # application. It uses a slim base image and only includes production
39
- # dependencies and build artifacts.
37
+ # Installs the production dependency tree for the target platform. Every step
38
+ # here can run JavaScript — bunfig.toml's security scanner runs as a Bun
39
+ # program, and so do the OTel and musl-prune scripts — so the stage runs on
40
+ # $BUILDPLATFORM and cross-installs with `--os`/`--cpu`, which pick each
41
+ # platform-specific optional dependency for the target. Only `node_modules`
42
+ # leaves this stage.
43
+ #
44
+ # A clean image rather than `FROM build`: the build stage's node_modules holds
45
+ # devDependencies.
40
46
  # ==============================================================================
41
- FROM oven/bun:1.4.0-slim AS production
47
+ FROM --platform=$BUILDPLATFORM oven/bun:1.4.2 AS deps
42
48
 
43
49
  WORKDIR /usr/src/app
44
50
 
45
- # Set the environment to production for performance and to ensure only
46
- # production dependencies are installed.
47
- ENV NODE_ENV=production
48
-
49
- # OCI image metadata (https://github.com/opencontainers/image-spec/blob/main/annotations.md)
50
- LABEL org.opencontainers.image.title="@cyanheads/pubmed-mcp-server"
51
- LABEL org.opencontainers.image.description="MCP server for PubMed/NCBI E-utilities. Search articles, fetch metadata, generate citations, explore MeSH terms, and discover related research."
52
- LABEL org.opencontainers.image.licenses="Apache-2.0"
53
- LABEL org.opencontainers.image.source="https://github.com/cyanheads/pubmed-mcp-server"
54
-
55
- # Copy dependency manifests
56
- COPY package.json bun.lock ./
51
+ # Copy dependency manifests. `bunfig.toml` rides along so every install below
52
+ # passes its release-age gate and security scanner, as a local install does.
53
+ COPY package.json bun.lock bunfig.toml ./
54
+
55
+ # The scanner bunfig.toml names is a devDependency, and Bun installs a missing
56
+ # scanner through the same production-filtered install, which omits it and
57
+ # aborts. Seed it from the build stage's full install instead. Remove this line,
58
+ # and the `rm` at the end of this stage, if bunfig.toml stops naming a scanner.
59
+ COPY --from=build /usr/src/app/node_modules/@socketsecurity/bun-security-scanner ./node_modules/@socketsecurity/bun-security-scanner
60
+
61
+ # Docker names the target architecture `amd64`/`arm64`; Bun's `--cpu` takes
62
+ # `x64`/`arm64`. Mapped once here, read by both installs below. `oven/bun`
63
+ # publishes only these two architectures, so any other target fails here.
64
+ ARG TARGETOS
65
+ ARG TARGETARCH
66
+ RUN case "$TARGETARCH" in \
67
+ amd64) echo x64 ;; \
68
+ arm64) echo arm64 ;; \
69
+ *) echo "Unsupported TARGETARCH '$TARGETARCH': expected amd64 or arm64" >&2; exit 1 ;; \
70
+ esac > .bun-cpu
57
71
 
58
72
  # Install only production dependencies, ignoring any lifecycle scripts (like 'prepare')
59
73
  # that are not needed in the final production image.
60
74
  # `--omit=peer` drops the framework's optional peer tiers (test runner, service
61
75
  # SDKs, parsers) that Bun would otherwise auto-install. Anything this server
62
76
  # actually imports belongs in its own `dependencies`, so nothing needed at
63
- # runtime is lost. The OTEL step below carries the same flag — without it, that
64
- # install re-resolves the graph and pulls every optional peer back in.
77
+ # runtime is lost.
65
78
  RUN --mount=type=cache,target=/root/.bun/install/cache \
66
- bun install --production --omit=peer --frozen-lockfile --ignore-scripts
79
+ bun install --production --omit=peer --frozen-lockfile --ignore-scripts \
80
+ --os="$TARGETOS" --cpu="$(cat .bun-cpu)"
67
81
 
68
82
  # Conditionally install OpenTelemetry optional peer dependencies (Tier 3).
69
- # These are not bundled by default to keep the base image lean. Enable at build time
70
- # with: docker build --build-arg OTEL_ENABLED=true
83
+ # Installed by default. Omit them for a leaner image at build time
84
+ # with: docker build --build-arg OTEL_ENABLED=false
85
+ # The script reads the list and each range from the installed framework's
86
+ # `peerDependencies` and passes the target flags on to its `bun install`.
87
+ COPY scripts/install-otel.ts ./scripts/
71
88
  ARG OTEL_ENABLED=true
72
89
  RUN --mount=type=cache,target=/root/.bun/install/cache \
73
90
  if [ "$OTEL_ENABLED" = "true" ]; then \
74
- bun add --omit=dev --omit=peer --ignore-scripts @hono/otel \
75
- @opentelemetry/instrumentation-http \
76
- @opentelemetry/exporter-metrics-otlp-http \
77
- @opentelemetry/exporter-trace-otlp-http \
78
- @opentelemetry/instrumentation-pino \
79
- @opentelemetry/resources \
80
- @opentelemetry/sdk-metrics \
81
- @opentelemetry/sdk-node \
82
- @opentelemetry/sdk-trace-node \
83
- @opentelemetry/semantic-conventions; \
91
+ bun scripts/install-otel.ts --os="$TARGETOS" --cpu="$(cat .bun-cpu)"; \
84
92
  fi
85
93
 
94
+ # `--os`/`--cpu` have no libc counterpart, so a native dependency published in
95
+ # glibc and musl variants installs both. The runtime image is Debian (glibc)
96
+ # and never loads the musl copy; the script deletes every package whose own
97
+ # `libc` admits only musl. It follows every install, since a later
98
+ # `bun install` restores what it removes.
99
+ COPY scripts/prune-musl-packages.ts ./scripts/
100
+ RUN bun scripts/prune-musl-packages.ts
101
+
102
+ # The seeded scanner served only the installs above; keep it out of the image.
103
+ RUN rm -rf node_modules/@socketsecurity/bun-security-scanner
104
+
105
+
106
+ # ==============================================================================
107
+ # Production Stage
108
+ #
109
+ # This stage creates a minimal, optimized, and secure image for running the
110
+ # application. It uses a slim base image and only includes production
111
+ # dependencies and build artifacts. Its only Bun invocations are HEALTHCHECK
112
+ # and CMD, which run on the real target at container start.
113
+ # ==============================================================================
114
+ FROM oven/bun:1.4.2-slim AS production
115
+
116
+ WORKDIR /usr/src/app
117
+
118
+ # Set the environment to production for performance.
119
+ ENV NODE_ENV=production
120
+
121
+ # OCI image metadata (https://github.com/opencontainers/image-spec/blob/main/annotations.md)
122
+ ARG APP_VERSION
123
+ LABEL org.opencontainers.image.title="@cyanheads/pubmed-mcp-server"
124
+ LABEL org.opencontainers.image.description="MCP server for PubMed/NCBI E-utilities. Search articles, fetch metadata, generate citations, explore MeSH terms, and discover related research."
125
+ LABEL org.opencontainers.image.licenses="Apache-2.0"
126
+ LABEL org.opencontainers.image.version="${APP_VERSION}"
127
+ LABEL org.opencontainers.image.source="https://github.com/cyanheads/pubmed-mcp-server"
128
+
129
+ # The manifest comes from the build context: the deps stage's copy was rewritten
130
+ # by the OTel install, and the runtime reads only its name, version, and type.
131
+ COPY package.json ./
132
+ COPY --from=deps /usr/src/app/node_modules ./node_modules
133
+
86
134
  # Copy the compiled application code from the build stage
87
135
  COPY --from=build /usr/src/app/dist ./dist
88
136
 
@@ -107,10 +155,12 @@ ENV MCP_TRANSPORT_TYPE="http"
107
155
  ENV MCP_SESSION_MODE="stateless"
108
156
  ENV MCP_LOG_LEVEL="info"
109
157
  ENV LOGS_DIR="/var/log/pubmed-mcp-server"
110
- ENV MCP_FORCE_CONSOLE_LOGGING="true"
111
158
 
112
159
  # Expose the port the server listens on
113
160
  EXPOSE ${MCP_HTTP_PORT}
114
161
 
162
+ # Health check using a bun-native fetch (slim image ships no curl/wget)
163
+ HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 CMD bun -e "fetch('http://localhost:'+(process.env.MCP_HTTP_PORT??'3010')+'/healthz').then((r)=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
164
+
115
165
  # The command to start the server
116
166
  CMD ["bun", "run", "dist/index.js"]