hmcp-gateway 0.1.0 → 0.2.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/README.md +94 -0
- package/dist/adopt-cli.d.ts +5 -1
- package/dist/adopt-cli.js +45 -17
- package/dist/adopt-plan.js +116 -1
- package/dist/cli.js +124 -3
- package/dist/client-config.d.ts +65 -2
- package/dist/client-config.js +235 -24
- package/dist/connect-client.d.ts +3 -1
- package/dist/connect-client.js +55 -5
- package/dist/desktop-extensions.d.ts +53 -0
- package/dist/desktop-extensions.js +126 -0
- package/dist/gateway.d.ts +10 -0
- package/dist/gateway.js +21 -5
- package/dist/github-doors.d.ts +162 -0
- package/dist/github-doors.js +780 -0
- package/dist/guard-install.d.ts +109 -0
- package/dist/guard-install.js +396 -0
- package/dist/guard.d.ts +265 -0
- package/dist/guard.js +975 -0
- package/dist/import-client.d.ts +184 -0
- package/dist/import-client.js +578 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/toml-edit.d.ts +43 -0
- package/dist/toml-edit.js +363 -0
- package/package.json +4 -3
package/dist/client-config.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export declare class ClientConfigError extends Error {
|
|
|
49
49
|
* everything this command does to one of them is identical: read the servers,
|
|
50
50
|
* write a gateway entry in their place, and be able to put them back.
|
|
51
51
|
*/
|
|
52
|
-
export type Scope = "project" | "local" | "user" | "claude-desktop" | "cursor-project" | "cursor-user" | "vscode-project" | "vscode-user" | "windsurf";
|
|
52
|
+
export type Scope = "project" | "local" | "user" | "claude-desktop" | "cursor-project" | "cursor-user" | "vscode-project" | "vscode-user" | "windsurf" | "copilot-cli" | "antigravity" | "antigravity-project" | "devin" | "devin-project" | "junie" | "junie-project" | "roo-project" | "codex" | "codex-project";
|
|
53
53
|
export interface ScopeTarget {
|
|
54
54
|
readonly scope: Scope;
|
|
55
55
|
/** The JSON file holding them. */
|
|
@@ -65,12 +65,33 @@ export interface ScopeTarget {
|
|
|
65
65
|
readonly key: string;
|
|
66
66
|
/** Which program owns this file, for anything shown to a person. */
|
|
67
67
|
readonly client: string;
|
|
68
|
+
/**
|
|
69
|
+
* Fields this app wants on an entry it starts as a program, beside
|
|
70
|
+
* `command`/`args`/`env`. VS Code names the transport (`type: "stdio"`);
|
|
71
|
+
* GitHub Copilot CLI says `type: "local"` and lists the tools it may use.
|
|
72
|
+
* Absent for the apps that work it out from `command`.
|
|
73
|
+
*/
|
|
74
|
+
readonly stdioFields?: Readonly<Record<string, unknown>>;
|
|
75
|
+
/**
|
|
76
|
+
* The app reaches remote servers over Streamable HTTP only (Antigravity
|
|
77
|
+
* CLI), so a web address ending in `/sse` is read as HTTP there, not as
|
|
78
|
+
* the older SSE transport. Pass it to `parseServers`.
|
|
79
|
+
*/
|
|
80
|
+
readonly httpOnly?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The file is TOML (Codex), not JSON. It is only ever read with a parser;
|
|
83
|
+
* every change is a cut or an append on its own text (toml-edit.ts), so
|
|
84
|
+
* the person's comments and layout survive.
|
|
85
|
+
*/
|
|
86
|
+
readonly format?: "toml";
|
|
68
87
|
}
|
|
69
88
|
export interface ScopeOptions {
|
|
70
89
|
readonly cwd?: string;
|
|
71
90
|
readonly home?: string;
|
|
72
91
|
/** Overridable so the per-platform paths can be tested on one machine. */
|
|
73
92
|
readonly platform?: string;
|
|
93
|
+
/** Codex's own folder. Default: `CODEX_HOME` when set, else `~/.codex`. */
|
|
94
|
+
readonly codexHome?: string;
|
|
74
95
|
}
|
|
75
96
|
/**
|
|
76
97
|
* The three places Claude Code keeps MCP servers, in the order it resolves
|
|
@@ -81,6 +102,15 @@ export interface ScopeOptions {
|
|
|
81
102
|
* project.
|
|
82
103
|
*/
|
|
83
104
|
export declare function scopeTargets(options?: ScopeOptions): ScopeTarget[];
|
|
105
|
+
/**
|
|
106
|
+
* When CODEX_HOME has moved Codex's folder away from `~/.codex`, words that
|
|
107
|
+
* say so: Codex follows it, but the ChatGPT desktop app may not. Null for
|
|
108
|
+
* every other scope, and for the usual folder.
|
|
109
|
+
*/
|
|
110
|
+
export declare function codexHomeNote(target: {
|
|
111
|
+
readonly scope: string;
|
|
112
|
+
readonly path: string;
|
|
113
|
+
}, home?: string): string | null;
|
|
84
114
|
export interface ClientConfigFile {
|
|
85
115
|
readonly target: ScopeTarget;
|
|
86
116
|
/** The file's bytes as read, so a backup and an undo can be exact. Null when there is no file. */
|
|
@@ -107,6 +137,8 @@ export declare function readClientConfig(scope: Scope, options?: ScopeOptions):
|
|
|
107
137
|
* line numbers in an error still point at the person's own file.
|
|
108
138
|
*/
|
|
109
139
|
export declare function stripJsonc(text: string): string;
|
|
140
|
+
/** The indent a file uses (two spaces, four, a tab), so a rewrite looks like the file it replaces. */
|
|
141
|
+
export declare function detectIndent(text: string | null): string | number;
|
|
110
142
|
/**
|
|
111
143
|
* Whether the file reads the same as `value`: same keys and values, whatever
|
|
112
144
|
* the spacing. Used to decide that an undo may put the original bytes back.
|
|
@@ -126,8 +158,13 @@ export interface ParsedServers {
|
|
|
126
158
|
* An entry carrying `type: "http"` or `"sse"` is held to the remote shape
|
|
127
159
|
* rather than being offered to both: a remote entry missing its `url` should
|
|
128
160
|
* report that, not the stdio schema's complaint about a missing `command`.
|
|
161
|
+
*
|
|
162
|
+
* `httpOnly` is the scope's own flag (Antigravity CLI): a typeless web
|
|
163
|
+
* address is then Streamable HTTP whatever its path ends in.
|
|
129
164
|
*/
|
|
130
|
-
export declare function parseServers(raw: Record<string, unknown
|
|
165
|
+
export declare function parseServers(raw: Record<string, unknown>, options?: {
|
|
166
|
+
readonly httpOnly?: boolean | undefined;
|
|
167
|
+
}): ParsedServers;
|
|
131
168
|
/**
|
|
132
169
|
* Which scope `adopt` should act on when nobody said.
|
|
133
170
|
*
|
|
@@ -145,6 +182,12 @@ export declare function resolveScope(explicit: Scope | undefined, options?: Scop
|
|
|
145
182
|
* replaced in its text, so every comment outside that list survives.
|
|
146
183
|
*/
|
|
147
184
|
export declare function writeClientConfig(file: ClientConfigFile, servers: Record<string, unknown>): void;
|
|
185
|
+
/**
|
|
186
|
+
* Why this file cannot be changed safely, before anything is written, or
|
|
187
|
+
* null. Only Codex's TOML has forms that are refused; reading and listing
|
|
188
|
+
* such a file still work.
|
|
189
|
+
*/
|
|
190
|
+
export declare function clientEditProblem(file: ClientConfigFile): string | null;
|
|
148
191
|
export interface RestoreResult {
|
|
149
192
|
/** "bytes": the original file came back exactly; "removed": the file did not exist before and is gone again. */
|
|
150
193
|
readonly how: "bytes" | "removed" | "rewritten";
|
|
@@ -160,6 +203,26 @@ export interface RestoreResult {
|
|
|
160
203
|
* with the file's own indent, and the copy stays.
|
|
161
204
|
*/
|
|
162
205
|
export declare function restoreClientConfig(file: ClientConfigFile, servers: Record<string, unknown>): RestoreResult;
|
|
206
|
+
/**
|
|
207
|
+
* Atomic write through a temporary file, as `writeRegistry` does: a crash
|
|
208
|
+
* mid-write must not leave a half-written config that then fails to parse and
|
|
209
|
+
* takes every one of the user's MCP servers with it.
|
|
210
|
+
*
|
|
211
|
+
* The existing mode is preserved rather than assumed. `~/.claude.json` is
|
|
212
|
+
* `0600` on a normal install and holds an OAuth account; widening it while
|
|
213
|
+
* adding a server would be a quiet regression. A file we are creating gets
|
|
214
|
+
* `0600` outright. (Backups are written by `writePrivateText`, always 0600.)
|
|
215
|
+
*/
|
|
216
|
+
export declare function writeTextPreservingMode(path: string, text: string): void;
|
|
217
|
+
/**
|
|
218
|
+
* A backup's write: atomic, and readable by its owner only, whatever mode the
|
|
219
|
+
* file it copies has. A backup holds the app's original entries, keys and
|
|
220
|
+
* all; a project's `.mcp.json` is often 0644 because it is meant to be
|
|
221
|
+
* shared, and its copy must not be (R4-2). Undo writes the original bytes
|
|
222
|
+
* back into the app's own file, which keeps that file's mode, so the backup's
|
|
223
|
+
* mode never reaches it.
|
|
224
|
+
*/
|
|
225
|
+
export declare function writePrivateText(path: string, text: string): void;
|
|
163
226
|
/** After undo: the project's backups folder goes once nothing but its own `.gitignore` is left in it. */
|
|
164
227
|
export declare function tidyProjectBackups(target: ScopeTarget): void;
|
|
165
228
|
/** A verbatim copy of the file before adoption touched it. One made by an earlier build, beside the file, is still used. */
|
package/dist/client-config.js
CHANGED
|
@@ -2,7 +2,9 @@ import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { basename, dirname, join, resolve } from "node:path";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
+
import { TomlError } from "smol-toml";
|
|
5
6
|
import { canonicalJson } from "hmcp-core";
|
|
7
|
+
import { editTomlServers, parseToml, sameToml, TomlEditError, tomlEditProblem } from "./toml-edit.js";
|
|
6
8
|
/**
|
|
7
9
|
* Claude Code's own MCP server configuration: finding it, reading it, and
|
|
8
10
|
* putting it back.
|
|
@@ -44,7 +46,9 @@ export function isRemote(server) {
|
|
|
44
46
|
* SSE servers conventionally end their path in `/sse`, and everything else is
|
|
45
47
|
* streamable HTTP.
|
|
46
48
|
*/
|
|
47
|
-
function remoteTypeFor(url) {
|
|
49
|
+
function remoteTypeFor(url, httpOnly) {
|
|
50
|
+
if (httpOnly)
|
|
51
|
+
return "http";
|
|
48
52
|
try {
|
|
49
53
|
return /\/sse\/?$/.test(new URL(url).pathname) ? "sse" : "http";
|
|
50
54
|
}
|
|
@@ -81,6 +85,15 @@ function vscodeUserPath(home, platform) {
|
|
|
81
85
|
return join(home, "Library", "Application Support", "Code", "User", "mcp.json");
|
|
82
86
|
return join(home, ".config", "Code", "User", "mcp.json");
|
|
83
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Devin Desktop's (formerly Windsurf's) all-projects file: under `.config`
|
|
90
|
+
* on macOS and Linux, under the roaming AppData folder on Windows.
|
|
91
|
+
*/
|
|
92
|
+
function devinUserPath(home, platform) {
|
|
93
|
+
if (platform === "win32")
|
|
94
|
+
return join(home, "AppData", "Roaming", "devin", "mcp_config.json");
|
|
95
|
+
return join(home, ".config", "devin", "mcp_config.json");
|
|
96
|
+
}
|
|
84
97
|
/**
|
|
85
98
|
* The three places Claude Code keeps MCP servers, in the order it resolves
|
|
86
99
|
* them.
|
|
@@ -131,26 +144,145 @@ export function scopeTargets(options = {}) {
|
|
|
131
144
|
path: join(cwd, ".vscode", "mcp.json"),
|
|
132
145
|
where: "servers",
|
|
133
146
|
key: "servers",
|
|
134
|
-
client: "VS Code (this project)"
|
|
147
|
+
client: "VS Code (this project)",
|
|
148
|
+
stdioFields: { type: "stdio" }
|
|
135
149
|
},
|
|
136
150
|
{
|
|
137
151
|
scope: "vscode-user",
|
|
138
152
|
path: vscodeUserPath(home, platform),
|
|
139
153
|
where: "servers",
|
|
140
154
|
key: "servers",
|
|
141
|
-
client: "VS Code (all projects)"
|
|
155
|
+
client: "VS Code (all projects)",
|
|
156
|
+
stdioFields: { type: "stdio" }
|
|
142
157
|
},
|
|
143
158
|
{
|
|
144
159
|
// The same place on every platform (under %USERPROFILE% on Windows),
|
|
145
|
-
// and the same shape as Claude Desktop's file.
|
|
160
|
+
// and the same shape as Claude Desktop's file. Windsurf is now Devin
|
|
161
|
+
// Desktop, which has its own file (below); this one is the older place.
|
|
146
162
|
scope: "windsurf",
|
|
147
163
|
path: join(home, ".codeium", "windsurf", "mcp_config.json"),
|
|
148
164
|
where: "mcpServers",
|
|
149
165
|
key: "mcpServers",
|
|
150
|
-
client: "Windsurf"
|
|
166
|
+
client: "Windsurf (now Devin Desktop; older settings file)"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
/*
|
|
170
|
+
* GitHub Copilot CLI: one file on every platform. A program it starts
|
|
171
|
+
* says `type: "local"`, and `tools: ["*"]` lets it use every tool the
|
|
172
|
+
* gateway offers -- the gateway's own policy is what decides. The
|
|
173
|
+
* research notes (2026-11-28) list this file as Copilot's portable
|
|
174
|
+
* config that VS Code's Copilot reads too; not yet checked against a
|
|
175
|
+
* real VS Code install.
|
|
176
|
+
*/
|
|
177
|
+
scope: "copilot-cli",
|
|
178
|
+
path: join(home, ".copilot", "mcp-config.json"),
|
|
179
|
+
where: "mcpServers",
|
|
180
|
+
key: "mcpServers",
|
|
181
|
+
client: "GitHub Copilot CLI",
|
|
182
|
+
stdioFields: { type: "local", tools: ["*"] }
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
// Antigravity CLI took over from the consumer Gemini CLI, and kept its folder.
|
|
186
|
+
scope: "antigravity",
|
|
187
|
+
path: join(home, ".gemini", "config", "mcp_config.json"),
|
|
188
|
+
where: "mcpServers",
|
|
189
|
+
key: "mcpServers",
|
|
190
|
+
client: "Antigravity CLI (formerly Gemini CLI) (all projects)",
|
|
191
|
+
httpOnly: true
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
scope: "antigravity-project",
|
|
195
|
+
path: join(cwd, ".agents", "mcp_config.json"),
|
|
196
|
+
where: "mcpServers",
|
|
197
|
+
key: "mcpServers",
|
|
198
|
+
client: "Antigravity CLI (formerly Gemini CLI) (this project)",
|
|
199
|
+
httpOnly: true
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
/*
|
|
203
|
+
* Devin Desktop, formerly Windsurf. Its remote entries are documented
|
|
204
|
+
* as `serverUrl`, which parseServers reads; that still needs checking
|
|
205
|
+
* against a real install.
|
|
206
|
+
*/
|
|
207
|
+
scope: "devin",
|
|
208
|
+
path: devinUserPath(home, platform),
|
|
209
|
+
where: "mcpServers",
|
|
210
|
+
key: "mcpServers",
|
|
211
|
+
client: "Devin Desktop (all projects)"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
scope: "devin-project",
|
|
215
|
+
path: join(cwd, ".devin", "mcp_config.json"),
|
|
216
|
+
where: "mcpServers",
|
|
217
|
+
key: "mcpServers",
|
|
218
|
+
client: "Devin Desktop (this project)"
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
scope: "junie",
|
|
222
|
+
path: join(home, ".junie", "mcp", "mcp.json"),
|
|
223
|
+
where: "mcpServers",
|
|
224
|
+
key: "mcpServers",
|
|
225
|
+
client: "Junie (all projects)"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
scope: "junie-project",
|
|
229
|
+
path: join(cwd, ".junie", "mcp", "mcp.json"),
|
|
230
|
+
where: "mcpServers",
|
|
231
|
+
key: "mcpServers",
|
|
232
|
+
client: "Junie (this project)"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
// Roo Code's all-projects file is inside VS Code's extension storage, so only the project one.
|
|
236
|
+
scope: "roo-project",
|
|
237
|
+
path: join(cwd, ".roo", "mcp.json"),
|
|
238
|
+
where: "mcpServers",
|
|
239
|
+
key: "mcpServers",
|
|
240
|
+
client: "Roo Code (this project)"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
/*
|
|
244
|
+
* Codex, whose config the ChatGPT desktop app shares. TOML: servers
|
|
245
|
+
* are `[mcp_servers.<name>]` tables. Codex keeps its folder where
|
|
246
|
+
* CODEX_HOME says, else ~/.codex. It speaks stdio and Streamable HTTP.
|
|
247
|
+
*/
|
|
248
|
+
scope: "codex",
|
|
249
|
+
path: join(codexHome(options, home), "config.toml"),
|
|
250
|
+
where: "mcp_servers",
|
|
251
|
+
key: "mcp_servers",
|
|
252
|
+
client: "Codex and the ChatGPT desktop app",
|
|
253
|
+
httpOnly: true,
|
|
254
|
+
format: "toml"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
// A project's own Codex settings, which Codex reads only for a project you have trusted.
|
|
258
|
+
scope: "codex-project",
|
|
259
|
+
path: join(cwd, ".codex", "config.toml"),
|
|
260
|
+
where: "mcp_servers",
|
|
261
|
+
key: "mcp_servers",
|
|
262
|
+
client: "Codex (this project)",
|
|
263
|
+
httpOnly: true,
|
|
264
|
+
format: "toml"
|
|
151
265
|
}
|
|
152
266
|
];
|
|
153
267
|
}
|
|
268
|
+
/** Codex's folder: as passed, else `CODEX_HOME` (an empty one counts as unset), else `~/.codex`. */
|
|
269
|
+
function codexHome(options, home) {
|
|
270
|
+
const fromEnv = process.env["CODEX_HOME"];
|
|
271
|
+
const chosen = options.codexHome ?? (fromEnv ? fromEnv : undefined);
|
|
272
|
+
return chosen ? resolve(chosen) : join(home, ".codex");
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* When CODEX_HOME has moved Codex's folder away from `~/.codex`, words that
|
|
276
|
+
* say so: Codex follows it, but the ChatGPT desktop app may not. Null for
|
|
277
|
+
* every other scope, and for the usual folder.
|
|
278
|
+
*/
|
|
279
|
+
export function codexHomeNote(target, home = homedir()) {
|
|
280
|
+
if (target.scope !== "codex")
|
|
281
|
+
return null;
|
|
282
|
+
if (resolve(target.path) === resolve(join(home, ".codex", "config.toml")))
|
|
283
|
+
return null;
|
|
284
|
+
return `using CODEX_HOME: ${dirname(target.path)} — the ChatGPT desktop app may read ~/.codex instead`;
|
|
285
|
+
}
|
|
154
286
|
function targetFor(scope, options) {
|
|
155
287
|
const target = scopeTargets(options).find((t) => t.scope === scope);
|
|
156
288
|
if (!target)
|
|
@@ -174,6 +306,19 @@ export function readClientConfig(scope, options = {}) {
|
|
|
174
306
|
return { target, text: null, jsonc: false, raw: {}, servers: {}, exists: false };
|
|
175
307
|
}
|
|
176
308
|
const text = readFileSync(target.path, "utf8");
|
|
309
|
+
if (target.format === "toml") {
|
|
310
|
+
let raw;
|
|
311
|
+
try {
|
|
312
|
+
raw = parseToml(text);
|
|
313
|
+
}
|
|
314
|
+
catch (err) {
|
|
315
|
+
// The parser's own message quotes the lines around the mistake, which can hold a key: only where it is.
|
|
316
|
+
const at = err instanceof TomlError ? ` (line ${err.line}, column ${err.column})` : "";
|
|
317
|
+
throw new ClientConfigError(`${target.client}'s settings file can't be read: it has a mistake in it${at}, so nothing was changed. ` +
|
|
318
|
+
`Open ${target.path} in a text editor, fix it, and try again.`);
|
|
319
|
+
}
|
|
320
|
+
return { target, text, jsonc: false, raw, servers: serversIn(raw, target), exists: true };
|
|
321
|
+
}
|
|
177
322
|
let parsed;
|
|
178
323
|
let jsonc = false;
|
|
179
324
|
try {
|
|
@@ -338,7 +483,7 @@ function valueEnd(clean, from) {
|
|
|
338
483
|
return i;
|
|
339
484
|
}
|
|
340
485
|
/** The indent a file uses (two spaces, four, a tab), so a rewrite looks like the file it replaces. */
|
|
341
|
-
function detectIndent(text) {
|
|
486
|
+
export function detectIndent(text) {
|
|
342
487
|
if (!text)
|
|
343
488
|
return 2;
|
|
344
489
|
const lead = /\n([ \t]+)\S/.exec(text)?.[1];
|
|
@@ -374,8 +519,11 @@ function projectKey(target) {
|
|
|
374
519
|
* An entry carrying `type: "http"` or `"sse"` is held to the remote shape
|
|
375
520
|
* rather than being offered to both: a remote entry missing its `url` should
|
|
376
521
|
* report that, not the stdio schema's complaint about a missing `command`.
|
|
522
|
+
*
|
|
523
|
+
* `httpOnly` is the scope's own flag (Antigravity CLI): a typeless web
|
|
524
|
+
* address is then Streamable HTTP whatever its path ends in.
|
|
377
525
|
*/
|
|
378
|
-
export function parseServers(raw) {
|
|
526
|
+
export function parseServers(raw, options = {}) {
|
|
379
527
|
const servers = new Map();
|
|
380
528
|
const malformed = [];
|
|
381
529
|
for (const name of Object.keys(raw).sort()) {
|
|
@@ -387,22 +535,29 @@ export function parseServers(raw) {
|
|
|
387
535
|
let type = entry["type"];
|
|
388
536
|
let candidate = entry;
|
|
389
537
|
/*
|
|
390
|
-
* Cursor's and Windsurf's remote shape: a `url` (Windsurf
|
|
391
|
-
* and no `type`, no `command`. Read as the
|
|
392
|
-
* than as a stdio server missing its command.
|
|
538
|
+
* Cursor's and Windsurf's remote shape: a `url` (Windsurf, Devin and
|
|
539
|
+
* Antigravity: `serverUrl`) and no `type`, no `command`. Read as the
|
|
540
|
+
* remote server it is rather than as a stdio server missing its command.
|
|
393
541
|
*/
|
|
394
542
|
const url = typeof entry["url"] === "string" ? entry["url"] : typeof entry["serverUrl"] === "string" ? entry["serverUrl"] : undefined;
|
|
395
543
|
if (type === undefined && entry["command"] === undefined && url !== undefined) {
|
|
396
|
-
type = remoteTypeFor(url);
|
|
544
|
+
type = remoteTypeFor(url, options.httpOnly === true);
|
|
397
545
|
candidate = { ...entry, type, url };
|
|
398
546
|
}
|
|
547
|
+
// Codex's name for the same headers.
|
|
548
|
+
if (entry["headers"] === undefined && asRecord(entry["http_headers"]))
|
|
549
|
+
candidate = { ...candidate, headers: entry["http_headers"] };
|
|
399
550
|
const schema = type === "http" || type === "sse" || type === "streamable-http"
|
|
400
551
|
? ClaudeRemoteServerSchema
|
|
401
|
-
: type === undefined || type === "stdio"
|
|
552
|
+
: type === undefined || type === "stdio" || type === "local"
|
|
402
553
|
? ClaudeStdioServerSchema
|
|
403
554
|
: undefined;
|
|
555
|
+
// Other apps' names for the same two transports: "streamable-http" is
|
|
556
|
+
// HTTP, and GitHub Copilot CLI's "local" is a program it starts.
|
|
404
557
|
if (type === "streamable-http")
|
|
405
558
|
candidate = { ...candidate, type: "http" };
|
|
559
|
+
if (type === "local")
|
|
560
|
+
candidate = { ...candidate, type: "stdio" };
|
|
406
561
|
if (!schema) {
|
|
407
562
|
malformed.push({
|
|
408
563
|
name,
|
|
@@ -498,6 +653,19 @@ function withServers(file, servers) {
|
|
|
498
653
|
* replaced in its text, so every comment outside that list survives.
|
|
499
654
|
*/
|
|
500
655
|
export function writeClientConfig(file, servers) {
|
|
656
|
+
if (file.target.format === "toml") {
|
|
657
|
+
let text;
|
|
658
|
+
try {
|
|
659
|
+
text = editTomlServers(file.text ?? "", servers);
|
|
660
|
+
}
|
|
661
|
+
catch (err) {
|
|
662
|
+
if (err instanceof TomlEditError)
|
|
663
|
+
throw new ClientConfigError(tomlRefusal(file.target, err.message));
|
|
664
|
+
throw err;
|
|
665
|
+
}
|
|
666
|
+
writeTextPreservingMode(file.target.path, text);
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
501
669
|
const raw = withServers(file, servers);
|
|
502
670
|
const indent = detectIndent(file.text);
|
|
503
671
|
const newline = file.text === null || file.text.endsWith("\n") ? "\n" : "";
|
|
@@ -507,6 +675,22 @@ export function writeClientConfig(file, servers) {
|
|
|
507
675
|
}
|
|
508
676
|
writeTextPreservingMode(file.target.path, `${JSON.stringify(raw, null, indent)}${newline}`);
|
|
509
677
|
}
|
|
678
|
+
/** A TOML file this cannot change safely, said as what to do. Names a form, never a value. */
|
|
679
|
+
function tomlRefusal(target, problem) {
|
|
680
|
+
return (`${target.client}'s settings file (${target.path}) can't be changed safely: ${problem}. Nothing was changed. ` +
|
|
681
|
+
`Write each server as its own [mcp_servers.<name>] table, or add the toolbox to it by hand.`);
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Why this file cannot be changed safely, before anything is written, or
|
|
685
|
+
* null. Only Codex's TOML has forms that are refused; reading and listing
|
|
686
|
+
* such a file still work.
|
|
687
|
+
*/
|
|
688
|
+
export function clientEditProblem(file) {
|
|
689
|
+
if (file.target.format !== "toml" || file.text === null)
|
|
690
|
+
return null;
|
|
691
|
+
const problem = tomlEditProblem(file.text);
|
|
692
|
+
return problem ? tomlRefusal(file.target, problem) : null;
|
|
693
|
+
}
|
|
510
694
|
/** `text` with the top-level `key`'s value replaced by `value`, or the key added at the end. */
|
|
511
695
|
function spliceTopLevel(text, key, value, indent) {
|
|
512
696
|
const unit = typeof indent === "number" ? " ".repeat(indent) : indent;
|
|
@@ -537,17 +721,18 @@ export function restoreClientConfig(file, servers) {
|
|
|
537
721
|
const original = readFileSync(copy, "utf8");
|
|
538
722
|
let parsed;
|
|
539
723
|
try {
|
|
540
|
-
parsed = JSON.parse(original);
|
|
724
|
+
parsed = file.target.format === "toml" ? parseToml(original) : JSON.parse(original);
|
|
541
725
|
}
|
|
542
726
|
catch {
|
|
543
727
|
try {
|
|
544
|
-
parsed = JSON.parse(stripJsonc(original));
|
|
728
|
+
parsed = file.target.format === "toml" ? undefined : JSON.parse(stripJsonc(original));
|
|
545
729
|
}
|
|
546
730
|
catch {
|
|
547
731
|
parsed = undefined;
|
|
548
732
|
}
|
|
549
733
|
}
|
|
550
|
-
|
|
734
|
+
const same = file.target.format === "toml" ? sameToml(parsed, raw) : parsed !== undefined && sameJson(parsed, raw);
|
|
735
|
+
if (same) {
|
|
551
736
|
writeTextPreservingMode(file.target.path, original);
|
|
552
737
|
unlinkSync(copy);
|
|
553
738
|
return { how: "bytes", backupLeft: null };
|
|
@@ -584,28 +769,54 @@ function isEmptySkeleton(raw, target) {
|
|
|
584
769
|
* adding a server would be a quiet regression. A file we are creating gets
|
|
585
770
|
* `0600` outright. (Backups are written by `writePrivateText`, always 0600.)
|
|
586
771
|
*/
|
|
587
|
-
function writeTextPreservingMode(path, text) {
|
|
772
|
+
export function writeTextPreservingMode(path, text) {
|
|
588
773
|
const mode = existsSync(path) ? statSync(path).mode & 0o777 : 0o600;
|
|
589
774
|
mkdirSync(dirname(path), { recursive: true });
|
|
590
775
|
const tmp = join(dirname(path), `.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`);
|
|
591
776
|
writeFileSync(tmp, text, { encoding: "utf8", mode });
|
|
592
777
|
renameSync(tmp, path);
|
|
593
778
|
}
|
|
779
|
+
/**
|
|
780
|
+
* How many folders down from the project each project file sits:
|
|
781
|
+
* `.mcp.json` is in the project itself, `.cursor/mcp.json` one folder down,
|
|
782
|
+
* Junie's `.junie/mcp/mcp.json` two.
|
|
783
|
+
*/
|
|
784
|
+
const PROJECT_FILE_DEPTH = {
|
|
785
|
+
project: 0,
|
|
786
|
+
"cursor-project": 1,
|
|
787
|
+
"vscode-project": 1,
|
|
788
|
+
"antigravity-project": 1,
|
|
789
|
+
"devin-project": 1,
|
|
790
|
+
"roo-project": 1,
|
|
791
|
+
"codex-project": 1,
|
|
792
|
+
"junie-project": 2
|
|
793
|
+
};
|
|
594
794
|
/**
|
|
595
795
|
* Where a project's backups go: under the project's own `.hmcp/`, which is
|
|
596
796
|
* kept out of git, rather than loose in the project folder beside the file
|
|
597
797
|
* people commit (UT5 round 3). Null for a file outside any project.
|
|
598
798
|
*/
|
|
599
799
|
function projectBackupDir(target) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
800
|
+
const depth = PROJECT_FILE_DEPTH[target.scope];
|
|
801
|
+
if (depth === undefined)
|
|
802
|
+
return null;
|
|
803
|
+
let project = dirname(target.path);
|
|
804
|
+
for (let i = 0; i < depth; i++)
|
|
805
|
+
project = dirname(project);
|
|
806
|
+
return join(project, ".hmcp", "backups");
|
|
605
807
|
}
|
|
606
|
-
/**
|
|
808
|
+
/**
|
|
809
|
+
* `.mcp.json`, `.vscode-mcp.json`, `.junie-mcp-mcp.json`: the file's place in
|
|
810
|
+
* the project, as one name -- its path below the project joined with `-`.
|
|
811
|
+
*/
|
|
607
812
|
function projectBackupStem(target) {
|
|
608
|
-
|
|
813
|
+
const parts = [basename(target.path)];
|
|
814
|
+
let dir = dirname(target.path);
|
|
815
|
+
for (let i = 0; i < (PROJECT_FILE_DEPTH[target.scope] ?? 0); i++) {
|
|
816
|
+
parts.unshift(basename(dir));
|
|
817
|
+
dir = dirname(dir);
|
|
818
|
+
}
|
|
819
|
+
return parts.join("-");
|
|
609
820
|
}
|
|
610
821
|
/**
|
|
611
822
|
* Makes sure git skips the backups folder even if the person removed the
|
|
@@ -650,7 +861,7 @@ function privateBackupDir(dir) {
|
|
|
650
861
|
* back into the app's own file, which keeps that file's mode, so the backup's
|
|
651
862
|
* mode never reaches it.
|
|
652
863
|
*/
|
|
653
|
-
function writePrivateText(path, text) {
|
|
864
|
+
export function writePrivateText(path, text) {
|
|
654
865
|
mkdirSync(dirname(path), { recursive: true });
|
|
655
866
|
const tmp = join(dirname(path), `.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`);
|
|
656
867
|
writeFileSync(tmp, text, { encoding: "utf8", mode: 0o600 });
|
package/dist/connect-client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClientConfigError, type Scope as ClientScope } from "./client-config.js";
|
|
1
|
+
import { ClientConfigError, type Scope as ClientScope, type ScopeTarget } from "./client-config.js";
|
|
2
2
|
export interface ConnectClientOptions {
|
|
3
3
|
scope: ClientScope;
|
|
4
4
|
cwd: string;
|
|
@@ -47,3 +47,5 @@ export declare function stableNodePath(options?: {
|
|
|
47
47
|
}): string;
|
|
48
48
|
/** The PATH the app gives the gateway: found folders, node's folder, then the system's. */
|
|
49
49
|
export declare function pathFor(pathDirs: readonly string[], platform?: string): string;
|
|
50
|
+
/** What a person does next in each app, in plain words. */
|
|
51
|
+
export declare function restartHintFor(target: ScopeTarget, platform: string): string;
|
package/dist/connect-client.js
CHANGED
|
@@ -13,7 +13,7 @@ import { delimiter, dirname, join, resolve, sep } from "node:path";
|
|
|
13
13
|
import { fileURLToPath } from "node:url";
|
|
14
14
|
import { emitClientEntry } from "./adopt-emit.js";
|
|
15
15
|
import { clientCommand } from "./adopt-cli.js";
|
|
16
|
-
import { backupPath, ClientConfigError, readBackup, readClientConfig, scopeTargets, writeBackup, writeClientConfig, writeWholeFileBackup } from "./client-config.js";
|
|
16
|
+
import { backupPath, clientEditProblem, ClientConfigError, codexHomeNote, readBackup, readClientConfig, scopeTargets, writeBackup, writeClientConfig, writeWholeFileBackup } from "./client-config.js";
|
|
17
17
|
import { VERSION } from "./version.js";
|
|
18
18
|
/** A refusal with nothing written, in words a person can act on. */
|
|
19
19
|
export class ConnectClientError extends ClientConfigError {
|
|
@@ -32,7 +32,14 @@ export async function connectClient(options) {
|
|
|
32
32
|
throw new ConnectClientError(`the toolbox's settings file ${gatewayConfig} is not there, so there is nothing to connect`);
|
|
33
33
|
}
|
|
34
34
|
const file = readClientConfig(target.scope, scopeOptions);
|
|
35
|
-
const
|
|
35
|
+
const codexNote = codexHomeNote(target, options.home);
|
|
36
|
+
const restartHint = [
|
|
37
|
+
restartHintFor(target, platform),
|
|
38
|
+
sharedWithVsCode(target, scopeOptions, gatewayConfig),
|
|
39
|
+
codexNote ? `Codex is ${codexNote}.` : ""
|
|
40
|
+
]
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
.join(" ");
|
|
36
43
|
// Already pointing at this gateway, under whatever name: nothing to do.
|
|
37
44
|
const existing = Object.entries(file.servers).find(([, entry]) => pointsAt(entry, gatewayConfig, target));
|
|
38
45
|
if (existing) {
|
|
@@ -49,6 +56,10 @@ export async function connectClient(options) {
|
|
|
49
56
|
throw new ConnectClientError(`${target.client} already has a connection made by hardened-mcp ("${earlier.gateway_entry_name}"), ` +
|
|
50
57
|
`and its undo record is in ${backupPath(target)}. Undo that connection first, then connect this toolbox.`);
|
|
51
58
|
}
|
|
59
|
+
// Codex's TOML in a form that cannot be changed safely: refused before anything, the backup included, is written.
|
|
60
|
+
const editProblem = clientEditProblem(file);
|
|
61
|
+
if (editProblem)
|
|
62
|
+
throw new ConnectClientError(editProblem);
|
|
52
63
|
const entryName = freeName(options.entryName ?? DEFAULT_ENTRY, file.servers, target);
|
|
53
64
|
const node = stableNodePath({ execPath: options.execPath ?? process.execPath, pathDirs: options.pathDirs ?? [], platform });
|
|
54
65
|
const launch = launchCommand(platform, node);
|
|
@@ -63,8 +74,8 @@ export async function connectClient(options) {
|
|
|
63
74
|
malformed: []
|
|
64
75
|
};
|
|
65
76
|
const entry = {
|
|
66
|
-
// VS Code
|
|
67
|
-
...
|
|
77
|
+
// VS Code and Copilot CLI name the transport; the others infer it from `command`.
|
|
78
|
+
...target.stdioFields,
|
|
68
79
|
...emitClientEntry(empty, { configPath: gatewayConfig, command: launch.command, args: launch.args }),
|
|
69
80
|
/*
|
|
70
81
|
* An app started from the Dock or Start menu gets a minimal PATH, so a
|
|
@@ -97,6 +108,28 @@ export async function connectClient(options) {
|
|
|
97
108
|
});
|
|
98
109
|
return { configPath: target.path, entryName, backupPath: backupPath(target), alreadyConnected: false, restartHint };
|
|
99
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Copilot in VS Code may read Copilot CLI's file as well as its own
|
|
113
|
+
* (unverified against a real install), so with both connected the toolbox
|
|
114
|
+
* can show up twice there. Said when the other one is already connected by
|
|
115
|
+
* hardened-mcp: it has an undo record, or an entry pointing at this toolbox.
|
|
116
|
+
*/
|
|
117
|
+
function sharedWithVsCode(target, scopeOptions, gatewayConfig) {
|
|
118
|
+
const other = target.scope === "copilot-cli" ? "vscode-user" : target.scope === "vscode-user" ? "copilot-cli" : undefined;
|
|
119
|
+
if (!other)
|
|
120
|
+
return "";
|
|
121
|
+
try {
|
|
122
|
+
const otherTarget = scopeTargets(scopeOptions).find((t) => t.scope === other);
|
|
123
|
+
const connected = readBackup(otherTarget) !== undefined ||
|
|
124
|
+
Object.values(readClientConfig(other, scopeOptions).servers).some((entry) => pointsAt(entry, gatewayConfig, otherTarget));
|
|
125
|
+
if (!connected)
|
|
126
|
+
return "";
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return "";
|
|
130
|
+
}
|
|
131
|
+
return "GitHub Copilot CLI and VS Code are both connected, so the two entries may both appear in VS Code; that is harmless, and you can switch one off there.";
|
|
132
|
+
}
|
|
100
133
|
/** Whether an app entry runs `serve -c <this gateway's config>`. */
|
|
101
134
|
function pointsAt(entry, gatewayConfig, target) {
|
|
102
135
|
if (typeof entry !== "object" || entry === null)
|
|
@@ -224,7 +257,7 @@ function pathWith(pathDirs, node, platform) {
|
|
|
224
257
|
return [...new Set(dirs)].join(platform === "win32" ? ";" : ":");
|
|
225
258
|
}
|
|
226
259
|
/** What a person does next in each app, in plain words. */
|
|
227
|
-
function restartHintFor(target, platform) {
|
|
260
|
+
export function restartHintFor(target, platform) {
|
|
228
261
|
switch (target.scope) {
|
|
229
262
|
case "claude-desktop":
|
|
230
263
|
return platform === "darwin"
|
|
@@ -243,6 +276,23 @@ function restartHintFor(target, platform) {
|
|
|
243
276
|
return "In VS Code, open the Command Palette, run \"MCP: List Servers\" and start the new entry. Reloading the window works too.";
|
|
244
277
|
case "windsurf":
|
|
245
278
|
return "In Windsurf, open the MCP servers list in the Cascade panel and press refresh, or restart Windsurf once.";
|
|
279
|
+
case "copilot-cli":
|
|
280
|
+
return "Restart GitHub Copilot CLI (or start a new session) so it picks up the change.";
|
|
281
|
+
case "antigravity":
|
|
282
|
+
case "antigravity-project":
|
|
283
|
+
return "Restart Antigravity CLI (or start a new session) so it picks up the change.";
|
|
284
|
+
case "devin":
|
|
285
|
+
case "devin-project":
|
|
286
|
+
return "Restart Devin Desktop (or start a new session) so it picks up the change.";
|
|
287
|
+
case "junie":
|
|
288
|
+
case "junie-project":
|
|
289
|
+
return "Restart Junie or your JetBrains IDE (or start a new session) so it picks up the change.";
|
|
290
|
+
case "codex":
|
|
291
|
+
return "Restart Codex or the ChatGPT desktop app so it picks up the change.";
|
|
292
|
+
case "codex-project":
|
|
293
|
+
return "Restart Codex so it picks up the change. Codex reads a project's own settings only when you have marked the project as trusted.";
|
|
294
|
+
case "roo-project":
|
|
295
|
+
return "Restart Roo Code by reloading the VS Code window (or start a new session) so it picks up the change.";
|
|
246
296
|
default:
|
|
247
297
|
return `Restart ${target.client} once so it picks this up.`;
|
|
248
298
|
}
|