Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
21cd283
ADFA-7139 Refresh libs/plugin-api.jar for DebuggerEndpointService
davidschachterADFA Nov 16, 2026
6f2fde4
ADFA-7139 AI-Agent-MCP: automatic server entry for the open project's…
davidschachterADFA Nov 16, 2026
aa490b6
ADFA-7139 AI-Agent-MCP: document the debugger entry
davidschachterADFA Nov 16, 2026
816e8cc
ADFA-7139 AI-Agent-MCP: raise plugin.min_ide_version to 26.47, the fi…
davidschachterADFA Nov 16, 2026
d2aa392
ADFA-7139 AI-Agent-MCP: an activation that ends during the first endp…
davidschachterADFA Nov 16, 2026
185d360
ADFA-7139 AI-Agent-MCP: a session for a replaced debugger endpoint se…
davidschachterADFA Nov 16, 2026
3fc5002
ADFA-7139 AI-Agent-MCP: move the stacked KDoc onto installDebuggerEnd…
davidschachterADFA Nov 17, 2026
5911aac
ADFA-7139 AI-Agent-MCP: the health probe refreshes nothing once its a…
davidschachterADFA Nov 17, 2026
994860e
ADFA-7139 AI-Agent-MCP: no refresh restores automatic entries after d…
davidschachterADFA Nov 17, 2026
6e57f6a
ADFA-7139 AI-Agent-MCP: tidy the keepGoing KDoc and a duplicate tool-…
davidschachterADFA Nov 17, 2026
02704e7
ADFA-7139 AI-Agent-MCP: a cancelled tool call does not run its endpoi…
davidschachterADFA Nov 17, 2026
d102bfe
ADFA-7139 AI-Agent-MCP: tell each app's SQLite debugger tools apart b…
davidschachterADFA Nov 17, 2026
96b49e3
ADFA-7139 AI-Agent-MCP: switch on only the SQLite debugger's four cor…
davidschachterADFA Nov 17, 2026
eb97b3a
ADFA-7139 AI-Agent-MCP: README names the seven-character app prefix; …
davidschachterADFA Nov 17, 2026
7122208
ADFA-7139 AI-Agent-MCP: read the server list once when naming the too…
davidschachterADFA Nov 17, 2026
57477d2
ADFA-7139 AI-Agent-MCP: an Error from the host no longer crashes Code…
davidschachterADFA Nov 18, 2026
3620d18
ADFA-7139 AI-Agent-MCP: the help text names the SQLite debugger tools…
davidschachterADFA Nov 18, 2026
be3dc86
ADFA-7139 AI-Agent-MCP: an older endpoint read never stores over a ne…
davidschachterADFA Nov 18, 2026
fe8e819
ADFA-7139 AI-Agent-MCP: the docs name debugger.endpoints beside netwo…
davidschachterADFA Nov 18, 2026
21944cf
ADFA-7139 AI-Agent-MCP: an OutOfMemoryError from the host reaches the…
davidschachterADFA Nov 18, 2026
d68fde9
ADFA-7139 AI-Agent-MCP: min_ide_version is 26.48, since 26.47 shipped…
davidschachterADFA Nov 18, 2026
ac56d6e
ADFA-7139 AI-Agent-MCP: an endpoint listener's OutOfMemoryError reach…
davidschachterADFA Nov 19, 2026
f95d21e
ADFA-7139 AI-Agent-MCP: deactivate stops the scope even when the host…
davidschachterADFA Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified libs/plugin-api.jar
Binary file not shown.
51 changes: 47 additions & 4 deletions plugins/AI-Agent-MCP/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ This is a *tool* plugin, not a model backend: it adds no inference. Install

`ai-core` declares the filesystem, shell and project permissions its own tools
need, and **no network access**. MCP is the mirror image: it declares
`network.access` and nothing else. Keeping them apart is what lets a user install
`network.access`, plus `debugger.endpoints` to read the SQLite debugger endpoints
Code on the Go stores, and nothing else. Keeping them apart is what lets a user install
the Agent without granting it the network, or add remote tools without widening
what the Agent itself may touch.

