Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/client/src/mcp.ts?version=2&format=json
210 linesFirst import 100%Last change First import in version 0, 1 version changed it

You're reading version 2. The newest is 318, and 15 versions since then changed this file. Go to the newestCompare with 318

1// abso mcp: an MCP server on stdin and stdout (#42, #44). Each tool is one avcs
2// command, run by the same code as the command line and answering with the
3// same text, so the CLI and the tools can't drift apart and an agent learns
4// one set of words. The folder and the token come from where the server runs,
5// as for the CLI: .avcs/config.json, and AVCS_TOKEN or ~/.avcs/token.
6//
7// claude mcp add avcs -- node <repo>/client/avcs.ts mcp
8//
9// The protocol is JSON-RPC 2.0, one message per line, with no library: the
10// client uses nothing outside Node.
12import { resolve } from "node:path";
13import { clientVersion } from "./client-version.ts";
14import { commandTable, main } from "./main.ts";
16/**
17 * The commands served as tools: reading, and the writes an agent makes every
18 * day. The box commands (run, shot, bisect, prep, logs, fetch) stream for
19 * minutes and stay in the shell, as do setting a folder up (init, join) and
20 * the ones that rewrite history or move between drafts.
21 */
22export const MCP_COMMANDS = [
23 "status",
24 "log",
25 "show",
26 "diff",
27 "files",
28 "who",
29 "where",
30 "blame",
31 "why",
32 "ci",
33 "news",
34 "announce",
35 "start",
36 "record",
37 "sync",
38 "publish",
39 "unqueue",
40 "restore",
41 "settle",
42 "check-ignore",
43 "labels",
44 "mv",
45 "review",
46 "note",
47 "notes",
48 "issues",
49 "issue",
50 "ask",
51 "waiting",
52 "answer",
53] as const;
55const PROTOCOLS = ["2025-06-18", "2025-03-26", "2024-11-05"];
57interface Tool {
58 readonly name: string;
59 readonly description: string;
60 readonly inputSchema: Record<string, unknown>;
63/** A tool's name: the command, with _ for - (check-ignore is check_ignore). */
64const toolName = (command: string): string => command.replace(/-/g, "_");
66export function mcpTools(): Tool[] {
67 const table = commandTable();
68 return MCP_COMMANDS.map((command) => {
69 const def = table[command]!;
70 const flags = Object.fromEntries(
71 Object.entries(def.flags).map(([flag, kind]) => [
72 flag,
73 kind === "boolean"
74 ? { type: "boolean", description: `--${flag}` }
75 : {
76 type: "string",
77 description: kind === "optional" ? `--${flag} "<value>"; "" gives --${flag} alone` : `--${flag} <value>`,
78 },
79 ]),
80 );
81 return {
82 name: toolName(command),
83 description: `${def.usage}\n${def.about}`,
84 inputSchema: {
85 type: "object",
86 properties: {
87 args: {
88 type: "array",
89 items: { type: "string" },
90 description: "The words after the command, as on the command line: files, versions, text.",
91 },
92 folder: {
93 type: "string",
94 description: "The abso folder to run in (default: the folder this server started in).",
95 },
96 json: { type: "boolean", description: "Answer with the command's JSON (as --json) instead of its text." },
97 ...flags,
98 },
99 additionalProperties: false,
100 },
101 };
102 });
105/** The command line a tool call stands for: flags as --name=value, then the words after --. */
106export function argvFor(command: string, input: Readonly<Record<string, unknown>>): string[] {
107 const def = commandTable()[command]!;
108 const argv = [command];
109 for (const [flag, kind] of Object.entries(def.flags)) {
110 const value = input[flag];
111 if (value === undefined || value === null || value === false) continue;
112 if (kind === "boolean") argv.push(`--${flag}`);
113 else argv.push(`--${flag}=${String(value)}`);
114 }
115 const words = Array.isArray(input.args) ? input.args.map(String) : [];
116 if (words.length > 0) argv.push("--", ...words);
117 return argv;
120type Message = { jsonrpc?: string; id?: string | number | null; method?: string; params?: Record<string, unknown> };
122/**
123 * Serve MCP on `lines` (each one JSON-RPC message), answering through `send`.
124 * Calls run one at a time, since a command's news is gathered process-wide.
125 */
126export async function serveMcp(
127 input: AsyncIterable<Buffer | string>,
128 send: (line: string) => void,
129 cwd: string,
130 env: Readonly<Record<string, string | undefined>>,
131): Promise<void> {
132 let queue: Promise<void> = Promise.resolve();
133 const reply = (id: Message["id"], result: unknown) => send(JSON.stringify({ jsonrpc: "2.0", id, result }));
134 const fail = (id: Message["id"], code: number, message: string) =>
135 send(JSON.stringify({ jsonrpc: "2.0", id: id ?? null, error: { code, message } }));
137 const handle = async (msg: Message): Promise<void> => {
138 const { id, method, params = {} } = msg;
139 const isRequest = id !== undefined && id !== null;
140 switch (method) {
141 case "initialize": {
142 const asked = typeof params.protocolVersion === "string" ? params.protocolVersion : "";
143 return reply(id, {
144 protocolVersion: PROTOCOLS.includes(asked) ? asked : PROTOCOLS[0],
145 capabilities: { tools: {} },
146 serverInfo: { name: "avcs", version: clientVersion() },
147 instructions:
148 "avcs, the agent-first version control client. Each tool is the abso command of the same name and answers with the command line's text. Box runs (abso run, shot, bisect) stay in the shell.",
149 });
150 }
151 case "ping":
152 return reply(id, {});
153 case "tools/list":
154 return reply(id, { tools: mcpTools() });
155 case "tools/call": {
156 const name = typeof params.name === "string" ? params.name : "";
157 const command = MCP_COMMANDS.find((c) => toolName(c) === name);
158 if (command === undefined) return fail(id, -32602, `no tool ${JSON.stringify(name)}; tools/list names them`);
159 const args = (params.arguments ?? {}) as Record<string, unknown>;
160 const folder = typeof args.folder === "string" && args.folder !== "" ? resolve(cwd, args.folder) : cwd;
161 let streamed = "";
162 const result = await main(argvFor(command, args), {
163 cwd: folder,
164 env,
165 write: (t) => (streamed += t),
166 writeErr: (t) => (streamed += t),
167 });
168 // Text only: Claude Code shows the model structuredContent in place of the text when both are there,
169 // and the point is the command line's words. json: true answers with the JSON instead.
170 const text =
171 args.json === true && result.data
172 ? JSON.stringify({ ...result.data, exit: result.exit }, null, 2)
173 : [streamed, result.stdout, result.stderr]
174 .map((t) => t.replace(/\n+$/, ""))
175 .filter((t) => t !== "")
176 .join("\n");
177 return reply(id, {
178 content: [{ type: "text", text: text === "" ? "(no output)" : text }],
179 // Exit 1 is a failure; 2 (refused) and 3 (still queued) are answers the text explains.
180 isError: result.exit === 1,
181 });
182 }
183 default:
184 // Notifications (no id) need no answer; an unknown request does.
185 if (isRequest) fail(id, -32601, `abso mcp doesn't know ${JSON.stringify(method)}`);
186 }
187 };
189 let buffer = "";
190 for await (const chunk of input) {
191 buffer += typeof chunk === "string" ? chunk : chunk.toString("utf8");
192 let nl: number;
193 while ((nl = buffer.indexOf("\n")) >= 0) {
194 const line = buffer.slice(0, nl).trim();
195 buffer = buffer.slice(nl + 1);
196 if (line === "") continue;
197 let msg: Message;
198 try {
199 msg = JSON.parse(line) as Message;
200 } catch {
201 fail(null, -32700, "not JSON");
202 continue;
203 }
204 queue = queue
205 .then(() => handle(msg))
206 .catch((e: unknown) => fail(msg.id, -32603, e instanceof Error ? e.message : String(e)));
207 }
208 }
209 await queue;