hmcp-gateway 0.0.2 → 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/LICENSE +77 -0
- package/README.md +135 -9
- package/bin/hmcp-gateway.js +20 -0
- package/catalog/atlassian.yaml +41 -0
- package/catalog/brave-search.yaml +57 -0
- package/catalog/context7.yaml +42 -0
- package/catalog/fetch.yaml +37 -0
- package/catalog/figma.yaml +48 -0
- package/catalog/filesystem.yaml +48 -0
- package/catalog/git.yaml +48 -0
- package/catalog/github.yaml +103 -0
- package/catalog/huggingface.yaml +59 -0
- package/catalog/linear.yaml +47 -0
- package/catalog/memory.yaml +47 -0
- package/catalog/notion.yaml +41 -0
- package/catalog/playwright.yaml +38 -0
- package/catalog/postgres.yaml +66 -0
- package/catalog/sentry.yaml +39 -0
- package/catalog/sequential-thinking.yaml +29 -0
- package/catalog/stripe.yaml +41 -0
- package/catalog/supabase.yaml +45 -0
- package/catalog/time.yaml +49 -0
- package/dist/adopt-cli.d.ts +355 -0
- package/dist/adopt-cli.js +1885 -0
- package/dist/adopt-emit.d.ts +64 -0
- package/dist/adopt-emit.js +248 -0
- package/dist/adopt-plan.d.ts +108 -0
- package/dist/adopt-plan.js +501 -0
- package/dist/catalog.d.ts +140 -0
- package/dist/catalog.js +250 -0
- package/dist/classify.d.ts +23 -0
- package/dist/classify.js +47 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +656 -0
- package/dist/client-allow.d.ts +42 -0
- package/dist/client-allow.js +95 -0
- package/dist/client-config.d.ts +263 -0
- package/dist/client-config.js +995 -0
- package/dist/config-source.d.ts +106 -0
- package/dist/config-source.js +156 -0
- package/dist/config.d.ts +159 -0
- package/dist/config.js +330 -0
- package/dist/connect-client.d.ts +51 -0
- package/dist/connect-client.js +299 -0
- package/dist/contracts.d.ts +251 -0
- package/dist/contracts.js +9 -0
- package/dist/credential.d.ts +63 -0
- package/dist/credential.js +136 -0
- package/dist/desktop-extensions.d.ts +53 -0
- package/dist/desktop-extensions.js +126 -0
- package/dist/draft.d.ts +71 -0
- package/dist/draft.js +596 -0
- package/dist/exposure-cli.d.ts +28 -0
- package/dist/exposure-cli.js +119 -0
- package/dist/gateway.d.ts +766 -0
- package/dist/gateway.js +2122 -0
- 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 +31 -0
- package/dist/index.js +31 -0
- package/dist/notify.d.ts +44 -0
- package/dist/notify.js +93 -0
- package/dist/oauth.d.ts +139 -0
- package/dist/oauth.js +641 -0
- package/dist/observe.d.ts +10 -0
- package/dist/observe.js +26 -0
- package/dist/open.d.ts +24 -0
- package/dist/open.js +31 -0
- package/dist/packs.d.ts +119 -0
- package/dist/packs.js +131 -0
- package/dist/pin-cli.d.ts +28 -0
- package/dist/pin-cli.js +103 -0
- package/dist/probe-upstream.d.ts +31 -0
- package/dist/probe-upstream.js +377 -0
- package/dist/registry-map.d.ts +39 -0
- package/dist/registry-map.js +390 -0
- package/dist/rule-cli.d.ts +51 -0
- package/dist/rule-cli.js +412 -0
- package/dist/serve-http.d.ts +67 -0
- package/dist/serve-http.js +478 -0
- package/dist/snippet.d.ts +20 -0
- package/dist/snippet.js +826 -0
- package/dist/status-cli.d.ts +61 -0
- package/dist/status-cli.js +195 -0
- package/dist/suggest-cli.d.ts +43 -0
- package/dist/suggest-cli.js +279 -0
- package/dist/toml-edit.d.ts +43 -0
- package/dist/toml-edit.js +363 -0
- package/dist/toolname.d.ts +47 -0
- package/dist/toolname.js +149 -0
- package/dist/upstream-errors.d.ts +54 -0
- package/dist/upstream-errors.js +330 -0
- package/dist/upstream.d.ts +128 -0
- package/dist/upstream.js +413 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.js +11 -0
- package/package.json +51 -6
- package/packs/brave-search.yaml +20 -0
- package/packs/context7.yaml +13 -0
- package/packs/fetch.yaml +14 -0
- package/packs/filesystem.yaml +79 -0
- package/packs/git.yaml +29 -0
- package/packs/github.yaml +47 -0
- package/packs/huggingface.yaml +16 -0
- package/packs/memory.yaml +23 -0
- package/packs/playwright.yaml +41 -0
- package/packs/sequential-thinking.yaml +13 -0
- package/packs/time.yaml +14 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ScopeOptions, type ScopeTarget } from "./client-config.js";
|
|
2
|
+
/**
|
|
3
|
+
* The client's own permission to call the gateway's tools.
|
|
4
|
+
*
|
|
5
|
+
* Claude Code asks before it calls an MCP tool it has not been told to allow.
|
|
6
|
+
* Behind an enforcing gateway that question is redundant for every tool the
|
|
7
|
+
* gateway fronts: the gateway decides each call, and holds the ones a person
|
|
8
|
+
* should see. Being asked twice about one write is how people learn to click
|
|
9
|
+
* through, so `adopt` can add one allow rule covering the gateway's tools.
|
|
10
|
+
*
|
|
11
|
+
* It is a change to the *client's* settings, which is why it is offered and
|
|
12
|
+
* explained rather than done, why it is refused while the gateway is only
|
|
13
|
+
* observing -- the client's prompt is then the only thing asking -- and why
|
|
14
|
+
* `adopt --revert` takes it back out.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Where the rule goes for the scope that was adopted.
|
|
18
|
+
*
|
|
19
|
+
* A project's `.mcp.json` and the per-project block in `~/.claude.json` both
|
|
20
|
+
* get the project's *local* settings file, which Claude Code keeps out of
|
|
21
|
+
* version control: an allow rule is one person's choice about their own
|
|
22
|
+
* prompts, not something to commit for a team. User-wide servers get the
|
|
23
|
+
* user-wide settings.
|
|
24
|
+
*/
|
|
25
|
+
export declare function clientSettingsPath(target: ScopeTarget, options?: ScopeOptions): string;
|
|
26
|
+
/**
|
|
27
|
+
* The rule that allows every tool the gateway's entry serves.
|
|
28
|
+
*
|
|
29
|
+
* The bare `mcp__<server>` form rather than `mcp__<server>__*`: both are
|
|
30
|
+
* documented, and the bare one is the one that has matched consistently.
|
|
31
|
+
*/
|
|
32
|
+
export declare function allowRuleFor(entryName: string): string;
|
|
33
|
+
type Settings = Record<string, unknown> & {
|
|
34
|
+
permissions?: Record<string, unknown>;
|
|
35
|
+
};
|
|
36
|
+
/** The settings file as an object, `{}` if it does not exist. Throws rather than guess at a file it cannot read. */
|
|
37
|
+
export declare function readClientSettings(path: string): Settings;
|
|
38
|
+
/** Adds the rule. False, and nothing written, when it was already there. */
|
|
39
|
+
export declare function addAllowRule(path: string, rule: string): boolean;
|
|
40
|
+
/** Removes the rule. False when it was not there. */
|
|
41
|
+
export declare function removeAllowRule(path: string, rule: string): boolean;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { ClientConfigError } from "./client-config.js";
|
|
5
|
+
/**
|
|
6
|
+
* The client's own permission to call the gateway's tools.
|
|
7
|
+
*
|
|
8
|
+
* Claude Code asks before it calls an MCP tool it has not been told to allow.
|
|
9
|
+
* Behind an enforcing gateway that question is redundant for every tool the
|
|
10
|
+
* gateway fronts: the gateway decides each call, and holds the ones a person
|
|
11
|
+
* should see. Being asked twice about one write is how people learn to click
|
|
12
|
+
* through, so `adopt` can add one allow rule covering the gateway's tools.
|
|
13
|
+
*
|
|
14
|
+
* It is a change to the *client's* settings, which is why it is offered and
|
|
15
|
+
* explained rather than done, why it is refused while the gateway is only
|
|
16
|
+
* observing -- the client's prompt is then the only thing asking -- and why
|
|
17
|
+
* `adopt --revert` takes it back out.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Where the rule goes for the scope that was adopted.
|
|
21
|
+
*
|
|
22
|
+
* A project's `.mcp.json` and the per-project block in `~/.claude.json` both
|
|
23
|
+
* get the project's *local* settings file, which Claude Code keeps out of
|
|
24
|
+
* version control: an allow rule is one person's choice about their own
|
|
25
|
+
* prompts, not something to commit for a team. User-wide servers get the
|
|
26
|
+
* user-wide settings.
|
|
27
|
+
*/
|
|
28
|
+
export function clientSettingsPath(target, options = {}) {
|
|
29
|
+
const home = resolve(options.home ?? homedir());
|
|
30
|
+
const cwd = resolve(options.cwd ?? process.cwd());
|
|
31
|
+
return target.scope === "user"
|
|
32
|
+
? join(home, ".claude", "settings.json")
|
|
33
|
+
: join(cwd, ".claude", "settings.local.json");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The rule that allows every tool the gateway's entry serves.
|
|
37
|
+
*
|
|
38
|
+
* The bare `mcp__<server>` form rather than `mcp__<server>__*`: both are
|
|
39
|
+
* documented, and the bare one is the one that has matched consistently.
|
|
40
|
+
*/
|
|
41
|
+
export function allowRuleFor(entryName) {
|
|
42
|
+
return `mcp__${entryName}`;
|
|
43
|
+
}
|
|
44
|
+
/** The settings file as an object, `{}` if it does not exist. Throws rather than guess at a file it cannot read. */
|
|
45
|
+
export function readClientSettings(path) {
|
|
46
|
+
if (!existsSync(path))
|
|
47
|
+
return {};
|
|
48
|
+
let parsed;
|
|
49
|
+
try {
|
|
50
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
throw new ClientConfigError(`${path} is not valid JSON (${err.message}), so the allow rule cannot be added to it. ` +
|
|
54
|
+
`Fix that file, or leave the rule out and add it by hand.`);
|
|
55
|
+
}
|
|
56
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
57
|
+
throw new ClientConfigError(`${path} does not hold a JSON object, so the allow rule cannot be added to it.`);
|
|
58
|
+
}
|
|
59
|
+
const permissions = parsed.permissions;
|
|
60
|
+
if (permissions !== undefined && (typeof permissions !== "object" || permissions === null || Array.isArray(permissions))) {
|
|
61
|
+
throw new ClientConfigError(`"permissions" in ${path} is not an object, so the allow rule cannot be added to it.`);
|
|
62
|
+
}
|
|
63
|
+
const allow = permissions?.["allow"];
|
|
64
|
+
if (allow !== undefined && !Array.isArray(allow)) {
|
|
65
|
+
throw new ClientConfigError(`"permissions.allow" in ${path} is not a list, so the allow rule cannot be added to it.`);
|
|
66
|
+
}
|
|
67
|
+
return parsed;
|
|
68
|
+
}
|
|
69
|
+
function writeSettings(path, settings) {
|
|
70
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
71
|
+
writeFileSync(path, `${JSON.stringify(settings, null, 2)}\n`, "utf8");
|
|
72
|
+
}
|
|
73
|
+
/** Adds the rule. False, and nothing written, when it was already there. */
|
|
74
|
+
export function addAllowRule(path, rule) {
|
|
75
|
+
const settings = readClientSettings(path);
|
|
76
|
+
const allow = settings.permissions?.["allow"] ?? [];
|
|
77
|
+
if (allow.includes(rule))
|
|
78
|
+
return false;
|
|
79
|
+
writeSettings(path, { ...settings, permissions: { ...(settings.permissions ?? {}), allow: [...allow, rule] } });
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
/** Removes the rule. False when it was not there. */
|
|
83
|
+
export function removeAllowRule(path, rule) {
|
|
84
|
+
if (!existsSync(path))
|
|
85
|
+
return false;
|
|
86
|
+
const settings = readClientSettings(path);
|
|
87
|
+
const allow = settings.permissions?.["allow"] ?? [];
|
|
88
|
+
if (!allow.includes(rule))
|
|
89
|
+
return false;
|
|
90
|
+
writeSettings(path, {
|
|
91
|
+
...settings,
|
|
92
|
+
permissions: { ...(settings.permissions ?? {}), allow: allow.filter((r) => r !== rule) }
|
|
93
|
+
});
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Claude Code's own MCP server configuration: finding it, reading it, and
|
|
4
|
+
* putting it back.
|
|
5
|
+
*
|
|
6
|
+
* This is the one file in the gateway that touches a config another program
|
|
7
|
+
* owns, and that ownership drives two departures from how every other schema
|
|
8
|
+
* here is written.
|
|
9
|
+
*
|
|
10
|
+
* The schemas are loose rather than `.strict()`. The gateway's own config is
|
|
11
|
+
* strict because the gateway defines it, and an unknown key there is a typo
|
|
12
|
+
* worth refusing. This format belongs to Claude Code, which adds fields
|
|
13
|
+
* between releases; a strict parse would make `adopt` refuse a config that is
|
|
14
|
+
* perfectly good and merely newer than this build.
|
|
15
|
+
*
|
|
16
|
+
* And entries are validated one at a time rather than as a whole file, so a
|
|
17
|
+
* single malformed entry costs itself and not every sibling. That is the same
|
|
18
|
+
* reasoning as `dropUnknownKinds` in core's registry: a config shared between
|
|
19
|
+
* versions must not let one bad row hide the rest.
|
|
20
|
+
*/
|
|
21
|
+
/** A server Claude Code starts as a child process. */
|
|
22
|
+
export declare const ClaudeStdioServerSchema: z.ZodObject<{
|
|
23
|
+
type: z.ZodOptional<z.ZodLiteral<"stdio">>;
|
|
24
|
+
command: z.ZodString;
|
|
25
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
26
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
27
|
+
}, z.core.$loose>;
|
|
28
|
+
/** A server Claude Code reaches over the network. */
|
|
29
|
+
export declare const ClaudeRemoteServerSchema: z.ZodObject<{
|
|
30
|
+
type: z.ZodEnum<{
|
|
31
|
+
http: "http";
|
|
32
|
+
sse: "sse";
|
|
33
|
+
}>;
|
|
34
|
+
url: z.ZodString;
|
|
35
|
+
headers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
36
|
+
}, z.core.$loose>;
|
|
37
|
+
export type ClaudeStdioServer = z.infer<typeof ClaudeStdioServerSchema>;
|
|
38
|
+
export type ClaudeRemoteServer = z.infer<typeof ClaudeRemoteServerSchema>;
|
|
39
|
+
export type ClaudeServer = ClaudeStdioServer | ClaudeRemoteServer;
|
|
40
|
+
export declare function isRemote(server: ClaudeServer): server is ClaudeRemoteServer;
|
|
41
|
+
export declare class ClientConfigError extends Error {
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Where one scope's servers live.
|
|
45
|
+
*
|
|
46
|
+
* The first three are Claude Code's. The rest are other clients, each with
|
|
47
|
+
* its own file in its own place -- and, for VS Code, its own spelling of the
|
|
48
|
+
* same object. They are scopes rather than a separate concept because
|
|
49
|
+
* everything this command does to one of them is identical: read the servers,
|
|
50
|
+
* write a gateway entry in their place, and be able to put them back.
|
|
51
|
+
*/
|
|
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
|
+
export interface ScopeTarget {
|
|
54
|
+
readonly scope: Scope;
|
|
55
|
+
/** The JSON file holding them. */
|
|
56
|
+
readonly path: string;
|
|
57
|
+
/** Where inside that file, for an error message a human can act on. */
|
|
58
|
+
readonly where: string;
|
|
59
|
+
/**
|
|
60
|
+
* The top-level key the servers sit under. VS Code says `servers`;
|
|
61
|
+
* everything else says `mcpServers`, and writing the wrong one would add a
|
|
62
|
+
* key the client never reads while its own servers went on running
|
|
63
|
+
* unwrapped.
|
|
64
|
+
*/
|
|
65
|
+
readonly key: string;
|
|
66
|
+
/** Which program owns this file, for anything shown to a person. */
|
|
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";
|
|
87
|
+
}
|
|
88
|
+
export interface ScopeOptions {
|
|
89
|
+
readonly cwd?: string;
|
|
90
|
+
readonly home?: string;
|
|
91
|
+
/** Overridable so the per-platform paths can be tested on one machine. */
|
|
92
|
+
readonly platform?: string;
|
|
93
|
+
/** Codex's own folder. Default: `CODEX_HOME` when set, else `~/.codex`. */
|
|
94
|
+
readonly codexHome?: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The three places Claude Code keeps MCP servers, in the order it resolves
|
|
98
|
+
* them.
|
|
99
|
+
*
|
|
100
|
+
* `local` is per-project state inside the user-wide file, which is why its
|
|
101
|
+
* entry is keyed by an absolute project path rather than living next to the
|
|
102
|
+
* project.
|
|
103
|
+
*/
|
|
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;
|
|
114
|
+
export interface ClientConfigFile {
|
|
115
|
+
readonly target: ScopeTarget;
|
|
116
|
+
/** The file's bytes as read, so a backup and an undo can be exact. Null when there is no file. */
|
|
117
|
+
readonly text: string | null;
|
|
118
|
+
/** The file had comments or trailing commas (VS Code allows both), so it is rewritten with care. */
|
|
119
|
+
readonly jsonc: boolean;
|
|
120
|
+
/** The whole file, so everything this command does not own survives a write. */
|
|
121
|
+
readonly raw: Record<string, unknown>;
|
|
122
|
+
/** The `mcpServers` object for this scope, values still unvalidated. */
|
|
123
|
+
readonly servers: Record<string, unknown>;
|
|
124
|
+
readonly exists: boolean;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Reads one scope.
|
|
128
|
+
*
|
|
129
|
+
* A missing file is an empty scope rather than an error, matching
|
|
130
|
+
* `readRegistry`: not having adopted anything yet is a state, not a fault.
|
|
131
|
+
*/
|
|
132
|
+
export declare function readClientConfig(scope: Scope, options?: ScopeOptions): ClientConfigFile;
|
|
133
|
+
/**
|
|
134
|
+
* JSON with comments, as VS Code reads its `mcp.json`: `//` and block
|
|
135
|
+
* comments and trailing commas removed, everything inside strings left alone.
|
|
136
|
+
* Every removed character becomes a space (newlines kept), so positions and
|
|
137
|
+
* line numbers in an error still point at the person's own file.
|
|
138
|
+
*/
|
|
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;
|
|
142
|
+
/**
|
|
143
|
+
* Whether the file reads the same as `value`: same keys and values, whatever
|
|
144
|
+
* the spacing. Used to decide that an undo may put the original bytes back.
|
|
145
|
+
*/
|
|
146
|
+
export declare function sameJson(a: unknown, b: unknown): boolean;
|
|
147
|
+
export interface ParsedServers {
|
|
148
|
+
readonly servers: ReadonlyMap<string, ClaudeServer>;
|
|
149
|
+
/** Entries that did not validate, each with the reason, never silently dropped. */
|
|
150
|
+
readonly malformed: readonly {
|
|
151
|
+
readonly name: string;
|
|
152
|
+
readonly message: string;
|
|
153
|
+
}[];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Validates each entry on its own.
|
|
157
|
+
*
|
|
158
|
+
* An entry carrying `type: "http"` or `"sse"` is held to the remote shape
|
|
159
|
+
* rather than being offered to both: a remote entry missing its `url` should
|
|
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.
|
|
164
|
+
*/
|
|
165
|
+
export declare function parseServers(raw: Record<string, unknown>, options?: {
|
|
166
|
+
readonly httpOnly?: boolean | undefined;
|
|
167
|
+
}): ParsedServers;
|
|
168
|
+
/**
|
|
169
|
+
* Which scope `adopt` should act on when nobody said.
|
|
170
|
+
*
|
|
171
|
+
* More than one populated scope refuses rather than merging. Which project
|
|
172
|
+
* sees which server is a semantic Claude Code owns, and collapsing three
|
|
173
|
+
* scopes into one gateway would change it -- a user-scope server would start
|
|
174
|
+
* being visible only in the project that happened to run `adopt`.
|
|
175
|
+
*/
|
|
176
|
+
export declare function resolveScope(explicit: Scope | undefined, options?: ScopeOptions): ScopeTarget;
|
|
177
|
+
/**
|
|
178
|
+
* Writes `servers` back into the scope, leaving the rest of the file alone.
|
|
179
|
+
*
|
|
180
|
+
* The file keeps its own indent and its trailing newline (or lack of one).
|
|
181
|
+
* A file with comments (VS Code's JSONC) has only the server list's value
|
|
182
|
+
* replaced in its text, so every comment outside that list survives.
|
|
183
|
+
*/
|
|
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;
|
|
191
|
+
export interface RestoreResult {
|
|
192
|
+
/** "bytes": the original file came back exactly; "removed": the file did not exist before and is gone again. */
|
|
193
|
+
readonly how: "bytes" | "removed" | "rewritten";
|
|
194
|
+
/** A copy of the old file still on disk, which holds its old values. Null when none is left. */
|
|
195
|
+
readonly backupLeft: string | null;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Undo's write: puts `servers` back, and when that leaves the file exactly as
|
|
199
|
+
* it was before (same keys and values), writes the original bytes from the
|
|
200
|
+
* whole-file copy and removes the copy, so a file under version control shows
|
|
201
|
+
* no diff. A file that did not exist before and is now an empty skeleton is
|
|
202
|
+
* removed. Anything else -- the person changed the file since -- is written
|
|
203
|
+
* with the file's own indent, and the copy stays.
|
|
204
|
+
*/
|
|
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;
|
|
226
|
+
/** After undo: the project's backups folder goes once nothing but its own `.gitignore` is left in it. */
|
|
227
|
+
export declare function tidyProjectBackups(target: ScopeTarget): void;
|
|
228
|
+
/** A verbatim copy of the file before adoption touched it. One made by an earlier build, beside the file, is still used. */
|
|
229
|
+
export declare function wholeFileBackupPath(target: ScopeTarget): string;
|
|
230
|
+
/**
|
|
231
|
+
* The structured record `--revert` reads. Claude Code's file sits in the home
|
|
232
|
+
* folder itself, and its record went beside it, loose in the home folder
|
|
233
|
+
* (UT5); it is kept under that folder's `.hmcp` now. A project's record goes
|
|
234
|
+
* under the project's `.hmcp/backups` (UT5 round 3). A record left by an
|
|
235
|
+
* earlier build where it used to go is still read and removed.
|
|
236
|
+
*/
|
|
237
|
+
export declare function backupPath(target: ScopeTarget): string;
|
|
238
|
+
/** Where this target's record is now, if it has one. */
|
|
239
|
+
export declare function existingBackupPath(target: ScopeTarget): string | undefined;
|
|
240
|
+
export declare const AdoptBackupSchema: z.ZodObject<{
|
|
241
|
+
version: z.ZodLiteral<1>;
|
|
242
|
+
created_at: z.ZodString;
|
|
243
|
+
scope: z.ZodString;
|
|
244
|
+
config_path: z.ZodString;
|
|
245
|
+
gateway_entry_name: z.ZodString;
|
|
246
|
+
replaced: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
247
|
+
generated: z.ZodArray<z.ZodString>;
|
|
248
|
+
registry_id: z.ZodOptional<z.ZodString>;
|
|
249
|
+
client_allow: z.ZodOptional<z.ZodObject<{
|
|
250
|
+
path: z.ZodString;
|
|
251
|
+
rule: z.ZodString;
|
|
252
|
+
}, z.core.$strict>>;
|
|
253
|
+
}, z.core.$strict>;
|
|
254
|
+
export type AdoptBackup = z.infer<typeof AdoptBackupSchema>;
|
|
255
|
+
export declare function readBackup(target: ScopeTarget): AdoptBackup | undefined;
|
|
256
|
+
export declare function writeBackup(target: ScopeTarget, backup: AdoptBackup): void;
|
|
257
|
+
/**
|
|
258
|
+
* Copies the file byte for byte, for the human who would rather just move it
|
|
259
|
+
* back, and for undo to put back exactly. A second connection to the same
|
|
260
|
+
* file (its adoption record is already there) keeps the first copy: that one
|
|
261
|
+
* is the file as it was before any of this.
|
|
262
|
+
*/
|
|
263
|
+
export declare function writeWholeFileBackup(file: ClientConfigFile): void;
|