Skip to content

Database Models API

The backend utilizes SQLAlchemy for ORM-based interactions with the SQLite/PostgreSQL database.

Location: backend/app/models/


User Model

File: user.py

Represents the identity of an actor in the system. The system supports both authenticated "Registered Users" and temporary "Guest Users".

python
class User(Base):
    __tablename__ = "Users"
Field NameTypeKeyDescription
idStringPKUnique Identifier (typically UUID).
usernameStringDisplay name (Nullable for guests).
emailStringLogin email (Nullable for guests).
is_guestBooleanTrue for temporary sessions, False for persistent accounts.
tool_permissionsListOne-to-Many relation to ToolPermission.

MCP Server Settings

File: settings.py

This is a critical model that stores the User Configuration for external tools. It holds the "keys to the kingdom" (auth tokens), so security here is paramount.

python
class McpServerSetting(Base):
    __tablename__ = "mcp_server_settings"
Field NameTypeDescription
server_nameStringUnique Index (with user_id). A user-friendly name (e.g., "My Notion").
server_urlStringThe endpoint (e.g., https://api.notion.com/v1/mcp).
credentialsJSON StringSENSITIVE. Stores {access_token, refresh_token}. In production, this column should be encrypted at rest.
client_id / secretStringOAuth client details required for token refreshing.
tools_manifestJSON StringA textual cache of the tools/list response. Used to speed up agent boot time by avoiding initial introspection network calls.

Tool Permissions

File: tool_permissions.py

The system checks these records before allowing the Agent to invoke any tool.

Model: ToolPermission

Global Switch: Controls whether a specific tool (e.g., "delete_page") is fundamentally enabled for a user on a server.

Field NameTypeDescription
user_idFKThe owner.
server_setting_idFKThe server this tool belongs to.
tool_nameStringThe exact function name (e.g., notion_archive_page).
is_enabledBooleanIf False, the tool is completely hidden from the Agent's view.

Model: ToolApproval

Runtime Governance: Used by the "Human-in-the-loop" system. Tracks whether a user has pre-approved a tool's execution.

Field NameTypeDescription
approval_typeStringEnum: once (approve just this call), always (whitelist for future), never (blacklist).
expires_atDateTimeOptional. Allows granting temporary access (e.g., "Allow for 1 hour").