Expand All @@ -36,7 +37,8 @@ Configuration → MCP servers**:
1. **Add server** — name, endpoint URL, optional token.
2. **Connect** — saves the server, performs the MCP handshake and lists the tools
it offers, all in one step.
3. Switch on the tools you want. **They start off**: one popular GitHub server
3. Switch on the tools you want. **They start off** (except four read-only tools
of the automatic SQLite debugger entry, below): one popular GitHub server
advertises around ninety tools, which would fill a phone-sized context window
on its own.
4. **Clear stored credential** — removes the stored token and headers. The token
Expand All @@ -47,6 +49,42 @@ Every remote tool asks for approval on every call, and there is no "always
allow" for contributed tools — they run outside the Agent's own path
containment, so the dialog is the only gate.

### The SQLite debugger entry

For an app built in Code on the Go with `cogo.sqliteDebugger=true`, the plugin
adds a server entry on its own, named "SQLite debugger (<application ID>)", with
no URL or token to type. Code on the Go stores the port and token the running
debug app reports; the plugin reads them through the `DebuggerEndpointService`
(permission `debugger.endpoints`, so it needs Code on the Go 26.48 or later) and
points the entry at `http://127.0.0.1:<port>/mcp`. A relaunched app gets a new
port and token, and the plugin reads them again after a refused connection. An
app that has not reported yet has no entry, and no error is shown.

Each app's tools are told apart for the model. Their names start with `db_` and
Comment thread
davidschachterADFA marked this conversation as resolved.
Resolved
the first seven characters of the application ID's last segment
(`db_notes_query` for `com.example.notes`, `db_myappli_query` for
`com.example.myapplication`); when two apps would share that prefix, both use the first
five characters of the segment and four hex digits derived from the full
application ID (`notes_3fa1_query`), so a name never depends on which app was
read first. Each description starts with the application ID, as
"com.example.notes (SQLite debugger): ...", and the approval dialog shows it.
Servers you add yourself keep the name prefix taken from their label.

