Expand description
Shared logic for the rtk-mcp-agy plugin.
Everything here is pure: JSON-RPC dispatch, response shaping, and the
PreInvocation payload. The two binaries in src/bin/ only move bytes and
spawn processes.
The split exists because the interesting behaviour is otherwise unreachable
by a test. handle_line takes the rewriter and the executor as closures,
so the tools/call path — which in production shells out to rtk and then
to a shell — can be exercised on a machine that has neither installed, and
its failure modes can be forced rather than waited for.
The seam earned itself immediately: it is what made the hardcoded pwsh
visible as a portability bug (see resolve_shell) rather than something
only a Linux user would ever discover.
Macros§
- plugin_
name 🔒 - The plugin ID in
plugin.json, and the plugin’s directory name in Antigravity. - server_
name 🔒 - The server key registered in
mcp_config.json.
Structs§
- PreInvocation
Output - The payload the
PreInvocationhook writes to stdout.
Enums§
- Execution
- The outcome of trying to run a command.
Constants§
- AGY_
SERVER_ NAME - The namespaced server name Antigravity assigns to this plugin’s MCP server.
- DEFAULT_
RTK_ BIN - The rtk executable, when
RTK_BINsays nothing. - DEFAULT_
UNIX_ SHELL - The shell used to run commands everywhere else.
- DEFAULT_
WINDOWS_ SHELL - The shell used to run commands on Windows.
- METHOD_
NOT_ FOUND - JSON-RPC’s “method not found”.
- PLUGIN_
NAME - The plugin directory / ID in Antigravity.
- PROTOCOL_
VERSION - The MCP protocol revision spoken by this server.
- SERVER_
NAME - The server name an MCP client sees, and the key
mcp_config.jsonregisters. - TOOL_
CHECK - Show how rtk would rewrite a shell command without running it.
- TOOL_
DISCOVER - Analyze past session history for missed token savings.
- TOOL_
GAIN - Report rtk token savings.
- TOOL_
NAME - Run an rtk-optimized command.
Functions§
- build_
check_ command - Build the command line for
rtk hook check. - build_
discover_ command - Build the command line for
rtk discover. - build_
gain_ command - Build the command line for
rtk gain. - call_
arguments - Pull
CommandLineandCwdout of atools/callrequest. - dispatch_
request - Dispatch a parsed JSON-RPC request to the appropriate method handler.
- envelope 🔒
- Wrap a result body in its JSON-RPC envelope.
- extract_
cwd - Extract the
Cwdargument or fall back to".". - format_
execution - Render an execution as the
tools/callresult body. - handle_
line - Handle one line of input, returning the response to write — or
Nonewhen the server must stay silent. - handle_
request - Handle a parsed JSON-RPC request using default fallback closures.
- method_
not_ found - The body used for an unrecognised method.
- non_
blank 🔒 - Trim a value, discarding it if nothing is left.
- parse_
rewrite - Interpret the stdout of
rtk rewrite. - preinvocation_
payload - Build the injected instruction that steers the model onto the MCP tool.
- resolve_
rtk_ bin - Decide which rtk executable to invoke.
- resolve_
shell - Decide which shell runs the rewritten command.
- server_
info - The
initializeresult. - shell_
quote - Quote a string safely for inclusion in a shell command line.
- tools_
list - The
tools/listresult advertising all 4 tools. - validate_
format 🔒 - version
- The crate version, and the single source for every place one is reported.