zotero_get_item_children
Retrieve all child items, such as attachments and notes, associated with a specific Zotero library item using the provided item key. Streamline research by accessing detailed content linked to your references.
Instructions
Get all child items (attachments, notes) for a specific Zotero item.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| item_key | Yes |
Implementation Reference
- src/zotero_mcp/server.py:534-645 (handler)The complete implementation of the zotero_get_item_children tool. This handler function retrieves child items (attachments, notes, and others) for a specified Zotero item using the pyzotero library, categorizes them, formats the details into markdown sections, and returns the result. The @mcp.tool decorator registers it with the specified name and description.name="zotero_get_item_children", description="Get all child items (attachments, notes) for a specific Zotero item." ) def get_item_children( item_key: str, *, ctx: Context ) -> str: """ Get all child items (attachments, notes) for a specific Zotero item. Args: item_key: Zotero item key/ID ctx: MCP context Returns: Markdown-formatted list of child items """ try: ctx.info(f"Fetching children for item {item_key}") zot = get_zotero_client() # First get the parent item details try: parent = zot.item(item_key) parent_title = parent["data"].get("title", "Untitled Item") except Exception: parent_title = f"Item {item_key}" # Then get the children children = zot.children(item_key) if not children: return f"No child items found for: {parent_title} (Key: {item_key})" # Format children as markdown output = [f"# Child Items for: {parent_title}", ""] # Group children by type attachments = [] notes = [] others = [] for child in children: data = child.get("data", {}) item_type = data.get("itemType", "unknown") if item_type == "attachment": attachments.append(child) elif item_type == "note": notes.append(child) else: others.append(child) # Format attachments if attachments: output.append("## Attachments") for i, att in enumerate(attachments, 1): data = att.get("data", {}) title = data.get("title", "Untitled") key = att.get("key", "") content_type = data.get("contentType", "Unknown") filename = data.get("filename", "") output.append(f"{i}. **{title}**") output.append(f" - Key: {key}") output.append(f" - Type: {content_type}") if filename: output.append(f" - Filename: {filename}") output.append("") # Format notes if notes: output.append("## Notes") for i, note in enumerate(notes, 1): data = note.get("data", {}) title = data.get("title", "Untitled Note") key = note.get("key", "") note_text = data.get("note", "") # Clean up HTML in notes note_text = note_text.replace("<p>", "").replace("</p>", "\n\n") note_text = note_text.replace("<br/>", "\n").replace("<br>", "\n") # Limit note length for display if len(note_text) > 500: note_text = note_text[:500] + "...\n\n(Note truncated)" output.append(f"{i}. **{title}**") output.append(f" - Key: {key}") output.append(f" - Content:\n```\n{note_text}\n```") output.append("") # Format other item types if others: output.append("## Other Items") for i, other in enumerate(others, 1): data = other.get("data", {}) title = data.get("title", "Untitled") key = other.get("key", "") item_type = data.get("itemType", "unknown") output.append(f"{i}. **{title}**") output.append(f" - Key: {key}") output.append(f" - Type: {item_type}") output.append("") return "\n".join(output) except Exception as e: ctx.error(f"Error fetching item children: {str(e)}") return f"Error fetching item children: {str(e)}"