@xevos117/mcp-zotero 2.0.2 → 2.0.4

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.
@@ -4,9 +4,10 @@ import { isZoteroApiError } from "../types/zotero-types.js";
4
4
  import { formatJsonResult, formatErrorResponse } from "../utils/error-formatter.js";
5
5
  import { canDeleteCollections } from "../utils/unsafe-operations.js";
6
6
  import { resolveLibrary, libraryArgsSchema } from "../utils/library-context.js";
7
+ import { COLLECTION_KEY_HINT, unsafeOperationsHint, zoteroStatusHint } from "../utils/error-hints.js";
7
8
  export const toolConfig = {
8
9
  name: "delete_collection",
9
- description: "Delete a collection (folder) from your Zotero library. Items inside the collection are NOT deleted — they remain in your library. Requires UNSAFE_OPERATIONS environment variable set to 'all'.",
10
+ description: "Delete a collection (folder) from your Zotero library; confirm with the user first. Items inside the collection are NOT deleted — they remain in your library. Disabled unless the server setting UNSAFE_OPERATIONS is 'all'.",
10
11
  inputSchema: {
11
12
  collection_key: zoteroKey()
12
13
  .describe("Zotero collection key to delete. Get this from get_collections."),
@@ -18,34 +19,46 @@ export async function handleDeleteCollection(zoteroApi, userId, args, unsafeOps
18
19
  const { collection_key, library_type, library_id } = DeleteCollectionSchema.parse(args);
19
20
  const { type: libraryType, id: libraryId } = resolveLibrary({ library_type, library_id }, userId);
20
21
  if (!canDeleteCollections(unsafeOps)) {
21
- return formatErrorResponse("Deletion of collections is not allowed. Set the UNSAFE_OPERATIONS environment variable to 'all' to enable this operation.", {
22
+ return formatErrorResponse(`Deletion of collections is not allowed: it needs UNSAFE_OPERATIONS 'all' in this server's configuration (it is '${unsafeOps}'). Nothing was deleted.`, {
23
+ hint: unsafeOperationsHint("collections"),
22
24
  env_var: "UNSAFE_OPERATIONS",
23
25
  current_value: unsafeOps,
24
26
  required_values: ["all"],
25
27
  });
26
28
  }
27
29
  try {
28
- const response = await zoteroApi
29
- .library(libraryType, libraryId)
30
- .collections(collection_key)
31
- .get();
32
- const collection = response.getData();
33
- const version = response.getVersion();
34
- if (version === null) {
35
- return formatErrorResponse("Could not determine collection version", {
30
+ for (let attempt = 1;; attempt++) {
31
+ const response = await zoteroApi
32
+ .library(libraryType, libraryId)
33
+ .collections(collection_key)
34
+ .get();
35
+ const collection = response.getData();
36
+ const version = response.getVersion();
37
+ if (version === null) {
38
+ return formatErrorResponse("Could not determine collection version", {
39
+ collection_key,
40
+ hint: "Nothing was deleted. Retry the same call once.",
41
+ });
42
+ }
43
+ try {
44
+ await zoteroApi
45
+ .library(libraryType, libraryId)
46
+ .collections(collection_key)
47
+ .version(version)
48
+ .delete();
49
+ }
50
+ catch (err) {
51
+ // 412: the collection changed between the GET and the DELETE; read it again and retry once
52
+ if (attempt === 1 && isZoteroApiError(err) && err.response.status === 412)
53
+ continue;
54
+ throw err;
55
+ }
56
+ return formatJsonResult({
57
+ deleted: true,
36
58
  collection_key,
59
+ name: collection.name || collection_key,
37
60
  });
38
61
  }
39
- await zoteroApi
40
- .library(libraryType, libraryId)
41
- .collections(collection_key)
42
- .version(version)
43
- .delete();
44
- return formatJsonResult({
45
- deleted: true,
46
- collection_key,
47
- name: collection.name || collection_key,
48
- });
49
62
  }
50
63
  catch (err) {
51
64
  if (isZoteroApiError(err)) {
@@ -53,12 +66,16 @@ export async function handleDeleteCollection(zoteroApi, userId, args, unsafeOps
53
66
  return formatErrorResponse("Collection not found", {
54
67
  collection_key,
55
68
  status: "not_found",
69
+ hint: `Nothing was deleted. ${COLLECTION_KEY_HINT}`,
56
70
  });
57
71
  }
58
72
  if (err.response.status === 412) {
59
- return formatErrorResponse("Collection was modified by another client. Retry the operation.", {
73
+ const { hint } = zoteroStatusHint(412);
74
+ return formatErrorResponse("Collection was modified by another client (HTTP 412 Precondition Failed), also on a second try with its new version, so it was not deleted.", {
60
75
  collection_key,
61
76
  status: "version_conflict",
77
+ http_status: 412,
78
+ hint,
62
79
  });
63
80
  }
64
81
  }
@@ -5,9 +5,10 @@ import { formatJsonResult, formatErrorResponse } from "../utils/error-formatter.
5
5
  import { canDeleteItems } from "../utils/unsafe-operations.js";
6
6
  import { fetchItemsByKeys } from "../utils/pagination.js";
7
7
  import { resolveLibrary, libraryArgsSchema } from "../utils/library-context.js";
8
+ import { ITEM_KEY_HINT, unsafeOperationsHint, zoteroStatusHint } from "../utils/error-hints.js";
8
9
  export const toolConfig = {
9
10
  name: "delete_items",
10
- description: "Delete one or more items from your Zotero library: they are permanently deleted (not moved to the Zotero trash). Accepts up to 50 item keys per call. Requires UNSAFE_OPERATIONS environment variable set to 'items' or 'all'.",
11
+ description: "Delete one or more items from your Zotero library: they are permanently deleted (not moved to the Zotero trash), so confirm with the user first. Accepts up to 50 item keys per call. Disabled unless the server setting UNSAFE_OPERATIONS is 'items' or 'all'.",
11
12
  inputSchema: {
12
13
  item_keys: z
13
14
  .array(zoteroKey())
@@ -22,53 +23,72 @@ export async function handleDeleteItems(zoteroApi, userId, args, unsafeOps = "no
22
23
  const { item_keys, library_type, library_id } = DeleteItemsSchema.parse(args);
23
24
  const { type: libraryType, id: libraryId } = resolveLibrary({ library_type, library_id }, userId);
24
25
  if (!canDeleteItems(unsafeOps)) {
25
- return formatErrorResponse("Deletion of items is not allowed. Set the UNSAFE_OPERATIONS environment variable to 'items' or 'all' to enable this operation.", {
26
+ return formatErrorResponse(`Deletion of items is not allowed: destructive operations are disabled in this server's configuration (UNSAFE_OPERATIONS is '${unsafeOps}'). Nothing was deleted.`, {
26
27
  env_var: "UNSAFE_OPERATIONS",
27
28
  current_value: unsafeOps,
28
29
  required_values: ["items", "all"],
30
+ hint: unsafeOperationsHint("items"),
29
31
  });
30
32
  }
31
33
  try {
32
- const { items, version: libraryVersion } = await fetchItemsByKeys((params) => zoteroApi.library(libraryType, libraryId).items().get(params), item_keys);
33
- const foundKeys = new Set(items.map((item) => item.key).filter(Boolean));
34
- const notFoundKeys = item_keys.filter((k) => !foundKeys.has(k));
35
- if (foundKeys.size === 0) {
36
- return formatErrorResponse("No items found for the given keys", {
37
- item_keys,
38
- status: "not_found",
39
- });
40
- }
41
- // Use library version from response header (Last-Modified-Version),
42
- // not individual item versions — required for multi-object DELETE
43
- if (libraryVersion === null) {
44
- return formatErrorResponse("Could not determine library version", {
45
- item_keys,
46
- });
47
- }
48
- // only keys the caller asked for, whatever the API returned
49
- const keysToDelete = item_keys.filter((k) => foundKeys.has(k));
50
- await zoteroApi
51
- .library(libraryType, libraryId)
52
- .items()
53
- .version(libraryVersion)
54
- .delete(keysToDelete);
55
- const result = {
56
- deleted_keys: keysToDelete,
57
- deleted_count: keysToDelete.length,
58
- };
59
- if (notFoundKeys.length > 0) {
60
- result.not_found = notFoundKeys;
61
- }
62
- return formatJsonResult(result);
63
- }
64
- catch (err) {
65
- if (isZoteroApiError(err)) {
66
- if (err.response.status === 412) {
67
- return formatErrorResponse("Items were modified by another client. Retry the operation.", {
34
+ const notFoundKeys = [];
35
+ let pending = item_keys;
36
+ for (let attempt = 1;; attempt++) {
37
+ const { items, version: libraryVersion } = await fetchItemsByKeys((params) => zoteroApi.library(libraryType, libraryId).items().get(params), pending);
38
+ const foundKeys = new Set(items.map((item) => item.key).filter(Boolean));
39
+ notFoundKeys.push(...pending.filter((k) => !foundKeys.has(k)));
40
+ if (foundKeys.size === 0) {
41
+ return formatErrorResponse("No items found for the given keys", {
42
+ item_keys,
43
+ status: "not_found",
44
+ hint: `Nothing was deleted: none of these keys exists in this library (already deleted, or in another library). ${ITEM_KEY_HINT}`,
45
+ });
46
+ }
47
+ // Use library version from response header (Last-Modified-Version),
48
+ // not individual item versions — required for multi-object DELETE
49
+ if (libraryVersion === null) {
50
+ return formatErrorResponse("Could not determine library version", {
68
51
  item_keys,
69
- status: "version_conflict",
52
+ hint: "Nothing was deleted. Retry the same call once.",
70
53
  });
71
54
  }
55
+ // only keys the caller asked for, whatever the API returned
56
+ const keysToDelete = pending.filter((k) => foundKeys.has(k));
57
+ try {
58
+ await zoteroApi
59
+ .library(libraryType, libraryId)
60
+ .items()
61
+ .version(libraryVersion)
62
+ .delete(keysToDelete);
63
+ }
64
+ catch (err) {
65
+ // 412: the library changed between the GET and the DELETE (another client, a sync). Read the new
66
+ // version and the keys that still exist, and retry once with those.
67
+ if (attempt === 1 && isZoteroApiError(err) && err.response.status === 412) {
68
+ pending = keysToDelete;
69
+ continue;
70
+ }
71
+ throw err;
72
+ }
73
+ const result = {
74
+ deleted_keys: keysToDelete,
75
+ deleted_count: keysToDelete.length,
76
+ };
77
+ if (notFoundKeys.length > 0) {
78
+ result.not_found = notFoundKeys;
79
+ }
80
+ return formatJsonResult(result);
81
+ }
82
+ }
83
+ catch (err) {
84
+ if (isZoteroApiError(err) && err.response.status === 412) {
85
+ const { hint } = zoteroStatusHint(412);
86
+ return formatErrorResponse("Items were modified by another client (HTTP 412 Precondition Failed), also on a second try with the new library version, so nothing was deleted.", {
87
+ item_keys,
88
+ status: "version_conflict",
89
+ http_status: 412,
90
+ hint,
91
+ });
72
92
  }
73
93
  throw err;
74
94
  }
@@ -4,9 +4,11 @@ import { formatJsonResult, formatErrorResponse, formatEmptyResult, errorMessage,
4
4
  import { attachOpenAccessPdfs } from "../utils/oa-pdf.js";
5
5
  import { fetchAllPages, fetchItemsByKeys } from "../utils/pagination.js";
6
6
  import { resolveLibrary, libraryArgsSchema } from "../utils/library-context.js";
7
+ import { describeAnyError, MISSING_API_KEY, MISSING_API_KEY_HINT } from "../utils/error-hints.js";
8
+ import { UNPAYWALL_EMAIL_HINT, UNPAYWALL_EMAIL_MISSING } from "../utils/unpaywall.js";
7
9
  export const toolConfig = {
8
10
  name: "find_and_attach_pdfs",
9
- description: "For each Zotero item, check Unpaywall for open access PDFs and attach them. Items must have a DOI. Uses the same source as Zotero Desktop's 'Find Available PDFs'.",
11
+ description: "For each Zotero item, check Unpaywall for open access PDFs and attach them. Items must have a DOI; needs UNPAYWALL_EMAIL in the server settings. Uploads use the user's Zotero file storage; dry_run only reports what is available. Uses the same source as Zotero Desktop's 'Find Available PDFs'.",
10
12
  inputSchema: {
11
13
  item_keys: z
12
14
  .array(zoteroKey())
@@ -32,14 +34,14 @@ export async function handleFindAndAttachPdfs(zoteroApi, userId, args) {
32
34
  const { type: libraryType, id: libraryId } = resolveLibrary({ library_type, library_id }, userId);
33
35
  // Validate: exactly one of item_keys or collection_key
34
36
  if (item_keys && collection_key) {
35
- return formatErrorResponse("Provide either item_keys or collection_key, not both");
37
+ return formatErrorResponse("Provide either item_keys or collection_key, not both: call once per selection.");
36
38
  }
37
39
  if (!item_keys && !collection_key) {
38
- return formatErrorResponse("Provide either item_keys or collection_key");
40
+ return formatErrorResponse("Provide either item_keys or collection_key: item_keys for specific items (from search_library), collection_key for every item of a collection (from get_collections).");
39
41
  }
40
42
  const apiKey = process.env.ZOTERO_API_KEY;
41
43
  if (!apiKey) {
42
- return formatErrorResponse("ZOTERO_API_KEY environment variable is not set");
44
+ return formatErrorResponse(MISSING_API_KEY, { hint: MISSING_API_KEY_HINT });
43
45
  }
44
46
  try {
45
47
  // 1. Resolve item keys
@@ -55,7 +57,11 @@ export async function handleFindAndAttachPdfs(zoteroApi, userId, args) {
55
57
  keys = item_keys;
56
58
  }
57
59
  if (keys.length === 0) {
58
- return formatEmptyResult("No items to process");
60
+ return formatEmptyResult("No items to process", {
61
+ suggestion: collection_key
62
+ ? "The collection is empty or holds only attachments and notes: check it with get_collection_items."
63
+ : "item_keys is empty: pass at least one item key (from search_library or get_collection_items).",
64
+ });
59
65
  }
60
66
  // 2. Batch-fetch item metadata to get DOIs
61
67
  const { items: metaItems } = await fetchItemsByKeys((params) => zoteroApi.library(libraryType, libraryId).items().get(params), keys);
@@ -71,9 +77,9 @@ export async function handleFindAndAttachPdfs(zoteroApi, userId, args) {
71
77
  for (const key of keys) {
72
78
  const item = itemMap.get(key);
73
79
  if (!item)
74
- preResults.set(key, { item_key: key, doi: null, status: "error", reason: "Item not found" });
80
+ preResults.set(key, { item_key: key, doi: null, status: "error", reason: "Item not found in this library" });
75
81
  else if (!item.DOI)
76
- preResults.set(key, { item_key: key, doi: null, status: "error", reason: "No DOI" });
82
+ preResults.set(key, { item_key: key, doi: null, status: "error", reason: "No DOI: Unpaywall needs one. Add the DOI to the item, or attach a PDF from a known URL with import_pdf_to_zotero" });
77
83
  else
78
84
  targets.push({ itemKey: key, doi: item.DOI });
79
85
  }
@@ -118,14 +124,16 @@ export async function handleFindAndAttachPdfs(zoteroApi, userId, args) {
118
124
  dry_run,
119
125
  ...(quotaExceeded > 0
120
126
  ? {
121
- storage_quota_warning: "Zotero storage quota is full. Remaining PDF uploads were skipped. Free up space at https://www.zotero.org/settings/storage or upgrade your plan.",
127
+ storage_quota_warning: "Zotero storage quota is full. Remaining PDF uploads were skipped. Tell the user they can free up space or upgrade at https://www.zotero.org/settings/storage, then run this tool again.",
122
128
  }
123
129
  : {}),
130
+ ...(results.some((r) => r.reason === UNPAYWALL_EMAIL_MISSING) ? { hint: UNPAYWALL_EMAIL_HINT } : {}),
124
131
  results,
125
132
  });
126
133
  }
127
134
  catch (err) {
128
135
  logToolError("find_and_attach_pdfs", err);
129
- return formatErrorResponse("find_and_attach_pdfs failed", { details: errorMessage(err) });
136
+ const { error, ...described } = describeAnyError(err);
137
+ return formatErrorResponse(`find_and_attach_pdfs failed: ${error}`, { ...described, details: errorMessage(err) });
130
138
  }
131
139
  }
@@ -5,15 +5,16 @@ import { formatJsonResult, formatErrorResponse, formatEmptyResult } from "../uti
5
5
  import { formatCreators, formatTags } from "../utils/item-formatter.js";
6
6
  import { fetchAllPages } from "../utils/pagination.js";
7
7
  import { resolveLibrary, libraryArgsSchema } from "../utils/library-context.js";
8
+ import { COLLECTION_KEY_HINT } from "../utils/error-hints.js";
8
9
  export const toolConfig = {
9
10
  name: "get_collection_items",
10
- description: "Get all items in a specific Zotero collection. Returns item keys, titles, authors, and dates. Use the collectionKey from get_collections. Use the returned item keys with get_items_details, get_item_fulltext, or inject_citations.",
11
+ description: "Get all items in a specific Zotero collection (only items directly in it, not those in its subcollections). Returns item keys, titles, authors, and dates. Use the collectionKey from get_collections. Use the returned item keys with get_items_details, get_item_fulltext, or inject_citations.",
11
12
  inputSchema: {
12
- collectionKey: zoteroKey().describe("The collection key/ID"),
13
+ collectionKey: zoteroKey().describe("Collection key from get_collections"),
13
14
  excludeAttachments: z
14
15
  .boolean()
15
16
  .default(true)
16
- .describe("Exclude attachment and note items (default: true)"),
17
+ .describe("Exclude attachment and note items (default: true). Set false to list them too."),
17
18
  ...libraryArgsSchema,
18
19
  },
19
20
  };
@@ -26,7 +27,7 @@ export async function handleGetCollectionItems(zoteroApi, userId, args) {
26
27
  if (!allItems || allItems.length === 0) {
27
28
  return formatEmptyResult("Collection is empty", {
28
29
  collectionKey,
29
- suggestion: "Add some items to this collection in Zotero",
30
+ suggestion: "No items directly in this collection. Items of its subcollections are not listed: find them with get_collections (parentCollection = this key). To add items, pass collection_key to add_items_by_doi or add_items.",
30
31
  status: "empty",
31
32
  });
32
33
  }
@@ -50,7 +51,7 @@ export async function handleGetCollectionItems(zoteroApi, userId, args) {
50
51
  if (formatted.length === 0) {
51
52
  return formatEmptyResult("No valid items found in collection", {
52
53
  collectionKey,
53
- suggestion: "Check that items in this collection have the expected metadata",
54
+ suggestion: "The collection contains only attachments or notes, which excludeAttachments=true (the default) hides: call again with excludeAttachments=false to list them.",
54
55
  status: "invalid_items",
55
56
  });
56
57
  }
@@ -63,9 +64,9 @@ export async function handleGetCollectionItems(zoteroApi, userId, args) {
63
64
  catch (err) {
64
65
  if (isZoteroApiError(err)) {
65
66
  if (err.response?.status === 404) {
66
- return formatErrorResponse("Collection is empty or not accessible", {
67
+ return formatErrorResponse("Collection not found: no collection with this key in this library, or the API key cannot access it.", {
67
68
  collectionKey,
68
- suggestion: "Verify the collection exists and try adding some items to it",
69
+ suggestion: COLLECTION_KEY_HINT,
69
70
  status: "not_found",
70
71
  });
71
72
  }
@@ -21,7 +21,7 @@ export async function handleGetCollections(zoteroApi, userId, args) {
21
21
  const { items: allCollections } = await fetchAllPages((params) => zoteroApi.library(libraryType, libraryId).collections().get(params));
22
22
  if (!Array.isArray(allCollections) || allCollections.length === 0) {
23
23
  return formatEmptyResult("No collections found", {
24
- suggestion: "Create a collection in your Zotero library first",
24
+ suggestion: "This library has no collections. Items can still be found with search_library; to organize them, create one with create_collection.",
25
25
  helpUrl: "https://www.zotero.org/support/collections",
26
26
  });
27
27
  }
@@ -32,7 +32,7 @@ export async function handleGetCollections(zoteroApi, userId, args) {
32
32
  : allCollections.filter((c) => !c.deleted);
33
33
  if (collections.length === 0) {
34
34
  return formatEmptyResult("No collections found", {
35
- suggestion: "All collections are in the trash. Use include_trashed=true to see them.",
35
+ suggestion: "All collections of this library are in the Zotero trash: call again with include_trashed=true to see them, or create a new one with create_collection.",
36
36
  });
37
37
  }
38
38
  return formatJsonResult(collections);
@@ -6,16 +6,19 @@ import { formatJsonResult, formatErrorResponse } from "../utils/error-formatter.
6
6
  import { resolveLibrary, libraryArgsSchema } from "../utils/library-context.js";
7
7
  import { findPdfAttachments, isLinkedUrl, isPdfAttachment } from "../utils/attachments.js";
8
8
  import { fetchWithTimeout, isTimeoutAbort, timeoutError, TIMEOUTS } from "../utils/timeouts.js";
9
+ import { ITEM_KEY_HINT, MISSING_API_KEY, MISSING_API_KEY_HINT, zoteroStatusHint } from "../utils/error-hints.js";
9
10
  export const toolConfig = {
10
11
  name: "get_item_fulltext",
11
- description: "Get the full text content of a Zotero item's PDF attachment via Zotero's fulltext index. Zotero desktop automatically indexes PDFs when synced. Use this to read the full content of papers instead of relying on abstracts.",
12
+ description: "Get the text of a Zotero item's stored PDF from Zotero's full-text index. Works for PDFs indexed by Zotero desktop and synced, or imported with import_pdf_to_zotero / find_and_attach_pdfs; not for linked URLs or web pages. Use this to read the full content of papers instead of relying on abstracts.",
12
13
  inputSchema: {
13
- item_key: zoteroKey().describe("The Zotero item key (parent item or attachment key)"),
14
+ item_key: zoteroKey().describe("Item key (the parent item or its PDF attachment), from search_library or get_collection_items"),
14
15
  max_characters: z
15
16
  .number()
17
+ .int()
18
+ .min(0)
16
19
  .optional()
17
20
  .default(50000)
18
- .describe("Maximum characters to return (default: 50000, 0 = no limit)"),
21
+ .describe("Maximum characters to return: a positive integer, or 0 for no limit (default: 50000); truncated: true in the result when cut"),
19
22
  ...libraryArgsSchema,
20
23
  },
21
24
  };
@@ -25,7 +28,7 @@ export async function handleGetItemFulltext(zoteroApi, userId, args) {
25
28
  const { type: libraryType, id: libraryId } = resolveLibrary({ library_type, library_id }, userId);
26
29
  const apiKey = process.env.ZOTERO_API_KEY;
27
30
  if (!apiKey) {
28
- return formatErrorResponse("ZOTERO_API_KEY environment variable is not set");
31
+ return formatErrorResponse(MISSING_API_KEY, { hint: MISSING_API_KEY_HINT });
29
32
  }
30
33
  try {
31
34
  // Fetch parent item metadata for context
@@ -37,7 +40,7 @@ export async function handleGetItemFulltext(zoteroApi, userId, args) {
37
40
  // If the item itself is a PDF attachment, use it directly (a web link has no stored file)
38
41
  if (isPdfAttachment(itemData)) {
39
42
  if (isLinkedUrl(itemData)) {
40
- return formatErrorResponse("This attachment is a link to a PDF on the web (linked URL): Zotero stores no file or full text for it. Fetch the URL directly.", { item_key, url: itemData.url || undefined });
43
+ return formatErrorResponse("This attachment is a link to a PDF on the web (linked URL): Zotero stores no file or full text for it. Fetch the URL directly if you have a web tool, or store the PDF with import_pdf_to_zotero and call again.", { item_key, url: itemData.url || undefined });
41
44
  }
42
45
  return fetchFulltext(item_key, item_key, libraryType, libraryId, apiKey, max_characters);
43
46
  }
@@ -46,24 +49,25 @@ export async function handleGetItemFulltext(zoteroApi, userId, args) {
46
49
  const pdfAttachment = pdfs.find((p) => !isLinkedUrl(p));
47
50
  const linkedPdf = pdfs.find(isLinkedUrl);
48
51
  if (!pdfAttachment?.key && linkedPdf) {
49
- return formatErrorResponse("No stored PDF attachment found. This item only links to a PDF on the web (linked URL attachment), which Zotero does not index — fetch the linked URL directly.", { item_key, attachment_key: linkedPdf.key, url: linkedPdf.url || undefined });
52
+ return formatErrorResponse("No stored PDF attachment found. This item only links to a PDF on the web (linked URL attachment), which Zotero does not index — fetch the linked URL directly if you have a web tool, or store the PDF with import_pdf_to_zotero (parent_item = this item) and call again.", { item_key, attachment_key: linkedPdf.key, url: linkedPdf.url || undefined });
50
53
  }
51
54
  if (!pdfAttachment?.key) {
52
55
  // Provide context-aware error messages
53
56
  if (itemData.itemType === "webpage" || itemData.itemType === "blogPost") {
54
- return formatErrorResponse("This is a web page item. Use the item's URL to fetch its content directly.", { item_key, url: itemData.url || undefined });
57
+ return formatErrorResponse("This is a web page item: Zotero has no PDF text for it. Fetch its URL directly if you have a web tool; otherwise tell the user.", { item_key, url: itemData.url || undefined });
55
58
  }
56
59
  if (itemData.url) {
57
- return formatErrorResponse(`No PDF attachment found. This item has a URL — you can fetch its content directly from the web.`, { item_key, url: itemData.url });
60
+ return formatErrorResponse("No PDF attachment found. This item has a URL — you can fetch its content directly from the web, or attach the PDF " +
61
+ "(find_and_attach_pdfs if the item has a DOI, import_pdf_to_zotero for a PDF URL) and call again.", { item_key, url: itemData.url });
58
62
  }
59
- return formatErrorResponse("No PDF attachment found for this item.", { item_key });
63
+ return formatErrorResponse("No PDF attachment found for this item. Attach one with find_and_attach_pdfs (items with a DOI) or import_pdf_to_zotero (a PDF URL), then call again.", { item_key });
60
64
  }
61
65
  return fetchFulltext(item_key, pdfAttachment.key, libraryType, libraryId, apiKey, max_characters);
62
66
  }
63
67
  catch (err) {
64
68
  if (isZoteroApiError(err)) {
65
69
  if (err.response?.status === 404) {
66
- return formatErrorResponse("Item not found", { item_key });
70
+ return formatErrorResponse("Item not found in this library", { item_key, hint: ITEM_KEY_HINT });
67
71
  }
68
72
  }
69
73
  throw err;
@@ -73,10 +77,20 @@ async function fetchFulltext(itemKey, attachmentKey, libraryType, userId, apiKey
73
77
  const url = `https://api.zotero.org/${libraryType}s/${userId}/items/${attachmentKey}/fulltext`;
74
78
  const response = await fetchWithTimeout(url, { headers: { "Zotero-API-Key": apiKey } }, TIMEOUTS.zoteroApiMs, "Zotero fulltext request");
75
79
  if (response.status === 404) {
76
- return formatErrorResponse("Full text not indexed for this item. Open the PDF in Zotero desktop to trigger indexing, then sync.", { item_key: itemKey, attachment_key: attachmentKey });
80
+ return formatErrorResponse("Full text not indexed for this item: Zotero has no text for this PDF yet. Retrying now will not help.", {
81
+ item_key: itemKey,
82
+ attachment_key: attachmentKey,
83
+ hint: "Tell the user to open the PDF in Zotero desktop (or right-click it → Reindex Item) and let Zotero sync, then try again. " +
84
+ "A scanned PDF without a text layer cannot be indexed.",
85
+ });
77
86
  }
78
87
  if (!response.ok) {
79
- return formatErrorResponse(`Zotero fulltext API returned status ${response.status}`, { item_key: itemKey, attachment_key: attachmentKey });
88
+ const { error, hint } = zoteroStatusHint(response.status);
89
+ return formatErrorResponse(`Zotero fulltext API returned status ${response.status}. ${error}`, {
90
+ item_key: itemKey,
91
+ attachment_key: attachmentKey,
92
+ hint,
93
+ });
80
94
  }
81
95
  let data;
82
96
  try {
@@ -91,6 +105,7 @@ async function fetchFulltext(itemKey, attachmentKey, libraryType, userId, apiKey
91
105
  return formatErrorResponse(timeoutError("Zotero fulltext request", url, TIMEOUTS.zoteroApiMs).message, {
92
106
  item_key: itemKey,
93
107
  attachment_key: attachmentKey,
108
+ hint: "Retry once; large PDFs can be slow. If it keeps timing out, tell the user to check the network connection of the machine running this server.",
94
109
  });
95
110
  }
96
111
  let text = data.content;
@@ -4,9 +4,10 @@ import { formatJsonResult, formatErrorResponse, formatEmptyResult } from "../uti
4
4
  import { formatCreators } from "../utils/item-formatter.js";
5
5
  import { fetchItemsByKeys } from "../utils/pagination.js";
6
6
  import { resolveLibrary, libraryArgsSchema } from "../utils/library-context.js";
7
+ import { ITEM_KEY_HINT } from "../utils/error-hints.js";
7
8
  export const toolConfig = {
8
9
  name: "get_items_details",
9
- description: "Get metadata for multiple Zotero items in a single call. Accepts an array of item keys and returns a map of key → metadata. Use this instead of one call per item. Returns all type-specific fields (e.g. bookTitle for bookSection, proceedingsTitle for conferencePaper, university for thesis). Set include_abstract to include abstracts (excluded by default to keep responses lightweight).",
10
+ description: "Get metadata for multiple Zotero items in a single call. Accepts an array of item keys and returns a map of key → metadata. Use this instead of one call per item. Returns all type-specific fields (e.g. bookTitle for bookSection, proceedingsTitle for conferencePaper, university for thesis). Set include_abstract to include abstracts (excluded by default to keep responses lightweight). Keys not found in the library are listed in not_found (present only when some are missing).",
10
11
  inputSchema: {
11
12
  item_keys: z
12
13
  .array(zoteroKey())
@@ -30,12 +31,13 @@ export async function handleGetItemsDetails(zoteroApi, userId, args) {
30
31
  const { item_keys, include_abstract, library_type, library_id } = GetItemsDetailsSchema.parse(args);
31
32
  const { type: libraryType, id: libraryId } = resolveLibrary({ library_type, library_id }, userId);
32
33
  if (item_keys.length === 0) {
33
- return formatErrorResponse("At least one item key is required");
34
+ return formatErrorResponse("At least one item key is required: pass item_keys from search_library, get_collection_items or add_items_by_doi.");
34
35
  }
35
36
  const { items } = await fetchItemsByKeys((params) => zoteroApi.library(libraryType, libraryId).items().get(params), item_keys);
36
37
  if (items.length === 0) {
37
38
  return formatEmptyResult("No items found for the given keys", {
38
39
  item_keys,
40
+ suggestion: `None of these keys exists in this library (deleted, or from another library). ${ITEM_KEY_HINT}`,
39
41
  });
40
42
  }
41
43
  const result = {};
@@ -69,5 +71,7 @@ export async function handleGetItemsDetails(zoteroApi, userId, args) {
69
71
  }
70
72
  result[key] = entry;
71
73
  }
72
- return formatJsonResult(result);
74
+ // Lowercase name: never collides with an item key (8 uppercase characters); the skill's inject.js skips it
75
+ const notFound = [...new Set(item_keys)].filter((k) => !(k in result));
76
+ return formatJsonResult(notFound.length > 0 ? { ...result, not_found: notFound } : result);
73
77
  }
@@ -2,7 +2,7 @@ import { resolveLibrary } from "../utils/library-context.js";
2
2
  import { formatJsonResult } from "../utils/error-formatter.js";
3
3
  export const toolConfig = {
4
4
  name: "get_user_id",
5
- description: "Returns the Zotero library configured in the server environment: user_id, library_type, library_id and library_path (\"users/<id>\" or \"groups/<id>\"). Pass library_path to the standalone inject-citations skill script (inject.js) to generate Zotero field code URIs. Not needed when using the inject_citations MCP tool, which reads the library internally.",
5
+ description: "Returns the Zotero library configured in the server environment: user_id, library_type, library_id and library_path (\"users/<id>\" or \"groups/<id>\"). Pass library_path to the zotero-mcp-integrations skill script (inject.js) to generate Zotero field code URIs. Not needed when using the inject_citations MCP tool, which reads the library internally.",
6
6
  inputSchema: {},
7
7
  };
8
8
  export async function handleGetUserId(_zoteroApi, userId, _args) {