Skip to main content
Glama

update_document

Modify metadata for academic papers in Paperlib MCP. Update specific fields like title, authors, year, venue, DOI, or URL while preserving unchanged information.

Instructions

更新指定文档的元数据

根据 doc_id 更新文档的元数据信息。只有提供的字段会被更新, 未提供的字段保持原值不变。

Args: doc_id: 文档的唯一标识符(SHA256 哈希) title: 新的论文标题 authors: 新的作者列表 year: 新的发表年份 venue: 新的期刊/会议名称 doi: 新的 DOI 标识符 url: 新的论文链接

Returns: 更新结果,包含: - success: 是否成功 - doc_id: 文档 ID - updated_fields: 更新的字段列表 - document: 更新后的文档信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doc_idYes
titleNo
authorsNo
yearNo
venueNo
doiNo
urlNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function that implements the logic for updating document metadata in the database. Decorated with @mcp.tool() to register it as an MCP tool.
    @mcp.tool()
    def update_document(
        doc_id: str,
        title: str | None = None,
        authors: str | None = None,
        year: int | None = None,
        venue: str | None = None,
        doi: str | None = None,
        url: str | None = None,
    ) -> dict[str, Any]:
        """更新指定文档的元数据
        
        根据 doc_id 更新文档的元数据信息。只有提供的字段会被更新,
        未提供的字段保持原值不变。
        
        Args:
            doc_id: 文档的唯一标识符(SHA256 哈希)
            title: 新的论文标题
            authors: 新的作者列表
            year: 新的发表年份
            venue: 新的期刊/会议名称
            doi: 新的 DOI 标识符
            url: 新的论文链接
            
        Returns:
            更新结果,包含:
            - success: 是否成功
            - doc_id: 文档 ID
            - updated_fields: 更新的字段列表
            - document: 更新后的文档信息
        """
        try:
            # 检查文档是否存在
            existing = query_one(
                "SELECT doc_id FROM documents WHERE doc_id = %s",
                (doc_id,)
            )
            
            if not existing:
                return {
                    "success": False,
                    "error": f"Document not found: {doc_id}",
                    "doc_id": doc_id,
                }
            
            # 收集要更新的字段
            update_fields = []
            update_values = []
            updated_field_names = []
            
            if title is not None:
                update_fields.append("title = %s")
                update_values.append(title)
                updated_field_names.append("title")
            
            if authors is not None:
                update_fields.append("authors = %s")
                update_values.append(authors)
                updated_field_names.append("authors")
            
            if year is not None:
                update_fields.append("year = %s")
                update_values.append(year)
                updated_field_names.append("year")
            
            if venue is not None:
                update_fields.append("venue = %s")
                update_values.append(venue)
                updated_field_names.append("venue")
            
            if doi is not None:
                update_fields.append("doi = %s")
                update_values.append(doi)
                updated_field_names.append("doi")
            
            if url is not None:
                update_fields.append("url = %s")
                update_values.append(url)
                updated_field_names.append("url")
            
            if not update_fields:
                return {
                    "success": False,
                    "error": "No fields to update. Please provide at least one field.",
                    "doc_id": doc_id,
                }
            
            # 添加 updated_at
            update_fields.append("updated_at = now()")
            
            # 构建并执行 UPDATE 语句
            update_sql = f"""
                UPDATE documents
                SET {', '.join(update_fields)}
                WHERE doc_id = %s
                RETURNING 
                    doc_id, title, authors, year, venue, doi, url,
                    pdf_bucket, pdf_key, pdf_sha256,
                    created_at::text, updated_at::text
            """
            update_values.append(doc_id)
            
            with get_db() as conn:
                with conn.cursor() as cur:
                    cur.execute(update_sql, tuple(update_values))
                    updated_doc = cur.fetchone()
            
            if not updated_doc:
                return {
                    "success": False,
                    "error": f"Failed to update document: {doc_id}",
                    "doc_id": doc_id,
                }
            
            return {
                "success": True,
                "doc_id": doc_id,
                "updated_fields": updated_field_names,
                "document": {
                    "doc_id": updated_doc["doc_id"],
                    "title": updated_doc["title"],
                    "authors": updated_doc["authors"],
                    "year": updated_doc["year"],
                    "venue": updated_doc["venue"],
                    "doi": updated_doc["doi"],
                    "url": updated_doc["url"],
                    "pdf_bucket": updated_doc["pdf_bucket"],
                    "pdf_key": updated_doc["pdf_key"],
                    "pdf_sha256": updated_doc["pdf_sha256"],
                    "created_at": updated_doc["created_at"],
                    "updated_at": updated_doc["updated_at"],
                },
            }
            
        except Exception as e:
            return {
                "success": False,
                "error": str(e),
                "doc_id": doc_id,
            }
  • Invocation of register_fetch_tools(mcp) which registers the update_document tool (and other fetch tools) with the MCP server.
    register_fetch_tools(mcp)
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It explains the partial update behavior and describes the return structure, which is helpful. However, it doesn't mention important behavioral aspects like authentication requirements, error handling, rate limits, or whether the operation is idempotent. For a mutation tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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

Conciseness4/5

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

The description is well-structured with clear sections: purpose statement, behavioral note about partial updates, parameter documentation, and return value description. It's appropriately sized for a 7-parameter mutation tool. While efficient, the Chinese-to-English translation creates some minor redundancy in the parameter documentation that could be slightly more concise.

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?

Given this is a mutation tool with no annotations but with an output schema (implied by the Returns section), the description provides good coverage. It explains the partial update behavior, documents all parameters thoroughly, and describes the return structure. However, it lacks information about authentication, error conditions, and rate limits which would be important for a mutation operation.

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?

The description provides excellent parameter semantics despite 0% schema description coverage. It clearly documents all 7 parameters with their purposes: 'doc_id: 文档的唯一标识符(SHA256 哈希)' (document's unique identifier - SHA256 hash), and explains what each field represents (title, authors, year, venue, doi, url). This fully compensates for the lack of schema descriptions and adds meaningful context beyond just parameter names.

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

Purpose4/5

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

The description clearly states the tool's purpose: '更新指定文档的元数据' (Update the metadata of a specified document). It specifies the resource (document metadata) and the action (update), but doesn't differentiate from sibling tools like 'delete_document' or 'get_document' beyond the basic verb difference. The description is specific but lacks explicit sibling differentiation.

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

Usage Guidelines2/5

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

The description provides minimal usage guidance. It mentions that '只有提供的字段会被更新,未提供的字段保持原值不变' (Only provided fields will be updated, unprovided fields remain unchanged), which gives some context about partial updates. However, it doesn't specify when to use this tool versus alternatives like 'delete_document' or 'get_document', nor does it mention prerequisites, permissions, or error conditions.

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/h-lu/paperlib-mcp'

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