@cyanheads/openalex-mcp-server 0.7.16 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/AGENTS.md +32 -30
  2. package/CLAUDE.md +32 -30
  3. package/Dockerfile +88 -32
  4. package/README.md +6 -2
  5. package/changelog/0.8.x/0.8.0.md +38 -0
  6. package/dist/index.js +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/mcp-server/prompts/definitions/literature-review.prompt.js +1 -1
  9. package/dist/mcp-server/tools/definitions/analyze-trends.tool.d.ts +1 -1
  10. package/dist/mcp-server/tools/definitions/analyze-trends.tool.d.ts.map +1 -1
  11. package/dist/mcp-server/tools/definitions/analyze-trends.tool.js +23 -6
  12. package/dist/mcp-server/tools/definitions/analyze-trends.tool.js.map +1 -1
  13. package/dist/mcp-server/tools/definitions/citation-graph.tool.d.ts +21 -1
  14. package/dist/mcp-server/tools/definitions/citation-graph.tool.d.ts.map +1 -1
  15. package/dist/mcp-server/tools/definitions/citation-graph.tool.js +42 -42
  16. package/dist/mcp-server/tools/definitions/citation-graph.tool.js.map +1 -1
  17. package/dist/mcp-server/tools/definitions/resolve-name.tool.d.ts +1 -1
  18. package/dist/mcp-server/tools/definitions/resolve-name.tool.js +1 -1
  19. package/dist/mcp-server/tools/definitions/resolve-name.tool.js.map +1 -1
  20. package/dist/mcp-server/tools/definitions/search-entities.tool.d.ts +35 -1
  21. package/dist/mcp-server/tools/definitions/search-entities.tool.d.ts.map +1 -1
  22. package/dist/mcp-server/tools/definitions/search-entities.tool.js +110 -62
  23. package/dist/mcp-server/tools/definitions/search-entities.tool.js.map +1 -1
  24. package/dist/mcp-server/tools/render-entity-record.d.ts +12 -1
  25. package/dist/mcp-server/tools/render-entity-record.d.ts.map +1 -1
  26. package/dist/mcp-server/tools/render-entity-record.js +23 -8
  27. package/dist/mcp-server/tools/render-entity-record.js.map +1 -1
  28. package/dist/mcp-server/tools/response-budget.d.ts +159 -0
  29. package/dist/mcp-server/tools/response-budget.d.ts.map +1 -0
  30. package/dist/mcp-server/tools/response-budget.js +480 -0
  31. package/dist/mcp-server/tools/response-budget.js.map +1 -0
  32. package/dist/services/openalex/openalex-service.d.ts +13 -0
  33. package/dist/services/openalex/openalex-service.d.ts.map +1 -1
  34. package/dist/services/openalex/openalex-service.js +46 -34
  35. package/dist/services/openalex/openalex-service.js.map +1 -1
  36. package/dist/services/openalex/provider-text.d.ts +12 -5
  37. package/dist/services/openalex/provider-text.d.ts.map +1 -1
  38. package/dist/services/openalex/provider-text.js +357 -33
  39. package/dist/services/openalex/provider-text.js.map +1 -1
  40. package/dist/services/openalex/types.d.ts +1 -1
  41. package/dist/services/openalex/types.js +1 -1
  42. package/package.json +8 -7
  43. package/server.json +3 -3
package/AGENTS.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Developer Protocol
2
2
 
3
3
  **Server:** openalex-mcp-server
4
- **Version:** 0.7.16
5
- **Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.6`
4
+ **Version:** 0.8.0
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
- **MCP SDK:** `@modelcontextprotocol/server` ^2.0.0
7
+ **MCP SDK:** `@modelcontextprotocol/server` ^2.1.0
8
8
  **Zod:** ^4.6.5
9
9
 
10
10
  > **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.
@@ -151,15 +151,15 @@ Handlers receive a unified `ctx` object. Key properties:
151
151
  | Property | Description |
152
152
  |:---------|:------------|
153
153
  | `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. |
154
- | `ctx.state` | Tenant-scoped KV — `.get(key)`, `.set(key, value, { ttl? })`, `.delete(key)`, `.getMany(keys)`, `.list(prefix, { cursor, limit })`. Accepts any serializable value. |
154
+ | `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). |
155
155
  | `ctx.requestInput` | Suspend and ask the caller for more input with `return ctx.requestInput(...)`; the handler is re-entered with answers. |
156
- | `ctx.inputs` | Reader over a retried request's responses — `.accepted(key, schema)`, `.view(key)`, `.state()`, `.dropped`. |
157
- | `ctx.enrich` | Success-path agent context for notices, query echoes, totals, and truncation disclosure. Reaches both client response surfaces. |
158
- | `ctx.content` | Non-text content blocks appended to `content[]`; never enters `structuredContent`. |
156
+ | `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). |
157
+ | `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. |
158
+ | `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). |
159
+ | `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`. |
159
160
  | `ctx.signal` | `AbortSignal` for cancellation. Passed to `withRetry` in the OpenAlex service, whose per-attempt signal reaches `fetch()`. |
160
161
  | `ctx.fail` | Typed throw keyed by a declared `errors[]` contract — `ctx.fail(reason, msg?, data?)`. Auto-populates `data.reason` and resolves `code` from the contract. |
161
- | `ctx.recoveryFor` | Opt-in resolver returning `{ recovery: { hint } }` for a declared reason. Spread into `data` at throw site to surface contract recovery on the wire. |
162
- | `ctx.requestId` | Unique request ID. |
162
+ | `ctx.requestId` | Request ID — the one every log record of the call carries and its error envelope returns as `data.requestId`. |
163
163
  | `ctx.tenantId` | `'default'` for stdio and `MCP_AUTH_MODE=none` over HTTP; JWT `tid` claim for `MCP_AUTH_MODE=jwt`/`oauth`. |
164
164
 
165
165
  ---
@@ -168,7 +168,7 @@ Handlers receive a unified `ctx` object. Key properties:
168
168
 
169
169
  Handlers throw — the framework catches, classifies, and formats.
170
170
 
171
- **Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable?, thrownBy? }]` on `tool()` to receive a typed `ctx.fail(reason, …)` keyed by the declared reason union — `ctx.fail('typo')` is a TS error, `data.reason` is auto-populated, and the linter enforces conformance against the handler. The `recovery` field is required (≥5 words). Spread `ctx.recoveryFor('reason')` into `data` to opt the contract recovery onto the wire; `error-contract-recovery-unforwarded` warns per `ctx.fail` site that forwards neither the resolver nor its own `recovery` key.
171
+ **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, 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>)`. Mark an entry the service layer throws with `thrownBy: 'service'` so `error-contract-unthrown` skips it — lint-only metadata, nothing at runtime reads it. Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`, `RequestCancelled`) bubble freely and don't need declaring.
172
172
 
173
173
  ```ts
174
174
  import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
@@ -183,13 +183,13 @@ errors: [
183
183
  thrownBy: 'service' },
184
184
  ],
185
185
  async handler(input, ctx) {
186
- if (overCap) throw ctx.fail('semantic_per_page_cap', message, { ...ctx.recoveryFor('semantic_per_page_cap') });
186
+ if (overCap) throw ctx.fail('semantic_per_page_cap', message);
187
187
  }
