Skip to main content
Glama

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
NameRequiredDescriptionDefault
entity_idYes
is_lockedNo

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
  • Registration of the graph_canonicalize_tools module, which includes the lock_entity tool, on the main FastMCP instance.
    register_graph_canonicalize_tools(mcp)
  • 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()

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