@meshpoint/cli 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { randomUUID } from "node:crypto";
2
3
  import { readFileSync } from "node:fs";
3
4
  import path from "node:path";
4
5
  import { fileURLToPath } from "node:url";
@@ -17,7 +18,7 @@ import { connectPi } from "./pi/connect.js";
17
18
  import { Checkpoints } from "./checkpoints.js";
18
19
  import { configPath, deleteConfig, loadConfig, repoContext, saveConfig, spoolDir, stateDir } from "./config.js";
19
20
  import { SessionCache } from "./context.js";
20
- import { localChecks } from "./tap.js";
21
+ import { localChecks, Tap } from "./tap.js";
21
22
  import { Touched } from "./touched.js";
22
23
  import { MeshpointError } from "@meshpoint/sdk";
23
24
  import { api, ApiError, canOpenBrowser, deviceLogin, freshConfig, login } from "./control.js";
@@ -27,6 +28,9 @@ import { branchItems, confirmItems, parseItemArgs, parseItems, putItems, retract
27
28
  import { importOffer } from "./import/offer.js";
28
29
  import { applyProposalFile, DEFAULT_SINCE_DAYS, importSessions } from "./import/run.js";
29
30
  import { AGENTS_FILE, exportConventions, hasBlock } from "./agents-md.js";
31
+ import { connectMcp } from "./mcp/connect.js";
32
+ import { McpServer } from "./mcp/server.js";
33
+ import { MCP_INSTRUCTIONS, MCP_SERVER_NAME, meshpointTools } from "./mcp/tools.js";
30
34
  import { detectRunner } from "./import/runner.js";
31
35
  import { Spool } from "./spool.js";
32
36
  const IMPORT_USAGE = ` import sessions [--since <days>] [--all-repos] [--with-turns] [--apply | --propose] [--yes] [--fresh]
@@ -88,6 +92,12 @@ const USAGE = `meshpoint <command>
88
92
  opencode [--config-dir <dir>] <dir>/plugins/meshpoint.js + <dir>/skills/meshpoint
89
93
  (default dir: ~/.config/opencode)
90
94
  openclaw hook pack installed through 'openclaw plugins install'
95
+ mcp prints where MCP clients take the server; --project <dir>
96
+ writes <dir>/.mcp.json (Claude Code project scope, VS Code
97
+ with Copilot)
98
+ mcp [--cwd <dir>] stdio MCP server for clients without a hook: tools for recall,
99
+ file context and item writes; the repository is the working
100
+ directory
91
101
  items put --item <kind> <title> <body> [--item ...]
92
102
  items put --file <path> | items put < items.json
93
103
  write items for the current repo and branch; the file or
@@ -106,6 +116,9 @@ function flag(args, name) {
106
116
  const i = args.indexOf(name);
107
117
  return i >= 0 ? args[i + 1] : undefined;
108
118
  }
119
+ function installedVersion() {
120
+ return JSON.parse(readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), "utf8")).version;
121
+ }
109
122
  const DEFAULT_BASE_URL = "https://api.meshpoint.dev";
110
123
  async function requireConfig() {
111
124
  const config = loadConfig();
@@ -176,8 +189,7 @@ async function main(argv) {
176
189
  case "--version":
177
190
  case "-v":
178
191
  case "version": {
179
- const pkg = JSON.parse(readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), "utf8"));
180
- process.stdout.write(`${pkg.version}\n`);
192
+ process.stdout.write(`${installedVersion()}\n`);
181
193
  return 0;
182
194
  }
