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
| Name | Required | Description | Default |
|---|---|---|---|
| doc_id | Yes | ||
| title | No | ||
| authors | No | ||
| year | No | ||
| venue | No | ||
| doi | No | ||
| url | No |
Implementation Reference
- src/paperlib_mcp/tools/fetch.py:439-579 (handler)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, }
- src/paperlib_mcp/server.py:36-36 (registration)Invocation of register_fetch_tools(mcp) which registers the update_document tool (and other fetch tools) with the MCP server.register_fetch_tools(mcp)