@cyanheads/openalex-mcp-server 0.7.16 → 0.9.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 (63) hide show
  1. package/AGENTS.md +48 -33
  2. package/CLAUDE.md +48 -33
  3. package/Dockerfile +98 -33
  4. package/README.md +23 -16
  5. package/changelog/0.8.x/0.8.0.md +38 -0
  6. package/changelog/0.9.x/0.9.0.md +48 -0
  7. package/dist/index.js +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/mcp-server/prompts/definitions/literature-review.prompt.js +1 -1
  10. package/dist/mcp-server/prompts/definitions/research-landscape.prompt.js +1 -1
  11. package/dist/mcp-server/tools/definitions/analyze-trends.tool.d.ts +28 -3
  12. package/dist/mcp-server/tools/definitions/analyze-trends.tool.d.ts.map +1 -1
  13. package/dist/mcp-server/tools/definitions/analyze-trends.tool.js +57 -10
  14. package/dist/mcp-server/tools/definitions/analyze-trends.tool.js.map +1 -1
  15. package/dist/mcp-server/tools/definitions/citation-graph.tool.d.ts +62 -5
  16. package/dist/mcp-server/tools/definitions/citation-graph.tool.d.ts.map +1 -1
  17. package/dist/mcp-server/tools/definitions/citation-graph.tool.js +100 -52
  18. package/dist/mcp-server/tools/definitions/citation-graph.tool.js.map +1 -1
  19. package/dist/mcp-server/tools/definitions/describe-fields.tool.d.ts.map +1 -1
  20. package/dist/mcp-server/tools/definitions/describe-fields.tool.js +34 -4
  21. package/dist/mcp-server/tools/definitions/describe-fields.tool.js.map +1 -1
  22. package/dist/mcp-server/tools/definitions/resolve-name.tool.d.ts +38 -2
  23. package/dist/mcp-server/tools/definitions/resolve-name.tool.d.ts.map +1 -1
  24. package/dist/mcp-server/tools/definitions/resolve-name.tool.js +176 -41
  25. package/dist/mcp-server/tools/definitions/resolve-name.tool.js.map +1 -1
  26. package/dist/mcp-server/tools/definitions/search-entities.tool.d.ts +75 -4
  27. package/dist/mcp-server/tools/definitions/search-entities.tool.d.ts.map +1 -1
  28. package/dist/mcp-server/tools/definitions/search-entities.tool.js +169 -73
  29. package/dist/mcp-server/tools/definitions/search-entities.tool.js.map +1 -1
  30. package/dist/mcp-server/tools/render-budget.d.ts +4 -2
  31. package/dist/mcp-server/tools/render-budget.d.ts.map +1 -1
  32. package/dist/mcp-server/tools/render-budget.js +4 -2
  33. package/dist/mcp-server/tools/render-budget.js.map +1 -1
  34. package/dist/mcp-server/tools/render-entity-record.d.ts +12 -1
  35. package/dist/mcp-server/tools/render-entity-record.d.ts.map +1 -1
  36. package/dist/mcp-server/tools/render-entity-record.js +23 -8
  37. package/dist/mcp-server/tools/render-entity-record.js.map +1 -1
  38. package/dist/mcp-server/tools/response-budget.d.ts +160 -0
  39. package/dist/mcp-server/tools/response-budget.d.ts.map +1 -0
  40. package/dist/mcp-server/tools/response-budget.js +489 -0
  41. package/dist/mcp-server/tools/response-budget.js.map +1 -0
  42. package/dist/services/openalex/budget.d.ts +3 -1
  43. package/dist/services/openalex/budget.d.ts.map +1 -1
  44. package/dist/services/openalex/budget.js +3 -1
  45. package/dist/services/openalex/budget.js.map +1 -1
  46. package/dist/services/openalex/field-catalog.json +50 -1
  47. package/dist/services/openalex/filter-values.d.ts +46 -0
  48. package/dist/services/openalex/filter-values.d.ts.map +1 -0
  49. package/dist/services/openalex/filter-values.js +294 -0
  50. package/dist/services/openalex/filter-values.js.map +1 -0
  51. package/dist/services/openalex/iso-codes.json +1565 -0
  52. package/dist/services/openalex/openalex-service.d.ts +181 -16
  53. package/dist/services/openalex/openalex-service.d.ts.map +1 -1
  54. package/dist/services/openalex/openalex-service.js +593 -141
  55. package/dist/services/openalex/openalex-service.js.map +1 -1
  56. package/dist/services/openalex/provider-text.d.ts +13 -5
  57. package/dist/services/openalex/provider-text.d.ts.map +1 -1
  58. package/dist/services/openalex/provider-text.js +799 -51
  59. package/dist/services/openalex/provider-text.js.map +1 -1
  60. package/dist/services/openalex/types.d.ts +1 -1
  61. package/dist/services/openalex/types.js +1 -1
  62. package/package.json +16 -13
  63. package/server.json +10 -24
@@ -6,8 +6,11 @@ import { tool, z } from '@cyanheads/mcp-ts-core';
6
6
  import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
7
7
  import { escapeMarkdown } from '../escape-markdown.js';
8
8
  import { renderBudgetTrailer } from '../render-budget.js';
9
+ import { joinNotices } from '../response-budget.js';
9
10
  import { getOpenAlexService } from '../../../services/openalex/openalex-service.js';
10
11
  import { ENTITY_TYPES } from '../../../services/openalex/types.js';