183
195
  case "login": {
@@ -256,9 +268,11 @@ async function main(argv) {
256
268
  console.log(connectOpenclaw({ remove }));
257
269
  else if (rest[0] === "opencode")
258
270
  console.log(connectOpencode({ remove, ...(configDir ? { configDir } : {}) }));
271
+ else if (rest[0] === "mcp")
272
+ console.log(connectMcp({ remove, ...inProject }));
259
273
  else
260
- throw new Error("connect supports: claude-code, codex, cursor, antigravity, pi, opencode, openclaw");
261
- if (!remove) {
274
+ throw new Error("connect supports: claude-code, codex, cursor, antigravity, pi, opencode, openclaw, mcp");
275
+ if (!remove && rest[0] !== "mcp") {
262
276
  // Past sessions for this repository are worth a line; the offer never fails the connect.
263
277
  try {
264
278
  const repo = repoContext(process.cwd());
@@ -297,6 +311,35 @@ async function main(argv) {
297
311
  console.log(JSON.stringify({ ...out, project: repo.project, branch: repo.branch }));
298
312
  return 0;
299
313
  }
314
+ case "mcp": {
315
+ const cwd = flag(rest, "--cwd") ?? process.cwd();
316
+ if (!path.isAbsolute(cwd))
317
+ throw new Error("--cwd must be an absolute path");
318
+ const stored = loadConfig();
319
+ const config = stored ? await freshConfig(stored).catch(() => stored) : null;
320
+ const repo = repoContext(cwd);
321
+ const tap = config && repo
322
+ ? new Tap({
323
+ config,
324
+ repo,
325
+ session: `mcp-${randomUUID()}`,
326
+ spool: new Spool(spoolDir()),
327
+ checkpoints: new Checkpoints(stateDir()),
328
+ touched: new Touched(stateDir()),
329
+ cache: new SessionCache(stateDir()),
330
+ local: localChecks(repo.root),
331
+ refresh: () => freshConfig(config, { force: true }).catch(() => null),
332
+ })
333
+ : null;
334
+ const server = new McpServer({
335
+ name: MCP_SERVER_NAME,
336
+ version: installedVersion(),
337
+ instructions: MCP_INSTRUCTIONS,
338
+ tools: meshpointTools({ tap, cwd, config: requireConfig, checkpoints: new Checkpoints(stateDir()), touched: new Touched(stateDir()) }),
339
+ });
340
+ await server.serve(process.stdin, process.stdout);
341
+ return 0;
342
+ }
300
343
  case "export": {
301
344
  if (rest[0] !== "agents")
302
345
  throw new Error("export supports: agents");
@@ -0,0 +1,61 @@
1
+ import { readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import path from "node:path";
4
+ // Registers the stdio server where MCP clients look. One file is written: <repo>/.mcp.json, which
5
+ // Claude Code (project scope) and VS Code with Copilot both read. Other clients keep their own
6
+ // user-level files; connect prints the entry for them instead of guessing at those files.
7
+ export const MCP_FILE = ".mcp.json";
8
+ export const MCP_ENTRY = { type: "stdio", command: "meshpoint", args: ["mcp"] };
9
+ export function installMcpEntry(file) {
10
+ return { ...file, mcpServers: { ...file.mcpServers, meshpoint: MCP_ENTRY } };
11
+ }
12
+ export function removeMcpEntry(file) {
13
+ const { meshpoint: _dropped, ...servers } = file.mcpServers ?? {};
14
+ const { mcpServers: _old, ...rest } = file;
15
+ return Object.keys(servers).length > 0 ? { ...rest, mcpServers: servers } : rest;
16
+ }
17
+ export function mcpSnippets(home = homedir(), platform = process.platform) {
18
+ const entry = JSON.stringify({ mcpServers: { meshpoint: MCP_ENTRY } }, null, 2);
19
+ const desktop = platform === "darwin" ? path.join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json") : platform === "win32" ? "%APPDATA%\\Claude\\claude_desktop_config.json" : path.join(home, ".config", "Claude", "claude_desktop_config.json");
20
+ return [
21
+ "Add the Meshpoint MCP server to a client by hand:",
22
+ "",
23
+ ` Claude Code, VS Code with Copilot (one repository): meshpoint connect mcp --project <repo> writes <repo>/${MCP_FILE}`,
24
+ ` Claude Code (every repository): claude mcp add --scope user meshpoint -- meshpoint mcp`,
25
+ ` VS Code with Copilot (every repository): ${path.join(home, ".copilot", "mcp-config.json")}`,
26
+ ` Claude Desktop: ${desktop}`,
27
+ ` Zed: settings.json, key "context_servers": {"meshpoint": {"command": "meshpoint", "args": ["mcp"]}}`,
28
+ "",
29
+ "The entry for the mcpServers files:",
30
+ "",
31
+ entry.replace(/^/gm, " "),
32
+ "",
33
+ "The server finds the repository from its working directory; clients that start it elsewhere pass --cwd <repo> in args.",
34
+ ].join("\n");
35
+ }
36
+ export function connectMcp(opts) {
37
+ if (!opts.projectDir) {
38
+ if (opts.remove)
39
+ return "connect mcp --remove needs --project <repo>; user-level entries were added by hand and are removed the same way";
40
+ return mcpSnippets();
41
+ }
42
+ const file = path.join(opts.projectDir, MCP_FILE);
43
+ let current = {};
44
+ try {
45
+ current = JSON.parse(readFileSync(file, "utf8"));
46
+ }
47
+ catch (err) {
48
+ if (err.code !== "ENOENT")
49
+ throw new Error(`could not read ${file}: ${err.message}`);
50
+ }
51
+ if (opts.remove) {
52
+ const next = removeMcpEntry(current);
53
+ if (Object.keys(next).length > 0)
54
+ writeFileSync(file, `${JSON.stringify(next, null, 2)}\n`);
55
+ else
56
+ rmSync(file, { force: true });
57
+ return `removed the meshpoint server from ${file}`;
58
+ }
59
+ writeFileSync(file, `${JSON.stringify(installMcpEntry(current), null, 2)}\n`);
60
+ return `registered the meshpoint MCP server in ${file} (Claude Code project scope, VS Code with Copilot). Commit it so the team gets it; Claude Code asks once to approve a project server.`;
61
+ }
@@ -0,0 +1,111 @@
1
+ // A stdio MCP server: JSON-RPC 2.0, one message per line. Only the lifecycle and the tools
2
+ // methods are implemented; everything else answers "method not found". No SDK: the protocol
3
+ // surface used here is five methods and fits in a file.
4
+ export const PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
5
+ const DEFAULT_PROTOCOL = PROTOCOL_VERSIONS[0];
6
+ const PARSE_ERROR = -32700;
7
+ const INVALID_REQUEST = -32600;
8
+ const METHOD_NOT_FOUND = -32601;
9
+ const INVALID_PARAMS = -32602;
10
+ const INTERNAL = -32603;
11
+ class RpcError extends Error {
12
+ code;
13
+ constructor(code, message) {
14
+ super(message);
15
+ this.code = code;
16
+ }
17
+ }
18
+ export class McpServer {
19
+ opts;
20
+ constructor(opts) {
21
+ this.opts = opts;
22
+ }
23
+ // One request in, one result or error out; null for notifications.
24
+ async handle(req) {
25
+ const id = req.id ?? null;
26
+ if (req.jsonrpc !== "2.0" || typeof req.method !== "string")
27
+ return id === null ? null : error(id, INVALID_REQUEST, "invalid request");
28
+ if (req.method.startsWith("notifications/"))
29
+ return null;
30
+ try {
31
+ return { jsonrpc: "2.0", id, result: await this.dispatch(req.method, req.params ?? {}) };
32
+ }
33
+ catch (err) {
34
+ if (err instanceof RpcError)
35
+ return error(id, err.code, err.message);
36
+ return error(id, INTERNAL, err instanceof Error ? err.message : String(err));
37
+ }
38
+ }
39
+ async dispatch(method, params) {
40
+ switch (method) {
41
+ case "initialize": {
42
+ const asked = typeof params.protocolVersion === "string" ? params.protocolVersion : "";
43
+ return {
44
+ protocolVersion: PROTOCOL_VERSIONS.includes(asked) ? asked : DEFAULT_PROTOCOL,
45
+ capabilities: { tools: {} },
46
+ serverInfo: { name: this.opts.name, version: this.opts.version },
47
+ instructions: this.opts.instructions,
48
+ };
49
+ }
50
+ case "ping":
51
+ return {};
52
+ case "tools/list":
53
+ return { tools: this.opts.tools.map(({ name, description, inputSchema }) => ({ name, description, inputSchema })) };
54
+ case "tools/call": {
55
+ const tool = this.opts.tools.find((t) => t.name === params.name);
56
+ if (!tool)
57
+ throw new RpcError(INVALID_PARAMS, `unknown tool: ${String(params.name)}`);
58
+ const args = params.arguments;
59
+ if (args !== undefined && (typeof args !== "object" || args === null || Array.isArray(args)))
60
+ throw new RpcError(INVALID_PARAMS, "arguments must be an object");
61
+ try {
62
+ return { content: [{ type: "text", text: await tool.run(args ?? {}) }], isError: false };
63
+ }
64
+ catch (err) {
65
+ return { content: [{ type: "text", text: err instanceof Error ? err.message : String(err) }], isError: true };
66
+ }
67
+ }
68
+ default:
69
+ throw new RpcError(METHOD_NOT_FOUND, `method not found: ${method}`);
70
+ }
71
+ }
72
+ // Reads lines until the input ends; answers are written as they are ready.
73
+ async serve(input, output) {
74
+ let buffer = "";
75
+ const pending = [];
76
+ const write = (msg) => {
77
+ output.write(`${JSON.stringify(msg)}\n`);
78
+ };
79
+ const take = (line) => {
80
+ const text = line.trim();
81
+ if (!text)
82
+ return;
83
+ let req;
84
+ try {
85
+ req = JSON.parse(text);
86
+ }
87
+ catch {
88
+ write(error(null, PARSE_ERROR, "parse error"));
89
+ return;
90
+ }
91
+ pending.push(this.handle(req).then((res) => {
92
+ if (res)
93
+ write(res);
94
+ }));
95
+ };
96
+ for await (const chunk of input) {
97
+ buffer += typeof chunk === "string" ? chunk : chunk.toString("utf8");
98
+ let nl = buffer.indexOf("\n");
99
+ while (nl >= 0) {
100
+ take(buffer.slice(0, nl));
101
+ buffer = buffer.slice(nl + 1);
102
+ nl = buffer.indexOf("\n");
103
+ }
104
+ }
105
+ take(buffer);
106
+ await Promise.all(pending);
107
+ }
108
+ }
109
+ function error(id, code, message) {
110
+ return { jsonrpc: "2.0", id, error: { code, message } };
111
+ }
@@ -0,0 +1,90 @@
1
+ import { KINDS } from "@meshpoint/sdk";
2
+ import { confirmItems, ITEMS_MAX, parseItems, putItems, retractItems } from "../items.js";
3
+ // The Meshpoint tools an MCP client gets: the session-start context, the notice for one file,
4
+ // and the three item writes. Capture and presence need a hook or plugin and are not here.
5
+ export const MCP_SERVER_NAME = "meshpoint";
6
+ export const MCP_INSTRUCTIONS = `Meshpoint is the team's shared memory for this repository, per branch.
7
+ Call meshpoint_recall once at the start of a task: it lists what teammates' agents learned (decisions, gotchas, conventions, facts, status, todos) and who is active now. Before editing a file, meshpoint_file_context tells you what is known about that file and whether a teammate is on it.
8
+ Record what you establish with meshpoint_items_put: one item per decision, gotcha, convention, fact, status or todo, bodies concrete (repo-relative file names, commands, values, reasons), nothing already listed by recall unless it changed, no secrets. Retract items you proved wrong with meshpoint_items_retract.`;
9
+ const IDS_SCHEMA = { type: "array", items: { type: "string" }, minItems: 1, description: "Item ids or unique id prefixes, as recall lists them." };
10
+ function strings(v, what) {
11
+ if (!Array.isArray(v) || v.length === 0 || !v.every((s) => typeof s === "string" && s.trim()))
12
+ throw new Error(`${what} must be a non-empty list of strings`);
13
+ return v.map((s) => s.trim());
14
+ }
15
+ export function meshpointTools(deps) {
16
+ const tap = () => {
17
+ if (!deps.tap)
18
+ throw new Error(`${deps.cwd} is not inside a git repository with an origin remote; start the server in one or pass --cwd`);
19
+ return deps.tap;
20
+ };
21
+ const repo = () => tap().repo;
22
+ const itemDeps = async () => ({ config: await deps.config(), repo: repo(), ...(deps.fetch ? { fetch: deps.fetch } : {}) });
23
+ return [
24
+ {
25
+ name: "meshpoint_recall",
26
+ description: "Team knowledge for this repository and branch: items from teammates' agents (first column is the item id, ? marks an item whose referenced file changed since) and who is active now. Call once at the start of a task.",
27
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
28
+ run: async () => {
29
+ const text = await tap().start();
30
+ return text || `No team knowledge for ${repo().project} @ ${repo().branch} yet.`;
31
+ },
32
+ },
33
+ {
34
+ name: "meshpoint_file_context",
35
+ description: "What is known about one file before you edit it: items naming it and teammates editing it now. Path is repo-relative or absolute.",
36
+ inputSchema: { type: "object", properties: { path: { type: "string", description: "File path, repo-relative or absolute." } }, required: ["path"], additionalProperties: false },
37
+ run: async (args) => {
38
+ if (typeof args.path !== "string" || !args.path.trim())
39
+ throw new Error("path is required");
40
+ const text = await tap().fileContext(args.path.trim());
41
+ return text || `Nothing recorded about ${args.path.trim()}; nobody else is on it.`;
42
+ },
43
+ },
44
+ {
45
+ name: "meshpoint_items_put",
46
+ description: `Write knowledge items for this repository and branch. Each item: kind (${KINDS.join(", ")}), one-line title, one to three concrete sentences as body; optional key (a stable slot such as test-runner; a later item with the same key replaces this one) and supersedes (ids this item replaces). At most ${ITEMS_MAX} per call. Name files by repo-relative path; the result lists paths that do not exist in the checkout.`,
47
+ inputSchema: {
48
+ type: "object",
49
+ properties: {
50
+ items: {
51
+ type: "array",
52
+ minItems: 1,
53
+ maxItems: ITEMS_MAX,
54
+ items: {
55
+ type: "object",
56
+ properties: {
57
+ kind: { type: "string", enum: [...KINDS] },
58
+ title: { type: "string" },
59
+ body: { type: "string" },
60
+ key: { type: "string" },
61
+ supersedes: { type: "array", items: { type: "string" } },
62
+ },
63
+ required: ["kind", "title", "body"],
64
+ additionalProperties: false,
65
+ },
66
+ },
67
+ },
68
+ required: ["items"],
69
+ additionalProperties: false,
70
+ },
71
+ run: async (args) => {
72
+ const drafts = parseItems(JSON.stringify(args.items ?? null));
73
+ const { missing, ...out } = await putItems(drafts, { ...(await itemDeps()), checkpoints: deps.checkpoints, touched: deps.touched });
74
+ return JSON.stringify({ ...out, project: repo().project, branch: repo().branch, ...(missing.length ? { ref_not_found: missing } : {}) });
75
+ },
76
+ },
77
+ {
78
+ name: "meshpoint_items_retract",
79
+ description: "Retract items on this branch that this session proved wrong: a finished todo, a reversed decision with nothing in its place.",
80
+ inputSchema: { type: "object", properties: { ids: IDS_SCHEMA }, required: ["ids"], additionalProperties: false },
81
+ run: async (args) => JSON.stringify(await retractItems(strings(args.ids, "ids"), await itemDeps())),
82
+ },
83
+ {
84
+ name: "meshpoint_items_confirm",
85
+ description: "Confirm items that held true in this session; confirmations raise an item in recall and keep status and todo items from expiring.",
86
+ inputSchema: { type: "object", properties: { ids: IDS_SCHEMA }, required: ["ids"], additionalProperties: false },
87
+ run: async (args) => JSON.stringify(await confirmItems(strings(args.ids, "ids"), await itemDeps())),
88
+ },
89
+ ];
90
+ }
package/dist/tap.js CHANGED
@@ -93,18 +93,25 @@ export class Tap {
93
93
  return "";
94
94
  if (this.deps.cache && !this.deps.cache.firstEdit(this.deps.session, rel))
95
95
  return "";
96
- const cached = this.deps.cache?.loadRecall(this.deps.session);
97
- const ctx = await Promise.race([
98
- this.client(this.repo.branch).context(rel).catch(() => null),
99
- new Promise((r) => setTimeout(() => r(null), EDIT_WAIT_MS)),
100
- ]);
101
- const items = cached ? itemsForFile(cached.items, cached.verdicts, rel) : (ctx?.items ?? []);
102
- return renderEditNotice(rel, items, ctx?.presence ?? [], this.now());
96
+ return await this.fileContext(rel);
103
97
  }
104
98
  catch {
105
99
  return "";
106
100
  }
107
101
  }
102
+ // The same notice on demand, every time it is asked for (the MCP tool).
103
+ async fileContext(filePath) {
104
+ const rel = this.relative(filePath);
105
+ if (!rel)
106
+ return "";
107
+ const cached = this.deps.cache?.loadRecall(this.deps.session);
108
+ const ctx = await Promise.race([
109
+ this.client(this.repo.branch).context(rel).catch(() => null),
110
+ new Promise((r) => setTimeout(() => r(null), EDIT_WAIT_MS)),
111
+ ]);
112
+ const items = cached ? itemsForFile(cached.items, cached.verdicts, rel) : (ctx?.items ?? []);
113
+ return renderEditNotice(rel, items, ctx?.presence ?? [], this.now());
114
+ }
108
115
  async user(prompt) {
109
116
  if (prompt)
110
117
  this.spoolTurn(`[user] ${prompt}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshpoint/cli",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Meshpoint CLI and harness adapters: shared agent memory for developer teams",
5
5
  "keywords": [
6
6
  "meshpoint",