On this page

Schedule the checks

Run the StitchDB monitoring prompts on a schedule with Claude Code, Codex or Cursor, with only read-only tools pre-approved, and send reports to an issue tracker, Telegram or e-mail.

Run each monitoring prompt on its own schedule: health and performance every hour, security and resources once a day. Whatever runs it, set it up the same way:

  1. Connect StitchDB with read_only=true and features=monitoring (below).
  2. Pre-approve only the read-only StitchDB tools, reading the checks file from stitchdb.com, and writing the state file. Leave everything else on ask or deny.
  3. Run the prompt once by hand and check its report before you schedule it.
MCP server URL
https://stitchdb.com/platform/mcp?project_ref=<ref>&read_only=true&features=monitoring

#Claude Code

#Scheduled tasks in the cloud (/schedule)

Cloud scheduled tasks (also called routines) run on a schedule while your computer is off.

  1. Add StitchDB as a connector on claude.ai (Customize › Connectors › Add custom connector) with the MCP URL above and sign in with read-only access (see claude.ai connector).
  2. In Claude Code run /schedule and describe the task, for example "every hour at :07, run the StitchDB health check", and paste the prompt; or create it at claude.ai/code/routines. For a cadence the presets lack, use /schedule update with a cron expression (at most once an hour; plain cron hours are UTC).
  3. Under Connectors keep only StitchDB (and your issue tracker if it reports there). All your connectors are included by default.
  4. In the task's cloud environment, add stitchdb.com to Allowed domains so the run can load the checks file. Connector calls do not need it.

Each cloud run starts from a fresh copy of the repository, so a state file does not survive between runs. Use your issue tracker as the state instead (see report destinations), or let the run commit the state file to a branch of its own.

#On your computer (/loop and Desktop tasks)

Save the prompt as a file in a folder for monitoring and pre-approve the read-only tools in that folder's .claude/settings.json:

.claude/settings.json
{
  "permissions": {
    "allow": [
      "mcp__stitchdb__query_logs",
      "mcp__stitchdb__get_logs",
      "mcp__stitchdb__get_advisors",
      "mcp__stitchdb__check_exposure",
      "mcp__stitchdb__execute_sql",
      "mcp__stitchdb__list_connections",
      "mcp__stitchdb__get_usage",
      "mcp__stitchdb__get_project",
      "mcp__stitchdb__list_storage_buckets",
      "mcp__stitchdb__list_policies",
      "mcp__stitchdb__list_edge_functions",
      "mcp__stitchdb__get_edge_function_logs",
      "mcp__stitchdb__search_docs",
      "WebFetch(domain:stitchdb.com)",
      "Read(./.stitchdb/**)",
      "Edit(./.stitchdb/**)"
    ],
    "deny": [
      "mcp__stitchdb__apply_migration",
      "mcp__stitchdb__deploy_edge_function"
    ]
  }
}
Terminal
claude mcp add --transport http --scope project stitchdb \
  "https://stitchdb.com/platform/mcp?project_ref=<ref>&read_only=true&features=monitoring" \
  --header "Authorization: Bearer ${STITCHDB_ACCESS_TOKEN}"

# then, in Claude Code in that folder:
/loop 1h follow the instructions in prompts/health.md

/loop runs while the session is open and stops after seven days. For checks that should keep running, create a Desktop scheduled task in the Claude desktop app (Code › Scheduled › New task › Local) with the same folder and prompt; it runs whenever your computer is on.

#Codex

Add StitchDB to ~/.codex/config.toml, with enabled_tools as an allow list of the read-only tools:

~/.codex/config.toml
[mcp_servers.stitchdb]
url = "https://stitchdb.com/platform/mcp?project_ref=<ref>&read_only=true&features=monitoring"
bearer_token_env_var = "STITCHDB_ACCESS_TOKEN"
enabled_tools = ["query_logs", "get_logs", "get_advisors", "check_exposure", "execute_sql", "list_connections", "get_usage", "get_project", "list_storage_buckets", "list_policies", "list_edge_functions", "get_edge_function_logs", "search_docs"]
  • Codex app: open Scheduled in the sidebar (or ask in a thread: "create a scheduled task that runs every hour: …" and paste the prompt), choose the monitoring folder and the workspace-write sandbox so it can write the state file. Runs with findings appear in the Scheduled inbox; the app must be running.
  • Codex CLI with cron: codex exec runs one prompt without a session. The script below loads the checks file with curl first (so the run fails loudly when it cannot), points CHECKS_URL at .stitchdb/checks.json, and sends a report only when there is one:
run-check.sh
#!/bin/sh
# run-check.sh <area>: one monitoring run with Codex, report only when there is something to say
set -u
area="$1"; cd "$(dirname "$0")"; mkdir -p .stitchdb
if ! curl -fsS https://stitchdb.com/agent/checks/v1.json -o .stitchdb/checks.json; then
  echo "StitchDB $area check FAILED: could not load checks" | ./notify.sh; exit 1
fi
codex exec --sandbox workspace-write --output-last-message ".stitchdb/last-$area.txt" \
  "$(cat "prompts/$area.md")" > /dev/null 2>> ".stitchdb/codex-$area.log"
grep -qx "No new findings." ".stitchdb/last-$area.txt" || ./notify.sh < ".stitchdb/last-$area.txt"
crontab -e
# m h dom mon dow
7 * * * *  $HOME/stitchdb-monitor/run-check.sh health
17 * * * * $HOME/stitchdb-monitor/run-check.sh performance
30 6 * * * $HOME/stitchdb-monitor/run-check.sh security
40 6 * * * $HOME/stitchdb-monitor/run-check.sh resources

In the prompt files for this script set CHECKS_URL: .stitchdb/checks.json, since the workspace-write sandbox has no network access of its own (MCP calls still work).

#Cursor

Cursor automations run a cloud agent on a schedule.

  1. Open cursor.com/automations (or run /automate in an agent session) and create an automation with a Scheduled trigger: a preset or a cron expression such as 7 * * * *.
  2. Paste the prompt and set STATE_FILE: your automation memory (MEMORIES.md); keep the Memories tool on so the alert state survives between runs.
  3. Under tools add an MCP server: the URL above with the header Authorization: Bearer sdb_pat_… of a read-only token. The agent gets every tool that server offers, which is why the URL itself is read-only and limited with features.
  4. Turn off the tools a monitoring run does not need (pull request creation, computer use), choose no repository, and add Send to Slack if you want reports there.

If the server refuses the token, the run continues without StitchDB tools and the run page shows an MCP authentication error: the prompt then fails loudly because it cannot measure anything.

#Report destinations

By default the report is the agent's answer. To send it somewhere, add a REPORT TO line to the prompt and allow only that one action, or pipe the answer of a scripted run into a small notify.sh. Clean runs send nothing.

#Issue tracker

Prompt
REPORT TO: when there are new or worse findings, open one issue per finding in acme/app with the label stitchdb-alert, titled "<check id>: <subject>". Search open issues with that label first: comment on an existing one instead of opening a duplicate, and close issues whose finding cleared. Use the issues as your alert state.
notify.sh
#!/bin/sh
# notify.sh: open a GitHub issue with the report (gh must be signed in)
gh issue create --repo acme/app --label stitchdb-alert \
  --title "StitchDB: $(head -n 1)" --body-file -

In Claude Code cloud tasks and Cursor automations, add your issue tracker as a connector or MCP server instead and allow only creating, commenting and closing issues.

#Telegram

notify.sh
#!/bin/sh
# notify.sh: send stdin to a Telegram chat (create a bot with @BotFather, then get your chat id)
curl -fsS "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
  -d chat_id="$TELEGRAM_CHAT_ID" --data-urlencode text@- > /dev/null

#E-mail

notify.sh
#!/bin/sh
# notify.sh: e-mail stdin (any mail transfer agent with sendmail works)
{ printf 'To: [email protected]\nSubject: StitchDB monitoring\n\n'; cat; } | sendmail -t

With a mail connector in your agent, a line such as REPORT TO: e-mail the report to [email protected] with the subject "StitchDB <area> check" works the same way.

#No agent needed

For alerts without running an agent, use what is built in: Studio › Advisors › Health, scheduled reports with Only send when the query returns rows (any SQL check from the checks file works), Job monitoring and Project budgets. They alert by e-mail, Telegram or webhook.