188
188
  ```
189
189
 
190
190
  **Declare contracts inline on each tool, even when similar across tools.** The contract is part of the tool's documented public surface — reading one tool definition file should give the full picture. Don't extract a shared `errors[]` constant; per-tool repetition is the intended cost of locality.
191
191
 
192
- The OpenAlex service throws factory errors (`notFound`, `rateLimited`, etc.) based on upstream status codes, carrying the contract `reason` on `data.reason` and the recovery via `ctx.recoveryFor(reason)`; those bubble through and are auto-classified. Every such entry carries `thrownBy: 'service'` — lint-only metadata that tells `error-contract-unthrown`, whose scan reads the handler body alone, to skip a reason produced a layer below it. Handler-local precondition throws stay inline and unmarked so the rule keeps checking them: `semantic_without_query`, `semantic_per_page_cap`, `semantic_with_cursor`, `page_without_semantic`, `sample_with_cursor`, `sample_with_page`, `sample_with_semantic`, `sample_with_sort`, and `seed_without_sample` on `openalex_search_entities`; `reserved_filter_key` and the seed-lookup `entity_not_found` on `openalex_get_citation_graph`. Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`, `RequestCancelled`) bubble freely without needing to be declared on a contract.
192
+ The OpenAlex service throws factory errors (`notFound`, `rateLimited`, etc.) based on upstream status codes, carrying the contract `reason` on `data.reason` and nothing else of the contract; the framework fills the calling tool's `recovery` for that reason at the handler boundary, and the errors bubble through and are auto-classified. Two service throws set their own `recovery: { hint }`, which wins over the fill: the PMCID 404, since the generic "verify the ID" recovery would send the caller back to retry an identifier OpenAlex never indexes; and `upstream_budget_exhausted` on a server with no `OPENALEX_API_KEY`, whose hint adds the free-key advice to the contract's key-neutral midnight-UTC recovery (a keyed server's budget is already the larger one, so it gets the contract text alone). Every service-thrown entry carries `thrownBy: 'service'` — lint-only metadata that tells `error-contract-unthrown`, whose scan reads the handler body alone, to skip a reason produced a layer below it. Handler-local precondition throws stay inline and unmarked so the rule keeps checking them: `semantic_without_query`, `semantic_per_page_cap`, `semantic_with_cursor`, `page_without_semantic`, `sample_with_cursor`, `sample_with_page`, `sample_with_semantic`, `sample_with_sort`, `seed_without_sample`, `slice_without_id`, and `slice_field_not_array` on `openalex_search_entities`; `reserved_filter_key` and the seed-lookup `entity_not_found` on `openalex_get_citation_graph`. Recovery assertions belong on the contract path (`runToolContract`), where the fill applies — a direct `definition.handler(...)` or service throw carries only what the throw site wrote.
193
193
 
194
194
  **Fallback for ad-hoc throws:** error factories or plain `Error`.
195
195
 
@@ -221,6 +221,7 @@ src/
221
221
  analyze-trends.tool.ts # openalex_analyze_trends
222
222
  resolve-name.tool.ts # openalex_resolve_name
223
223
  citation-graph.tool.ts # openalex_get_citation_graph
224
+ describe-fields.tool.ts # openalex_describe_fields
224
225
  prompts/definitions/
225
226
  literature-review.prompt.ts # openalex_literature_review
226
227
  research-landscape.prompt.ts # openalex_research_landscape
@@ -241,9 +242,9 @@ src/
241
242
 
242
243
  ## Skills
243
244
 
244
- Skills are modular instructions in `framework-skills/` at the project root. Read them directly when a task matches — e.g., `framework-skills/add-tool/SKILL.md` when adding a tool. `bun run list-skills` prints the full registry. The directory is deliberately not `skills/`: Claude Code and Codex auto-load a plugin's root `skills/`, so a server that ships `.claude-plugin/` or `.codex-plugin/` would hand these development skills to every agent that installs it.
245
+ Skills are modular instructions in `framework-skills/` at the project root. Read them directly when a task matches — e.g., `framework-skills/add-tool/SKILL.md` when adding a tool. `bun run list-skills` prints the full registry. The directory is deliberately not `skills/`: Claude Code and Codex auto-load a plugin's root `skills/`, so a server that ships `.claude-plugin/` or `.codex-plugin/` would hand these development skills to every agent that installs it. Keep `skills/` free for skills meant for those agents.
245
246
 
246
- **Agent skill directory:** Copy skills into the directory your agent discovers (Claude Code: `.claude/skills/`, others: equivalent). This makes skills available as context without needing to reference `framework-skills/` paths manually. After framework updates, run the `maintenance` skill — it re-syncs the agent directory automatically (Phase B).
247
+ **Agent skill directory:** Copy skills into the directory your agent discovers (Claude Code: `.claude/skills/`, others: equivalent). Skills then load as context without referencing `framework-skills/` paths. After framework updates, run the `maintenance` skill — Phase B re-syncs the agent directory.
247
248
 
248
249
  Available skills:
249
250
 
@@ -259,29 +260,29 @@ Available skills:
259
260
  | `add-test` | Scaffold test file for a tool, resource, or service |
260
261
  | `field-test` | Exercise tools/resources/prompts with real inputs, verify behavior, report issues |
261
262
  | `tool-defs-analysis` | Read-only audit of MCP definition language across the surface — voice, leaks, defaults, recovery hints, output descriptions |
262
- | `security-pass` | Audit the server for MCP-flavored security gaps: output injection, scope blast radius, input sinks, tenant isolation |
263
+ | `security-pass` | Audit server for MCP-flavored security gaps: output injection, scope blast radius, input sinks, tenant isolation |
263
264
  | `code-simplifier` | Post-session cleanup against `git diff` — modernize syntax, consolidate duplication, align with the codebase |
264
- | `techniques` | Reusable response/data-shaping patterns — overflow handling, payload shaping, retrieval |
265
265
  | `polish-docs-meta` | Finalize docs, README, metadata, and agent protocol for shipping |
266
- | `git-wrapup` | Prepare the version, changelog, verification, and commit stack. |
267
- | `release-pr-review` | Review an open release PR when the project opts into release PR mode. |
268
- | `release-and-publish` | Tag + push + npm + MCP Registry + GH Release + Docker. Picks up from `git-wrapup`. |
266
+ | `git-wrapup` | Land working-tree changes as a commit stack — version bump, changelog, verify, commit by concern, release commit on top. No tag, no push to main; opens the release PR when the project declares release PR mode |
267
+ | `release-pr-review` | Review pass on an open release PR — simplifier + correctness review, fixes as ordinary commits on top of the stack, PR body kept in sync. Release PR mode only |
268
+ | `release-and-publish` | Fast-forward merge (release PR mode) + tag + push + npm + MCP Registry + GH Release + Docker. Picks up from `git-wrapup` |
269
269
  | `maintenance` | Investigate changelogs, adopt upstream changes, sync skills to agent dirs |
270
270
  | `orchestrations` | Chain task skills into a gated multi-phase pipeline — build-out, QA-fix, update-ship — when you can spawn sub-agents |
271
- | `report-issue-framework` | File a bug or feature request against `@cyanheads/mcp-ts-core` |
272
- | `report-issue-local` | File a bug or feature request against this server's own repo |
271
+ | `report-issue-framework` | File a bug or feature request against `@cyanheads/mcp-ts-core` via `gh` CLI |
272
+ | `report-issue-local` | File a bug or feature request against this server's own repo via `gh` CLI |
273
+ | `techniques` | Catalog of response/data-shaping techniques — overflow handling, payload shaping, retrieval patterns |
273
274
  | `api-auth` | Auth modes, scopes, JWT/OAuth |
274
- | `api-canvas` | DataCanvas: register tabular data, run SQL, export, plus the `spillover()` helper — Tier 3 opt-in |
275
+ | `api-canvas` | DataCanvas: register tabular data, run SQL, export, plus the `spillover()` helper for big result sets — Tier 3 opt-in |
275
276
  | `api-config` | AppConfig, parseConfig, env vars |
276
277
  | `api-context` | Context interface, RequestContext, logger, state, multi-round-trip input |
277
278
  | `api-errors` | McpError, JsonRpcErrorCode, error patterns |
278
279
  | `api-linter` | Definition linter rule catalog — invoked by `bun run lint:mcp` and `devcheck` |
280
+ | `api-mirror` | MirrorService: persistent self-refreshing local mirror (embedded SQLite + FTS5) of a bulk upstream dataset — Tier 3 opt-in |
279
281
  | `api-services` | LLM, Speech, Graph services |
280
282
  | `api-testing` | createMockContext, test patterns |
281
283
  | `api-utils` | Formatting, parsing, security, pagination, scheduling, telemetry helpers |
282
284
  | `api-telemetry` | OTel catalog: spans, metrics, completion logs, env config, cardinality rules |
283
285
  | `api-workers` | Cloudflare Workers runtime |
284
- | `api-mirror` | MirrorService: persistent local SQLite mirror of a bulk upstream dataset — Tier 3 opt-in |
285
286
 
286
287
  **Chaining skills into pipelines.** When the user wants a multi-phase effort — build this server out, QA-and-fix the surface, update-and-ship — *and you can spawn sub-agents*, `framework-skills/orchestrations/SKILL.md` sequences the task skills above into a gated pipeline with verification at each step. Read it to drive the run. Optional: skip it if you can't orchestrate sub-agents, and ignore it entirely if you were *spawned* as one — you've already been scoped to a single phase.
287
288
 
@@ -297,21 +298,21 @@ When you complete a skill's checklist, check the boxes and add a completion time
297
298
  | `bun run rebuild` | Clean + build |
298
299
  | `bun run clean` | Remove build artifacts |
299
300
  | `bun run devcheck` | Lint + format + typecheck + security + changelog sync |
300
- | `bun run audit:fix` | Run `bun audit fix` to upgrade vulnerable packages within existing ranges. |
301
- | `bun run audit:refresh` | Delete `bun.lock` and reinstall; last resort after `audit:fix`, targeted updates, and `bun dedupe`. |
301
+ | `bun run audit:fix` | `bun audit fix` — upgrade vulnerable packages to the lowest safe version within existing ranges (`--dry-run` previews, `--latest` rewrites ranges). First response when `devcheck` flags a transitive advisory; then `bun update <name>`, then `bun dedupe` |
302
+ | `bun run audit:refresh` | Delete `bun.lock` and reinstall. Last resort after `audit:fix`, `bun update <name>`, and `bun dedupe` — re-resolves every ranged dep (the framework pin included) and rewrites the lockfile as `lockfileVersion: 2` |
302
303
  | `bun run tree` | Generate directory structure doc |
303
304
  | `bun run format` | Auto-fix formatting (safe fixes only) |
304
305
  | `bun run format:unsafe` | Also apply Biome's unsafe autofixes — review the diff; they can change behavior |
305
306
  | `bun run lint:mcp` | Validate MCP tool/prompt definitions (rule catalog: `api-linter` skill) |
306
307
  | `bun run lint:packaging` | Packaging surface checks — env-var parity, plugin metadata, README version badge (run by devcheck) |
307
308
  | `bun run list-skills` | List available skills |
308
- | `bun run test` | Run tests |
309
+ | `bun run test` | Run tests (Vitest — use `bun run test`, not `bun test`) |
309
310
  | `bun run start:stdio` | Production mode (stdio, after `rebuild`) |
310
311
  | `bun run start:http` | Production mode (HTTP, after `rebuild`) |
311
312
  | `bun run changelog:build` | Regenerate `CHANGELOG.md` from `changelog/*.md` |
312
313
  | `bun run changelog:check` | Verify `CHANGELOG.md` is in sync (used by devcheck) |
313
314
  | `bun run release:github` | Create GitHub Release from the latest annotated tag (title `v<VERSION>: <subject>`, optional `.mcpb` attach) |
314
- | `bun run bundle` | Build and pack as `.mcpb` for one-click Claude Desktop install |
315
+ | `bun run bundle` | Build, pack, and clean a `.mcpb` for one-click Claude Desktop install |
315
316
 
316
317
  **CI is one file.** `.github/workflows/codeql.yml` is the only GitHub Actions workflow: CodeQL is GitHub-owned end to end, and the file runs only while the repo's CodeQL *default setup* is turned off. Verification — `devcheck`, tests, the release gates — runs locally; don't add a workflow that re-runs it.
317
318
 
@@ -346,6 +347,7 @@ Run the `release-and-publish` skill — it runs the verification gate (`devcheck
346
347
  bun publish --access public
347
348
 
348
349
  docker buildx build --platform linux/amd64,linux/arm64 \
350
+ --build-arg APP_VERSION=<version> \
349
351
  -t ghcr.io/cyanheads/openalex-mcp-server:<version> \
350
352
  -t ghcr.io/cyanheads/openalex-mcp-server:latest \
351
353
  --push .
@@ -379,7 +381,7 @@ import { getOpenAlexService } from '@/services/openalex/openalex-service.js';
379
381
  - [ ] OpenAlex wrapping: tests include at least one sparse payload case with omitted upstream fields
380
382
  - [ ] Registered in `createApp()` arrays (directly or via barrel exports)
381
383
  - [ ] Tests use `createMockContext()` from `@cyanheads/mcp-ts-core/testing`
382
- - [ ] `.codex-plugin/plugin.json` populated — `name`, `version`, `description`, `repository`, `license` from `package.json`; `interface.displayName` = the unscoped repo name; `interface.shortDescription` from `package.json` description
383
- - [ ] `.codex-plugin/mcp.json` updated — server name key is the unscoped repo name; user-supplied variables are listed in `env_vars`
384
- - [ ] `.claude-plugin/plugin.json` populated — `name`, `version`, `description`, `repository`, `license` from `package.json`; inline `mcpServers` entry keyed by the unscoped repo name; user-supplied variables are declared under `userConfig` and referenced as `${user_config.<option>}`
384
+ - [ ] `.codex-plugin/plugin.json` populated — `name`, `version`, `description`, `repository`, `license` from `package.json`; `interface.displayName` = the unscoped repo name (never the npm scope — `lint:packaging` enforces this); `interface.shortDescription` from `package.json` description
385
+ - [ ] `.codex-plugin/mcp.json` updated — server name key is the unscoped repo name; every user-supplied variable (API key, contact email, instance URL) is listed in `env_vars` so Codex forwards it from the user's environment. Never write `"KEY": ""` into `env` — an empty value replaces the user's exported key and is read as unset
386
+ - [ ] `.claude-plugin/plugin.json` populated — `name`, `version`, `description`, `author`, `repository`, `license`, `keywords` from `package.json`; inline `mcpServers` entry keyed by the unscoped repo name. Every user-supplied variable is declared under `userConfig` (`type`, `title`, `description`; `sensitive: true` for keys and tokens; `required: true` or `default: ""`) and referenced from `env` as `"KEY": "${user_config.<option>}"` — mirror the `user_config` block in `manifest.json`. Never write `"KEY": ""` into `env`
385
387
  - [ ] `bun run devcheck` passes
package/CLAUDE.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Developer Protocol
2
2
 
3
3
  **Server:** openalex-mcp-server
4
- **Version:** 0.7.16
5
- **Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.13.6`
4
+ **Version:** 0.8.0
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
- **MCP SDK:** `@modelcontextprotocol/server` ^2.0.0
7
+ **MCP SDK:** `@modelcontextprotocol/server` ^2.1.0
8
8
  **Zod:** ^4.6.5
9
9
 
10
10
  > **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.
@@ -151,15 +151,15 @@ Handlers receive a unified `ctx` object. Key properties:
151
151
  | Property | Description |
152
152
  |:---------|:------------|
153
153
  | `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. |
154
- | `ctx.state` | Tenant-scoped KV — `.get(key)`, `.set(key, value, { ttl? })`, `.delete(key)`, `.getMany(keys)`, `.list(prefix, { cursor, limit })`. Accepts any serializable value. |
154
+ | `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). |
155
155
  | `ctx.requestInput` | Suspend and ask the caller for more input with `return ctx.requestInput(...)`; the handler is re-entered with answers. |
156
- | `ctx.inputs` | Reader over a retried request's responses — `.accepted(key, schema)`, `.view(key)`, `.state()`, `.dropped`. |
157
- | `ctx.enrich` | Success-path agent context for notices, query echoes, totals, and truncation disclosure. Reaches both client response surfaces. |
158
- | `ctx.content` | Non-text content blocks appended to `content[]`; never enters `structuredContent`. |
156
+ | `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). |
157
+ | `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. |
158
+ | `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). |
159
+ | `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`. |
159
160
  | `ctx.signal` | `AbortSignal` for cancellation. Passed to `withRetry` in the OpenAlex service, whose per-attempt signal reaches `fetch()`. |
160
161
  | `ctx.fail` | Typed throw keyed by a declared `errors[]` contract — `ctx.fail(reason, msg?, data?)`. Auto-populates `data.reason` and resolves `code` from the contract. |
161
- | `ctx.recoveryFor` | Opt-in resolver returning `{ recovery: { hint } }` for a declared reason. Spread into `data` at throw site to surface contract recovery on the wire. |
162
- | `ctx.requestId` | Unique request ID. |
162
+ | `ctx.requestId` | Request ID — the one every log record of the call carries and its error envelope returns as `data.requestId`. |
163
163
  | `ctx.tenantId` | `'default'` for stdio and `MCP_AUTH_MODE=none` over HTTP; JWT `tid` claim for `MCP_AUTH_MODE=jwt`/`oauth`. |
164
164
 
165
165
  ---
@@ -168,7 +168,7 @@ Handlers receive a unified `ctx` object. Key properties:
168
168
 
169
169
  Handlers throw — the framework catches, classifies, and formats.
170
170
 
171
- **Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable?, thrownBy? }]` on `tool()` to receive a typed `ctx.fail(reason, …)` keyed by the declared reason union — `ctx.fail('typo')` is a TS error, `data.reason` is auto-populated, and the linter enforces conformance against the handler. The `recovery` field is required (≥5 words). Spread `ctx.recoveryFor('reason')` into `data` to opt the contract recovery onto the wire; `error-contract-recovery-unforwarded` warns per `ctx.fail` site that forwards neither the resolver nor its own `recovery` key.
171
+ **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, 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>)`. Mark an entry the service layer throws with `thrownBy: 'service'` so `error-contract-unthrown` skips it — lint-only metadata, nothing at runtime reads it. Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`, `RequestCancelled`) bubble freely and don't need declaring.
172
172
 
