@cyanheads/pubmed-mcp-server 2.10.17 → 2.10.19
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/AGENTS.md +12 -14
- package/CLAUDE.md +12 -14
- package/Dockerfile +77 -36
- package/README.md +86 -109
- package/changelog/2.10.x/2.10.17.md +1 -1
- package/changelog/2.10.x/2.10.18.md +14 -0
- package/changelog/2.10.x/2.10.19.md +42 -0
- package/dist/config/server-config.d.ts.map +1 -1
- package/dist/config/server-config.js +7 -3
- package/dist/config/server-config.js.map +1 -1
- package/dist/mcp-server/resources/definitions/database-info.resource.d.ts +43 -1
- package/dist/mcp-server/resources/definitions/database-info.resource.d.ts.map +1 -1
- package/dist/mcp-server/resources/definitions/database-info.resource.js +2 -0
- package/dist/mcp-server/resources/definitions/database-info.resource.js.map +1 -1
- package/dist/mcp-server/tools/definitions/_visible-text.d.ts +19 -0
- package/dist/mcp-server/tools/definitions/_visible-text.d.ts.map +1 -0
- package/dist/mcp-server/tools/definitions/_visible-text.js +22 -0
- package/dist/mcp-server/tools/definitions/_visible-text.js.map +1 -0
- package/dist/mcp-server/tools/definitions/convert-ids.tool.d.ts +11 -4
- package/dist/mcp-server/tools/definitions/convert-ids.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/convert-ids.tool.js +1 -1
- package/dist/mcp-server/tools/definitions/convert-ids.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/fetch-articles.tool.d.ts +20 -7
- package/dist/mcp-server/tools/definitions/fetch-articles.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/fetch-articles.tool.js +40 -5
- package/dist/mcp-server/tools/definitions/fetch-articles.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/fetch-fulltext.tool.d.ts +11 -4
- package/dist/mcp-server/tools/definitions/fetch-fulltext.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/fetch-fulltext.tool.js +18 -1
- package/dist/mcp-server/tools/definitions/fetch-fulltext.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/find-related.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/find-related.tool.js +39 -10
- package/dist/mcp-server/tools/definitions/find-related.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/format-citations.tool.d.ts +11 -4
- package/dist/mcp-server/tools/definitions/format-citations.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/lookup-citation.tool.d.ts +16 -15
- package/dist/mcp-server/tools/definitions/lookup-citation.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/lookup-citation.tool.js +40 -22
- package/dist/mcp-server/tools/definitions/lookup-citation.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/lookup-mesh.tool.d.ts +13 -6
- package/dist/mcp-server/tools/definitions/lookup-mesh.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/lookup-mesh.tool.js +8 -8
- package/dist/mcp-server/tools/definitions/lookup-mesh.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/pubmed-europepmc-fetch.tool.d.ts +2 -2
- package/dist/mcp-server/tools/definitions/pubmed-europepmc-fetch.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/pubmed-europepmc-fetch.tool.js +1 -1
- package/dist/mcp-server/tools/definitions/pubmed-europepmc-fetch.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/pubmed-europepmc-search.tool.d.ts +19 -5
- package/dist/mcp-server/tools/definitions/pubmed-europepmc-search.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/pubmed-europepmc-search.tool.js +37 -7
- package/dist/mcp-server/tools/definitions/pubmed-europepmc-search.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/search-articles.tool.d.ts +40 -18
- package/dist/mcp-server/tools/definitions/search-articles.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/search-articles.tool.js +193 -43
- package/dist/mcp-server/tools/definitions/search-articles.tool.js.map +1 -1
- package/dist/mcp-server/tools/definitions/spell-check.tool.d.ts +13 -6
- package/dist/mcp-server/tools/definitions/spell-check.tool.d.ts.map +1 -1
- package/dist/mcp-server/tools/definitions/spell-check.tool.js +8 -8
- package/dist/mcp-server/tools/definitions/spell-check.tool.js.map +1 -1
- package/dist/services/error-contracts.d.ts +42 -71
- package/dist/services/error-contracts.d.ts.map +1 -1
- package/dist/services/error-contracts.js +43 -75
- package/dist/services/error-contracts.js.map +1 -1
- package/dist/services/europe-pmc/api-client.d.ts +8 -2
- package/dist/services/europe-pmc/api-client.d.ts.map +1 -1
- package/dist/services/europe-pmc/api-client.js +13 -8
- package/dist/services/europe-pmc/api-client.js.map +1 -1
- package/dist/services/europe-pmc/europe-pmc-service.d.ts +43 -14
- package/dist/services/europe-pmc/europe-pmc-service.d.ts.map +1 -1
- package/dist/services/europe-pmc/europe-pmc-service.js +165 -85
- package/dist/services/europe-pmc/europe-pmc-service.js.map +1 -1
- package/dist/services/europe-pmc/request-queue.d.ts +11 -27
- package/dist/services/europe-pmc/request-queue.d.ts.map +1 -1
- package/dist/services/europe-pmc/request-queue.js +17 -104
- package/dist/services/europe-pmc/request-queue.js.map +1 -1
- package/dist/services/europe-pmc/types.d.ts +6 -1
- package/dist/services/europe-pmc/types.d.ts.map +1 -1
- package/dist/services/ncbi/api-client.d.ts.map +1 -1
- package/dist/services/ncbi/api-client.js +2 -3
- package/dist/services/ncbi/api-client.js.map +1 -1
- package/dist/services/ncbi/ncbi-service.d.ts +2 -1
- package/dist/services/ncbi/ncbi-service.d.ts.map +1 -1
- package/dist/services/ncbi/ncbi-service.js +67 -20
- package/dist/services/ncbi/ncbi-service.js.map +1 -1
- package/dist/services/ncbi/parsing/article-parser.d.ts +15 -1
- package/dist/services/ncbi/parsing/article-parser.d.ts.map +1 -1
- package/dist/services/ncbi/parsing/article-parser.js +29 -0
- package/dist/services/ncbi/parsing/article-parser.js.map +1 -1
- package/dist/services/ncbi/response-handler.d.ts.map +1 -1
- package/dist/services/ncbi/response-handler.js +22 -19
- package/dist/services/ncbi/response-handler.js.map +1 -1
- package/dist/services/ncbi/types.d.ts +33 -0
- package/dist/services/ncbi/types.d.ts.map +1 -1
- package/dist/services/openalex/api-client.d.ts.map +1 -1
- package/dist/services/openalex/api-client.js +6 -7
- package/dist/services/openalex/api-client.js.map +1 -1
- package/dist/services/openalex/openalex-service.d.ts +11 -1
- package/dist/services/openalex/openalex-service.d.ts.map +1 -1
- package/dist/services/openalex/openalex-service.js +18 -11
- package/dist/services/openalex/openalex-service.js.map +1 -1
- package/dist/services/unpaywall/unpaywall-service.d.ts.map +1 -1
- package/dist/services/unpaywall/unpaywall-service.js +1 -3
- package/dist/services/unpaywall/unpaywall-service.js.map +1 -1
- package/package.json +6 -5
- package/server.json +3 -3
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.
|
|
5
|
-
**Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.
|
|
4
|
+
**Version:** 2.10.19
|
|
5
|
+
**Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.10`
|
|
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.
|
|
@@ -115,7 +115,7 @@ const ServerConfigSchema = z.object({
|
|
|
115
115
|
apiKey: z.string().optional().describe('NCBI API key'),
|
|
116
116
|
toolIdentifier: z.string().default('pubmed-mcp-server').describe('NCBI tool identifier'),
|
|
117
117
|
adminEmail: z.email().optional().describe('Admin contact email'),
|
|
118
|
-
requestDelayMs: z.coerce.number().min(50).max(5000).default(
|
|
118
|
+
requestDelayMs: z.coerce.number().min(50).max(5000).default(400).describe('Request delay in ms'),
|
|
119
119
|
maxRetries: z.coerce.number().min(0).max(10).default(6).describe('Max retry attempts'),
|
|
120
120
|
timeoutMs: z.coerce.number().min(1000).max(120000).default(30000).describe('Request timeout in ms'),
|
|
121
121
|
});
|
|
@@ -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` |
|
|
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` |
|
|
193
|
-
| `ctx.tenantId` | Tenant ID from JWT
|
|
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
|
|
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
|
-
//
|
|
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
|
|
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.
|
|
5
|
-
**Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.
|
|
4
|
+
**Version:** 2.10.19
|
|
5
|
+
**Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.10`
|
|
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.
|
|
@@ -115,7 +115,7 @@ const ServerConfigSchema = z.object({
|
|
|
115
115
|
apiKey: z.string().optional().describe('NCBI API key'),
|
|
116
116
|
toolIdentifier: z.string().default('pubmed-mcp-server').describe('NCBI tool identifier'),
|
|
117
117
|
adminEmail: z.email().optional().describe('Admin contact email'),
|
|
118
|
-
requestDelayMs: z.coerce.number().min(50).max(5000).default(
|
|
118
|
+
requestDelayMs: z.coerce.number().min(50).max(5000).default(400).describe('Request delay in ms'),
|
|
119
119
|
maxRetries: z.coerce.number().min(0).max(10).default(6).describe('Max retry attempts'),
|
|
120
120
|
timeoutMs: z.coerce.number().min(1000).max(120000).default(30000).describe('Request timeout in ms'),
|
|
121
121
|
});
|
|
@@ -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` |
|
|
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` |
|
|
193
|
-
| `ctx.tenantId` | Tenant ID from JWT
|
|
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
|
|
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
|
-
//
|
|
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
|
|
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
|
|
11
|
-
#
|
|
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.
|
|
13
|
+
FROM --platform=$BUILDPLATFORM oven/bun:1.4.2 AS build
|
|
14
14
|
|
|
15
15
|
WORKDIR /usr/src/app
|
|
16
16
|
|
|
@@ -32,57 +32,96 @@ RUN bun run build
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
# ==============================================================================
|
|
35
|
-
# Production Stage
|
|
35
|
+
# Production Dependencies Stage
|
|
36
36
|
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
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 does the OTel script — so the stage runs on $BUILDPLATFORM
|
|
40
|
+
# and cross-installs with `--os`/`--cpu`, which pick each platform-specific
|
|
41
|
+
# optional dependency for the target. Only `node_modules` leaves this stage.
|
|
42
|
+
#
|
|
43
|
+
# A clean image rather than `FROM build`: the build stage's node_modules holds
|
|
44
|
+
# devDependencies.
|
|
40
45
|
# ==============================================================================
|
|
41
|
-
FROM oven/bun:1.4.
|
|
46
|
+
FROM --platform=$BUILDPLATFORM oven/bun:1.4.2 AS deps
|
|
42
47
|
|
|
43
48
|
WORKDIR /usr/src/app
|
|
44
49
|
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
#
|
|
56
|
-
|
|
50
|
+
# Copy dependency manifests. `bunfig.toml` rides along so every install below
|
|
51
|
+
# passes its release-age gate and security scanner, as a local install does.
|
|
52
|
+
COPY package.json bun.lock bunfig.toml ./
|
|
53
|
+
|
|
54
|
+
# The scanner bunfig.toml names is a devDependency, and Bun installs a missing
|
|
55
|
+
# scanner through the same production-filtered install, which omits it and
|
|
56
|
+
# aborts. Seed it from the build stage's full install instead. Remove this line,
|
|
57
|
+
# and the `rm` at the end of this stage, if bunfig.toml stops naming a scanner.
|
|
58
|
+
COPY --from=build /usr/src/app/node_modules/@socketsecurity/bun-security-scanner ./node_modules/@socketsecurity/bun-security-scanner
|
|
59
|
+
|
|
60
|
+
# Docker names the target architecture `amd64`/`arm64`; Bun's `--cpu` takes
|
|
61
|
+
# `x64`/`arm64`. Mapped once here, read by both installs below. `oven/bun`
|
|
62
|
+
# publishes only these two architectures, so any other target fails here.
|
|
63
|
+
ARG TARGETOS
|
|
64
|
+
ARG TARGETARCH
|
|
65
|
+
RUN case "$TARGETARCH" in \
|
|
66
|
+
amd64) echo x64 ;; \
|
|
67
|
+
arm64) echo arm64 ;; \
|
|
68
|
+
*) echo "Unsupported TARGETARCH '$TARGETARCH': expected amd64 or arm64" >&2; exit 1 ;; \
|
|
69
|
+
esac > .bun-cpu
|
|
57
70
|
|
|
58
71
|
# Install only production dependencies, ignoring any lifecycle scripts (like 'prepare')
|
|
59
72
|
# that are not needed in the final production image.
|
|
60
73
|
# `--omit=peer` drops the framework's optional peer tiers (test runner, service
|
|
61
74
|
# SDKs, parsers) that Bun would otherwise auto-install. Anything this server
|
|
62
75
|
# actually imports belongs in its own `dependencies`, so nothing needed at
|
|
63
|
-
# runtime is lost.
|
|
64
|
-
# install re-resolves the graph and pulls every optional peer back in.
|
|
76
|
+
# runtime is lost.
|
|
65
77
|
RUN --mount=type=cache,target=/root/.bun/install/cache \
|
|
66
|
-
bun install --production --omit=peer --frozen-lockfile --ignore-scripts
|
|
78
|
+
bun install --production --omit=peer --frozen-lockfile --ignore-scripts \
|
|
79
|
+
--os="$TARGETOS" --cpu="$(cat .bun-cpu)"
|
|
67
80
|
|
|
68
81
|
# Conditionally install OpenTelemetry optional peer dependencies (Tier 3).
|
|
69
|
-
#
|
|
70
|
-
# with: docker build --build-arg OTEL_ENABLED=
|
|
82
|
+
# Installed by default. Omit them for a leaner image at build time
|
|
83
|
+
# with: docker build --build-arg OTEL_ENABLED=false
|
|
84
|
+
# The script reads the list and each range from the installed framework's
|
|
85
|
+
# `peerDependencies` and passes the target flags on to its `bun install`.
|
|
86
|
+
COPY scripts/install-otel.ts ./scripts/
|
|
71
87
|
ARG OTEL_ENABLED=true
|
|
72
88
|
RUN --mount=type=cache,target=/root/.bun/install/cache \
|
|
73
89
|
if [ "$OTEL_ENABLED" = "true" ]; then \
|
|
74
|
-
bun
|
|
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; \
|
|
90
|
+
bun scripts/install-otel.ts --os="$TARGETOS" --cpu="$(cat .bun-cpu)"; \
|
|
84
91
|
fi
|
|
85
92
|
|
|
93
|
+
# The seeded scanner served only the installs above; keep it out of the image.
|
|
94
|
+
RUN rm -rf node_modules/@socketsecurity/bun-security-scanner
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# ==============================================================================
|
|
98
|
+
# Production Stage
|
|
99
|
+
#
|
|
100
|
+
# This stage creates a minimal, optimized, and secure image for running the
|
|
101
|
+
# application. It uses a slim base image and only includes production
|
|
102
|
+
# dependencies and build artifacts. Its only Bun invocations are HEALTHCHECK
|
|
103
|
+
# and CMD, which run on the real target at container start.
|
|
104
|
+
# ==============================================================================
|
|
105
|
+
FROM oven/bun:1.4.2-slim AS production
|
|
106
|
+
|
|
107
|
+
WORKDIR /usr/src/app
|
|
108
|
+
|
|
109
|
+
# Set the environment to production for performance.
|
|
110
|
+
ENV NODE_ENV=production
|
|
111
|
+
|
|
112
|
+
# OCI image metadata (https://github.com/opencontainers/image-spec/blob/main/annotations.md)
|
|
113
|
+
ARG APP_VERSION
|
|
114
|
+
LABEL org.opencontainers.image.title="@cyanheads/pubmed-mcp-server"
|
|
115
|
+
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."
|
|
116
|
+
LABEL org.opencontainers.image.licenses="Apache-2.0"
|
|
117
|
+
LABEL org.opencontainers.image.version="${APP_VERSION}"
|
|
118
|
+
LABEL org.opencontainers.image.source="https://github.com/cyanheads/pubmed-mcp-server"
|
|
119
|
+
|
|
120
|
+
# The manifest comes from the build context: the deps stage's copy was rewritten
|
|
121
|
+
# by the OTel install, and the runtime reads only its name, version, and type.
|
|
122
|
+
COPY package.json ./
|
|
123
|
+
COPY --from=deps /usr/src/app/node_modules ./node_modules
|
|
124
|
+
|
|
86
125
|
# Copy the compiled application code from the build stage
|
|
87
126
|
COPY --from=build /usr/src/app/dist ./dist
|
|
88
127
|
|
|
@@ -107,10 +146,12 @@ ENV MCP_TRANSPORT_TYPE="http"
|
|
|
107
146
|
ENV MCP_SESSION_MODE="stateless"
|
|
108
147
|
ENV MCP_LOG_LEVEL="info"
|
|
109
148
|
ENV LOGS_DIR="/var/log/pubmed-mcp-server"
|
|
110
|
-
ENV MCP_FORCE_CONSOLE_LOGGING="true"
|
|
111
149
|
|
|
112
150
|
# Expose the port the server listens on
|
|
113
151
|
EXPOSE ${MCP_HTTP_PORT}
|
|
114
152
|
|
|
153
|
+
# Health check using a bun-native fetch (slim image ships no curl/wget)
|
|
154
|
+
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))"
|
|
155
|
+
|
|
115
156
|
# The command to start the server
|
|
116
157
|
CMD ["bun", "run", "dist/index.js"]
|