Use this skill when you need to inspect, query, maintain, or carefully modify the MoviePilot database. This skill uses the bundled scripts/mp-db.py helper, which reads MoviePilot local settings itself and never requires database passwords or full PostgreSQL DSNs in the agent prompt. Applicable scenarios include data statistics, counts, aggregations, inspecting or fixing records, cleanup requests, and questions like "how many downloads", "show site stats", "delete old records", or "why is this subscription stuck".
72
89%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Low
Low-risk findings worth noting
All script paths are relative to this skill file.
Use scripts/mp-db.py for all database access. Do not extract database passwords, API tokens, or full PostgreSQL DSNs from the prompt. The script reads MoviePilot local settings and connects to SQLite or PostgreSQL internally.
This skill is the direct SQL boundary. It is implemented as a Python script and is appropriate when the agent must inspect records, run data statistics, repair stuck state, or perform an explicitly requested database update.
Prefer safer product surfaces first:
| Request | Preferred skill |
|---|---|
| Normal MoviePilot product operation | moviepilot-api structured operations |
| Operation outside the structured API catalog | A more specific Skill or explicit unsupported result |
| Slash commands or plugin/system command dispatch | command-dispatch |
| Manual file organization | organize-files |
| Retry failed transfer history records | transfer-failed-retry |
Use this skill as the final fallback for data access or mutation. It may run
SELECT, INSERT, UPDATE, DELETE, and schema-changing statements through
the bundled script, but broad or destructive writes still require explicit user
authorization.
System settings have two managed sources and should not normally be edited here:
Settings variables are queried and updated by moviepilot-api
operations config.system.get / config.system.update; updates perform type
conversion and persist to app.env.SystemConfigKey values are stored in the database systemconfig table, but
the same API operations must be preferred because they enforce registered
keys, plugin mutation admission, value normalization, secret redaction, and
configuration-change events.Use direct SQL against systemconfig only for an explicitly authorized repair
when the managed API cannot complete the operation. Inspect the exact row first,
avoid broad writes, and verify the managed API can read the repaired value.
List tables:
python scripts/mp-db.py tablesShow table schema:
python scripts/mp-db.py schema downloadhistoryRun a read query:
python scripts/mp-db.py query "SELECT COUNT(*) AS total FROM downloadhistory"Read SQL from stdin or a file:
python scripts/mp-db.py query --file /path/to/query.sqlRun a write statement:
python scripts/mp-db.py write "UPDATE subscribe SET state = 'S' WHERE id = 123"query --write is also supported for compatibility, but prefer the write subcommand for INSERT, UPDATE, DELETE, and schema changes.
tables first, then schema <table>.SELECT queries, execute directly with a narrow projection and an explicit LIMIT when reading rows.INSERT, UPDATE, DELETE, DROP, ALTER, TRUNCATE, CREATE, or REPLACE, use write and report the affected row count.query defaults to read-only mode.write executes data updates and schema-changing statements directly.query --write remains available as a compatibility alias for write statements.SELECT queries get a default LIMIT 100 if no limit is present.DELETE, DROP, or TRUNCATE.UPDATE or DELETE without a WHERE clause unless the user explicitly intends to affect all rows.tables returns the tables that exist in the current instance. The catalog below covers every MoviePilot ORM table plus Alembic metadata. Always treat the live schema <table> result as authoritative.
agentchatid, session_id, client_session_id, user_id, username, channel, source, original_chat_id, title, preview, agent_messages, display_messages, message_count, created_at, updated_atagentinvocationid, principal_id, session_id, invocation_id, tool_name, arguments_digest, claim_token, status, summary, created_at, updated_atagenttaskid, name, content, trigger_type, cron_expression, run_at, enabled, user_id, username, session_id, channel, source, original_chat_id, last_status, last_run_at, last_result, last_run_id, run_count, created_at, updated_atagenttaskrunid, run_id, task_id, trigger_source, name, content, trigger_type, cron_expression, run_at, user_id, username, session_id, channel, message_source, original_chat_id, status, started_at, finished_at, resultalembic_versionversion_numdownloadfailureid, fingerprint, type, title, year, media_source, media_id, seasons, episodes, site, site_name, torrent_id, torrent_name, torrent_size, downloader, source, error_message, retry_count, first_failed_at, last_failed_at, next_retry_atdownloadfilesid, downloader, download_hash, fullpath, savepath, filepath, torrentname, statedownloadhistoryid, path, type, title, year, media_source, media_id, music_type, seasons, episodes, image, poster, downloader, download_hash, torrent_name, torrent_description, torrent_site, userid, username, channel, date, note, media_category_id, media_category, classification_rule_id, classification_policy_revision, classification_source, episode_group, custom_wordsmediaserveritemid, server, library, item_id, item_type, title, original_title, year, media_source, media_id, path, seasoninfo, note, lst_mod_datemessageid, channel, source, mtype, title, text, image, link, userid, reg_time, action, noteoutboxmessageid, event_key, topic, payload_version, payload, status, attempt, next_retry_at, lease_until, last_error, created_at, completed_atpasskeyid, user_id, credential_id, public_key, sign_count, name, aaguid, created_at, last_used_at, is_active, transportsplugindataid, plugin_id, key, valuepluginidentityid, plugin_id, normalized_plugin_id, trusted_source_type, trusted_source_key, binding_basis, payload_source_type, payload_source_key, declared_version, package_generation, declared_metadata, payload_receipt, revision, created_at, updated_at, bound_at, payload_applied_atplugininstallationid, transaction_id, plugin_id, phase, membership_before, membership_target, identity_before_revision, identity_target_revision, package_existed, persistent_backup_existed, created_at, updated_at, schema_versionplugininstanceid, instance_id, source_plugin_id, plugin_name, plugin_desc, plugin_icon, is_default_target, is_enabled, log_level, log_expires_at, config_data, created_at, updated_atsiteid, name, domain, url, pri, rss, cookie, ua, apikey, token, proxy, filter, render, public, note, limit_interval, limit_count, limit_seconds, timeout, is_active, lst_mod_date, downloadersiteiconid, name, domain, url, base64sitestatisticid, domain, success, fail, seconds, lst_state, lst_mod_date, notesiteuserdataid, domain, name, username, userid, user_level, join_at, bonus, upload, download, ratio, seeding, leeching, seeding_size, leeching_size, seeding_info, message_unread, message_unread_contents, err_msg, updated_day, updated_timesubscribeid, name, year, type, search_interval, keyword, media_source, media_id, music_type, total_tracks, downloaded_tracks, season, poster, backdrop, vote, description, filter, include, exclude, quality, resolution, effect, audio_quality, audio_format, min_bitrate, min_bit_depth, min_sample_rate, total_episode, start_episode, lack_episode, note, state, last_search, last_update, date, username, sites, downloader, best_version, best_version_full, current_priority, current_audio_format, current_bitrate, current_bit_depth, current_sample_rate, episode_priority, save_path, search_imdbid, manual_total_episode, custom_words, media_category_id, media_category, filter_groups, episode_groupsubscribehistoryid, name, year, type, search_interval, keyword, media_source, media_id, music_type, total_tracks, season, poster, backdrop, vote, description, filter, include, exclude, quality, resolution, effect, audio_quality, audio_format, min_bitrate, min_bit_depth, min_sample_rate, total_episode, start_episode, date, username, sites, best_version, best_version_full, current_priority, current_audio_format, current_bitrate, current_bit_depth, current_sample_rate, episode_priority, save_path, search_imdbid, custom_words, media_category_id, media_category, classification_rule_id, classification_policy_revision, classification_source, filter_groups, episode_groupsubscriptionsearchbatchid, batch_id, source, state, priority, total_count, finished_count, failed_count, cancelled_count, skipped_count, cancel_requested, created_at, updated_at, started_at, finished_at, last_errorsubscriptionsearchtaskid, task_id, batch_id, subscription_id, active_key, source, priority, position, state, phase, current_site_id, pending_site_ids, attempt_count, cancel_requested, lease_owner, lease_token, lease_expires_at, available_at, created_at, updated_at, started_at, finished_at, last_errorsubscriptionsitebudgetid, site_id, lease_owner, lease_token, lease_expires_at, next_allowed_at, consecutive_failures, success_streak, last_outcome, last_error, updated_atsystemconfigid, key, valuetransferexecutionstepid, task_id, operation_id, checkpoint_fingerprint, ordinal, phase, kind, state, attempt_token, attempt_count, intent_version, intent_payload, result_version, result_payload, last_error, prepared_at, started_at, completed_at, updated_attransferhistoryid, transfer_task_id, transfer_settlement_revision, src, src_storage, src_fileitem, dest, dest_storage, dest_fileitem, mode, type, media_category_id, category, classification_rule_id, classification_policy_revision, classification_source, title, year, media_source, media_id, music_type, total_tracks, audio_format, audio_lossless, bit_depth, sample_rate, bitrate, seasons, episodes, image, downloader, download_hash, status, errmsg, retry_count, auto_paused, failure_stage, recovery_action, cleanup_status, cleanup_error, date, files, episode_grouptransferpendingid, task_id, storage, src_path, created_at, state, updated_at, last_error, input_version, planning_input, input_fingerprint, checkpoint_version, checkpoint_payload, planned_at, lease_owner, lease_token, lease_expires_at, heartbeat_at, attempt_count, execution_state, execution_version, execution_payload, execution_fingerprint, retry_generation, retry_count, retry_due_at, retry_requested_by, retry_reason, settlement_revision, terminal_history_id, manual_review_revision, reviewed_at, reviewed_by, review_reason, review_decisiontransfersettlementreceiptid, task_id, history_id, settlement_revision, outcome, execution_fingerprint, lease_token, history_status, src, src_storage, pending_deleted, error, created_at, updated_atuserid, name, email, hashed_password, is_active, is_superuser, avatar, is_otp, otp_secret, permissions, settingsuserconfigid, username, key, valueworkflowid, name, description, timer, trigger_type, event_type, event_conditions, state, current_action, result, run_count, actions, flows, context, execution_config, execution_state, add_time, last_timetables: arguments={} lists current database tables.schema: arguments={"table_name":"downloadhistory"}; table_name must come from tables.query: arguments={"sql":"SELECT ...","limit":100,"write":false}; provide exactly one of sql and file. SELECT/WITH/EXPLAIN are allowed by default.write: arguments={"sql":"UPDATE ... WHERE ..."}; provide exactly one of sql and file and only one statement.file is a local SQL path readable by the MoviePilot process. MCP clients normally send sql directly.Use the live schema result instead of guessing columns from older documentation. Treat media_source and media_id as one atomic identity pair.
Total downloads:
SELECT COUNT(*) AS total FROM downloadhistoryRecent download history:
SELECT title, year, type, torrent_site, date FROM downloadhistory ORDER BY id DESC LIMIT 10Failed transfers:
SELECT id, title, src, errmsg, date FROM transferhistory WHERE status = 0 ORDER BY id DESC LIMIT 10Active subscriptions:
SELECT name, year, type, season, state, lack_episode FROM subscribe WHERE state = 'R' LIMIT 50Site upload/download statistics:
SELECT name, domain, upload, download, ratio, bonus, seeding, user_level FROM siteuserdata ORDER BY upload DESC LIMIT 50Media library statistics:
SELECT server, library, COUNT(*) AS count FROM mediaserveritem GROUP BY server, librarySite access success rate:
SELECT domain, success, fail, ROUND(success * 100.0 / (success + fail), 1) AS success_rate FROM sitestatistic WHERE success + fail > 0 ORDER BY success_rate DESC LIMIT 50Plugin data keys:
SELECT plugin_id, key FROM plugindata ORDER BY plugin_id, key LIMIT 100| Feature | SQLite | PostgreSQL |
|---|---|---|
| Boolean values | 0 / 1 | false / true |
| String concat | ` | |
| Current time | datetime('now') | NOW() |
| JSON access | json_extract(col, '$.key') | col->>'key' |
| Case-insensitive match | LIKE | ILIKE |
moviepilot doctor.python scripts/mp-db.py tables, then inspect the table with schema.4f716c4
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.