lock_entity
Prevent automatic normalization and merging of academic literature entities by locking them in Paperlib MCP. Specify entity ID and lock status to control entity management.
Instructions
锁定或解锁实体
锁定的实体不会被自动规范化合并。
Args: entity_id: 实体 ID is_locked: 是否锁定,默认 True
Returns: 操作结果
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entity_id | Yes | ||
| is_locked | No |
Implementation Reference
- The handler function for the 'lock_entity' tool. Updates the 'is_locked' field in the 'entities' table for the given entity_id.@mcp.tool() def lock_entity(entity_id: int, is_locked: bool = True) -> dict[str, Any]: """锁定或解锁实体 锁定的实体不会被自动规范化合并。 Args: entity_id: 实体 ID is_locked: 是否锁定,默认 True Returns: 操作结果 """ try: with get_db() as conn: with conn.cursor() as cur: cur.execute( """ UPDATE entities SET is_locked = %s, updated_at = now() WHERE entity_id = %s RETURNING entity_id """, (is_locked, entity_id) ) result = cur.fetchone() if not result: return LockEntityOut( ok=False, error=MCPErrorModel(code="NOT_FOUND", message=f"Entity {entity_id} not found"), ).model_dump() return LockEntityOut(ok=True).model_dump() except Exception as e: return LockEntityOut( ok=False, error=MCPErrorModel(code="DB_CONN_ERROR", message=str(e)), ).model_dump()
- Pydantic schemas defining input (LockEntityIn) and output (LockEntityOut) models for the lock_entity tool.class LockEntityIn(BaseModel): """lock_entity 输入""" entity_id: int is_locked: bool = True class LockEntityOut(BaseModel): """lock_entity 输出""" ok: bool error: Optional[MCPErrorModel] = None
- src/paperlib_mcp/server.py:41-41 (registration)Registration of the graph_canonicalize_tools module, which includes the lock_entity tool, on the main FastMCP instance.register_graph_canonicalize_tools(mcp)
- src/paperlib_mcp/tools/graph_canonicalize.py:329-368 (registration)The @mcp.tool() decorator registers the lock_entity function directly when the register_graph_canonicalize_tools function is called.@mcp.tool() def lock_entity(entity_id: int, is_locked: bool = True) -> dict[str, Any]: """锁定或解锁实体 锁定的实体不会被自动规范化合并。 Args: entity_id: 实体 ID is_locked: 是否锁定,默认 True Returns: 操作结果 """ try: with get_db() as conn: with conn.cursor() as cur: cur.execute( """ UPDATE entities SET is_locked = %s, updated_at = now() WHERE entity_id = %s RETURNING entity_id """, (is_locked, entity_id) ) result = cur.fetchone() if not result: return LockEntityOut( ok=False, error=MCPErrorModel(code="NOT_FOUND", message=f"Entity {entity_id} not found"), ).model_dump() return LockEntityOut(ok=True).model_dump() except Exception as e: return LockEntityOut( ok=False, error=MCPErrorModel(code="DB_CONN_ERROR", message=str(e)), ).model_dump()