173
173
  ```ts
174
174
  import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
@@ -183,13 +183,13 @@ errors: [
183
183
  thrownBy: 'service' },
184
184
  ],
185
185
  async handler(input, ctx) {
186
- if (overCap) throw ctx.fail('semantic_per_page_cap', message, { ...ctx.recoveryFor('semantic_per_page_cap') });
186
+ if (overCap) throw ctx.fail('semantic_per_page_cap', message);
187
187
  }
188
188
  ```
189
189
 
190
190
  **Declare contracts inline on each tool, even when similar across tools.** The contract is part of the tool's documented public surface — reading one tool definition file should give the full picture. Don't extract a shared `errors[]` constant; per-tool repetition is the intended cost of locality.
191
191
 
192
- The OpenAlex service throws factory errors (`notFound`, `rateLimited`, etc.) based on upstream status codes, carrying the contract `reason` on `data.reason` and the recovery via `ctx.recoveryFor(reason)`; those bubble through and are auto-classified. Every such entry carries `thrownBy: 'service'` — lint-only metadata that tells `error-contract-unthrown`, whose scan reads the handler body alone, to skip a reason produced a layer below it. Handler-local precondition throws stay inline and unmarked so the rule keeps checking them: `semantic_without_query`, `semantic_per_page_cap`, `semantic_with_cursor`, `page_without_semantic`, `sample_with_cursor`, `sample_with_page`, `sample_with_semantic`, `sample_with_sort`, and `seed_without_sample` on `openalex_search_entities`; `reserved_filter_key` and the seed-lookup `entity_not_found` on `openalex_get_citation_graph`. Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`, `RequestCancelled`) bubble freely without needing to be declared on a contract.
192
+ The OpenAlex service throws factory errors (`notFound`, `rateLimited`, etc.) based on upstream status codes, carrying the contract `reason` on `data.reason` and nothing else of the contract; the framework fills the calling tool's `recovery` for that reason at the handler boundary, and the errors bubble through and are auto-classified. Two service throws set their own `recovery: { hint }`, which wins over the fill: the PMCID 404, since the generic "verify the ID" recovery would send the caller back to retry an identifier OpenAlex never indexes; and `upstream_budget_exhausted` on a server with no `OPENALEX_API_KEY`, whose hint adds the free-key advice to the contract's key-neutral midnight-UTC recovery (a keyed server's budget is already the larger one, so it gets the contract text alone). Every service-thrown entry carries `thrownBy: 'service'` — lint-only metadata that tells `error-contract-unthrown`, whose scan reads the handler body alone, to skip a reason produced a layer below it. Handler-local precondition throws stay inline and unmarked so the rule keeps checking them: `semantic_without_query`, `semantic_per_page_cap`, `semantic_with_cursor`, `page_without_semantic`, `sample_with_cursor`, `sample_with_page`, `sample_with_semantic`, `sample_with_sort`, `seed_without_sample`, `slice_without_id`, and `slice_field_not_array` on `openalex_search_entities`; `reserved_filter_key` and the seed-lookup `entity_not_found` on `openalex_get_citation_graph`. Recovery assertions belong on the contract path (`runToolContract`), where the fill applies — a direct `definition.handler(...)` or service throw carries only what the throw site wrote.
193
193
 
194
194
  **Fallback for ad-hoc throws:** error factories or plain `Error`.
195
195
 
@@ -221,6 +221,7 @@ src/
221
221
  analyze-trends.tool.ts # openalex_analyze_trends
222
222
  resolve-name.tool.ts # openalex_resolve_name
223
223
  citation-graph.tool.ts # openalex_get_citation_graph
224
+ describe-fields.tool.ts # openalex_describe_fields
224
225
  prompts/definitions/
225
226
  literature-review.prompt.ts # openalex_literature_review
226
227
  research-landscape.prompt.ts # openalex_research_landscape
@@ -241,9 +242,9 @@ src/
241
242
 
242
243
  ## Skills
243
244
 
244
- Skills are modular instructions in `framework-skills/` at the project root. Read them directly when a task matches — e.g., `framework-skills/add-tool/SKILL.md` when adding a tool. `bun run list-skills` prints the full registry. The directory is deliberately not `skills/`: Claude Code and Codex auto-load a plugin's root `skills/`, so a server that ships `.claude-plugin/` or `.codex-plugin/` would hand these development skills to every agent that installs it.
245
+ Skills are modular instructions in `framework-skills/` at the project root. Read them directly when a task matches — e.g., `framework-skills/add-tool/SKILL.md` when adding a tool. `bun run list-skills` prints the full registry. The directory is deliberately not `skills/`: Claude Code and Codex auto-load a plugin's root `skills/`, so a server that ships `.claude-plugin/` or `.codex-plugin/` would hand these development skills to every agent that installs it. Keep `skills/` free for skills meant for those agents.
245
246
 
246
- **Agent skill directory:** Copy skills into the directory your agent discovers (Claude Code: `.claude/skills/`, others: equivalent). This makes skills available as context without needing to reference `framework-skills/` paths manually. After framework updates, run the `maintenance` skill — it re-syncs the agent directory automatically (Phase B).
247
+ **Agent skill directory:** Copy skills into the directory your agent discovers (Claude Code: `.claude/skills/`, others: equivalent). Skills then load as context without referencing `framework-skills/` paths. After framework updates, run the `maintenance` skill — Phase B re-syncs the agent directory.
247
248
 
248
249
  Available skills:
249
250
 
@@ -259,29 +260,29 @@ Available skills:
259
260
  | `add-test` | Scaffold test file for a tool, resource, or service |
260
261
  | `field-test` | Exercise tools/resources/prompts with real inputs, verify behavior, report issues |
261
262
  | `tool-defs-analysis` | Read-only audit of MCP definition language across the surface — voice, leaks, defaults, recovery hints, output descriptions |
262
- | `security-pass` | Audit the server for MCP-flavored security gaps: output injection, scope blast radius, input sinks, tenant isolation |
263
+ | `security-pass` | Audit server for MCP-flavored security gaps: output injection, scope blast radius, input sinks, tenant isolation |
263
264
  | `code-simplifier` | Post-session cleanup against `git diff` — modernize syntax, consolidate duplication, align with the codebase |
264
- | `techniques` | Reusable response/data-shaping patterns — overflow handling, payload shaping, retrieval |
265
265
  | `polish-docs-meta` | Finalize docs, README, metadata, and agent protocol for shipping |
266
- | `git-wrapup` | Prepare the version, changelog, verification, and commit stack. |
267
- | `release-pr-review` | Review an open release PR when the project opts into release PR mode. |
268
- | `release-and-publish` | Tag + push + npm + MCP Registry + GH Release + Docker. Picks up from `git-wrapup`. |
266
+ | `git-wrapup` | Land working-tree changes as a commit stack — version bump, changelog, verify, commit by concern, release commit on top. No tag, no push to main; opens the release PR when the project declares release PR mode |
267
+ | `release-pr-review` | Review pass on an open release PR — simplifier + correctness review, fixes as ordinary commits on top of the stack, PR body kept in sync. Release PR mode only |
268
+ | `release-and-publish` | Fast-forward merge (release PR mode) + tag + push + npm + MCP Registry + GH Release + Docker. Picks up from `git-wrapup` |
269
269
  | `maintenance` | Investigate changelogs, adopt upstream changes, sync skills to agent dirs |
270
270
  | `orchestrations` | Chain task skills into a gated multi-phase pipeline — build-out, QA-fix, update-ship — when you can spawn sub-agents |
271
- | `report-issue-framework` | File a bug or feature request against `@cyanheads/mcp-ts-core` |
272
- | `report-issue-local` | File a bug or feature request against this server's own repo |
271
+ | `report-issue-framework` | File a bug or feature request against `@cyanheads/mcp-ts-core` via `gh` CLI |
272
+ | `report-issue-local` | File a bug or feature request against this server's own repo via `gh` CLI |
273
+ | `techniques` | Catalog of response/data-shaping techniques — overflow handling, payload shaping, retrieval patterns |
273
274
  | `api-auth` | Auth modes, scopes, JWT/OAuth |
274
- | `api-canvas` | DataCanvas: register tabular data, run SQL, export, plus the `spillover()` helper — Tier 3 opt-in |
275
+ | `api-canvas` | DataCanvas: register tabular data, run SQL, export, plus the `spillover()` helper for big result sets — Tier 3 opt-in |
275
276
  | `api-config` | AppConfig, parseConfig, env vars |
276
277
  | `api-context` | Context interface, RequestContext, logger, state, multi-round-trip input |
277
278
  | `api-errors` | McpError, JsonRpcErrorCode, error patterns |
278
279
  | `api-linter` | Definition linter rule catalog — invoked by `bun run lint:mcp` and `devcheck` |
280
+ | `api-mirror` | MirrorService: persistent self-refreshing local mirror (embedded SQLite + FTS5) of a bulk upstream dataset — Tier 3 opt-in |
279
281
  | `api-services` | LLM, Speech, Graph services |
280
282
  | `api-testing` | createMockContext, test patterns |
281
283
  | `api-utils` | Formatting, parsing, security, pagination, scheduling, telemetry helpers |
282
284
  | `api-telemetry` | OTel catalog: spans, metrics, completion logs, env config, cardinality rules |
283
285
  | `api-workers` | Cloudflare Workers runtime |
284
- | `api-mirror` | MirrorService: persistent local SQLite mirror of a bulk upstream dataset — Tier 3 opt-in |
285
286
 
286
287
  **Chaining skills into pipelines.** When the user wants a multi-phase effort — build this server out, QA-and-fix the surface, update-and-ship — *and you can spawn sub-agents*, `framework-skills/orchestrations/SKILL.md` sequences the task skills above into a gated pipeline with verification at each step. Read it to drive the run. Optional: skip it if you can't orchestrate sub-agents, and ignore it entirely if you were *spawned* as one — you've already been scoped to a single phase.
287
288
 
@@ -297,21 +298,21 @@ When you complete a skill's checklist, check the boxes and add a completion time
297
298
  | `bun run rebuild` | Clean + build |
298
299
  | `bun run clean` | Remove build artifacts |
299
300
  | `bun run devcheck` | Lint + format + typecheck + security + changelog sync |
300
- | `bun run audit:fix` | Run `bun audit fix` to upgrade vulnerable packages within existing ranges. |
301
- | `bun run audit:refresh` | Delete `bun.lock` and reinstall; last resort after `audit:fix`, targeted updates, and `bun dedupe`. |
301
+ | `bun run audit:fix` | `bun audit fix` — upgrade vulnerable packages to the lowest safe version within existing ranges (`--dry-run` previews, `--latest` rewrites ranges). First response when `devcheck` flags a transitive advisory; then `bun update <name>`, then `bun dedupe` |
302
+ | `bun run audit:refresh` | Delete `bun.lock` and reinstall. Last resort after `audit:fix`, `bun update <name>`, and `bun dedupe` — re-resolves every ranged dep (the framework pin included) and rewrites the lockfile as `lockfileVersion: 2` |
302
303
  | `bun run tree` | Generate directory structure doc |
303
304
  | `bun run format` | Auto-fix formatting (safe fixes only) |
304
305
  | `bun run format:unsafe` | Also apply Biome's unsafe autofixes — review the diff; they can change behavior |
305
306
  | `bun run lint:mcp` | Validate MCP tool/prompt definitions (rule catalog: `api-linter` skill) |
306
307
  | `bun run lint:packaging` | Packaging surface checks — env-var parity, plugin metadata, README version badge (run by devcheck) |
307
308
  | `bun run list-skills` | List available skills |
308
- | `bun run test` | Run tests |
309
+ | `bun run test` | Run tests (Vitest — use `bun run test`, not `bun test`) |
309
310
  | `bun run start:stdio` | Production mode (stdio, after `rebuild`) |
310
311
  | `bun run start:http` | Production mode (HTTP, after `rebuild`) |
311
312
  | `bun run changelog:build` | Regenerate `CHANGELOG.md` from `changelog/*.md` |
312
313
  | `bun run changelog:check` | Verify `CHANGELOG.md` is in sync (used by devcheck) |
313
314
  | `bun run release:github` | Create GitHub Release from the latest annotated tag (title `v<VERSION>: <subject>`, optional `.mcpb` attach) |
314
- | `bun run bundle` | Build and pack as `.mcpb` for one-click Claude Desktop install |
315
+ | `bun run bundle` | Build, pack, and clean a `.mcpb` for one-click Claude Desktop install |
315
316
 
316
317
  **CI is one file.** `.github/workflows/codeql.yml` is the only GitHub Actions workflow: CodeQL is GitHub-owned end to end, and the file runs only while the repo's CodeQL *default setup* is turned off. Verification — `devcheck`, tests, the release gates — runs locally; don't add a workflow that re-runs it.
317
318
 
@@ -346,6 +347,7 @@ Run the `release-and-publish` skill — it runs the verification gate (`devcheck
346
347
  bun publish --access public
347
348
 
348
349
  docker buildx build --platform linux/amd64,linux/arm64 \
350
+ --build-arg APP_VERSION=<version> \
349
351
  -t ghcr.io/cyanheads/openalex-mcp-server:<version> \
350
352
  -t ghcr.io/cyanheads/openalex-mcp-server:latest \
351
353
  --push .
@@ -379,7 +381,7 @@ import { getOpenAlexService } from '@/services/openalex/openalex-service.js';
379
381
  - [ ] OpenAlex wrapping: tests include at least one sparse payload case with omitted upstream fields
380
382
  - [ ] Registered in `createApp()` arrays (directly or via barrel exports)
381
383
  - [ ] Tests use `createMockContext()` from `@cyanheads/mcp-ts-core/testing`
382
- - [ ] `.codex-plugin/plugin.json` populated — `name`, `version`, `description`, `repository`, `license` from `package.json`; `interface.displayName` = the unscoped repo name; `interface.shortDescription` from `package.json` description
383
- - [ ] `.codex-plugin/mcp.json` updated — server name key is the unscoped repo name; user-supplied variables are listed in `env_vars`
384
- - [ ] `.claude-plugin/plugin.json` populated — `name`, `version`, `description`, `repository`, `license` from `package.json`; inline `mcpServers` entry keyed by the unscoped repo name; user-supplied variables are declared under `userConfig` and referenced as `${user_config.<option>}`
384
+ - [ ] `.codex-plugin/plugin.json` populated — `name`, `version`, `description`, `repository`, `license` from `package.json`; `interface.displayName` = the unscoped repo name (never the npm scope — `lint:packaging` enforces this); `interface.shortDescription` from `package.json` description
385
+ - [ ] `.codex-plugin/mcp.json` updated — server name key is the unscoped repo name; every user-supplied variable (API key, contact email, instance URL) is listed in `env_vars` so Codex forwards it from the user's environment. Never write `"KEY": ""` into `env` — an empty value replaces the user's exported key and is read as unset
386
+ - [ ] `.claude-plugin/plugin.json` populated — `name`, `version`, `description`, `author`, `repository`, `license`, `keywords` from `package.json`; inline `mcpServers` entry keyed by the unscoped repo name. Every user-supplied variable is declared under `userConfig` (`type`, `title`, `description`; `sensitive: true` for keys and tokens; `required: true` or `default: ""`) and referenced from `env` as `"KEY": "${user_config.<option>}"` — mirror the `user_config` block in `manifest.json`. Never write `"KEY": ""` into `env`
385
387
  - [ ] `bun run devcheck` passes
package/Dockerfile CHANGED
@@ -3,8 +3,18 @@
3
3
  #
4
4
  # This stage installs all dependencies (including dev), builds the TypeScript
5
5
  # source code into JavaScript, and prepares the production assets.
6
+ #
7
+ # Pinned to $BUILDPLATFORM rather than the target platform: `bun run build` emits
8
+ # JavaScript, and only `dist/` crosses into the production stage. Built for the
9
+ # target instead, the non-native leg of a `--platform linux/amd64,linux/arm64`
10
+ # build runs under QEMU, where bun >= 1.4 aborts with a JavaScriptCore allocator
11
+ # assertion and fails the multi-arch push.
12
+ #
13
+ # The constraint this assumes: the build stage produces platform-independent
14
+ # output. A stage that compiles a native addon needs the target-arch toolchain
15
+ # and cannot cross-compile this way — drop the flag there.
6
16
  # ==============================================================================
7
- FROM --platform=$BUILDPLATFORM oven/bun:1.4.0 AS build
17
+ FROM --platform=$BUILDPLATFORM oven/bun:1.4.2 AS build
8
18
 
9
19
  WORKDIR /usr/src/app
10
20
 
@@ -23,53 +33,97 @@ COPY . .
23
33
  RUN bun run build
24
34
 
25
35
 
36
+ # ==============================================================================
37
+ # Production Dependencies Stage
38
+ #
39
+ # Installs the production dependency tree for the target platform. Every step
40
+ # here can run JavaScript — bunfig.toml's security scanner runs as a Bun
41
+ # program, and so does the OTel script — so the stage runs on $BUILDPLATFORM
42
+ # and cross-installs with `--os`/`--cpu`, which pick each platform-specific
43
+ # optional dependency (native bindings such as DuckDB's) for the target. Only
44
+ # `node_modules` leaves this stage.
45
+ #
46
+ # A clean image rather than `FROM build`: the build stage's node_modules holds
47
+ # devDependencies.
48
+ # ==============================================================================
49
+ FROM --platform=$BUILDPLATFORM oven/bun:1.4.2 AS deps
50
+
51
+ WORKDIR /usr/src/app
52
+
53
+ # Copy dependency manifests. `bunfig.toml` rides along so every install below
54
+ # passes its release-age gate and security scanner, as a local install does.
55
+ COPY package.json bun.lock bunfig.toml ./
56
+
57
+ # The scanner bunfig.toml names is a devDependency, and Bun installs a missing
58
+ # scanner through the same production-filtered install, which omits it and
59
+ # aborts. Seed it from the build stage's full install instead. Remove this line,
60
+ # and the `rm` at the end of this stage, if bunfig.toml stops naming a scanner.
61
+ COPY --from=build /usr/src/app/node_modules/@socketsecurity/bun-security-scanner ./node_modules/@socketsecurity/bun-security-scanner
62
+
63
+ # Docker names the target architecture `amd64`/`arm64`; Bun's `--cpu` takes
64
+ # `x64`/`arm64`. Mapped once here, read by both installs below. `oven/bun`
65
+ # publishes only these two architectures, so any other target fails here.
66
+ ARG TARGETOS
67
+ ARG TARGETARCH
68
+ RUN case "$TARGETARCH" in \
69
+ amd64) echo x64 ;; \
70
+ arm64) echo arm64 ;; \
71
+ *) echo "Unsupported TARGETARCH '$TARGETARCH': expected amd64 or arm64" >&2; exit 1 ;; \
72
+ esac > .bun-cpu
73
+
74
+ # Install only production dependencies, ignoring any lifecycle scripts (like 'prepare')
75
+ # that are not needed in the final production image.
76
+ # `--omit=peer` drops the framework's optional peer tiers (test runner, service
77
+ # SDKs, parsers) that Bun would otherwise auto-install. Anything this server
78
+ # actually imports belongs in its own `dependencies`, so nothing needed at
79
+ # runtime is lost.
80
+ RUN --mount=type=cache,target=/root/.bun/install/cache \
81
+ bun install --production --omit=peer --frozen-lockfile --ignore-scripts \
82
+ --os="$TARGETOS" --cpu="$(cat .bun-cpu)"
83
+
84
+ # Conditionally install OpenTelemetry optional peer dependencies (Tier 3).
85
+ # Installed by default. Omit them for a leaner image at build time
86
+ # with: docker build --build-arg OTEL_ENABLED=false
87
+ # The script reads the list and each range from the installed framework's
88
+ # `peerDependencies` and passes the target flags on to its `bun install`.
89
+ COPY scripts/install-otel.ts ./scripts/
90
+ ARG OTEL_ENABLED=true
91
+ RUN --mount=type=cache,target=/root/.bun/install/cache \
92
+ if [ "$OTEL_ENABLED" = "true" ]; then \
93
+ bun scripts/install-otel.ts --os="$TARGETOS" --cpu="$(cat .bun-cpu)"; \
94
+ fi
95
+
96
+ # The seeded scanner served only the installs above; keep it out of the image.
97
+ RUN rm -rf node_modules/@socketsecurity/bun-security-scanner
98
+
99
+
26
100
  # ==============================================================================
27
101
  # Production Stage
28
102
  #
29
103
  # This stage creates a minimal, optimized, and secure image for running the
30
104
  # application. It uses a slim base image and only includes production
31
- # dependencies and build artifacts.
105
+ # dependencies and build artifacts. Its only Bun invocations are HEALTHCHECK
106
+ # and CMD, which run on the real target at container start.
32
107
  # ==============================================================================
33
- FROM oven/bun:1.4.0-slim AS production
108
+ FROM oven/bun:1.4.2-slim AS production
34
109
 
35
110
  WORKDIR /usr/src/app
36
111
 
37
- # Set the environment to production for performance and to ensure only
38
- # production dependencies are installed.
112
+ # Set the environment to production for performance.
39
113
  ENV NODE_ENV=production
40
114
 
41
115
  # OCI image metadata (https://github.com/opencontainers/image-spec/blob/main/annotations.md)
116
+ ARG APP_VERSION
42
117
  LABEL org.opencontainers.image.title="openalex-mcp-server"
43
118
  LABEL org.opencontainers.image.description="Access the OpenAlex academic research catalog - 270M+ publications through MCP. STDIO & Streamable HTTP."
44
119
  LABEL org.opencontainers.image.source="https://github.com/cyanheads/openalex-mcp-server"
45
120
  LABEL org.opencontainers.image.licenses="Apache-2.0"
121
+ LABEL org.opencontainers.image.version="${APP_VERSION}"
46
122
 
47
- # Copy dependency manifests
48
- COPY package.json bun.lock ./
49
-
50
- # Install only production dependencies, ignoring any lifecycle scripts (like 'prepare')
51
- # that are not needed in the final production image. `--omit=peer` keeps the
52
- # framework's optional peer tiers out; imported peers belong in dependencies.
53
- RUN --mount=type=cache,target=/root/.bun/install/cache \
54
- bun install --production --omit=peer --frozen-lockfile --ignore-scripts
55
-
56
- # Conditionally install OpenTelemetry optional peer dependencies (Tier 3).
57
- # These are not bundled by default to keep the base image lean. Enable at build time
58
- # with: docker build --build-arg OTEL_ENABLED=true
59
- ARG OTEL_ENABLED=true
60
- RUN --mount=type=cache,target=/root/.bun/install/cache \
61
- if [ "$OTEL_ENABLED" = "true" ]; then \
62
- bun add --omit=dev --omit=peer --ignore-scripts @hono/otel \
63
- @opentelemetry/instrumentation-http \
64
- @opentelemetry/exporter-metrics-otlp-http \
65
- @opentelemetry/exporter-trace-otlp-http \
66
- @opentelemetry/instrumentation-pino \
67
- @opentelemetry/resources \
68
- @opentelemetry/sdk-metrics \
69
- @opentelemetry/sdk-node \
70
- @opentelemetry/sdk-trace-node \
71
- @opentelemetry/semantic-conventions; \
72
- fi
123
+ # The manifest comes from the build context: the deps stage's copy was rewritten
124
+ # by the OTel install, and the runtime reads only its name, version, and type.
125
+ COPY package.json ./
126
+ COPY --from=deps /usr/src/app/node_modules ./node_modules
73
127
 
74
128
  # Copy the compiled application code from the build stage
75
129
  COPY --from=build /usr/src/app/dist ./dist
@@ -95,10 +149,12 @@ ENV MCP_TRANSPORT_TYPE="http"
95
149
  ENV MCP_SESSION_MODE="stateless"
96
150
  ENV MCP_LOG_LEVEL="info"
97
151
  ENV LOGS_DIR="/var/log/openalex-mcp-server"
98
- ENV MCP_FORCE_CONSOLE_LOGGING="true"
99
152
 
100
153
  # Expose the port the server listens on
101
154
  EXPOSE ${MCP_HTTP_PORT}
102
155
 
156
+ # Health check using a bun-native fetch (slim image ships no curl/wget)
157
+ 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))"
158
+
103
159
  # The command to start the server
104
160
  CMD ["bun", "run", "dist/index.js"]
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  <div align="center">
9
9
 
10
- [![Version](https://img.shields.io/badge/Version-0.7.16-blue.svg?style=flat-square)](./CHANGELOG.md) [![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg?style=flat-square)](./LICENSE) [![Docker](https://img.shields.io/badge/Docker-ghcr.io-2496ED?style=flat-square&logo=docker&logoColor=white)](https://github.com/users/cyanheads/packages/container/package/openalex-mcp-server) [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-^2.0.0-green.svg?style=flat-square)](https://modelcontextprotocol.io/) [![npm](https://img.shields.io/npm/v/@cyanheads/openalex-mcp-server?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@cyanheads/openalex-mcp-server) [![TypeScript](https://img.shields.io/badge/TypeScript-^7.0.2-3178C6.svg?style=flat-square)](https://www.typescriptlang.org/) [![Bun](https://img.shields.io/badge/Bun-v1.4.0-blueviolet.svg?style=flat-square)](https://bun.sh/)
10
+ [![Version](https://img.shields.io/badge/Version-0.8.0-blue.svg?style=flat-square)](./CHANGELOG.md) [![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg?style=flat-square)](./LICENSE) [![Docker](https://img.shields.io/badge/Docker-ghcr.io-2496ED?style=flat-square&logo=docker&logoColor=white)](https://github.com/users/cyanheads/packages/container/package/openalex-mcp-server) [![MCP SDK](https://img.shields.io/badge/MCP%20SDK-^2.1.0-green.svg?style=flat-square)](https://modelcontextprotocol.io/) [![npm](https://img.shields.io/npm/v/@cyanheads/openalex-mcp-server?style=flat-square&logo=npm&logoColor=white)](https://www.npmjs.com/package/@cyanheads/openalex-mcp-server) [![TypeScript](https://img.shields.io/badge/TypeScript-^7.0.2-3178C6.svg?style=flat-square)](https://www.typescriptlang.org/) [![Bun](https://img.shields.io/badge/Bun-v1.4.2-blueviolet.svg?style=flat-square)](https://bun.sh/)
11
11
 
12
12
  </div>
13
13
 
@@ -58,6 +58,8 @@ Scholarly catalog data from [OpenAlex](https://openalex.org) — 270M+ works, 90
58
58
  - `select` returns a curated per-entity-type default unless overridden, or `["*"]` for the full record; invalid field names error with the valid set
59
59
  - Cursor pagination for keyword and exact search, up to 100 results per page (default 25); semantic search walks its candidates with `page` (1-based) instead, and mixing either knob with the wrong `search_mode` is rejected before the upstream call
60
60
  - `sample` (up to 100, single page only — neither `cursor` nor `page` applies) plus a deterministic `seed` for reproducible random sampling; keyword and exact modes only, and never alongside `sort` — OpenAlex does not sample a semantic search and refuses a sorted sample, so both combinations are rejected before the upstream call
61
+ - Each response holds to 64,000 bytes per surface (`structuredContent`, and `content[]` with its trailer) unless the least it can return is larger, which it flags as `over_budget`: a page that would run over keeps its leading records whole and names the rest in `omitted` with the one call that returns them (as a set, in OpenAlex's order), without disturbing `next_cursor`; a record too large on its own comes back with its largest arrays windowed, filled in turn so each shows what fits and labeled with how much of the array it holds, and `slice: {field, offset}` on an `id` lookup pages any array to the end
62
+ - A list record carrying exactly 100 `authorships` — the most OpenAlex returns in a list response — is flagged as possibly capped, with the unbilled `id` + `slice` call that fetches the rest
61
63
  - `display_name` is nullable for untitled records; every call reports OpenAlex daily-budget cost and remaining balance
62
64
 
63
65
  ---
@@ -68,6 +70,7 @@ Scholarly catalog data from [OpenAlex](https://openalex.org) — 270M+ works, 90
68
70
  - Up to 200 groups per page (default). `order: "count"` (default) returns the top-N by count with no further pages; `order: "key"` enumerates all distinct values key-ascending with cursor pagination
69
71
  - `include_unknown` (default `false`) adds a group for entities with no value for the grouped field, flagged `is_unknown: true` and labeled as unknown in the text output. OpenAlex keys it `-111`/`-111.0` (numeric fields), `unknown` (text fields and `order: "key"`), or an ID ending in `/unknown`; the key is a sentinel, not a filter value. Boolean fields have no such group — a missing value counts as `false`
70
72
  - Not every field is groupable — raw date fields, `.search` operators, `from_*`/`to_*` range modifiers, decimal scores such as `fwci`, `display_name`, and external-ID fields such as `doi` are rejected; `openalex_describe_fields(entity_type, "group_by")` lists the fields that group
73
+ - A works group_by on `authorships.countries` says in its notice that OpenAlex counts only each work's first 100 authorships for that field, and names `authorships.institutions.country_code` as the field that counts all of them
71
74
  - Reports OpenAlex daily-budget cost and remaining balance — aggregation is priced far below paging the same entities
72
75
 
73
76
  ---
@@ -88,6 +91,7 @@ Scholarly catalog data from [OpenAlex](https://openalex.org) — 270M+ works, 90
88
91
  - `seed_id` accepts an OpenAlex ID, DOI, or PMID (PMCID recognized but resolves nothing); validated against a live lookup first, so a non-existent seed fails as `NotFound` rather than returning an empty graph
89
92
  - Stacks with `filters`/`sort`/`select` to narrow the graph; `filters` cannot set `cites`/`cited_by`/`related_to`, nor an alias of one such as `cited_works` — those keys are reserved for `direction`
90
93
  - Cursor pagination, up to 100 results per page (default 25)
94
+ - The same 64,000-byte response budget and 100-authorship cap disclosure as `openalex_search_entities`; works cut from a page are named in `omitted` with the `openalex_search_entities` call that returns them, in OpenAlex's order
91
95
  - Reports OpenAlex daily-budget cost, covering both the seed-validation lookup and the graph page, plus remaining balance
92
96
 
93
97
  ---
@@ -132,7 +136,7 @@ Agent-friendly output:
132
136
  - Effective-query echo — search, trends, and citation-graph responses echo the criteria that actually ran, so an empty result is diagnosable without re-reading the request
133
137
  - Discriminated output contracts — typed error reasons (`entity_not_found`, `upstream_budget_exhausted`, `semantic_per_page_cap`, `reserved_filter_key`, and more) each carrying an explicit recovery hint
134
138
  - Response shaping — abstracts are reconstructed from OpenAlex's inverted-index encoding into plaintext, and `display_name` stays `null` for untitled or paratext records instead of being backfilled
135
- - Clean provider text — OpenAlex passes titles, abstracts, and names through unsanitized; HTML entities are decoded against the full WHATWG table, comments and HTML/JATS/MathML formatting tags are removed, and literal text such as `A < B` is kept. The text output escapes that text for Markdown, so a stray `*`, `<tag>`, or `[x](y)` renders as written; IDs, and URLs that render as links, stay byte-identical
139
+ - Clean provider text — OpenAlex passes titles, abstracts, and names through unsanitized; HTML entities are decoded against the full WHATWG table, comments and HTML/JATS/MathML formatting tags are removed, CDATA wrappers and IOP's `<?CDATA …?>` math markers are unwrapped with their TeX kept, and a double-escaped line break (a literal `\n`) becomes a space; literal text such as `A < B` and TeX such as `\nu` is kept. Identifier and URL fields (`id`, `doi`, `ids`, `orcid`, `ror`, `issn`, `*_url`, lineages) are returned exactly as OpenAlex stores them, so each one resolves when passed back. The text output escapes that text for Markdown, so a stray `*`, `<tag>`, or `[x](y)` renders as written; IDs, and URLs that render as links, stay byte-identical
136
140
 
137
141
  ## Getting started
138
142