Skip to content

ADFA-7300: AI-Agent-MCP switch to let the Agent change app databases - #178

Open
davidschachterADFA wants to merge 6 commits into
sqlite-debugger/ADFA-7139from
sqlite-debugger/ADFA-7300
Open

davidschachterADFA wants to merge 6 commits into
sqlite-debugger/ADFA-7139from
sqlite-debugger/ADFA-7300

Conversation

@davidschachterADFA

@davidschachterADFA davidschachterADFA commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

ADFA-7300

Phase 2, P2-5 of the SQLite debugger (ADFA-7131 comment 41476, decision D14): AI-Agent-MCP lets the Agent use the debugger's execute tool, behind one switch, with the user's approval on every call. Stacked on #166 (sqlite-debugger/ADFA-7139); merge it after #166. On the device it needs CodeOnTheGo P2-3 (#2312, execute) and P2-4 (#2313, acknowledge_room).

What it does (plugins/AI-Agent-MCP)

  • The automatic SQLite debugger entry has no settings, so nothing could switch its execute on. David chose one switch (2026-11-25, ADFA-7300 comment 41560): "Let the Agent change app databases" at the top of the MCP servers screen, off by default, for every app (McpServerStore.allowDatabaseWrites). Changing it tells the change listeners, so the Agent's tool list follows.
  • ReadOnlyTrust.WRITE_TOOLS (execute) is offered only while the switch is on, and is never declared read-only, whatever hint the server sends (isReadOnly). So AI-Core asks before every call and never offers Always Allow for it.
  • A tooltip entry and long-press wiring for the switch; the README, ai-agent-mcp.html, the in-IDE help and the plugin tooltip are updated.
  • Version 2.1.0 / versionCode 4 (MINOR, on ADFA-7139: AI-Agent-MCP connects to the SQLite debugger automatically #166's 2.0.0 / 3).
  • With the switch on, each app offers five tools; in compact mode (4), AI-Core drops the first app's get_events (README).
  • While the switch is off, an app's query description ends with a sentence saying the user can switch writes on in the MCP servers screen (the switch's own label), and that the databases must not be changed any other way (ReadOnlyTrust.needsWriteSwitchHint, 29cbd00). On the Note 20, told only "use execute", a tool it didn't have, the model asked to run sqlite3 in the shell instead. The shell can't reach another app's private files, but the user was never told about the switch.
  • When SQLite refuses a write sent through an app's query while the switch is off ("not authorized", or a read-only database), the same sentence follows the failure's text (ReadOnlyTrust.isWriteRefusal, 4e2c0e7). AI-Core shows that text as the details, and it replaces the Agent's own answer after a failed call with "I couldn't complete that, the last action failed" (ADFA-7318). So the details are the one place the user is sure to see it. It also matches a refused BEGIN, SAVEPOINT, ATTACH or setting PRAGMA, which execute refuses too, so there the sentence names a switch that would not help. Accepted, and said in the KDoc (3ef6bac): the server reports every refusal as SQLite's plain "not authorized", and copying its authorizer's rules into the plugin would drift.
  • A switch that cannot be saved stays as it was (190f7e6). SharedPreferences keeps a value it failed to write in memory, so the switch looked on for the session and turned back at restart; the old value is now put back, no listener is told, and the screen sets the switch back with a toast: "The setting could not be saved, so it is unchanged."