- It is held in memory only and is **not shown in the settings screen in this
version**, so there is no switch to turn it off there.
- Four tools start switched **on**: `list_databases`, `get_schema`, `query` and
`get_events`, each only when the server declares MCP's `readOnlyHint: true` for
it. Every other tool of that entry (today `list_connections`,
`explain_query_plan`, `get_stats` and `integrity_check`) starts off, and so
does any tool without that hint. The hint is trusted for this entry only, never
for a server you add yourself. Four, not all eight, because AI-Core describes
at most 12 contributed tools per message (4 for a small on-device model), in
order, and drops the rest; every app has its own entry. Switching the others
on will come with showing this entry in the settings screen (phase 2).
- The Agent still asks for approval on every call: AI-Core makes every
Comment thread
davidschachterADFA marked this conversation as resolved.
Resolved
contributed tool ask (it ignores the tool's own `requiresApproval`). Approving
read-only calls automatically is tracked in ADFA-7147.

## Transport

MCP's **Streamable HTTP** transport over `HttpURLConnection`:
Expand Down Expand Up @@ -105,10 +143,15 @@ Two dependencies were deliberately not taken:
- `http://` is accepted only for a server on this device (`localhost`, `127.0.0.0/8`,
`[::1]`), with or without credentials; any other host needs `https://`, since its
traffic would cross a network in the clear. The check is `McpUrlPolicy`, built on
the host's `ServerUrl` (plugin-api **26.42**, hence this plugin's
`min_ide_version`), and judges the URL as typed with no DNS lookup. Save refuses
the host's `ServerUrl` (plugin-api 26.42), and judges the URL as typed with no DNS lookup. Save refuses
such a URL, and the transport refuses it again, so a server saved before the rule
is listed with a warning and never contacted until it is switched to `https://`.
- The plugin declares the `debugger.endpoints` permission, to offer the SQLite debugger of the
open project's app without typing a port or token. Code on the Go 26.47 and older reject a
manifest that names a permission they do not know (`PluginSecurityManager.validatePlugin`), so this
version needs **26.48 or later**, the first release that ships `DebuggerEndpointService`
(`plugin.min_ide_version`); users on 26.47 or older cannot install it. 26.48 assumes the
release after 26.47 ships it; recheck it against the real release number before merging.
- Redirects are never followed automatically. A 3xx is repeated only when it
resolves to the same origin, so the bearer token and the user's own headers
cannot be replayed to another host in one hop.
Expand Down
2 changes: 1 addition & 1 deletion plugins/AI-Agent-MCP/addon.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"summary": "Give the Agent tools from Model Context Protocol (MCP) servers. Requires the AI Core addon and an AI backend.",
"description": "Connects to MCP servers you configure and adds the tools they offer to the AI Core Agent, next to its own. Each tool starts switched off until you enable it. When the Agent calls a tool, the arguments it chose, which can include your code, are sent to the MCP server that offers that tool. This addon adds tools, not a model, so you still need an AI backend.",
"description": "Connects to MCP servers you configure and adds the tools they offer to the AI Core Agent, next to its own. Each tool starts switched off until you enable it, except four read-only tools of the SQLite debugger entry that Code on the Go adds for your own debug app. When the Agent calls a tool, the arguments it chose, which can include your code, are sent to the MCP server that offers that tool. This addon adds tools, not a model, so you still need an AI backend.",
"tags": [
"ai",
"agent",
Expand Down
10 changes: 7 additions & 3 deletions plugins/AI-Agent-MCP/ai-agent-mcp.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ <h2>Executive overview</h2>
<p>It is deliberately a plugin of its own rather than part of AI Core. AI Core
declares the filesystem, shell and project permissions its own tools need and
<b>no network access</b>; this plugin is the mirror image, declaring
<b>network.access and nothing else</b>. That split is what lets you run the
<b>network.access</b>, plus <b>debugger.endpoints</b> to read the SQLite debugger
endpoints Code on the Go stores, <b>and nothing else</b>. That split is what lets you run the
Agent without granting it the network, or add remote tools without widening
what the Agent itself may touch.</p>

Expand Down Expand Up @@ -119,7 +120,8 @@ <h2>Technical architecture</h2>
which is a Kotlin Multiplatform library with no stated Android target, ships no
HTTP engine, and required a Kotlin version these plugins do not standardise
on.</p>
<p>The plugin declares <b>network.access</b> and nothing else. It holds no
<p>The plugin declares <b>network.access</b> and <b>debugger.endpoints</b>, which
only reads the SQLite debugger endpoints Code on the Go stores, and nothing else. It holds no
filesystem, shell or project permission, so it cannot read your project;
project content reaches a server only if the model puts it in a tool argument
and you approve that call.</p>
Expand All @@ -141,7 +143,9 @@ <h2>Usage</h2>
</ol>
<div class="note">
New tools always arrive switched <b>off</b>, including on the connection
that discovers them. Nothing a server adds later becomes visible to the model
that discovers them. The one exception is four read-only tools (list databases, get schema,
query and get events) of the SQLite debugger entry that Code on the Go
supplies for your own debug app. Nothing a server adds later becomes visible to the model
without your say-so.
</div>

Expand Down
24 changes: 16 additions & 8 deletions plugins/AI-Agent-MCP/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,31 @@
android:name="plugin.author"
android:value="App Dev for All" />

<!-- 26.42: the first release whose plugin-api carries ServerUrl, which McpUrlPolicy
uses to allow http:// only to this device (ADFA-6314). 26.41 brought the
capability-tag contract (ADFA-6278). Do not lower it. -->
<!-- 26.48: the first release that can know the debugger.endpoints permission and carry
DebuggerEndpointService (ADFA-7139). 26.47, released on 2026-11-17, and every older
release have neither. Their PluginSecurityManager.validatePlugin rejects a manifest
that names a permission it does not know, so those IDEs cannot install this plugin
version at all. 26.48 is still a guess: recheck it against the real release number
before merging, and raise it if the release that ships ADFA-7139 is later. 26.43 made
plugin-api interface bodies Java default methods, which the bundled plugin-api.jar
relies on; 26.42 brought ServerUrl, which McpUrlPolicy uses to allow http:// only to
this device (ADFA-6314); 26.41 the capability-tag contract (ADFA-6278). Do not lower
it. -->
<meta-data
android:name="plugin.min_ide_version"
android:value="26.42" />
android:value="26.48" />

<meta-data
android:name="plugin.max_ide_version"
android:value="26.99" />

<!-- network.access and nothing else: this plugin only speaks HTTP to the servers the user
configured. It never touches the filesystem, the project or the shell — which is the
whole reason MCP lives here instead of inside ai-core. -->
<!-- network.access: this plugin only speaks HTTP to the servers the user configured, plus the
debugger of the open project's app. debugger.endpoints: asks Code on the Go for that
app's port and token (ADFA-7139). It never touches the filesystem, the project or the
shell — which is the whole reason MCP lives here instead of inside ai-core. -->
<meta-data
android:name="plugin.permissions"
android:value="network.access" />
android:value="network.access,debugger.endpoints" />

<meta-data
android:name="plugin.main_class"
Expand Down
22 changes: 16 additions & 6 deletions plugins/AI-Agent-MCP/src/main/assets/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,33 @@ <h2>Adding a server</h2>
</ul>

<h2>Choosing tools</h2>
<p>Every tool starts <b>switched off</b>. That is deliberate: each enabled tool
costs prompt space on every message you send, and a large server can advertise
ninety of them — enough to fill a phone-sized context window on its own. Switch
on the handful you actually want.</p>
<p>Every tool starts <b>switched off</b>, with the one exception below. That is
deliberate: each enabled tool costs prompt space on every message you send, and a
large server can advertise ninety of them — enough to fill a phone-sized context
window on its own. Switch on the handful you actually want.</p>
<p>The one exception is the <b>SQLite debugger</b> entry, which Code on the Go
adds by itself for an app you build with the SQLite debugger, named
"SQLite debugger (<i>application ID</i>)". Four of its read-only tools start
switched on: <code>list_databases</code>, <code>get_schema</code>,
<code>query</code> and <code>get_events</code>. Its other tools start off. This
version does not show the entry on the MCP servers screen, so it has no switches
there yet.</p>
<p>The Agent reads this list from memory, so tap <b>Connect</b> again after the
server changes; a chat that is already open picks the new list up.</p>

<h2>Approval</h2>
<p>Every remote tool asks for your approval before it runs, showing the
arguments it would send, and there is no "always allow" for them. The Agent's
arguments it would send, and there is no "always allow" for them. That includes
the four SQLite debugger tools that start switched on. The Agent's
own file tools are confined to the open project; a remote tool is confined by
nothing this device controls, so the dialog is the only gate — read it.</p>

<h2>What is sent</h2>
<ul>
<li>The tool's arguments, as the model composed them, to that server only.</li>
<li>Nothing else: this plugin has <b>network access and no other permission</b>.
<li>Nothing else: this plugin has <b>network access</b>, plus
<b>debugger.endpoints</b> to read the SQLite debugger endpoints Code on the Go
stores, <b>and no other permission</b>.
It cannot read your project or your files. Anything from your project reaches
a server only if the model puts it in an argument and you approve the call.</li>
<li>Server and tool names are reduced here to the alphabet a tool name may
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.itsaky.androidide.plugins.aiagentmcp.client

import android.util.Log
import com.itsaky.androidide.plugins.aiagentmcp.debugger.AutomaticServers
import com.itsaky.androidide.plugins.aiagentmcp.errors.runCatchingRecoverable
import com.itsaky.androidide.plugins.aiagentmcp.logging.LOG_PREFIX
import com.itsaky.androidide.plugins.aiagentmcp.security.UnavailableSecretException
import com.itsaky.androidide.plugins.aiagentmcp.security.UnreadableSecretException
Expand Down Expand Up @@ -58,25 +60,25 @@ object McpConnections {
stale = current?.second
// A supplier, not the values: the session is kept for the life of the process, and a
// token in one of its fields would be readable in a heap dump for just as long.
McpSession(server.url, { credentialsFor(server.id) })
McpSession(server.url, { credentialsFor(server.id, server.url) })
.also { sessions[server.id] = key to it }
}

stale?.let {
Log.i(TAG, "Server '${server.name}' changed; dropping its session")
runCatching { it.close() }
runCatchingRecoverable { it.close() }
}
return session
}