12
+ /** Disclosure for a works group_by over `authorships.countries` (see the handler). */
13
+ const COUNTRIES_CAP_NOTICE = 'OpenAlex builds authorships.countries groups from only the first 100 authorships of each work, so a country that appears only past position 100 on a large collaboration is not counted. Group by authorships.institutions.country_code to count every authorship.';
11
14
  export const analyzeTrendsTool = tool('openalex_analyze_trends', {
12
15
  description: 'Aggregate OpenAlex entities into groups and count them. Use for trend analysis (group works by publication_year), distribution analysis (group by oa_status, type, country), and comparative analysis (group by institution or topic). Combine with filters to scope the analysis. Returns up to 200 groups per page — use cursor pagination for fields with many distinct values.',
13
16
  sourceUrl: 'https://github.com/cyanheads/openalex-mcp-server/blob/main/src/mcp-server/tools/definitions/analyze-trends.tool.ts',
@@ -26,7 +29,15 @@ export const analyzeTrendsTool = tool('openalex_analyze_trends', {
26
29
  code: JsonRpcErrorCode.RateLimited,
27
30
  when: 'The OpenAlex daily usage budget is spent (HTTP 429).',
28
31
  retryable: false,
29
- recovery: 'The daily budget refills at midnight UTC — retrying sooner will not succeed. Set OPENALEX_API_KEY to a free key (https://openalex.org/settings/api) for a larger daily budget than anonymous access, or wait for the reset.',
32
+ recovery: "This server's daily OpenAlex budget is spent and refills at midnight UTC — retrying before then will not succeed.",
33
+ thrownBy: 'service',
34
+ },
35
+ {
36
+ reason: 'upstream_plan_required',
37
+ code: JsonRpcErrorCode.Forbidden,
38
+ when: 'A filter is one OpenAlex serves only on a paid plan — created_date, updated_date, or a from_/to_ form of either (HTTP 429 "Plan upgrade required").',
39
+ retryable: false,
40
+ recovery: 'Drop the plan-gated filter and rerun; retrying it unchanged will not succeed. To bound works by date, filter on publication_date, from_publication_date, or to_publication_date, which need no paid plan.',
30
41
  thrownBy: 'service',
31
42
  },
32
43
  {
@@ -62,8 +73,29 @@ export const analyzeTrendsTool = tool('openalex_analyze_trends', {
62
73
  {
63
74
  reason: 'comma_in_filter_value',
64
75
  code: JsonRpcErrorCode.InvalidParams,
65
- when: 'A filter value contains a comma, which collides with the OpenAlex filter separator.',
66
- recovery: 'Use `|` for OR within a filter value (e.g. "2020|2021"), or use a `.search` filter or the `query` parameter for free-text phrases that contain commas.',
76
+ when: 'A filter value contains a comma, which collides with the OpenAlex filter separator, on a field that takes no phrase. Free-text search filters (any `.search` key, such as title.search or abstract.search.exact) and fields matched as whole text (display_name, awards.funder_display_name, awards.funder_award_id, geo.city, geo.region, raw_affiliation_strings, block_key, parsed_longest_name, biblio fields) are exempt: a comma there is sent quoted, as part of the phrase.',
77
+ recovery: 'Use `|` for OR within a filter value (e.g. "2020|2021"), or move a phrase that contains commas into a free-text search filter such as title.search or raw_affiliation_strings.search.',
78
+ thrownBy: 'service',
79
+ },
80
+ {
81
+ reason: 'invalid_country_code',
82
+ code: JsonRpcErrorCode.ValidationError,
83
+ when: 'A country filter (a key ending in country_code, country_codes, or countries) holds a segment that cannot be a country code, such as a misspelled name, an unassigned number, "unknown", or two codes joined by a space ("DE US").',
84
+ recovery: 'Pass the country as an ISO 3166-1 alpha-2 code such as DE, US, or GB (an alpha-3 code, numeric code, or English name is converted), or null for records with no country.',
85
+ thrownBy: 'service',
86
+ },
87
+ {
88
+ reason: 'mixed_and_or_in_filter_value',
89
+ code: JsonRpcErrorCode.ValidationError,
90
+ when: 'A filter value puts "|" (OR) beside an AND operator — a "+", or a space on a field where words mean AND (on a country field a space is always part of a country name, and inside a language name it is part of the name). OpenAlex splits the value on "|" first and drops every alternative that ANDs more than one value, so no single value can carry both.',
91
+ recovery: 'Keep "|" and the AND operator in separate filter keys: OR the alternatives in this key and put the AND in a second key that reaches the same values — on works, {"authorships.institutions.country_code": "DE|FR", "institutions.country_code": "US"} matches (DE or FR) and US. The filters object holds each key once, so where no second key fits, run one call per alternative instead.',
92
+ thrownBy: 'service',
93
+ },
94
+ {
95
+ reason: 'quote_in_filter_value',
96
+ code: JsonRpcErrorCode.ValidationError,
97
+ when: 'A filter value sent to OpenAlex double-quoted holds a double quote inside its outer pair — a value the server quotes (a multi-word value on a field matched as whole text, or a value holding a comma on such a field or on a free-text search filter), or one the caller wrapped in double quotes on any filter but a free-text search.',
98
+ recovery: 'Remove the double quote from the value; a phrase is matched without quoting its own text.',
67
99
  thrownBy: 'service',
68
100
  },
69
101
  {
@@ -116,11 +148,11 @@ export const analyzeTrendsTool = tool('openalex_analyze_trends', {
116
148
  group_by: z
117
149
  .string()
118
150
  .min(1)
119
- .describe('Field to group by. Works examples: "publication_year", "type", "oa_status", "primary_topic.field.id", "authorships.institutions.country_code", "is_retracted". Authors: "last_known_institutions.country_code", "has_orcid". Sources: "type", "is_oa", "country_code". Not all fields support group_by — call openalex_describe_fields(entity_type, "group_by") for the groupable set.'),
151
+ .describe('Field to group by. Works examples: "publication_year", "type", "oa_status", "primary_topic.field.id", "authorships.institutions.country_code", "is_retracted". OpenAlex builds authorships.countries groups from only the first 100 authorships of each work; authorships.institutions.country_code counts every authorship. Authors: "last_known_institutions.country_code", "has_orcid". Sources: "type", "is_oa", "country_code". Not all fields support group_by — call openalex_describe_fields(entity_type, "group_by") for the groupable set.'),
120
152
  filters: z
121
153
  .record(z.string(), z.string())
122
154
  .optional()
123
- .describe("Filter criteria (same syntax as openalex_search_entities filters). Narrows the population before aggregation. For full-text within filters, use abstract.search, title.search, or default.search — there is no bare 'search' filter key. Example: group works by year filtered to a specific topic."),
155
+ .describe('Filter criteria (same syntax as openalex_search_entities filters). Narrows the population before aggregation. Country fields take ISO 3166-1 alpha-2 codes ("DE") and `language` takes ISO 639-1 codes ("en"); alpha-3, numeric, ISO 639-2, and English-name forms are converted — a multi-word name is one value, so "South Korea|Japan" ORs two countries — and a value that cannot be a country code is rejected. A multi-word value on a field matched as whole text (display_name, awards.funder_display_name, geo.city, raw_affiliation_strings) matches as one phrase ("National Science Foundation"; a comma, as in "University of California, Berkeley", is part of it, and it cannot contain a double quote of its own), "!" and "|" included, but cannot be ANDed with "+" in the same field. A value mixing "|" with an AND operator — a "+", or a space on a field where words mean AND — is rejected, since OpenAlex drops every "|" alternative that ANDs more than one value; put the AND in a second key instead. For full-text within filters, use abstract.search, title.search, or default.search — there is no bare \'search\' filter key. Example: group works by year filtered to a specific topic.'),
124
156
  include_unknown: z
125
157
  .boolean()
126
158
  .default(false)
@@ -184,7 +216,7 @@ export const analyzeTrendsTool = tool('openalex_analyze_trends', {
184
216
  notice: z
185
217
  .string()
186
218
  .optional()
187
- .describe('Guidance notice. Set when a first call returns no groups (recovery suggestions), when a `cursor` continuation returns none because the traversal is already finished, or when the page is full and more groups likely exist (truncation signal with narrowing advice). Absent otherwise.'),
219
+ .describe('Guidance notice. Set when a first call returns no groups (recovery suggestions), when a `cursor` continuation returns none because the traversal is already finished, when the page is full and more groups likely exist (truncation signal with narrowing advice), or when works are grouped by authorships.countries, which OpenAlex counts from only the first 100 authorships of each work. Absent otherwise.'),
188
220
  budget: z
189
221
  .object({
190
222
  costUsd: z
@@ -226,12 +258,14 @@ export const analyzeTrendsTool = tool('openalex_analyze_trends', {
226
258
  });
227
259
  const echo = buildAnalyzeEcho(input);
228
260
  ctx.enrich({ echo, totalCount: result.meta.count });
261
+ // `notice` is last-wins, so every sentence is collected and set once.
262
+ const notices = [];
229
263
  // An empty page on a `cursor` continuation means the key-ascending traversal already
230
264
  // enumerated every group, so there is nothing left to remove or regroup. On a first call
231
265
  // the same shape can still be an honest zero — including the all-values-unknown case,
232
266
  // where `count` is nonzero but every matched entity is null for the grouped field.
233
267
  if (result.groups.length === 0) {
234
- ctx.enrich.notice(input.cursor === undefined
268
+ notices.push(input.cursor === undefined
235
269
  ? `No groups returned for ${echo}. Try removing filters or grouping by a different field.`
236
270
  : `Pagination exhausted for ${echo} — the previous page held the last group, so this one came back empty. Stop paging rather than removing filters or regrouping.`);
237
271
  }
@@ -241,7 +275,7 @@ export const analyzeTrendsTool = tool('openalex_analyze_trends', {
241
275
  // "top by count"). The honest signal is whether OpenAlex returned a next_cursor; page-fill
242
276
  // is irrelevant in this mode.
243
277
  if (result.meta.next_cursor) {
244
- ctx.enrich.notice(`Showing ${result.groups.length} groups in key-ascending order. Pass the returned \`next_cursor\` to continue the traversal.`);
278
+ notices.push(`Showing ${result.groups.length} groups in key-ascending order. Pass the returned \`next_cursor\` to continue the traversal.`);
245
279
  }
246
280
  }
247
281
  else if (result.groups.length === input.per_page) {
@@ -249,8 +283,20 @@ export const analyzeTrendsTool = tool('openalex_analyze_trends', {
249
283
  // exist. The omitted groups all have counts ≤ the smallest group shown, so we can bound the
250
284
  // gap even though OpenAlex exposes no total group count.
251
285
  const smallestCount = result.groups[result.groups.length - 1]?.count ?? 0;
252
- ctx.enrich.notice(`Showing the top ${result.groups.length} groups by count. Smallest shown has count = ${smallestCount}; any omitted group has count ≤ ${smallestCount}. Narrow with \`filters\`, raise \`per_page\` (max 200), or enumerate all with \`order: "key"\`.`);
286
+ notices.push(`Showing the top ${result.groups.length} groups by count. Smallest shown has count = ${smallestCount}; any omitted group has count ≤ ${smallestCount}. Narrow with \`filters\`, raise \`per_page\` (max 200), or enumerate all with \`order: "key"\`.`);
287
+ }
288
+ // OpenAlex aggregates authorships.countries from the first-100 window its list records carry,
289
+ // so the counts undercount large collaborations with nothing upstream saying so; every other
290
+ // authorships.* group_by counts all authorships. An empty page is included: a work whose first
291
+ // 100 authorships carry no country contributes no group. The service also accepts OpenAlex's
292
+ // own `:include_unknown` suffix in group_by.
293
+ if (input.entity_type === 'works' &&
294
+ input.group_by.replace(/:include_unknown$/, '') === 'authorships.countries') {
295
+ notices.push(COUNTRIES_CAP_NOTICE);
253
296
  }
297
+ const notice = joinNotices(notices);
298
+ if (notice)
299
+ ctx.enrich.notice(notice);
254
300
  return {
255
301
  meta: {
256
302
  count: result.meta.count,
@@ -312,8 +358,9 @@ function renderGroupLabel(g) {
312
358
  const display = escapeMarkdown(g.key_display_name, 'line-start');
313
359
  return g.key === g.key_display_name ? display : `${display} (${key})`;
314
360
  }
361
+ /** The request as one line: caller text is JSON-encoded, so a line break in it stays escaped. */
315
362
  function buildAnalyzeEcho(input) {
316
- const parts = [`entity_type=${input.entity_type}`, `group_by=${input.group_by}`];
363
+ const parts = [`entity_type=${input.entity_type}`, `group_by=${JSON.stringify(input.group_by)}`];
317
364
  if (input.filters && Object.keys(input.filters).length > 0) {
318
365
  parts.push(`filters=${JSON.stringify(input.filters)}`);
319
366
  }
@@ -1 +1 @@
1
- {"version":3,"file":"analyze-trends.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/analyze-trends.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC,yBAAyB,EAAE;IAC/D,WAAW,EACT,oXAAoX;IACtX,SAAS,EACP,oHAAoH;IACtH,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE;IAC9E,MAAM,EAAE;QACN;YACE,MAAM,EAAE,cAAc;YACtB,IAAI,EAAE,gBAAgB,CAAC,WAAW;YAClC,IAAI,EAAE,iFAA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,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC"}
1
+ {"version":3,"file":"analyze-trends.tool.js","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/analyze-trends.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,sFAAsF;AACtF,MAAM,oBAAoB,GACxB,oQAAoQ,CAAC;AAEvQ,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC,yBAAyB,EAAE;IAC/D,WAAW,EACT,oXAAoX;IACtX,SAAS,EACP,oHAAoH;IACtH,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE;IAC9E,MAAM,EAAE;QACN;YACE,MAAM,EAAE,cAAc;YACtB,IAAI,EAAE,gBAAgB,CAAC,WAAW;YAClC,IAAI,EAAE,iFAAiF;YACvF,SAAS,EAAE,IAAI;YACf,QAAQ,EACN,sFAAsF;YACxF,QAAQ,EAAE,SAAS;SACpB;QACD;YACE,MAAM,EAAE,2BAA2B;YACnC,IAAI,EAAE,gBAAgB,CAAC,WAAW;YAClC,IAAI,EAAE,sDAAsD;YAC5D,SAAS,EAAE,KAAK;YAChB,QAAQ,EACN,mHAAmH;YACrH,QAAQ,EAAE,SAAS;SACpB;QACD;YACE,MAAM,EAAE,wBAAwB;YAChC,IAA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cAAc,CAAC,CAAC,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;IACjE,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,KAAK,GAAG,GAAG,CAAC;AACxE,CAAC;AAED,iGAAiG;AACjG,SAAS,gBAAgB,CAAC,KAMzB;IACC,MAAM,KAAK,GAAG,CAAC,eAAe,KAAK,CAAC,WAAW,EAAE,EAAE,YAAY,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjG,IAAI,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3D,KAAK,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,KAAK,CAAC,eAAe;QAAE,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAC9D,IAAI,KAAK,CAAC,KAAK;QAAE,KAAK,CAAC,IAAI,CAAC,SAAS,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IACpD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC"}
@@ -26,6 +26,26 @@ export declare const getCitationGraphTool: import("@cyanheads/mcp-ts-core").Tool
26
26
  id: z.ZodString;
27
27
  display_name: z.ZodNullable<z.ZodString>;
28
28
  }, z.core.$loose>>;
29
+ omitted: z.ZodOptional<z.ZodObject<{
30
+ ids: z.ZodArray<z.ZodString>;
31
+ next: z.ZodObject<{
32
+ tool: z.ZodLiteral<"openalex_search_entities">;
33
+ arguments: z.ZodObject<{}, z.core.$loose>;
34
+ }, z.core.$strip>;
35
+ }, z.core.$strip>>;
36
+ windows: z.ZodOptional<z.ZodArray<z.ZodObject<{
37
+ id: z.ZodString;
38
+ field: z.ZodString;
39
+ offset: z.ZodNumber;
40
+ shown: z.ZodNumber;
41
+ total: z.ZodNumber;
42
+ possibly_capped: z.ZodBoolean;
43
+ next: z.ZodNullable<z.ZodObject<{
44
+ tool: z.ZodLiteral<"openalex_search_entities">;
45
+ arguments: z.ZodObject<{}, z.core.$loose>;
46
+ }, z.core.$strip>>;
47
+ }, z.core.$strip>>>;
48
+ over_budget: z.ZodOptional<z.ZodBoolean>;
29
49
  }, z.core.$strip>, readonly [{
30
50
  readonly reason: "rate_limited";
31
51
  readonly code: JsonRpcErrorCode.RateLimited;
@@ -38,7 +58,14 @@ export declare const getCitationGraphTool: import("@cyanheads/mcp-ts-core").Tool
38
58
  readonly code: JsonRpcErrorCode.RateLimited;
39
59
  readonly when: "The OpenAlex daily usage budget is spent (HTTP 429).";
40
60
  readonly retryable: false;
41
- readonly recovery: "The daily budget refills at midnight UTC — retrying sooner will not succeed. Set OPENALEX_API_KEY to a free key (https://openalex.org/settings/api) for a larger daily budget than anonymous access, or wait for the reset.";
61
+ readonly recovery: "This server's daily OpenAlex budget is spent and refills at midnight UTC — retrying before then will not succeed.";
62
+ readonly thrownBy: "service";
63
+ }, {
64
+ readonly reason: "upstream_plan_required";
65
+ readonly code: JsonRpcErrorCode.Forbidden;
66
+ readonly when: "A filter is one OpenAlex serves only on a paid plan — created_date, updated_date, or a from_/to_ form of either (HTTP 429 \"Plan upgrade required\").";
67
+ readonly retryable: false;
68
+ readonly recovery: "Drop the plan-gated filter and rerun; retrying it unchanged will not succeed. To bound works by date, filter on publication_date, from_publication_date, or to_publication_date, which need no paid plan.";
42
69
  readonly thrownBy: "service";
43
70
  }, {
44
71
  readonly reason: "upstream_timeout";
@@ -69,14 +96,32 @@ export declare const getCitationGraphTool: import("@cyanheads/mcp-ts-core").Tool
69
96
  }, {
70
97
  readonly reason: "comma_in_filter_value";
71
98
  readonly code: JsonRpcErrorCode.InvalidParams;
72
- readonly when: "A filter value contains a comma, which collides with the OpenAlex filter separator.";
73
- readonly recovery: "Use `|` for OR within a filter value (e.g. \"2020|2021\"), or use a `.search` filter or the `query` parameter for free-text phrases that contain commas.";
99
+ readonly when: "A filter value contains a comma, which collides with the OpenAlex filter separator, on a field that takes no phrase. Free-text search filters (any `.search` key, such as title.search or abstract.search.exact) and fields matched as whole text (display_name, awards.funder_display_name, awards.funder_award_id, authorships.institutions.geo.city, authorships.institutions.geo.region, raw_affiliation_strings, biblio fields) are exempt: a comma there is sent quoted, as part of the phrase.";
100
+ readonly recovery: "Use `|` for OR within a filter value (e.g. \"2020|2021\"), or move a phrase that contains commas into a free-text search filter such as title.search or raw_affiliation_strings.search.";
101
+ readonly thrownBy: "service";
102
+ }, {
103
+ readonly reason: "invalid_country_code";
104
+ readonly code: JsonRpcErrorCode.ValidationError;
105
+ readonly when: "A country filter (a key ending in country_code, country_codes, or countries) holds a segment that cannot be a country code, such as a misspelled name, an unassigned number, \"unknown\", or two codes joined by a space (\"DE US\").";
106
+ readonly recovery: "Pass the country as an ISO 3166-1 alpha-2 code such as DE, US, or GB (an alpha-3 code, numeric code, or English name is converted), or null for works with no country.";
107
+ readonly thrownBy: "service";
108
+ }, {
109
+ readonly reason: "mixed_and_or_in_filter_value";
110
+ readonly code: JsonRpcErrorCode.ValidationError;
111
+ readonly when: "A filter value puts \"|\" (OR) beside an AND operator — a \"+\", or a space on a field where words mean AND (on a country field a space is always part of a country name, and inside a language name it is part of the name). OpenAlex splits the value on \"|\" first and drops every alternative that ANDs more than one value, so no single value can carry both.";
112
+ readonly recovery: "Keep \"|\" and the AND operator in separate filter keys: OR the alternatives in this key and put the AND in a second key that reaches the same values — {\"authorships.institutions.country_code\": \"DE|FR\", \"institutions.country_code\": \"US\"} matches works with (DE or FR) and US. The filters object holds each key once, so where no second key fits, run one call per alternative instead.";
113
+ readonly thrownBy: "service";
114
+ }, {
115
+ readonly reason: "quote_in_filter_value";
116
+ readonly code: JsonRpcErrorCode.ValidationError;
117
+ readonly when: "A filter value sent to OpenAlex double-quoted holds a double quote inside its outer pair — a value the server quotes (a multi-word value on a field matched as whole text, or a value holding a comma on such a field or on a free-text search filter), or one the caller wrapped in double quotes on any filter but a free-text search.";
118
+ readonly recovery: "Remove the double quote from the value; a phrase is matched without quoting its own text.";
74
119
  readonly thrownBy: "service";
75
120
  }, {
76
121
  readonly reason: "upstream_invalid_params";
77
122
  readonly code: JsonRpcErrorCode.InvalidParams;
78
- readonly when: "OpenAlex rejected an invalid filter or sort field name (HTTP 400).";
79
- readonly recovery: "The upstream message names the rejected token and suggests close matches. Pass a valid OpenAlex work ID (W…), DOI, or PMID for seed_id, or use openalex_describe_fields(entity_type, \"filter\") to browse valid filter fields.";
123
+ readonly when: "OpenAlex rejected an invalid filter, select, or sort field name (HTTP 400).";
124
+ readonly recovery: "The upstream message names the rejected token and suggests close matches. Pass a valid OpenAlex work ID (W…), DOI, or PMID for seed_id, and browse the valid work fields with openalex_describe_fields(\"works\", \"filter\") for filters or openalex_describe_fields(\"works\", \"select\") for select.";
80
125
  readonly thrownBy: "service";
81
126
  }, {
82
127
  readonly reason: "upstream_invalid_id_value";
@@ -101,6 +146,18 @@ export declare const getCitationGraphTool: import("@cyanheads/mcp-ts-core").Tool
101
146
  readonly code: JsonRpcErrorCode.ValidationError;
102
147
  readonly when: "filters contains cites/cited_by/related_to, or an alias of one such as cited_works — the direction parameter reserves those keys.";
103
148
  readonly recovery: "Remove the reserved key from filters, or restate the relationship through direction.";
149
+ }, {
150
+ readonly reason: "id_type_mismatch";
151
+ readonly code: JsonRpcErrorCode.ValidationError;
152
+ readonly when: "seed_id is a native OpenAlex ID of another entity type — an author, source, institution, topic, publisher, funder, or concept ID rather than a work ID.";
153
+ readonly recovery: "seed_id must identify a work — pass the work's OpenAlex ID (W…), DOI, or PMID. To walk the works of an author or other entity, list them first with openalex_search_entities filters.";
154
+ readonly thrownBy: "service";
155
+ }, {
156
+ readonly reason: "id_dot_segment";
157
+ readonly code: JsonRpcErrorCode.ValidationError;
158
+ readonly when: "seed_id holds a `.` or `..` path segment, written plainly or percent-encoded.";
159
+ readonly recovery: "Pass the work's identifier itself — its OpenAlex ID (W…), DOI, or PMID — with no relative path segments.";
160
+ readonly thrownBy: "service";
104
161
  }, {
105
162
  readonly reason: "entity_not_found";
106
163
  readonly code: JsonRpcErrorCode.NotFound;
@@ -1 +1 @@
1
- {"version":3,"file":"citation-graph.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/citation-graph.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AA2BjE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqW/B,CAAC"}
1
+ {"version":3,"file":"citation-graph.tool.d.ts","sourceRoot":"","sources":["../../../../src/mcp-server/tools/definitions/citation-graph.tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAQ,CAAC,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AA0CjE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyZ/B,CAAC"}
@@ -5,22 +5,26 @@
5
5
  import { tool, z } from '@cyanheads/mcp-ts-core';
6
6
  import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
7
7
  import { renderBudgetTrailer } from '../render-budget.js';
8
- import { renderEntityRecord } from '../render-entity-record.js';
9
- import { getOpenAlexService, translateFilterKey } from '../../../services/openalex/openalex-service.js';
8
+ import { fitRecordsToBudget, formatRecordPage, joinNotices, measurePageFrame, omittedOutputSchema, overBudgetOutputSchema, windowsOutputSchema, } from '../response-budget.js';
9
+ import { quoteCallerText } from '../../../services/openalex/filter-values.js';
10
+ import { buildSearchFilter, getOpenAlexService, translateFilterKey, } from '../../../services/openalex/openalex-service.js';
10
11
  const OPENALEX_URL_PREFIX = 'https://openalex.org/';
12
+ /** What `meta.count` counts, in the rendered header. */
13
+ const EDGE_NOUN = 'edge(s)';
11
14
  const DIRECTIONS = ['cites', 'cited_by', 'related_to'];
12
15
  const RESERVED_FILTER_KEYS = new Set(DIRECTIONS);
16
+ /** The request as one line: caller text is JSON-encoded, so a line break in it stays escaped. */
13
17
  function buildCitationEcho(input) {
14
- const parts = [`seed_id=${input.seed_id}`, `direction=${input.direction}`];
18
+ const parts = [`seed_id=${JSON.stringify(input.seed_id)}`, `direction=${input.direction}`];
15
19
  if (input.filters && Object.keys(input.filters).length > 0) {
16
20
  parts.push(`filters=${JSON.stringify(input.filters)}`);
17
21
  }
18
22
  if (input.sort)
19
- parts.push(`sort=${input.sort}`);
23
+ parts.push(`sort=${JSON.stringify(input.sort)}`);
20
24
  return parts.join(' | ');
21
25
  }
22
26
  export const getCitationGraphTool = tool('openalex_get_citation_graph', {
23
- description: "Walk the citation graph one hop from a seed work. Direction picks the edge: incoming citations (`cites`), the seed's own references (`cited_by`), or OpenAlex's algorithmically-related works (`related_to`). Note: `direction` follows OpenAlex's filter convention, which inverts the common English reading — `cites` returns works that cite the seed; `cited_by` returns works the seed cites. Results use the works schema; combine with filters/sort to narrow further.",
27
+ description: "Walk the citation graph one hop from a seed work. Direction picks the edge: incoming citations (`cites`), the seed's own references (`cited_by`), or OpenAlex's algorithmically-related works (`related_to`). Note: `direction` follows OpenAlex's filter convention, which inverts the common English reading — `cites` returns works that cite the seed; `cited_by` returns works the seed cites. Results use the works schema; combine with filters/sort to narrow further. Responses cap at 64,000 bytes per surface unless the least a call can return is larger (`over_budget`); `omitted` and `windows` give the openalex_search_entities calls that continue a cut.",
24
28
  sourceUrl: 'https://github.com/cyanheads/openalex-mcp-server/blob/main/src/mcp-server/tools/definitions/citation-graph.tool.ts',
25
29
  annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: true },
26
30
  errors: [
@@ -37,7 +41,15 @@ export const getCitationGraphTool = tool('openalex_get_citation_graph', {
37
41
  code: JsonRpcErrorCode.RateLimited,
38
42
  when: 'The OpenAlex daily usage budget is spent (HTTP 429).',
39
43
  retryable: false,
40
- recovery: 'The daily budget refills at midnight UTC — retrying sooner will not succeed. Set OPENALEX_API_KEY to a free key (https://openalex.org/settings/api) for a larger daily budget than anonymous access, or wait for the reset.',
44
+ recovery: "This server's daily OpenAlex budget is spent and refills at midnight UTC — retrying before then will not succeed.",
45
+ thrownBy: 'service',
46
+ },
47
+ {
48
+ reason: 'upstream_plan_required',
49
+ code: JsonRpcErrorCode.Forbidden,
50
+ when: 'A filter is one OpenAlex serves only on a paid plan — created_date, updated_date, or a from_/to_ form of either (HTTP 429 "Plan upgrade required").',
51
+ retryable: false,
52
+ recovery: 'Drop the plan-gated filter and rerun; retrying it unchanged will not succeed. To bound works by date, filter on publication_date, from_publication_date, or to_publication_date, which need no paid plan.',
41
53
  thrownBy: 'service',
42
54
  },
43
55
  {
@@ -73,15 +85,36 @@ export const getCitationGraphTool = tool('openalex_get_citation_graph', {
73
85
  {
74
86
  reason: 'comma_in_filter_value',
75
87
  code: JsonRpcErrorCode.InvalidParams,
76
- when: 'A filter value contains a comma, which collides with the OpenAlex filter separator.',
77
- recovery: 'Use `|` for OR within a filter value (e.g. "2020|2021"), or use a `.search` filter or the `query` parameter for free-text phrases that contain commas.',
88
+ when: 'A filter value contains a comma, which collides with the OpenAlex filter separator, on a field that takes no phrase. Free-text search filters (any `.search` key, such as title.search or abstract.search.exact) and fields matched as whole text (display_name, awards.funder_display_name, awards.funder_award_id, authorships.institutions.geo.city, authorships.institutions.geo.region, raw_affiliation_strings, biblio fields) are exempt: a comma there is sent quoted, as part of the phrase.',
89
+ recovery: 'Use `|` for OR within a filter value (e.g. "2020|2021"), or move a phrase that contains commas into a free-text search filter such as title.search or raw_affiliation_strings.search.',
90
+ thrownBy: 'service',
91
+ },
92
+ {
93
+ reason: 'invalid_country_code',
94
+ code: JsonRpcErrorCode.ValidationError,
95
+ when: 'A country filter (a key ending in country_code, country_codes, or countries) holds a segment that cannot be a country code, such as a misspelled name, an unassigned number, "unknown", or two codes joined by a space ("DE US").',
96
+ recovery: 'Pass the country as an ISO 3166-1 alpha-2 code such as DE, US, or GB (an alpha-3 code, numeric code, or English name is converted), or null for works with no country.',
97
+ thrownBy: 'service',
98
+ },
99
+ {
100
+ reason: 'mixed_and_or_in_filter_value',
101
+ code: JsonRpcErrorCode.ValidationError,
102
+ when: 'A filter value puts "|" (OR) beside an AND operator — a "+", or a space on a field where words mean AND (on a country field a space is always part of a country name, and inside a language name it is part of the name). OpenAlex splits the value on "|" first and drops every alternative that ANDs more than one value, so no single value can carry both.',
103
+ recovery: 'Keep "|" and the AND operator in separate filter keys: OR the alternatives in this key and put the AND in a second key that reaches the same values — {"authorships.institutions.country_code": "DE|FR", "institutions.country_code": "US"} matches works with (DE or FR) and US. The filters object holds each key once, so where no second key fits, run one call per alternative instead.',
104
+ thrownBy: 'service',
105
+ },
106
+ {
107
+ reason: 'quote_in_filter_value',
108
+ code: JsonRpcErrorCode.ValidationError,
109
+ when: 'A filter value sent to OpenAlex double-quoted holds a double quote inside its outer pair — a value the server quotes (a multi-word value on a field matched as whole text, or a value holding a comma on such a field or on a free-text search filter), or one the caller wrapped in double quotes on any filter but a free-text search.',
110
+ recovery: 'Remove the double quote from the value; a phrase is matched without quoting its own text.',
78
111
  thrownBy: 'service',
79
112
  },
80
113
  {
81
114
  reason: 'upstream_invalid_params',
82
115
  code: JsonRpcErrorCode.InvalidParams,
83
- when: 'OpenAlex rejected an invalid filter or sort field name (HTTP 400).',
84
- recovery: 'The upstream message names the rejected token and suggests close matches. Pass a valid OpenAlex work ID (W…), DOI, or PMID for seed_id, or use openalex_describe_fields(entity_type, "filter") to browse valid filter fields.',
116
+ when: 'OpenAlex rejected an invalid filter, select, or sort field name (HTTP 400).',
117
+ recovery: 'The upstream message names the rejected token and suggests close matches. Pass a valid OpenAlex work ID (W…), DOI, or PMID for seed_id, and browse the valid work fields with openalex_describe_fields("works", "filter") for filters or openalex_describe_fields("works", "select") for select.',
85
118
  thrownBy: 'service',
86
119
  },
87
120
  {
@@ -111,6 +144,20 @@ export const getCitationGraphTool = tool('openalex_get_citation_graph', {
111
144
  when: 'filters contains cites/cited_by/related_to, or an alias of one such as cited_works — the direction parameter reserves those keys.',
112
145
  recovery: 'Remove the reserved key from filters, or restate the relationship through direction.',
113
146
  },
147
+ {
148
+ reason: 'id_type_mismatch',
149
+ code: JsonRpcErrorCode.ValidationError,
150
+ when: 'seed_id is a native OpenAlex ID of another entity type — an author, source, institution, topic, publisher, funder, or concept ID rather than a work ID.',
151
+ recovery: "seed_id must identify a work — pass the work's OpenAlex ID (W…), DOI, or PMID. To walk the works of an author or other entity, list them first with openalex_search_entities filters.",
152
+ thrownBy: 'service',
153
+ },
154
+ {
155
+ reason: 'id_dot_segment',
156
+ code: JsonRpcErrorCode.ValidationError,
157
+ when: 'seed_id holds a `.` or `..` path segment, written plainly or percent-encoded.',
158
+ recovery: "Pass the work's identifier itself — its OpenAlex ID (W…), DOI, or PMID — with no relative path segments.",
159
+ thrownBy: 'service',
160
+ },
114
161
  {
115
162
  reason: 'entity_not_found',
116
163
  code: JsonRpcErrorCode.NotFound,
@@ -123,14 +170,14 @@ export const getCitationGraphTool = tool('openalex_get_citation_graph', {
123
170
  seed_id: z
124
171
  .string()
125
172
  .min(1)
126
- .describe('Seed work identifier. Accepts OpenAlex ID ("W2741809807"), DOI ("10.1038/nature12373" or full URL), or PMID ("12345678" or "https://pubmed.ncbi.nlm.nih.gov/12345678"). A PMCID is recognized too, bare or as a PubMed Central URL, but OpenAlex indexes no PMCIDs, so it resolves nothing — pass the work\'s PMID or DOI instead. Use openalex_resolve_name first if you only have a title.'),
173
+ .describe('Seed work identifier. Accepts OpenAlex work ID ("W2741809807", or its OpenAlex record-page or API URL such as "https://openalex.org/works/W2741809807"), DOI ("10.1038/nature12373" or full URL), or PMID ("12345678" or "https://pubmed.ncbi.nlm.nih.gov/12345678"). A PMCID is recognized too, bare or as a PubMed Central URL, but OpenAlex indexes no PMCIDs, so it resolves nothing — pass the work\'s PMID or DOI instead. Use openalex_resolve_name first if you only have a title.'),
127
174
  direction: z
128
175
  .enum(DIRECTIONS)
129
176
  .describe('"cites": works that cite seed_id (incoming citations). "cited_by": works that seed_id cites (its reference list). "related_to": OpenAlex algorithmically-related works (~8-30 typical, may be empty for less-cited seeds).'),
130
177
  filters: z
131
178
  .record(z.string(), z.string())
132
179
  .optional()
133
- .describe('Additional filters to narrow the graph, same syntax as openalex_search_entities. Example: publication_year=">2020", is_oa="true". Do not include cites/cited_by/related_to, nor an alias of one such as cited_works — those keys are set by the `direction` parameter.'),
180
+ .describe('Additional filters to narrow the graph, same syntax as openalex_search_entities. Example: publication_year=">2020", is_oa="true". Country fields take ISO 3166-1 alpha-2 codes ("DE") and `language` takes ISO 639-1 codes ("en"); alpha-3, numeric, ISO 639-2, and English-name forms are converted — a multi-word name is one value, so "South Korea|Japan" ORs two countries — and a value that cannot be a country code is rejected. A multi-word value on a field matched as whole text (display_name, awards.funder_display_name, authorships.institutions.geo.city, raw_affiliation_strings) matches as one phrase ("National Science Foundation"; a comma, as in "University of California, Berkeley", is part of it, and it cannot contain a double quote of its own), "!" and "|" included, but cannot be ANDed with "+" in the same field. A value mixing "|" with an AND operator — a "+", or a space on a field where words mean AND — is rejected, since OpenAlex drops every "|" alternative that ANDs more than one value; put the AND in a second key instead. Do not include cites/cited_by/related_to, nor an alias of one such as cited_works — those keys are set by the `direction` parameter.'),
134
181
  sort: z
135
182
  .string()
136
183
  .optional()
@@ -138,14 +185,14 @@ export const getCitationGraphTool = tool('openalex_get_citation_graph', {
138
185
  select: z
139
186
  .array(z.string())
140
187
  .optional()
141
- .describe('OpenAlex work field names to return. Always returned: id, display_name. Defaults to the curated works select if omitted.'),
188
+ .describe('OpenAlex work field names to return. Always returned: id, display_name. Defaults to the curated works select if omitted. `author_list` returns each author in authorship order as `{id, display_name, orcid}` (`orcid` null when absent), a compact alternative to `authorships`, which also carries institutions and affiliations; neither the default nor `["*"]` includes it. Large projections may be cut to fit the response budget (`omitted`, `windows`).'),
142
189
  per_page: z
143
190
  .number()
144
191
  .int()
145
192
  .min(1)
146
193
  .max(100)
147
194
  .default(25)
148
- .describe('Results per page (1-100). Default 25.'),
195
+ .describe('Results per page (1-100). Default 25. A budget-cut page returns fewer (`omitted`).'),
149
196
  cursor: z
150
197
  .string()
151
198
  .min(1)
@@ -160,11 +207,11 @@ export const getCitationGraphTool = tool('openalex_get_citation_graph', {
160
207
  .describe('Total edges from seed_id in this direction (across all pages).'),
161
208
  per_page: z
162
209
  .number()
163
- .describe('Page size OpenAlex echoed for this request — the requested per_page, not the number of records returned. A short or exhausted page carries fewer records than this.'),
210
+ .describe('Page size OpenAlex echoed for this request — the requested per_page, not the number of records returned. A short or exhausted page carries fewer records than this, as does a page the response budget cut (`omitted`).'),
164
211
  next_cursor: z
165
212
  .string()
166
213
  .nullable()
167
- .describe('Cursor for next page. null if no more results.'),
214
+ .describe('Cursor for next page. null if no more results. Continues after the full upstream page, `omitted` works included.'),
168
215
  })
169
216
  .describe('Result metadata including pagination.'),
170
217
  results: z
@@ -176,9 +223,12 @@ export const getCitationGraphTool = tool('openalex_get_citation_graph', {
176
223
  .nullable()
177
224
  .describe('Work title. null when OpenAlex holds no title for the record (paratext works and other untitled entries) — use `id` to identify it.'),
178
225
  })
179
- .passthrough()
226
+ .loose()
180
227
  .describe('A single OpenAlex work record on the citation graph. Additional fields vary by `select`.'))
181
- .describe('Works on the citation graph in this direction. Text values are plain text — HTML entities decoded, HTML/JATS/MathML markup removed.'),
228
+ .describe('Works on the citation graph in this direction. Text values are plain text — HTML entities decoded, HTML/JATS/MathML markup removed — except identifier and URL fields such as `id`, `doi`, `ids`, and `*_url`, returned exactly as OpenAlex stores them; an abstract arrives reconstructed as `abstract`, and a selected `author_list` as one `{id, display_name, orcid}` entry per author. Works cut by the response budget are in `omitted`; partial or possibly capped arrays are in `windows`.'),
229
+ omitted: omittedOutputSchema,
230
+ windows: windowsOutputSchema,
231
+ over_budget: overBudgetOutputSchema,
182
232
  }),
183
233
  // Agent-facing context for the success path — the query as parsed (seed + direction),
184
234
  // the total edge count, and recovery guidance for empty traversals. Populated via
@@ -191,12 +241,12 @@ export const getCitationGraphTool = tool('openalex_get_citation_graph', {
191
241
  notice: z
192
242
  .string()
193
243
  .optional()
194
- .describe('Guidance when no edges are returned. A first call suggests verifying the seed_id, broadening filters, or trying a different direction; a `cursor` continuation says the walk is already past its last edge instead. Absent when results are present.'),
244
+ .describe('Guidance notice. Set when no edges are returned — a first call suggests verifying the seed_id, broadening filters, or trying a different direction; a `cursor` continuation says the walk is already past its last edge instead — when the response budget cut works, windowed an array, or ran over, and when a work carries exactly 100 authorships or author_list entries (possibly capped). Absent otherwise.'),
195
245
  budget: z
196
246
  .object({
197
247
  costUsd: z
198
248
  .number()
199
- .describe('USD this call spent, covering both upstream requests — the seed validation lookup (unbilled) and the graph page itself.'),
249
+ .describe('USD this call spent, covering both upstream requests — the seed validation lookup and the graph page itself. The seed lookup is unbilled unless seed_id carries characters past the identifier itself (`W2741809807#x` still resolves to W2741809807), which OpenAlex bills like one list request.'),
200
250
  remainingUsd: z.number().describe("USD left in today's OpenAlex budget after this call."),
201
251
  resetsInSeconds: z
202
252
  .number()
@@ -225,12 +275,11 @@ export const getCitationGraphTool = tool('openalex_get_citation_graph', {
225
275
  if (reserved !== undefined) {
226
276
  const upstreamKey = translateFilterKey('works', reserved);
227
277
  const resolution = upstreamKey === reserved ? '' : ` — it resolves to \`${upstreamKey}\``;
228
- throw ctx.fail('reserved_filter_key', `${reserved} cannot be passed in filters${resolution}, and direction reserves cites/cited_by/related_to.`, {
229
- ...ctx.recoveryFor('reserved_filter_key'),
230
- reservedKey: reserved,
231
- direction: input.direction,
232
- });
278
+ throw ctx.fail('reserved_filter_key', `${reserved} cannot be passed in filters${resolution}, and direction reserves cites/cited_by/related_to.`, { reservedKey: reserved, direction: input.direction });
233
279
  }
280
+ // A filter value the graph search would refuse fails here, before the seed lookup's request.
281
+ if (input.filters)
282
+ buildSearchFilter('works', input.filters);
234
283
  const service = getOpenAlexService();
235
284
  /**
236
285
  * Resolve any accepted seed identifier to a bare W-ID and confirm it exists. The graph
@@ -243,7 +292,7 @@ export const getCitationGraphTool = tool('openalex_get_citation_graph', {
243
292
  const seedLookup = await service.search({ entityType: 'works', id: input.seed_id, select: ['id'] }, ctx);
244
293
  const seedRecord = seedLookup.results[0];
245
294
  if (!seedRecord?.id) {
246
- throw ctx.fail('entity_not_found', `Could not resolve seed_id "${input.seed_id}" to an OpenAlex work ID.`, { ...ctx.recoveryFor('entity_not_found'), seedId: input.seed_id });
295
+ throw ctx.fail('entity_not_found', `Could not resolve seed_id ${quoteCallerText(input.seed_id)} to an OpenAlex work ID.`, { seedId: input.seed_id });
247
296
  }
248
297
  const workId = seedRecord.id.replace(OPENALEX_URL_PREFIX, '');
249
298
  const mergedFilters = {
@@ -268,34 +317,33 @@ export const getCitationGraphTool = tool('openalex_get_citation_graph', {
268
317
  ctx.enrich({ echo, totalCount: result.meta.count });
269
318
  // An empty page on a `cursor` continuation means the walk already returned every edge it
270
319
  // had, so the verify-the-seed advice would send the caller after a seed that is fine.
271
- if (result.results.length === 0) {
272
- ctx.enrich.notice(input.cursor === undefined
320
+ const emptyNotice = result.results.length > 0
321
+ ? undefined
322
+ : input.cursor === undefined
273
323
  ? `No edges for ${echo}. Verify the seed_id with openalex_resolve_name, broaden filters, or try a different direction.`
274
- : `Pagination exhausted for ${echo} — the previous page held the last edge, so this one came back empty. Stop paging rather than broadening filters or changing direction.`);
275
- }
276
- return {
277
- meta: {
278
- count: result.meta.count,
279
- per_page: result.meta.per_page,
280
- next_cursor: result.meta.next_cursor,
281
- },
282
- results: result.results,
324
+ : `Pagination exhausted for ${echo} — the previous page held the last edge, so this one came back empty. Stop paging rather than broadening filters or changing direction.`;
325
+ const meta = {
326
+ count: result.meta.count,
327
+ per_page: result.meta.per_page,
328
+ next_cursor: result.meta.next_cursor,
283
329
  };
330
+ const page = fitRecordsToBudget({
331
+ records: result.results,
332
+ entityType: 'works',
333
+ path: 'list',
334
+ select: input.select,
335
+ measureFrame: (disclosure, budgetNotice) => measurePageFrame({ meta, results: [], ...disclosure }, EDGE_NOUN, {
336
+ echo,
337
+ totalCount: result.meta.count,
338
+ totalLabel: 'Total Edges',
339
+ notice: joinNotices([emptyNotice, budgetNotice]),
340
+ }),
341
+ });
342
+ const notice = joinNotices([emptyNotice, page.notice]);
343
+ if (notice)
344
+ ctx.enrich.notice(notice);
345
+ return { meta, results: page.results, ...page.disclosure };
284
346
  },
285
- format: (result) => {
286
- const lines = [];
287
- const countLabel = `${result.meta.count} edge(s) — ${result.meta.per_page} per page`;
288
- const header = result.meta.next_cursor
289
- ? `**${countLabel}** — next cursor: \`${result.meta.next_cursor}\``
290
- : `**${countLabel}**`;
291
- lines.push(header);
292
- if (result.results.length === 0) {
293
- return [{ type: 'text', text: lines.join('\n') }];
294
- }
295
- for (const record of result.results) {
296
- lines.push(...renderEntityRecord(record));
297
- }
298
- return [{ type: 'text', text: lines.join('\n') }];
299
- },
347
+ format: (result) => formatRecordPage(result, EDGE_NOUN),
300
348
  });
301
349
  //# sourceMappingURL=citation-graph.tool.js.map