Tests (local)

  • At c5caa68 (2026-11-30, David: merges ADFA-7139: AI-Agent-MCP connects to the SQLite debugger automatically #166 at 265fd64, which brings main and plugin.min_ide_version 26.49; no conflicts; this PR's own diff is unchanged, same patch-id): testDebugUnitTest 366, 0 failures; assemblePlugin and the addons check pass; the .cgp records 26.49 to 26.99.
  • At 3ef6bac, for the 2026-11-26 review (ADFA-7131 comment 41632): testDebugUnitTest 366, 0 failures; assemblePlugin and the addons check pass.
    • New WriteToolTest case: with every commit failing, the switch stays off, in memory too, and no listener is told; then it saves.
    • Revert proof: with the failure only logged, that test fails.
    • The toast was not checked on a device: it needs a failing disk write.
  • At 4e2c0e7: testDebugUnitTest 365, 0 failures. New: three WriteToolTest cases: switch off, a refused write's text gets the sentence; switch on, it passes through; another failure passes through. Revert proof: with errorWithHint bypassed, "with the switch off, a write refused through query says how writes get allowed" fails. assemblePlugin and the addons check pass.
  • At 29cbd00: testDebugUnitTest 362, 0 failures. New: four WriteToolTest cases: switch off gives the hint, with the exact text; switch on gives none; a debugger without execute gives none; a hand-added server's text passes through. Revert proof: with only the hint in describe() removed, "with the switch off, query says how writes get allowed" fails. assemblePlugin and the addons check pass.
  • At 7560587 (the cloud session's commit):
    • testDebugUnitTest: 358 tests in 69 classes, 0 failures. New: WriteToolTest (5: off by default even claiming the hint; on: offered, asks every time, not read-only; off again; listeners told; a hand-added server's execute stays an ordinary tool) and three ReadOnlyHintParsingTest cases (execute off unless writes are allowed; never read-only; allowing writes switches on no other tool).
    • Revert proof: without the WRITE_TOOLS exclusion in ReadOnlyTrust.isReadOnly, two tests fail: "execute is never read-only, even claiming the hint" (assertFalse(ReadOnlyTrust.isReadOnly(...))) and "with the switch on execute is offered, asks every time and is not read-only" (assertTrue(execute.requiresApproval())).
    • assemblePlugin: ai-agent-mcp.cgp, 10.3 MB, version 2.1.0. The addons check passes.

Device (Note 20, Code on the Go C-d-1125-0922 with P2-3 and P2-4, 2026-11-25; ADFA-7300 comment 41577):

  • Passed at 7560587: the switch is at the top of the MCP servers screen and off by default. At font scale 1.0 and 2.0, light and dark, its text and summary wrap with nothing cut off. With the switch off, the app offers 4 tools and no execute, and nothing was written. With it on, the app offers 5.
  • Third run at 29cbd00, with AI Core 3.7.0 installed for the run (ADFA-7300 comment 41584): the first execute dialog offered only Run Now and Decline, with no Always Allow. After Decline, nothing was written. After approval, the row was written, and it shows in the app before and after a restart.
  • The Room warning wasn't shown: the model put acknowledge_room: true in its first execute call (David: that's acceptable, P2-4 stays as it is). The Agent's answer mentioned the Room caveat after the write.
  • With the switch off, the model tried the shell (declined), then an INSERT through query (refused). AI-Core showed only its stock failure line, so the description's sentence didn't reach the user. 4e2c0e7 puts the sentence in the failure's text. A fourth run checked it on the device (ADFA-7300 comment 41587): the refused INSERT's details end with the sentence, which names "Let the Agent change app databases". Nothing was written.

No other screens changed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn

Phase 2, P2-5 (ADFA-7131 comment 41476, decision D14). On #166
(sqlite-debugger/ADFA-7139 at 38b5268). Needs CodeOnTheGo P2-3 and
P2-4 (execute, acknowledge_room) on the device.

- The automatic SQLite debugger entry has no settings, so nothing could
  switch its execute on. David chose one switch (2026-11-25): "Let the
  Agent change app databases" at the top of the MCP servers screen, off
  by default, for every app (McpServerStore.allowDatabaseWrites). It
  tells the change listeners, so the Agent's tool list follows.
- ReadOnlyTrust.WRITE_TOOLS ("execute") is offered only while it is on,
  and never declared read-only, whatever hint the server sends
  (isReadOnly). So AI-Core asks before every call and never offers
  Always Allow for it.
- Tooltip entry and long-press wiring for the switch; README,
  ai-agent-mcp.html, the in-IDE help and the plugin tooltip updated.
- Version 2.1.0 / versionCode 4 (MINOR, on #166's 2.0.0 / 3).

With the switch on, each app offers five tools; in compact mode (4)
AI-Core drops the first app's get_events (README).

Tests: WriteToolTest (off by default even claiming the hint; on: asks
and not read-only; off again; listeners told; a hand-added server's
execute stays ordinary) and three ReadOnlyHintParsingTest cases. Not
run here: no Android SDK or AndroidX (dl.google.com is blocked), so
neither Gradle nor these tests ran. ReadOnlyTrust and McpTool were
compiled alone with a scratch check of the same rules (8 checks pass;
isReadOnly without the WRITE_TOOLS exclusion fails "execute never
read-only"). The addons check passes. Not run: testDebugUnitTest,
assemblePlugin, the device check, font scale 1.0 and 2.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAZ8yszEP4MqbR9PLba
davidschachterADFA and others added 2 commits November 25, 2026 13:13
…he switch is off

On a Note 20 (2026-11-25), with "Let the Agent change app databases" off,
the Agent was asked to add a row. The SQLite debugger's query description
says "Writes are refused: use execute", but execute was not offered, so the
model asked to run sqlite3 on the app's database through
run_shell_command instead. The shell would not reach another app's private
files, and the call needs approval each time, but the user was never told
about the switch.

While an app's entry lists execute and the switch keeps it off, that
entry's query description now ends with a sentence saying the user can
switch writes on in the MCP servers screen (the switch's own label, from
strings.xml), and that the databases must not be changed any other way.
ReadOnlyTrust.needsWriteSwitchHint decides it; a hand-added server's text
and a debugger without execute are left as they were. The README's writes
paragraph says so. stringsXmlContext moves from AppEndpointReasonTest to
the shared test helpers, so WriteToolTest checks the shipped words too.
The version stays 2.1.0 (this PR already raised it).

Tests: four new WriteToolTest cases (switch off: the hint, with the exact
text; switch on: none; no execute: none; hand-added: passed through).
Revert proof: with only the hint in describe() removed, "with the switch
off, query says how writes get allowed" fails (ComparisonFailure). Full
testDebugUnitTest 362 (358 before), assemblePlugin, and the addons check
pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
… one

The Note 20 rerun at 29cbd00 (2026-11-25), switch off: asked to add a
row, the model asked for the shell (declined), then sent an INSERT
through the app's query tool. SQLite refused it ("not authorized"), and
AI-Core, whose rule replaces any answer after a failed call, showed only
"I couldn't complete that, the last action failed. See the details
above." So the switch sentence in query's description never reached the
user.

When a call to an app's query fails with SQLite's refusal of a write
("not authorized" from the read-only connection's authorizer, or
"attempt to write a readonly database"), and the switch keeps execute
off, the failure's text now ends with the same sentence as the
description (ReadOnlyTrust.isWriteRefusal; McpToolSource.errorWithHint).
That text is what AI-Core shows as the details, so the user reads how to
allow writes. Other failures, the switch on, and hand-added servers are
left as they were. FakeMcpServer can answer a tool with isError. The
README says so.

Tests: three new WriteToolTest cases (switch off: the refusal gets the
sentence; switch on: passed through; another failure: passed through).
Revert proof: with errorWithHint bypassed, "with the switch off, a write
refused through query says how writes get allowed" fails
(ComparisonFailure). Full testDebugUnitTest 365, assemblePlugin, and the
addons check pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn

@davidschachterADFA davidschachterADFA left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of #178 at 4e2c0e7376. Stack: addons #166 (ADFA-7139) <- #178 (this, top); claims checked at this head.

NITPICK - 2 inline, not listed

Verdict: COMMENT. This PR is authored by the account posting the review, and GitHub refuses APPROVE and REQUEST_CHANGES on your own PR. Severity rules: CodeOnTheGo REVIEW.md and CLAUDE.md (a ticket moves to QA with no outstanding critical, high or medium findings); addons has no written rule, so the default applied.


Generated by Claude Code

davidschachterADFA and others added 2 commits November 26, 2026 15:50
… it was

setAllowDatabaseWrites only logged a failed commit. SharedPreferences
keeps the new value in memory when its disk write fails, so the switch
looked saved and the session acted on it, and after a restart the old
value came back: writes switched off could be on again (#178 review,
comment 4713233488). The old value is now put back in memory, nothing is
told of a change, and the settings screen sets the switch back and says
the setting could not be saved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
isWriteRefusal also matches a refused BEGIN, SAVEPOINT, ATTACH or setting
PRAGMA, which execute refuses too, so the hint then names a switch that
would not help (#178 review, comment 4713233478). The server reports
every refusal as SQLite's "not authorized", so the KDoc now says so and
why it is accepted, rather than copying the server's rules here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA added a commit that referenced this pull request Nov 26, 2026
…gger/ADFA-7302

Brings in the #178 review fixes (the writes switch save, the hint KDoc).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
@davidschachterADFA

Copy link
Copy Markdown
Contributor Author

@hal-eisen-adfa New commits since you were asked to review, for the 2026-11-26 review's two NITPICKs:

  • 190f7e6: the writes switch stays as it was when its value cannot be saved, and the screen says so.
  • 3ef6bac: isWriteRefusal's KDoc says which refusals it misreads, and why that is accepted.

Each has a reply in its thread. The description lists the tests. The version stays 2.1.0/4, already bumped in this PR. #184 merges these.

…d Code on the Go 26.49

#166 merged main at 7c7e333 (main's plugin-api.jar, which has the SQLite
debugger API from stage) and raised plugin.min_ide_version from 26.48 to
26.49, because 26.48 was released before CodeOnTheGo#2261 merged. No
conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA added a commit that referenced this pull request Nov 30, 2026
…d Code on the Go 26.49

#178 merged #166 at 265fd64, which merged main at 7c7e333 (main's
plugin-api.jar, which has the SQLite debugger API from stage) and raised
plugin.min_ide_version from 26.48 to 26.49, because 26.48 was released
before CodeOnTheGo#2261 merged. No conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
@davidschachterADFA

Copy link
Copy Markdown
Contributor Author

@hal-eisen-adfa c5caa68 merges #166 at 265fd64 into this PR. That brings main and plugin.min_ide_version 26.49, because 26.48 was released before CodeOnTheGo #2261 merged (details on #166). There were no conflicts, and this PR's own diff is unchanged (same patch-id). 366 unit tests, assemblePlugin and the addons check pass; the .cgp records 26.49 to 26.99.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants