Skip to main content
Glama

batch_annotate

Create multiple PDF annotations in one batch operation to minimize calls. Provide an item ID or file path and a list of annotations with page index and coordinates.

Instructions

一次性创建多条 PDF 标注(减少调用次数)。

每条标注需包含 page_index 和 rects,可选 color/text/comment/type。 写操作需要关闭 Zotero 桌面应用。

Args: item_id: Zotero PDF 附件的 itemID(数字),或 PDF 文件的绝对路径 annotations: 标注列表,每项为: {"page_index": int, "rects": [[x0,y0,x1,y1],...], "color": str, "text": str, "comment": str, "type": str}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
item_idYes
annotationsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The batch_annotate handler function: iterates over a list of annotation dicts, caches page_heights via pdf_tools.extract_page_text, and calls zotero_db.create_annotation for each. Returns JSON with count and results.
    @mcp.tool()
    def batch_annotate(
        item_id: str,
        annotations: list[dict],
    ) -> str:
        """一次性创建多条 PDF 标注(减少调用次数)。
    
        每条标注需包含 page_index 和 rects,可选 color/text/comment/type。
        写操作需要关闭 Zotero 桌面应用。
    
        Args:
            item_id: Zotero PDF 附件的 itemID(数字),或 PDF 文件的绝对路径
            annotations: 标注列表,每项为:
                {"page_index": int, "rects": [[x0,y0,x1,y1],...],
                 "color": str, "text": str, "comment": str, "type": str}
        """
        try:
            attachment_id = _resolve_item_id(item_id)
            pdf_path = _resolve_pdf_path(item_id)
    
            # 缓存每页的 page_height,避免重复解析
            page_heights: dict[int, float] = {}
            results = []
    
            for ann in annotations:
                page_idx = ann["page_index"]
                rects = ann["rects"]
    
                if page_idx not in page_heights:
                    page_data = pdf_tools.extract_page_text(pdf_path, page_idx)
                    page_heights[page_idx] = page_data["page_height"]
    
                result = zotero_db.create_annotation(
                    parent_attachment_id=attachment_id,
                    page_index=page_idx,
                    rects=rects,
                    page_height=page_heights[page_idx],
                    color=ann.get("color", "#ffd400"),
                    comment=ann.get("comment", ""),
                    text=ann.get("text", ""),
                    ann_type=ann.get("type", "highlight"),
                )
                results.append(result)
    
            return json.dumps({
                "created": len(results),
                "annotations": results,
                "message": f"已创建 {len(results)} 条标注。请重启 Zotero 或按 Ctrl+Shift+R 刷新查看。",
            }, ensure_ascii=False)
        except sqlite3.OperationalError as e:
            if "locked" in str(e).lower():
                return json.dumps({
                    "error": "database_locked",
                    "message": "Zotero 数据库被锁定,请先关闭 Zotero 桌面应用再重试。",
                }, ensure_ascii=False)
            raise
  • Function signature and docstring defining input schema: item_id (str) and annotations (list[dict] with page_index, rects, and optional color/text/comment/type).
    def batch_annotate(
        item_id: str,
        annotations: list[dict],
    ) -> str:
        """一次性创建多条 PDF 标注(减少调用次数)。
    
        每条标注需包含 page_index 和 rects,可选 color/text/comment/type。
        写操作需要关闭 Zotero 桌面应用。
    
        Args:
            item_id: Zotero PDF 附件的 itemID(数字),或 PDF 文件的绝对路径
            annotations: 标注列表,每项为:
                {"page_index": int, "rects": [[x0,y0,x1,y1],...],
                 "color": str, "text": str, "comment": str, "type": str}
        """
  • Registration via @mcp.tool() decorator on the batch_annotate function (line 263).
    @mcp.tool()
  • Helper _resolve_pdf_path: resolves item_id to a PDF file path (used indirectly by batch_annotate).
    def _resolve_pdf_path(item_id: str) -> Path:
        """将 item_id 解析为 PDF 文件路径。
    
        如果是纯数字,按 Zotero itemID 查找;
        如果包含路径分隔符,按文件路径处理。
        """
        if "/" in item_id or "\\" in item_id or ":" in item_id:
            p = Path(item_id)
            if not p.exists():
                raise FileNotFoundError(f"PDF 文件不存在: {item_id}")
            return p
    
        attachment_id = int(item_id)
        pdf_path = zotero_db.get_pdf_path(attachment_id)
        if pdf_path is None:
            raise FileNotFoundError(
                f"在 Zotero 数据库中未找到 itemID={attachment_id} 对应的 PDF 文件"
            )
        if not pdf_path.exists():
            raise FileNotFoundError(f"PDF 文件在磁盘上不存在: {pdf_path}")
        return pdf_path
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description conveys important behavioral traits: it is a write operation that requires closing the Zotero application. It also specifies required fields for each annotation. It does not detail error handling or atomicity, but the output schema likely covers return values.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is very concise (~6 lines), front-loaded with the main purpose, and organized into clear sections (purpose, requirements, Args). Every sentence adds necessary information without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers input parameters and a critical precondition. The output is not described, but an output schema exists. It is sufficient for an agent to construct correct calls, though a brief note on expected output would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description fully compensates by detailing parameter types, constraints (numeric itemID or file path), and the structure of annotations with required and optional fields, including a JSON example.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it creates multiple PDF annotations at once to reduce API calls, distinguishing it from the sibling 'create_pdf_annotation' which likely creates a single annotation. The verb 'create' and resource 'multiple annotations' are specific.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies use for batching to reduce calls and explicitly states a prerequisite ('close Zotero desktop app'). However, it does not explicitly mention when not to use or directly reference alternatives, though the sibling context suggests it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dengls24/annota'

If you have feedback or need assistance with the MCP directory API, please join our Discord server