/** Drops the session for [serverId], ending it server-side when it had one. */
fun invalidate(serverId: String) {
sessions.remove(serverId)?.second?.let { runCatching { it.close() } }
sessions.remove(serverId)?.second?.let { runCatchingRecoverable { it.close() } }
}

/** Ends every session, for the plugin shutting down. */
fun closeAll() {
sessions.values.forEach { (_, session) -> runCatching { session.close() } }
sessions.values.forEach { (_, session) -> runCatchingRecoverable { session.close() } }
sessions.clear()
}

Expand All @@ -87,13 +89,22 @@ object McpConnections {
* does not register, and it is what keeps the plaintext from outliving the request.
*
* @param serverId the server being called.
* @param url the url the calling session was built for. An automatic entry's token is released
* only while the entry still points there; a session for a replaced endpoint gets none, so
* its `close()` and any call still in flight cannot hand the new process's token to the old port.
* @return its token and headers; either may be empty.
* @throws UnreadableSecretException when a stored credential cannot be decrypted here. Sending
* the request without it would earn a 401 and tell the user their token was refused.
* @throws UnavailableSecretException when the keystore could not be reached to decrypt one, a
* failure to retry rather than to report as a lost credential.
*/
private fun credentialsFor(serverId: String): McpCredentials {
private fun credentialsFor(serverId: String, url: String): McpCredentials {
if (AutomaticServers.isAutomatic(serverId)) {
// Read per request, so a token refreshed on the same port is used without a new session.
val endpoint = AutomaticServers.endpoint(serverId)
val token = if (endpoint != null && AutomaticServers.urlFor(endpoint) == url) endpoint.token else ""
return McpCredentials(token, emptyMap())
}
val token = when (val stored = McpServerStore.token(serverId)) {
// Trimmed here, not by the store: the host's readAndMigrate migrates verbatim, and a
// legacy token saved with a stray newline is one `setRequestProperty` refuses to send.
Expand Down Expand Up @@ -123,7 +134,7 @@ object McpConnections {
private fun keyFor(server: McpServer): Key {
// Headers join the key for the same reason the token does: edit one and the old session
// would keep sending the old value until the IDE restarts.
val credentials = credentialsFor(server.id)
val credentials = credentialsFor(server.id, server.url)
return Key(
serverId = server.id,
url = server.url,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.itsaky.androidide.plugins.aiagentmcp.client

import android.util.Log
import com.itsaky.androidide.plugins.aiagentmcp.debugger.ReadOnlyTrust
import com.itsaky.androidide.plugins.aiagentmcp.errors.runCatchingRecoverable
import com.itsaky.androidide.plugins.aiagentmcp.logging.LOG_PREFIX
import com.itsaky.androidide.plugins.aiagentmcp.transport.JsonRpc
import com.itsaky.androidide.plugins.aiagentmcp.transport.McpExchangeListener
Expand Down Expand Up @@ -192,11 +194,16 @@ class McpSession(
runCatching { liveConnection?.disconnect() }
}

/** Ends the server-side session, if there is one, and forgets the handshake. */
/**
* Ends the server-side session, if there is one, and forgets the handshake.
*
* The DELETE is best effort; its credentials come from the host's Keystore, so a LinkageError
* is survived as well as an Exception, and any other Error propagates.
*/
@Synchronized
fun close() {
sessionId?.let { id ->
runCatching {
runCatchingRecoverable {
val current = credentials()
http.deleteSession(endpoint, current.token, id, current.headers)
}
Expand Down Expand Up @@ -314,6 +321,9 @@ class McpSession(
name = name,
description = entry.optString("description"),
inputSchema = entry.optJSONObject("inputSchema")?.let(::toMap).orEmpty(),
readOnlyHint = ReadOnlyTrust.isReadOnlyHint(
entry.optJSONObject("annotations")?.opt("readOnlyHint")
),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ package com.itsaky.androidide.plugins.aiagentmcp.client
* @property name the tool's own name, unique within its server.
* @property description what it does, as the server describes it — untrusted remote text.
* @property inputSchema JSON Schema for the arguments, empty when the server sends none.
* @property readOnlyHint whether `annotations.readOnlyHint` was exactly boolean true. A claim by
* the server: only the automatic debugger entry acts on it.
*/
data class McpTool(
val name: String,
val description: String,
val inputSchema: Map<String, Any> = emptyMap(),
val readOnlyHint: Boolean = false,
)

/**
Expand Down
Loading
Loading