@pidgeon-ai/mcp 0.29.0 → 1.3.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.
@@ -1,246 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- CLIENT_NAMES,
4
- configPath,
5
- defaultScope,
6
- entry,
7
- nextSteps,
8
- render,
9
- writeClientConfig
10
- } from "./chunk-67QGOBKE.js";
11
-
12
- // src/init.ts
13
- import { readFileSync, writeFileSync } from "fs";
14
- import { homedir } from "os";
15
- import { resolve } from "path";
16
- var SERVER_NAME = "pidgeon";
17
- var CONFIG_FILE = ".mcp.json";
18
- var DEFAULT_BASE_URL = "https://pidgeon.ai/api/v1";
19
- function configBlock(baseUrl) {
20
- const env = { PIDGEON_API_KEY: "${PIDGEON_API_KEY}" };
21
- if (baseUrl !== DEFAULT_BASE_URL) env.PIDGEON_BASE_URL = baseUrl;
22
- return { command: "npx", args: ["-y", "@pidgeon-ai/mcp"], env };
23
- }
24
- var WHAT_IT_CAN_DO = {
25
- read: "It can read mail and nothing else \u2014 a model holding it cannot reply, send or change anything.",
26
- draft: "It can read and manage mail and write drafts, and can never send \u2014 a person reviews each draft and sends it.",
27
- send: "It can read and send. It cannot create addresses, mint keys or grant access.",
28
- admin: "It can do everything the API offers, including creating addresses and granting access."
29
- };
30
- async function init(options) {
31
- const { apiKey, baseUrl, cwd, write, force, fetch, out } = options;
32
- if (options.client) return initClient({ ...options, client: options.client });
33
- if (!apiKey) {
34
- out("PIDGEON_API_KEY is not set.");
35
- out("");
36
- out("Create one at https://pidgeon.ai/app/developers/keys, then:");
37
- out(" PIDGEON_API_KEY=pgn_live_\u2026 npx -y @pidgeon-ai/mcp init");
38
- out("");
39
- out("Give it the narrowest access the agent needs \u2014 this hands it to a model.");
40
- return { ok: false, addresses: [], access: null, wrote: null };
41
- }
42
- const identity = await describeKey({ apiKey, baseUrl, fetch, out });
43
- if (identity === null) return { ok: false, addresses: [], access: null, wrote: null };
44
- const { addresses, access, reachesAll, expiresAt } = identity;
45
- if (addresses.length === 0) {
46
- out("That key works, and reaches no address yet.");
47
- out("");
48
- out("Grant it one at https://pidgeon.ai/app/developers/keys \u2014 a key\u2019s reach is");
49
- out("a snapshot, so an address created after the key is not in it.");
50
- } else {
51
- const shown = addresses.slice(0, 5);
52
- const reach = reachesAll ? `That key reaches every address this workspace owns (${addresses.length} today):` : `That key reaches ${addresses.length} address${addresses.length === 1 ? "" : "es"}:`;
53
- out(reach);
54
- for (const address of shown) out(` ${address}`);
55
- if (addresses.length > shown.length) out(` \u2026 and ${addresses.length - shown.length} more`);
56
- if (reachesAll) {
57
- out("");
58
- out("An address created after this key will be in reach too, unlike a key");
59
- out("granted a fixed list.");
60
- }
61
- }
62
- if (access) {
63
- out("");
64
- out(`Access: ${access}. ${WHAT_IT_CAN_DO[access]}`);
65
- }
66
- if (expiresAt) {
67
- const when = new Date(expiresAt);
68
- const stale = Number.isNaN(when.getTime());
69
- out("");
70
- out(
71
- stale ? `This key expires: ${expiresAt}.` : `This key stops working on ${when.toUTCString()}.`
72
- );
73
- }
74
- const block = configBlock(baseUrl);
75
- const path = resolve(cwd, CONFIG_FILE);
76
- let wrote = null;
77
- if (write) {
78
- const result = merge(path, block, force);
79
- if (!result.ok) {
80
- out("");
81
- out(result.message);
82
- return { ok: false, addresses, access, wrote: null };
83
- }
84
- wrote = path;
85
- }
86
- out("");
87
- out(wrote ? `Wrote ${CONFIG_FILE}:` : `Add this to your MCP client\u2019s config:`);
88
- out("");
89
- out(JSON.stringify({ mcpServers: { [SERVER_NAME]: block } }, null, 2));
90
- out("");
91
- out("The key is read from the environment rather than written into the file,");
92
- out("so the config can be committed and the credential cannot.");
93
- return { ok: true, addresses, access, wrote };
94
- }
95
- async function initClient(options) {
96
- const { apiKey, baseUrl, cwd, write, force, fetch, out, client } = options;
97
- const name = CLIENT_NAMES[client];
98
- const withKey = Boolean(apiKey) && !options.signIn;
99
- let addresses = [];
100
- let access = null;
101
- if (withKey) {
102
- const identity = await describeKey({ apiKey, baseUrl, fetch, out });
103
- if (identity === null) return { ok: false, addresses: [], access: null, wrote: null };
104
- ({ addresses, access } = identity);
105
- if (addresses.length === 0) {
106
- out("That key works, and reaches no address yet. Grant it one at");
107
- out("https://pidgeon.ai/app/developers/keys.");
108
- } else {
109
- out(
110
- `That key reaches ${addresses.length} address${addresses.length === 1 ? "" : "es"}: ${addresses.slice(0, 3).join(", ")}${addresses.length > 3 ? ", \u2026" : ""}`
111
- );
112
- }
113
- if (access) out(`Access: ${access}. ${WHAT_IT_CAN_DO[access]}`);
114
- } else {
115
- out(
116
- apiKey ? `Signing in rather than using PIDGEON_API_KEY, as asked.` : `No PIDGEON_API_KEY, so ${name} will sign you in to Pidgeon instead.`
117
- );
118
- }
119
- const mcpUrl = baseUrl.replace(/\/v1\/?$/, "/mcp");
120
- const block = entry(client, mcpUrl, withKey);
121
- const where = {
122
- cwd,
123
- home: options.where?.home ?? homedir(),
124
- platform: options.where?.platform ?? process.platform,
125
- env: options.where?.env ?? process.env
126
- };
127
- const path = configPath(client, options.scope ?? defaultScope(client), where);
128
- out("");
129
- if (!write) {
130
- out(`Add this to ${path}:`);
131
- out("");
132
- out(render(client, block));
133
- } else {
134
- const result = writeClientConfig(client, path, block, force);
135
- if (!result.ok) {
136
- out(result.message);
137
- return { ok: false, addresses, access, wrote: null };
138
- }
139
- if (!result.changed) {
140
- out(`${path} already has this "pidgeon" server. Nothing changed.`);
141
- } else {
142
- out(`Wrote the "pidgeon" server to ${path}:`);
143
- out("");
144
- out(render(client, block));
145
- if (result.backup) {
146
- out("");
147
- out(`The file as it was is in ${result.backup}.`);
148
- }
149
- }
150
- }
151
- out("");
152
- for (const line of nextSteps(client, withKey)) out(line);
153
- return { ok: true, addresses, access, wrote: write ? path : null };
154
- }
155
- async function describeKey(context) {
156
- const [addresses, me] = await Promise.all([
157
- reachableAddresses(context),
158
- describeCredential(context)
159
- ]);
160
- if (addresses === null) return null;
161
- return {
162
- addresses,
163
- access: me?.key?.access ?? null,
164
- reachesAll: me?.key?.reaches_all_addresses ?? false,
165
- expiresAt: me?.key?.expires_at ?? null
166
- };
167
- }
168
- async function describeCredential(context) {
169
- const { apiKey, baseUrl, fetch } = context;
170
- try {
171
- const response = await fetch(`${baseUrl}/me`, {
172
- headers: { authorization: `Bearer ${apiKey}`, accept: "application/json" }
173
- });
174
- if (!response.ok) return null;
175
- const body = await response.json();
176
- const key = body.data?.key;
177
- if (!key?.access) return null;
178
- if (key.access !== "read" && key.access !== "draft" && key.access !== "send" && key.access !== "admin") {
179
- return null;
180
- }
181
- return {
182
- key: {
183
- access: key.access,
184
- reaches_all_addresses: key.reaches_all_addresses ?? false,
185
- expires_at: key.expires_at ?? null
186
- }
187
- };
188
- } catch {
189
- return null;
190
- }
191
- }
192
- async function reachableAddresses(context) {
193
- const { apiKey, baseUrl, fetch, out } = context;
194
- let response;
195
- try {
196
- response = await fetch(`${baseUrl}/identities`, {
197
- headers: { authorization: `Bearer ${apiKey}`, accept: "application/json" }
198
- });
199
- } catch (error) {
200
- out(`Could not reach ${baseUrl}: ${error instanceof Error ? error.message : String(error)}`);
201
- return null;
202
- }
203
- if (response.status === 401 || response.status === 403) {
204
- out("That key was refused. It may be revoked, or from another deployment.");
205
- out("Keys live at https://pidgeon.ai/app/developers/keys.");
206
- return null;
207
- }
208
- if (!response.ok) {
209
- out(`The API answered ${response.status}. Nothing was written.`);
210
- return null;
211
- }
212
- const body = await response.json();
213
- return (body.data ?? []).map((identity) => identity.email ?? "").filter(Boolean);
214
- }
215
- function merge(path, block, force) {
216
- let existing = {};
217
- try {
218
- existing = JSON.parse(readFileSync(path, "utf8"));
219
- } catch (error) {
220
- if (error.code !== "ENOENT") {
221
- return {
222
- ok: false,
223
- message: `${path} exists and is not valid JSON, so nothing was written.`
224
- };
225
- }
226
- }
227
- const servers = existing.mcpServers ?? {};
228
- const current = servers[SERVER_NAME];
229
- if (current && !force && JSON.stringify(current) !== JSON.stringify(block)) {
230
- return {
231
- ok: false,
232
- message: `${path} already has a different "${SERVER_NAME}" server, so nothing was written.
233
- Run again with --force to replace it, or edit the file by hand.`
234
- };
235
- }
236
- writeFileSync(
237
- path,
238
- `${JSON.stringify({ ...existing, mcpServers: { ...servers, [SERVER_NAME]: block } }, null, 2)}
239
- `
240
- );
241
- return { ok: true };
242
- }
243
- export {
244
- init
245
- };
246
- //# sourceMappingURL=init-TDXCNVQ5.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/init.ts"],"sourcesContent":["import { readFileSync, writeFileSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { resolve } from 'node:path';\n\nimport {\n CLIENT_NAMES,\n type Client,\n configPath,\n defaultScope,\n entry,\n nextSteps,\n render,\n type Scope,\n type Where,\n writeClientConfig,\n} from './clients.js';\n\n/**\n * `npx -y @pidgeon-ai/mcp init` — the install, as one command.\n *\n * The README has carried a correct block of JSON for as long as this package\n * has existed, and a block of JSON is not an install: somebody has to know\n * which file it goes in, paste it without breaking the file already there,\n * invent a name for the server, and then find out whether their key works by\n * asking a model to try.\n *\n * **The check is the part worth having.** A wrong key, a revoked key, or a\n * key granted no mailbox all fail the same way through an MCP client — the\n * tools are listed, the model calls one, and the answer is an error the\n * person never sees. This asks the API first and says what the key can\n * actually reach, which is the one question a copy-paste cannot answer.\n *\n * ## It writes `.mcp.json`, and says so\n *\n * That filename is the convention a project-scoped MCP config uses and\n * several clients read it from a project root. Deliberately **not** a map of\n * each client's own config path: those differ, they move between releases,\n * and a tool that writes confidently to the wrong one is worse than a tool\n * that writes somewhere predictable and tells you. The block it wrote is\n * printed either way, so moving it is a copy rather than a re-derivation.\n *\n * `--client codex|vscode|gemini` is the exception, for the three clients\n * whose one documented file and remote-server format were looked up and\n * tested (`clients.ts`). Those get the hosted server, and with no key they\n * get the URL alone and sign in.\n */\n\n/** The server's name in the config. One word, because a person types it. */\nconst SERVER_NAME = 'pidgeon';\n\nconst CONFIG_FILE = '.mcp.json';\n\nconst DEFAULT_BASE_URL = 'https://pidgeon.ai/api/v1';\n\ninterface InitOptions {\n apiKey: string | undefined;\n baseUrl: string;\n cwd: string;\n write: boolean;\n force: boolean;\n fetch: typeof globalThis.fetch;\n out: (line: string) => void;\n /** Write the hosted server into this client's own file instead of `.mcp.json`. */\n client?: Client;\n scope?: Scope;\n /** Write the sign-in entry even when a key is set. */\n signIn?: boolean;\n /** Where the user's files are; the tests point it at a sandbox. */\n where?: Omit<Where, 'cwd'>;\n}\n\n/** What goes in the config. The key is referenced, never printed. */\nfunction configBlock(baseUrl: string): Record<string, unknown> {\n const env: Record<string, string> = { PIDGEON_API_KEY: '${PIDGEON_API_KEY}' };\n\n // Only when it is not production, so the common case stays the short case.\n if (baseUrl !== DEFAULT_BASE_URL) env.PIDGEON_BASE_URL = baseUrl;\n\n return { command: 'npx', args: ['-y', '@pidgeon-ai/mcp'], env };\n}\n\nexport interface InitResult {\n ok: boolean;\n /** Addresses the key can reach, when the check ran. */\n addresses: string[];\n /** The highest rung it reaches on any of them, from `GET /v1/me`. */\n access: Access | null;\n wrote: string | null;\n}\n\n/** The rungs, lowest first. `admin` is what a key has unless narrowed. */\nexport type Access = 'read' | 'draft' | 'send' | 'admin';\n\n/**\n * What a model can actually do with this key, said plainly.\n *\n * The reason this command now makes a second call. It printed which\n * addresses a key reaches and never what it may *do* with them, and an\n * agent builder reported the consequence on 15 October: *\"`read` is the\n * thing that surprises someone later\"* — later being the first time the\n * agent tries to answer an email and is refused, inside a model's tool\n * call, where the error is nobody's to read.\n *\n * A rung is also the one property of a key whose wrongness is silent at\n * setup. A revoked key fails immediately; a key granted nothing prints an\n * empty list. A key at `read` sets up perfectly and then cannot work.\n */\nconst WHAT_IT_CAN_DO: Record<Access, string> = {\n read: 'It can read mail and nothing else — a model holding it cannot reply, send or change anything.',\n draft:\n 'It can read and manage mail and write drafts, and can never send — a person reviews each ' +\n 'draft and sends it.',\n send: 'It can read and send. It cannot create addresses, mint keys or grant access.',\n admin: 'It can do everything the API offers, including creating addresses and granting access.',\n};\n\nexport async function init(options: InitOptions): Promise<InitResult> {\n const { apiKey, baseUrl, cwd, write, force, fetch, out } = options;\n\n if (options.client) return initClient({ ...options, client: options.client });\n\n if (!apiKey) {\n out('PIDGEON_API_KEY is not set.');\n out('');\n out('Create one at https://pidgeon.ai/app/developers/keys, then:');\n out(' PIDGEON_API_KEY=pgn_live_… npx -y @pidgeon-ai/mcp init');\n out('');\n out('Give it the narrowest access the agent needs — this hands it to a model.');\n return { ok: false, addresses: [], access: null, wrote: null };\n }\n\n /*\n * The check, before anything is written. `GET /identities` is the cheapest\n * call that proves all three things at once: the key parses, it is live,\n * and it has been granted something. A key granted nothing returns an empty\n * list rather than an error, which is its own answer and a common one — a\n * key is created and the mailbox is granted separately.\n */\n const identity = await describeKey({ apiKey, baseUrl, fetch, out });\n if (identity === null) return { ok: false, addresses: [], access: null, wrote: null };\n\n const { addresses, access, reachesAll, expiresAt } = identity;\n\n if (addresses.length === 0) {\n out('That key works, and reaches no address yet.');\n out('');\n out('Grant it one at https://pidgeon.ai/app/developers/keys — a key’s reach is');\n out('a snapshot, so an address created after the key is not in it.');\n } else {\n const shown = addresses.slice(0, 5);\n const reach = reachesAll\n ? `That key reaches every address this workspace owns (${addresses.length} today):`\n : `That key reaches ${addresses.length} address${addresses.length === 1 ? '' : 'es'}:`;\n\n out(reach);\n for (const address of shown) out(` ${address}`);\n if (addresses.length > shown.length) out(` … and ${addresses.length - shown.length} more`);\n\n if (reachesAll) {\n out('');\n out('An address created after this key will be in reach too, unlike a key');\n out('granted a fixed list.');\n }\n }\n\n /*\n * The rung, on its own line, whatever the reach. Printed even for a key\n * that reaches nothing: *what this key could do if you granted it\n * something* is the thing somebody is about to get wrong.\n */\n if (access) {\n out('');\n out(`Access: ${access}. ${WHAT_IT_CAN_DO[access]}`);\n }\n\n /*\n * And the date, which is the other way a key that works today stops.\n * `§342` gave keys an end; nothing told the person setting one up.\n */\n if (expiresAt) {\n const when = new Date(expiresAt);\n const stale = Number.isNaN(when.getTime());\n\n out('');\n out(\n stale\n ? `This key expires: ${expiresAt}.`\n : `This key stops working on ${when.toUTCString()}.`,\n );\n }\n\n const block = configBlock(baseUrl);\n const path = resolve(cwd, CONFIG_FILE);\n let wrote: string | null = null;\n\n if (write) {\n const result = merge(path, block, force);\n if (!result.ok) {\n out('');\n out(result.message);\n return { ok: false, addresses, access, wrote: null };\n }\n wrote = path;\n }\n\n out('');\n out(wrote ? `Wrote ${CONFIG_FILE}:` : `Add this to your MCP client’s config:`);\n out('');\n out(JSON.stringify({ mcpServers: { [SERVER_NAME]: block } }, null, 2));\n out('');\n out('The key is read from the environment rather than written into the file,');\n out('so the config can be committed and the credential cannot.');\n\n return { ok: true, addresses, access, wrote };\n}\n\n/**\n * `init --client …`: the hosted server in that client's file.\n *\n * A key is checked exactly as the bare `init` checks it, and then referenced\n * the way that client can (an environment variable, or VS Code's prompt).\n * No key is not a failure here: all three clients sign in with OAuth, so the\n * entry is the URL alone and the person is told the one step left.\n */\nasync function initClient(options: InitOptions & { client: Client }): Promise<InitResult> {\n const { apiKey, baseUrl, cwd, write, force, fetch, out, client } = options;\n const name = CLIENT_NAMES[client];\n const withKey = Boolean(apiKey) && !options.signIn;\n\n let addresses: string[] = [];\n let access: Access | null = null;\n\n if (withKey) {\n const identity = await describeKey({ apiKey: apiKey!, baseUrl, fetch, out });\n if (identity === null) return { ok: false, addresses: [], access: null, wrote: null };\n\n ({ addresses, access } = identity);\n if (addresses.length === 0) {\n out('That key works, and reaches no address yet. Grant it one at');\n out('https://pidgeon.ai/app/developers/keys.');\n } else {\n out(\n `That key reaches ${addresses.length} address${addresses.length === 1 ? '' : 'es'}: ${addresses.slice(0, 3).join(', ')}${addresses.length > 3 ? ', …' : ''}`,\n );\n }\n if (access) out(`Access: ${access}. ${WHAT_IT_CAN_DO[access]}`);\n } else {\n out(\n apiKey\n ? `Signing in rather than using PIDGEON_API_KEY, as asked.`\n : `No PIDGEON_API_KEY, so ${name} will sign you in to Pidgeon instead.`,\n );\n }\n\n const mcpUrl = baseUrl.replace(/\\/v1\\/?$/, '/mcp');\n const block = entry(client, mcpUrl, withKey);\n const where: Where = {\n cwd,\n home: options.where?.home ?? homedir(),\n platform: options.where?.platform ?? process.platform,\n env: options.where?.env ?? process.env,\n };\n const path = configPath(client, options.scope ?? defaultScope(client), where);\n\n out('');\n\n if (!write) {\n out(`Add this to ${path}:`);\n out('');\n out(render(client, block));\n } else {\n const result = writeClientConfig(client, path, block, force);\n if (!result.ok) {\n out(result.message);\n return { ok: false, addresses, access, wrote: null };\n }\n\n if (!result.changed) {\n out(`${path} already has this \"pidgeon\" server. Nothing changed.`);\n } else {\n out(`Wrote the \"pidgeon\" server to ${path}:`);\n out('');\n out(render(client, block));\n if (result.backup) {\n out('');\n out(`The file as it was is in ${result.backup}.`);\n }\n }\n }\n\n out('');\n for (const line of nextSteps(client, withKey)) out(line);\n\n return { ok: true, addresses, access, wrote: write ? path : null };\n}\n\n/**\n * Everything this command knows about the key, or `null` when the key itself\n * is the problem.\n *\n * **Two calls, in parallel, because they answer different questions.**\n * `GET /identities` names the addresses; `GET /v1/me` says what the\n * credential may do with them, which no other endpoint will tell you — the\n * reason that endpoint was built. They go together rather than in sequence\n * because neither depends on the other and this runs while somebody waits.\n *\n * `/v1/me` failing is not fatal on its own. It is newer than this command,\n * and a client pointed at a deployment that predates it should still get the\n * setup it came for — the rung is then simply unknown, which is honest, and\n * better than refusing to write a config over a field that did not exist\n * last month.\n */\nasync function describeKey(context: {\n apiKey: string;\n baseUrl: string;\n fetch: typeof globalThis.fetch;\n out: (line: string) => void;\n}): Promise<{\n addresses: string[];\n access: Access | null;\n reachesAll: boolean;\n expiresAt: string | null;\n} | null> {\n const [addresses, me] = await Promise.all([\n reachableAddresses(context),\n describeCredential(context),\n ]);\n\n if (addresses === null) return null;\n\n return {\n addresses,\n access: me?.key?.access ?? null,\n reachesAll: me?.key?.reaches_all_addresses ?? false,\n expiresAt: me?.key?.expires_at ?? null,\n };\n}\n\n/** `GET /v1/me`, or null on any failure. See `describeKey` for why. */\nasync function describeCredential(context: {\n apiKey: string;\n baseUrl: string;\n fetch: typeof globalThis.fetch;\n}): Promise<{\n key: { access: Access; reaches_all_addresses: boolean; expires_at: string | null } | null;\n} | null> {\n const { apiKey, baseUrl, fetch } = context;\n\n try {\n const response = await fetch(`${baseUrl}/me`, {\n headers: { authorization: `Bearer ${apiKey}`, accept: 'application/json' },\n });\n\n if (!response.ok) return null;\n\n const body = (await response.json()) as {\n data?: {\n key?: { access?: string; reaches_all_addresses?: boolean; expires_at?: string | null };\n };\n };\n\n const key = body.data?.key;\n if (!key?.access) return null;\n\n // A rung this client does not know is a rung it must not print.\n if (\n key.access !== 'read' &&\n key.access !== 'draft' &&\n key.access !== 'send' &&\n key.access !== 'admin'\n ) {\n return null;\n }\n\n return {\n key: {\n access: key.access,\n reaches_all_addresses: key.reaches_all_addresses ?? false,\n expires_at: key.expires_at ?? null,\n },\n };\n } catch {\n return null;\n }\n}\n\n/**\n * The addresses this key can reach, or `null` when the key is the problem.\n *\n * Every failure gets a sentence that says what to do, because \"401\" through\n * an MCP client is a model's problem and this is a person's.\n */\nasync function reachableAddresses(context: {\n apiKey: string;\n baseUrl: string;\n fetch: typeof globalThis.fetch;\n out: (line: string) => void;\n}): Promise<string[] | null> {\n const { apiKey, baseUrl, fetch, out } = context;\n\n let response: Response;\n\n try {\n response = await fetch(`${baseUrl}/identities`, {\n headers: { authorization: `Bearer ${apiKey}`, accept: 'application/json' },\n });\n } catch (error) {\n out(`Could not reach ${baseUrl}: ${error instanceof Error ? error.message : String(error)}`);\n return null;\n }\n\n if (response.status === 401 || response.status === 403) {\n out('That key was refused. It may be revoked, or from another deployment.');\n out('Keys live at https://pidgeon.ai/app/developers/keys.');\n return null;\n }\n\n if (!response.ok) {\n out(`The API answered ${response.status}. Nothing was written.`);\n return null;\n }\n\n const body = (await response.json()) as { data?: { email?: string }[] };\n return (body.data ?? []).map((identity) => identity.email ?? '').filter(Boolean);\n}\n\n/**\n * Add the entry without destroying what is already in the file.\n *\n * A developer running this in a project that already talks to three MCP\n * servers must not lose them, and one who runs it twice must not be told off.\n * An entry that is already ours and already correct is a no-op; one that is\n * ours and different is the only case that needs a decision, and the decision\n * is theirs.\n */\nfunction merge(\n path: string,\n block: Record<string, unknown>,\n force: boolean,\n): { ok: true } | { ok: false; message: string } {\n let existing: Record<string, unknown> = {};\n\n try {\n existing = JSON.parse(readFileSync(path, 'utf8')) as Record<string, unknown>;\n } catch (error) {\n // A missing file is the normal case. Anything else is a file we must not\n // overwrite, because we could not read what it holds.\n if ((error as { code?: string }).code !== 'ENOENT') {\n return {\n ok: false,\n message: `${path} exists and is not valid JSON, so nothing was written.`,\n };\n }\n }\n\n const servers = (existing.mcpServers ?? {}) as Record<string, unknown>;\n const current = servers[SERVER_NAME];\n\n if (current && !force && JSON.stringify(current) !== JSON.stringify(block)) {\n return {\n ok: false,\n message:\n `${path} already has a different \"${SERVER_NAME}\" server, so nothing was written.\\n` +\n 'Run again with --force to replace it, or edit the file by hand.',\n };\n }\n\n writeFileSync(\n path,\n `${JSON.stringify({ ...existing, mcpServers: { ...servers, [SERVER_NAME]: block } }, null, 2)}\\n`,\n );\n\n return { ok: true };\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,cAAc,qBAAqB;AAC5C,SAAS,eAAe;AACxB,SAAS,eAAe;AA8CxB,IAAM,cAAc;AAEpB,IAAM,cAAc;AAEpB,IAAM,mBAAmB;AAoBzB,SAAS,YAAY,SAA0C;AAC7D,QAAM,MAA8B,EAAE,iBAAiB,qBAAqB;AAG5E,MAAI,YAAY,iBAAkB,KAAI,mBAAmB;AAEzD,SAAO,EAAE,SAAS,OAAO,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI;AAChE;AA4BA,IAAM,iBAAyC;AAAA,EAC7C,MAAM;AAAA,EACN,OACE;AAAA,EAEF,MAAM;AAAA,EACN,OAAO;AACT;AAEA,eAAsB,KAAK,SAA2C;AACpE,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