Repository navigation
ADFA-7139: AI-Agent-MCP connects to the SQLite debugger automatically - #166
davidschachterADFA wants to merge 6 commits into
Conversation
davidschachterADFA
left a comment
There was a problem hiding this comment.
Review of head a89b585 (not stacked in this repo: base is main). Governing rules: addons CLAUDE.md and plugins/README.md (no written approve/request-changes rule, so the default severity table applied). plugin-review criteria read for compatibility, permissions and manifest only; the rubric was not scored. Static review only: no build, no device. Self-authored PR, so the verdict is COMMENT (a verdict was computed as COMMENT anyway: MINOR findings only). No earlier review rounds and no approvals existed.
MINOR
- AndroidManifest.xml:49 - the 26.43 floor predates the feature, and its stated reason does not hold on stage
- McpPlugin.kt:208 - a deactivation during the first endpoint read leaves a listener and live entries behind (PLAUSIBLE)
Findings without a diff anchor
MINOR: libs/plugin-api.jar is a binary, so this cannot be anchored. The jar was built from the unmerged CoGo branch (#2259, #2260, #2261 are all open and none is on stage), and it carries more than the two new classes: about 100 classes differ from the committed jar, and for interfaces such as DocumentationExtension and net.Host the methods are now Kotlin default methods (-Xjvm-default), plus MenuItem and PluginTooltipButton constructor overloads and a new PluginFragmentKt. Every plugin compiles against this jar, but only AI-Agent-MCP was built or tested. plugins/README.md says libs/ is filled from stage and that Publish addons overwrites the jars with CoGo's plugin-api-latest, so an API that is not yet released passes PR CI and fails Publish. Not reachable today: nothing breaks until this merges. The fix is to say in the description that this PR must not merge before #2259-#2261 land and a plugin-api-latest release carries DebuggerEndpointService, and ideally to refresh libs/ from stage after that rather than from the branch.
Checked and found sound: debugger.endpoints is a real PluginPermission in the new jar and is declared in plugin.permissions (manifest completeness); the service is called from Dispatchers.IO, as the API requires; SecurityException and IllegalStateException from getEndpoints are caught and keep the previous entries; the token stays out of logs, the Keystore store and McpServer; the bearer is read per request and the session key includes its fingerprint; only the automatic entry gets preApproved, and AI-Core still prompts on every contributed tool (ContributedToolHandler), as the README says; isReadOnly=true only changes mutatesProject to false in AI-Core, which is intended here; the endpoint-replaced-during-list race is guarded by recordTools; the retry fires only when the URL or token changed. Not verified: behaviour on a device (the description says so too), and how a Code on the Go 26.42 build treats an unknown permission.
| <meta-data | ||
| android:name="plugin.min_ide_version" | ||
| android:value="26.42" /> | ||
| android:value="26.43" /> |
There was a problem hiding this comment.
MINOR: the 26.43 floor does not guarantee the feature, and the stated reason is not what current stage does.
Code on the Go 26.43 to 26.46 are already released, and #2259-#2261 are still open and not on stage, so no released IDE has debugger.endpoints or DebuggerEndpointService. On stage, PluginManager warns "Invalid permission in plugin manifest" and drops an unknown permission instead of rejecting the manifest (I could not check 26.42 itself). So a user on 26.43-26.46 can install this plugin, gets no debugger entry, and the code copes (installDebuggerEndpoints catches Throwable); the comment, README and plugins/README all say such an IDE cannot install it. The floor also drops 26.42 users with no functional reason. No current caller is hurt, which is why this is MINOR.
Set the floor to the first release that ships #2261 once it is known, or keep 26.42 and say that older IDEs simply show no entry; correct the "rejects the unknown permission" wording in the manifest comment, README and plugins/README to whichever is true.
There was a problem hiding this comment.
Fixed in 816e8cc, after checking the source: at tags 26.42 and 26.46 and on stage, PluginSecurityManager.validatePermissions rejects an unknown permission key before PluginManager's warn-and-drop runs, so 26.46 and older refuse this plugin. 26.43-26.46 are released without the API, so the floor is now 26.47, the next release; the manifest comment and both READMEs say so. CodeOnTheGo #2261's changelog entry moved to 26.47 too.
| // Off the main thread: the host reads its database. Before refreshAll, so the entry is | ||
| // connected like any other. | ||
| installDebuggerEndpoints() | ||
| AutomaticServers.addEndpointListener(relistAutomatic) |
There was a problem hiding this comment.
MINOR (PLAUSIBLE): this launch has no isActive check around installDebuggerEndpoints() and addEndpointListener, unlike refreshAll { isActive } just below.
installDebuggerEndpoints() blocks on the host's database read and cancellation cannot interrupt it. If the plugin is deactivated during that read, deactivate() removes the listener and releaseConnections() calls AutomaticServers.install(null), then the old coroutine resumes: it re-installs the source (refresh repopulates entries with tokens), and re-adds relistAutomatic, which nothing removes any more. On a quick deactivate and re-activate the listener is also added twice (one val, two list entries), so each endpoint change re-lists twice. The window is the first read after activation, so a real user rarely hits it.
Check isActive before installDebuggerEndpoints() and after it, and skip addEndpointListener when the activation is over.
There was a problem hiding this comment.
Fixed in d2aa392: the start of the debugger entry checks isActive before and after the first read and after adding the listener (removing it if the activation ended), and deactivate/dispose remove the listener. Test: an activation that ends during a blocked read leaves no entries and no extra listener.
davidschachterADFA
left a comment
There was a problem hiding this comment.
Re-run of the automated first pass after the earlier run's diff collision (its code-review step never ran on this PR). This review lists only the finding that was not already posted; the earlier review's findings (the 26.43 floor, the deactivation race in McpPlugin, and the libs/plugin-api.jar provenance) are not repeated. Head a89b585, not stacked (base is main). Static review only: no build, no device. Self-authored PR, so COMMENT.
MINOR
- McpConnections.kt:100 - a session for a replaced endpoint reads the new endpoint's token, so its close() sends it to the old port
NITPICK - none
| private fun credentialsFor(serverId: String): McpCredentials { | ||
| if (AutomaticServers.isAutomatic(serverId)) { | ||
| // Read per request, so a refreshed endpoint's token is used without a new session. | ||
| return McpCredentials(AutomaticServers.token(serverId).orEmpty(), emptyMap()) |
There was a problem hiding this comment.
MINOR: credentialsFor answers with the entry's current token for any session of that id, including a session built for an endpoint that has since been replaced.
When the app relaunches, refresh() stores the new port and token, session() sees a new key and builds a session for the new URL, then closes the old one. The old session's close() calls credentials() and sends DELETE http://127.0.0.1:<old port>/mcp with a bearer token, but the token it reads is now the new process's (the sqlite-debugger server does assign Mcp-Session-Id, so there is a session to delete). Normally nothing listens on the old port and the connection is refused. If anything does (a later debuggable app's server, or any local process that took the freed port), it receives the live token of the new endpoint. A call still in flight on the old session does the same. No current caller is hurt unless that port is reused, which is why this is MINOR.
Make the supplier session-specific: have it return the token only while AutomaticServers.endpoint(serverId) still maps to the URL the session was created with, and an empty or failing credential otherwise, so a replaced session sends nothing secret.
There was a problem hiding this comment.
Fixed in 185d360: credentialsFor(serverId, url) returns the token only while the entry still maps to the URL the session was built for; a replaced endpoint's session sends no token. Test: the old server's DELETE carries no new token.
The AI-Agent-MCP debugger entry compiles against DebuggerEndpointService,
DebuggerEndpoint and the debugger.endpoints permission, which the checked-in
plugin-api.jar lacks. The jar is rebuilt from CodeOnTheGo branch
sqlite-debugger/ADFA-7139, commit 8e7473b76 ("Add DebuggerEndpointService
and the debugger.endpoints permission"); the plugin-api module is unchanged
by the later commits on that branch.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
… debugger An app built in Code on the Go with cogo.sqliteDebugger=true serves its databases over MCP on 127.0.0.1. AI-Agent-MCP now offers that server to the Agent with nothing typed in. - One automatic server entry per endpoint reported by DebuggerEndpointService: http://127.0.0.1:<port>/mcp, the token kept in memory only and never stored in the Keystore. No endpoint means no entry and no error. - The endpoint is re-read before reconnecting after a refused connection, 401 or 403, so a relaunched app (new port and token) is picked up; its tools stay offered across the relaunch. A refused read is logged once. - For this entry only, tools whose readOnlyHint is exactly true (boolean) start switched on and others start off. Hand-added servers keep today's behaviour even when they claim the hint. AI-Core still asks for approval on every call of a contributed tool, so the pre-approval does not skip the prompt; automatic approval is ADFA-7147. - The manifest declares debugger.endpoints and plugin.min_ide_version 26.43: an older Code on the Go rejects the unknown permission at validation, so it cannot install this version at all. - Showing the entry in the settings screen is deferred to phase 2: the eight phase 1 tools are all read-only, so nothing needs switching on. Tests: no endpoint; stale endpoint (refused, 401, 403) re-read; relaunch through a fake MCP server keeps the tools; the annotation rule (true, false, missing, "true", 1, null); a hand-added server claiming the hint stays off; a repeated read failure is logged once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
The plugin README and the plugin's help page describe the automatic SQLite debugger entry, its read-only tool rule and the approval prompt. plugins/README.md lists debugger.endpoints among the permissions and says a plugin declaring it needs plugin.min_ide_version of at least 26.43. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…rst release with debugger.endpoints Code on the Go 26.43 to 26.46 are released and none carries PluginPermission.DEBUGGER_ENDPOINTS or DebuggerEndpointService. An unknown permission key does not only warn: PluginManager.loadPlugin (PluginManager.kt:568) calls PluginSecurityManager.validatePlugin, which returns false when validatePermissions (PluginSecurityManager.kt:50, :92) finds a key outside PluginPermission, and loadPlugin then fails with "plugin failed security validation". The same code is at tags 26.42 and 26.46 and on origin/stage. The warn-and-drop at PluginManager.kt:582 runs only after validation passed, so it never sees an unknown key from a manifest. 26.46 therefore rejects this plugin, and the floor must be the next release, 26.47 (26.46 was tagged 2026-11-10, weekly cadence). The manifest comment, plugin README and plugins/README.md say so. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…oint read leaves nothing behind The host's database read blocks and cannot be cancelled. If the plugin was deactivated meanwhile, the old coroutine resumed, re-installed the endpoint source and added the endpoint listener, which nothing removed; a quick re-activate added it twice. Now the launch checks the activation before and after the read, install() keeps neither the source nor the entries of a finished activation, and deactivate removes the listener after the scope ends so a late add is caught. McpPluginDebuggerStartTest fails without this (a listener is left registered when the activation ended during the read) and passes with it; it also checks that a live activation adds one listener. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…nds no token credentialsFor returned the entry's current token for any session of that id, so the old session's close() sent DELETE to the old port carrying the new process's token. The supplier now takes the url its session was built for and releases the token only while the entry still points there. ReplacedEndpointCredentialTest replaces an endpoint and checks the DELETE the old server saw: it fails without this (the DELETE carried "Bearer new-token") and passes with it. FakeMcpServer now records requests and can hand out a session id. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
a89b585 to
185d360
Compare
davidschachterADFA
left a comment
There was a problem hiding this comment.
Re-review of addons#166 at 185d360 (medium effort). Verdict computed: COMMENT (MINOR and NITPICK only; GitHub also refuses APPROVE/REQUEST_CHANGES on a self-authored PR). Nothing here blocks merge.
MINOR
- McpPlugin.kt:267 - the probe's
AutomaticServers.refresh()can repopulate the entries after deactivation, the same hazard as the earlier isActive thread but on the periodic path
NITPICK - 1 inline, not listed
Not stacked. Base is main. The PR is the counterpart of CodeOnTheGo #2261 (sqlite-debugger/ADFA-7139, tip of the #2259 > #2260 > #2261 stack): I read DebuggerEndpointService and DebuggerEndpoint there, and the bundled libs/plugin-api.jar here contains both classes and PluginPermission.DEBUGGER_ENDPOINTS with the same signatures. AI-Core's handling of read-only tools is addons#167, reviewed separately and not reviewed here.
Rules applied. The addons CLAUDE.md and plugins/README.md, and, for plugin criteria only (not scored), the plugin-review skill and RUBRIC: manifest completeness (both new permissions declared, min and max version present), no reflection into IDE internals (none found), resource discipline (the scope is cancelled and every listener is removed in deactivate and dispose), the html page and README updated, and libs/ carries the new API. None gives an approve/request-changes rule, so the skill's default table applied.
Prior threads (judged on the code at this head, not on the replies).
- AndroidManifest.xml:49 floor of 26.43: fixed. The floor is 26.47, which matches #2261's changelog entry (26.46 is the latest tag). I confirmed on CodeOnTheGo
stagethatPluginSecurityManager.validatePermissionsrejects an unknown permission key before the loader's warn-and-drop, so the manifest comment, README and plugins/README are right. - McpPlugin.kt:208 first read after deactivation: fixed for that path.
startDebuggerEntrycheckskeepGoingbefore and after the read and after adding the listener,installre-checks under the lock, and deactivate and dispose remove the listener after the scope ends. The periodic refresh is still open (finding above). - McpConnections.kt:100 token for a replaced endpoint: fixed.
credentialsFor(serverId, url)releases the token only while the entry's current URL equals the session's, so a replaced session (and itsclose()DELETE) sends none.
No thread needed a reply or an unresolve.
Static review only: no build, no device. Leads from the built-in review that I discarded: duplicate application IDs collapsing (the host keys rows by application ID, so one per app), EndpointRetry missing wrapped connect errors (the transport lets ConnectException through; the retry is for a refused connection), concurrent re-lists (McpConnections.session is locked), the 26.47 floor as a guess (the manifest comment says to raise it, and #2261 carries the same number), two tool caches (kept in step in list), trusting a loopback server's readOnlyHint (nothing authenticates a server beyond its token, the approval is still asked today, and honouring the hint is addons#167 and ADFA-7147; worth keeping in mind there because a dead app's port can be reused), and RepeatedFailureLog not resetting (documented as one per process).
| delay(PROBE_INTERVAL_MS) | ||
| cycle++ | ||
| val due = McpServerStore.servers().filter { server -> | ||
| if (AutomaticServers.refresh()) settingsChanged() |
There was a problem hiding this comment.
MINOR: AutomaticServers.refresh() here runs with the default keepGoing { true }, so a refresh blocked in the host read when the plugin deactivates can store its entries after install(null) has cleared them.
The first-read fix covers install, not this loop. refresh() captures source before the blocking read. deactivate() ends the scope, which cannot interrupt the read, then releaseConnections() calls install(null). When the read returns, refresh still writes states with each app's port and token and fires its listeners, although nothing owns them any more; EndpointRetry's refresh on a tool-call thread has the same window. The window is one host read, so a real user rarely hits it, which is why this is MINOR.
Have refresh compare source with the read it captured inside the synchronized block and return when they differ (as install(null) sets it null under that lock), and pass keepGoing from probeHealth.
| } | ||
|
|
||
| /** | ||
| * Points [AutomaticServers] at the host's debugger endpoints. |
There was a problem hiding this comment.
NITPICK: two KDoc blocks are stacked on startDebuggerEntry; the first ("Points AutomaticServers at the host's debugger endpoints") belongs to installDebuggerEndpoints and is attached to nothing.
Documentation tools and readers see only the second block, so the explanation of why min_ide_version keeps the plugin off an IDE without the service, and what the Throwable catch is for, is lost. The edit that added startDebuggerEntry split it from the function it described.
Move the first block down onto installDebuggerEndpoints.
ADFA-7139
AI-Agent-MCP connects to the SQLite debugger of the open project's app with nothing typed in, using the endpoint Code on the Go stores (Code on the Go side: appdevforall/CodeOnTheGo#2261, stacked on #2260 and #2259).
What it does
DebuggerEndpointService(http://127.0.0.1:<port>/mcp, token in memory only, never in the Keystore, not in the settings screen in this version). The endpoint is re-read before reconnecting after a refused connection, 401 or 403, so a relaunched app is picked up; its tools stay offered across the relaunch. No endpoint: no entry, no error.readOnlyHintis exactlytruestart switched on; others start off. Hand-added servers are unchanged, even when they claim the hint.debugger.endpoints;plugin.min_ide_version26.47: Code on the Go 26.46 and older reject a plugin that declares an unknown permission (PluginSecurityManager.validatePermissions), and 26.43-26.46 are already released without the API.libs/plugin-api.jarrefreshed from Code on the Gosqlite-debugger/ADFA-7139.Known: AI-Core asks for approval on every call of a contributed tool (
ContributedToolHandler), so these tools still prompt; README and comments say so. Automatic approval: ADFA-7147. Showing the entry in settings: phase 2.Tests: no endpoint; stale endpoint (refused, 401, 403; no retry when nothing changed; no retry of a timeout); relaunch through a fake MCP server; the annotation rule (true, false, missing, "true", 1, null); a hand-added server claiming the hint stays off; failed reads keep the previous entries.
testDebugUnitTest assemblePluginpasses.Merge precondition: do not merge until (1) CodeOnTheGo #2259, #2260 and #2261 are merged; (2) a
plugin-api-latestrelease and a Code on the Go release (expected 26.47) carryDebuggerEndpointServiceanddebugger.endpoints; (3)libs/is refreshed from that release with Update libs (this branch's jar is built from the unmerged CoGo branch, so Publish addons would replace it with one lacking the API); (4)plugin.min_ide_versionis rechecked against the actual release number.Not verified on a device: needs Code on the Go built from the CoGo stack.
No screens changed.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn