@pidgeon-ai/mcp 0.29.0 → 1.0.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/CHANGELOG.md +15 -0
- package/LICENSE +55 -21
- package/README.md +32 -209
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +5 -0
- package/dist/server.d.ts +27 -0
- package/dist/server.js +112 -0
- package/dist/tools.d.ts +31 -0
- package/dist/tools.js +204 -0
- package/package.json +30 -43
- package/server.json +8 -63
- package/dist/chunk-67QGOBKE.js +0 -267
- package/dist/chunk-67QGOBKE.js.map +0 -1
- package/dist/chunk-6HW5LN74.js +0 -1365
- package/dist/chunk-6HW5LN74.js.map +0 -1
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -8
- package/dist/cli.js.map +0 -1
- package/dist/clients-N7HG6WUL.js +0 -24
- package/dist/clients-N7HG6WUL.js.map +0 -1
- package/dist/index.d.ts +0 -107
- package/dist/index.js +0 -14
- package/dist/index.js.map +0 -1
- package/dist/init-TDXCNVQ5.js +0 -246
- package/dist/init-TDXCNVQ5.js.map +0 -1
package/dist/tools.js
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PidgeonError } from '@pidgeon-ai/sdk';
|
|
3
|
+
export const VERSION = '1.0.0';
|
|
4
|
+
export const json = (value) => ({
|
|
5
|
+
content: [{ type: 'text', text: JSON.stringify(value ?? { ok: true }, null, 2) }],
|
|
6
|
+
});
|
|
7
|
+
export const failed = (text) => ({
|
|
8
|
+
isError: true,
|
|
9
|
+
content: [{ type: 'text', text }],
|
|
10
|
+
});
|
|
11
|
+
/** Run a tool's work and answer its result, or the API's refusal in words the model can act on. */
|
|
12
|
+
export async function run(work, signInHint = 'Sign in to Pidgeon again.') {
|
|
13
|
+
try {
|
|
14
|
+
return json(await work());
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error instanceof PidgeonError) {
|
|
18
|
+
const hint = error.code === 'not_signed_in' || error.status === 401
|
|
19
|
+
? ` ${signInHint}`
|
|
20
|
+
: error.status === 403 && error.code === 'forbidden'
|
|
21
|
+
? ' A key or sign-in with more access can.'
|
|
22
|
+
: '';
|
|
23
|
+
return failed(`${error.message} (${error.status} ${error.code}).${hint}`);
|
|
24
|
+
}
|
|
25
|
+
return failed(error instanceof Error ? error.message : String(error));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const addresses = z.array(z.string().email()).min(1).max(50);
|
|
29
|
+
const messageShape = {
|
|
30
|
+
to: addresses.describe('Who it is to.'),
|
|
31
|
+
cc: z.array(z.string().email()).optional(),
|
|
32
|
+
bcc: z.array(z.string().email()).optional(),
|
|
33
|
+
subject: z.string().max(998),
|
|
34
|
+
text: z.string().optional().describe('The plain-text body. Send text, html or both.'),
|
|
35
|
+
html: z.string().optional(),
|
|
36
|
+
reply_to: z
|
|
37
|
+
.string()
|
|
38
|
+
.uuid()
|
|
39
|
+
.optional()
|
|
40
|
+
.describe('A message of this inbox to reply to; the reply joins its thread.'),
|
|
41
|
+
};
|
|
42
|
+
const asMessage = (args) => ({
|
|
43
|
+
to: args.to,
|
|
44
|
+
cc: args.cc,
|
|
45
|
+
bcc: args.bcc,
|
|
46
|
+
subject: args.subject,
|
|
47
|
+
text: args.text,
|
|
48
|
+
html: args.html,
|
|
49
|
+
replyTo: args.reply_to,
|
|
50
|
+
});
|
|
51
|
+
export const READ = { readOnlyHint: true, openWorldHint: true };
|
|
52
|
+
export const WRITE = { readOnlyHint: false, destructiveHint: false, openWorldHint: true };
|
|
53
|
+
export const DESTROY = { readOnlyHint: false, destructiveHint: true, openWorldHint: true };
|
|
54
|
+
/** Register every tool that is only an API call. `signInHint` is what to say when the caller is not signed in. */
|
|
55
|
+
export function registerApiTools(server, pidgeon, signInHint) {
|
|
56
|
+
const answer = (work) => run(work, signInHint);
|
|
57
|
+
server.registerTool('list_agents', {
|
|
58
|
+
title: 'List agents',
|
|
59
|
+
description: 'The account’s agents.',
|
|
60
|
+
inputSchema: { cursor: z.string().optional() },
|
|
61
|
+
annotations: READ,
|
|
62
|
+
}, ({ cursor }) => answer(() => pidgeon.agents.list({ cursor })));
|
|
63
|
+
server.registerTool('get_agent', {
|
|
64
|
+
title: 'Read an agent',
|
|
65
|
+
description: 'An agent: its published keys (public facts only), its directory and its operator’s reputation.',
|
|
66
|
+
inputSchema: { agent_id: z.string().uuid() },
|
|
67
|
+
annotations: READ,
|
|
68
|
+
}, ({ agent_id }) => answer(() => pidgeon.agents.get(agent_id)));
|
|
69
|
+
server.registerTool('get_reputation', {
|
|
70
|
+
title: 'Read reputation',
|
|
71
|
+
description: 'How websites treat the account’s agents: the band (unverified, new, good, flagged, suspended), what it means, and what would raise it. Reputation belongs to the operator, so every agent of the account shares it.',
|
|
72
|
+
inputSchema: {
|
|
73
|
+
agent_id: z
|
|
74
|
+
.string()
|
|
75
|
+
.uuid()
|
|
76
|
+
.optional()
|
|
77
|
+
.describe('Any of the account’s agents; the first if left out.'),
|
|
78
|
+
},
|
|
79
|
+
annotations: READ,
|
|
80
|
+
}, ({ agent_id }) => answer(async () => {
|
|
81
|
+
const id = agent_id ?? (await pidgeon.agents.list({ limit: 1 })).data[0]?.id;
|
|
82
|
+
if (!id)
|
|
83
|
+
return { reputation: null, note: 'The account has no agents yet: set_up_agent first.' };
|
|
84
|
+
const agent = await pidgeon.agents.get(id);
|
|
85
|
+
return { agent_id: agent.id, ...agent.reputation };
|
|
86
|
+
}));
|
|
87
|
+
// ----------------------------------------------------------------- Email
|
|
88
|
+
server.registerTool('list_inboxes', {
|
|
89
|
+
title: 'List inboxes',
|
|
90
|
+
description: 'The account’s inboxes.',
|
|
91
|
+
inputSchema: { cursor: z.string().optional() },
|
|
92
|
+
annotations: READ,
|
|
93
|
+
}, ({ cursor }) => answer(() => pidgeon.inboxes.list({ cursor })));
|
|
94
|
+
server.registerTool('get_inbox', {
|
|
95
|
+
title: 'Read an inbox',
|
|
96
|
+
description: 'One inbox.',
|
|
97
|
+
inputSchema: { inbox_id: z.string().uuid() },
|
|
98
|
+
annotations: READ,
|
|
99
|
+
}, ({ inbox_id }) => answer(() => pidgeon.inboxes.get(inbox_id)));
|
|
100
|
+
server.registerTool('create_inbox', {
|
|
101
|
+
title: 'Make an inbox',
|
|
102
|
+
description: 'Make an inbox. `name` is the part before the @. Pass agent_id to make it that agent’s: its mail then carries its signed declaration (binding needs a verified domain).',
|
|
103
|
+
inputSchema: {
|
|
104
|
+
name: z.string().min(1).max(64),
|
|
105
|
+
kind: z.enum(['agent', 'shared', 'person', 'events']).default('agent'),
|
|
106
|
+
agent_id: z.string().uuid().optional(),
|
|
107
|
+
display_name: z.string().max(120).optional(),
|
|
108
|
+
pod_id: z.string().uuid().optional(),
|
|
109
|
+
},
|
|
110
|
+
annotations: WRITE,
|
|
111
|
+
}, (args) => answer(() => pidgeon.inboxes.create({
|
|
112
|
+
name: args.name,
|
|
113
|
+
kind: args.kind,
|
|
114
|
+
agentId: args.agent_id,
|
|
115
|
+
displayName: args.display_name,
|
|
116
|
+
podId: args.pod_id,
|
|
117
|
+
})));
|
|
118
|
+
server.registerTool('remove_inbox', {
|
|
119
|
+
title: 'Remove an inbox',
|
|
120
|
+
description: 'Remove an inbox. Its address is retired and never given to anyone again.',
|
|
121
|
+
inputSchema: { inbox_id: z.string().uuid() },
|
|
122
|
+
annotations: DESTROY,
|
|
123
|
+
}, ({ inbox_id }) => answer(async () => (await pidgeon.inboxes.remove(inbox_id), { removed: inbox_id })));
|
|
124
|
+
server.registerTool('send_message', {
|
|
125
|
+
title: 'Send an email',
|
|
126
|
+
description: 'Send from an inbox now. The answer’s status is sent, or held when the account’s reputation needs a person to approve it first.',
|
|
127
|
+
inputSchema: { inbox_id: z.string().uuid(), ...messageShape },
|
|
128
|
+
annotations: WRITE,
|
|
129
|
+
}, ({ inbox_id, ...message }) => answer(() => pidgeon.messages.send(inbox_id, asMessage(message))));
|
|
130
|
+
server.registerTool('create_draft', {
|
|
131
|
+
title: 'Draft an email',
|
|
132
|
+
description: 'Write a draft in an inbox. Nothing is sent until send_draft, or a person approves it after request_approval.',
|
|
133
|
+
inputSchema: { inbox_id: z.string().uuid(), ...messageShape },
|
|
134
|
+
annotations: WRITE,
|
|
135
|
+
}, ({ inbox_id, ...message }) => answer(() => pidgeon.drafts.create(inbox_id, asMessage(message))));
|
|
136
|
+
server.registerTool('get_draft', {
|
|
137
|
+
title: 'Read a draft',
|
|
138
|
+
description: 'A draft, or a message held or scheduled.',
|
|
139
|
+
inputSchema: { draft_id: z.string().uuid() },
|
|
140
|
+
annotations: READ,
|
|
141
|
+
}, ({ draft_id }) => answer(() => pidgeon.drafts.get(draft_id)));
|
|
142
|
+
server.registerTool('update_draft', {
|
|
143
|
+
title: 'Edit a draft',
|
|
144
|
+
description: 'Replace a draft’s addresses and body.',
|
|
145
|
+
inputSchema: { draft_id: z.string().uuid(), ...messageShape },
|
|
146
|
+
annotations: WRITE,
|
|
147
|
+
}, ({ draft_id, ...message }) => answer(() => pidgeon.drafts.update(draft_id, asMessage(message))));
|
|
148
|
+
server.registerTool('delete_draft', {
|
|
149
|
+
title: 'Throw a draft away',
|
|
150
|
+
description: 'Delete a draft, or a message held or scheduled.',
|
|
151
|
+
inputSchema: { draft_id: z.string().uuid() },
|
|
152
|
+
annotations: DESTROY,
|
|
153
|
+
}, ({ draft_id }) => answer(async () => (await pidgeon.drafts.remove(draft_id), { deleted: draft_id })));
|
|
154
|
+
server.registerTool('send_draft', {
|
|
155
|
+
title: 'Send a draft',
|
|
156
|
+
description: 'Send a draft now, or at send_at (ISO 8601, up to 90 days ahead).',
|
|
157
|
+
inputSchema: { draft_id: z.string().uuid(), send_at: z.string().datetime().optional() },
|
|
158
|
+
annotations: WRITE,
|
|
159
|
+
}, ({ draft_id, send_at }) => answer(() => pidgeon.drafts.send(draft_id, { sendAt: send_at })));
|
|
160
|
+
server.registerTool('request_approval', {
|
|
161
|
+
title: 'Ask a person to approve',
|
|
162
|
+
description: 'Hold a draft for a person of the account to send or reject in Pidgeon. Use it when the mail matters and a person should look first.',
|
|
163
|
+
inputSchema: { draft_id: z.string().uuid() },
|
|
164
|
+
annotations: WRITE,
|
|
165
|
+
}, ({ draft_id }) => answer(() => pidgeon.drafts.requestApproval(draft_id)));
|
|
166
|
+
server.registerTool('list_rules', {
|
|
167
|
+
title: 'List mail rules',
|
|
168
|
+
description: 'The account’s send and receive rules.',
|
|
169
|
+
annotations: READ,
|
|
170
|
+
}, () => answer(() => pidgeon.rules.list()));
|
|
171
|
+
server.registerTool('add_rule', {
|
|
172
|
+
title: 'Add a mail rule',
|
|
173
|
+
description: 'Allow or block an address, or a domain and its subdomains, for sending or receiving; for one inbox, or every inbox when inbox_id is left out.',
|
|
174
|
+
inputSchema: {
|
|
175
|
+
direction: z.enum(['send', 'receive']),
|
|
176
|
+
action: z.enum(['allow', 'block']),
|
|
177
|
+
pattern: z.string().describe('ana@example.com, or example.com'),
|
|
178
|
+
inbox_id: z.string().uuid().optional(),
|
|
179
|
+
},
|
|
180
|
+
annotations: WRITE,
|
|
181
|
+
}, ({ direction, action, pattern, inbox_id }) => answer(() => pidgeon.rules.create({ direction, action, pattern, inboxId: inbox_id })));
|
|
182
|
+
server.registerTool('remove_rule', {
|
|
183
|
+
title: 'Remove a mail rule',
|
|
184
|
+
description: 'Remove a send or receive rule.',
|
|
185
|
+
inputSchema: { rule_id: z.string().uuid() },
|
|
186
|
+
annotations: DESTROY,
|
|
187
|
+
}, ({ rule_id }) => answer(async () => (await pidgeon.rules.remove(rule_id), { removed: rule_id })));
|
|
188
|
+
server.registerTool('list_suppressions', {
|
|
189
|
+
title: 'List the do-not-send list',
|
|
190
|
+
description: 'Addresses the account will not send to: bounces, complaints, and ones added by hand.',
|
|
191
|
+
annotations: READ,
|
|
192
|
+
}, () => answer(() => pidgeon.suppressions.list()));
|
|
193
|
+
// --------------------------------------------------------- the account
|
|
194
|
+
server.registerTool('list_events', {
|
|
195
|
+
title: 'Read the event log',
|
|
196
|
+
description: 'What happened in the account, newest first: mail sent, received and held, keys, agents, sign-ins.',
|
|
197
|
+
inputSchema: {
|
|
198
|
+
type: z.string().optional(),
|
|
199
|
+
limit: z.number().int().min(1).max(100).optional(),
|
|
200
|
+
cursor: z.string().optional(),
|
|
201
|
+
},
|
|
202
|
+
annotations: READ,
|
|
203
|
+
}, (args) => answer(() => pidgeon.events.list(args)));
|
|
204
|
+
}
|
package/package.json
CHANGED
|
@@ -1,70 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pidgeon-ai/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Pidgeon's MCP server: a coding agent sets an agent up end to end (registered, keyed on your machine, published, its reputation read) and works its inboxes.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
4
7
|
"mcpName": "ai.pidgeon/mcp",
|
|
5
|
-
"description": "Email inboxes for AI agents: an MCP server that gives your agent its own inbox (Pidgeon).",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"mcp",
|
|
8
|
-
"model-context-protocol",
|
|
9
|
-
"email",
|
|
10
|
-
"email-api",
|
|
11
|
-
"inbox",
|
|
12
|
-
"ai-agents",
|
|
13
|
-
"agent",
|
|
14
|
-
"llm",
|
|
15
|
-
"otp",
|
|
16
|
-
"verification-code",
|
|
17
|
-
"pidgeon"
|
|
18
|
-
],
|
|
19
|
-
"license": "MIT",
|
|
20
8
|
"repository": {
|
|
21
9
|
"type": "git",
|
|
22
10
|
"url": "git+https://github.com/pidgeon-ai/pidgeon-js.git",
|
|
23
11
|
"directory": "packages/mcp"
|
|
24
12
|
},
|
|
25
13
|
"homepage": "https://pidgeon.ai",
|
|
26
|
-
"
|
|
14
|
+
"keywords": [
|
|
15
|
+
"pidgeon",
|
|
16
|
+
"mcp",
|
|
17
|
+
"model-context-protocol",
|
|
18
|
+
"ai-agents",
|
|
19
|
+
"agent-identity",
|
|
20
|
+
"email"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=20"
|
|
24
|
+
},
|
|
27
25
|
"bin": {
|
|
28
|
-
"pidgeon-mcp": "dist/
|
|
26
|
+
"pidgeon-mcp": "dist/bin.js"
|
|
29
27
|
},
|
|
30
28
|
"exports": {
|
|
31
29
|
".": {
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
"types": "./dist/server.d.ts",
|
|
31
|
+
"default": "./dist/server.js"
|
|
32
|
+
},
|
|
33
|
+
"./tools": {
|
|
34
|
+
"types": "./dist/tools.d.ts",
|
|
35
|
+
"default": "./dist/tools.js"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
|
-
"types": "./dist/index.d.ts",
|
|
39
38
|
"files": [
|
|
40
39
|
"dist",
|
|
40
|
+
"server.json",
|
|
41
41
|
"README.md",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
42
|
+
"CHANGELOG.md",
|
|
43
|
+
"LICENSE"
|
|
44
44
|
],
|
|
45
|
-
"engines": {
|
|
46
|
-
"node": ">=18"
|
|
47
|
-
},
|
|
48
|
-
"publishConfig": {
|
|
49
|
-
"access": "public"
|
|
50
|
-
},
|
|
51
45
|
"dependencies": {
|
|
52
|
-
"@modelcontextprotocol/
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"zod": "^4.6.5",
|
|
56
|
-
"@pidgeon-ai/sdk": "1.68.0"
|
|
46
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
47
|
+
"zod": "^4.6.7",
|
|
48
|
+
"@pidgeon-ai/sdk": "^2.0.0"
|
|
57
49
|
},
|
|
58
50
|
"devDependencies": {
|
|
59
|
-
"@types/node": "^24",
|
|
60
|
-
"tsup": "^8.5.0",
|
|
51
|
+
"@types/node": "^24.10.1",
|
|
61
52
|
"typescript": "^5"
|
|
62
53
|
},
|
|
63
|
-
"bugs": {
|
|
64
|
-
"url": "https://github.com/pidgeon-ai/pidgeon-js/issues"
|
|
65
|
-
},
|
|
66
54
|
"scripts": {
|
|
67
|
-
"build": "
|
|
68
|
-
"typecheck": "tsc --noEmit"
|
|
55
|
+
"build": "tsc -p tsconfig.build.json"
|
|
69
56
|
}
|
|
70
57
|
}
|
package/server.json
CHANGED
|
@@ -2,81 +2,26 @@
|
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "ai.pidgeon/mcp",
|
|
4
4
|
"title": "Pidgeon",
|
|
5
|
-
"description": "
|
|
6
|
-
"websiteUrl": "https://pidgeon.ai
|
|
7
|
-
"icons": [
|
|
8
|
-
{
|
|
9
|
-
"src": "https://pidgeon.ai/brand/icon-light.png",
|
|
10
|
-
"mimeType": "image/png",
|
|
11
|
-
"sizes": ["512x512"],
|
|
12
|
-
"theme": "light"
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"src": "https://pidgeon.ai/brand/icon-dark.png",
|
|
16
|
-
"mimeType": "image/png",
|
|
17
|
-
"sizes": ["512x512"],
|
|
18
|
-
"theme": "dark"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"src": "https://pidgeon.ai/brand/icon-light.svg",
|
|
22
|
-
"mimeType": "image/svg+xml",
|
|
23
|
-
"sizes": ["any"],
|
|
24
|
-
"theme": "light"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"src": "https://pidgeon.ai/brand/icon-dark.svg",
|
|
28
|
-
"mimeType": "image/svg+xml",
|
|
29
|
-
"sizes": ["any"],
|
|
30
|
-
"theme": "dark"
|
|
31
|
-
}
|
|
32
|
-
],
|
|
5
|
+
"description": "Give AI agents their own identity and inbox: registered, keyed on your machine, reputation read.",
|
|
6
|
+
"websiteUrl": "https://pidgeon.ai",
|
|
33
7
|
"repository": {
|
|
34
8
|
"url": "https://github.com/pidgeon-ai/pidgeon-js",
|
|
35
9
|
"source": "github",
|
|
36
10
|
"subfolder": "packages/mcp"
|
|
37
11
|
},
|
|
38
|
-
"version": "0.
|
|
12
|
+
"version": "1.0.0",
|
|
39
13
|
"packages": [
|
|
40
14
|
{
|
|
41
15
|
"registryType": "npm",
|
|
42
|
-
"registryBaseUrl": "https://registry.npmjs.org",
|
|
43
16
|
"identifier": "@pidgeon-ai/mcp",
|
|
44
|
-
"version": "0.
|
|
45
|
-
"
|
|
46
|
-
"transport": {
|
|
47
|
-
"type": "stdio"
|
|
48
|
-
},
|
|
17
|
+
"version": "1.0.0",
|
|
18
|
+
"transport": { "type": "stdio" },
|
|
49
19
|
"environmentVariables": [
|
|
50
20
|
{
|
|
51
21
|
"name": "PIDGEON_API_KEY",
|
|
52
|
-
"description": "
|
|
53
|
-
"isRequired":
|
|
54
|
-
"isSecret": true
|
|
55
|
-
"format": "string",
|
|
56
|
-
"placeholder": "pgn_live_..."
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
],
|
|
61
|
-
"remotes": [
|
|
62
|
-
{
|
|
63
|
-
"type": "streamable-http",
|
|
64
|
-
"url": "https://pidgeon.ai/api/mcp",
|
|
65
|
-
"headers": [
|
|
66
|
-
{
|
|
67
|
-
"name": "Authorization",
|
|
68
|
-
"description": "Your Pidgeon API key as a bearer token",
|
|
69
|
-
"isRequired": true,
|
|
70
|
-
"isSecret": true,
|
|
71
|
-
"value": "Bearer {pidgeon_api_key}",
|
|
72
|
-
"variables": {
|
|
73
|
-
"pidgeon_api_key": {
|
|
74
|
-
"description": "Your Pidgeon API key (pgn_live_…)",
|
|
75
|
-
"isRequired": true,
|
|
76
|
-
"isSecret": true,
|
|
77
|
-
"placeholder": "pgn_live_..."
|
|
78
|
-
}
|
|
79
|
-
}
|
|
22
|
+
"description": "An API key, instead of signing in with the browser.",
|
|
23
|
+
"isRequired": false,
|
|
24
|
+
"isSecret": true
|
|
80
25
|
}
|
|
81
26
|
]
|
|
82
27
|
}
|
package/dist/chunk-67QGOBKE.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// src/clients.ts
|
|
4
|
-
import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
5
|
-
import { dirname, join, resolve } from "path";
|
|
6
|
-
import { applyEdits, modify, parse } from "jsonc-parser";
|
|
7
|
-
import { parse as parseToml } from "smol-toml";
|
|
8
|
-
var CLIENTS = ["codex", "vscode", "gemini"];
|
|
9
|
-
var SERVER_NAME = "pidgeon";
|
|
10
|
-
var KEY_VARIABLE = "PIDGEON_API_KEY";
|
|
11
|
-
var VSCODE_INPUT = {
|
|
12
|
-
type: "promptString",
|
|
13
|
-
id: "pidgeon-key",
|
|
14
|
-
description: "Pidgeon API key",
|
|
15
|
-
password: true
|
|
16
|
-
};
|
|
17
|
-
var CODEX_TOOL_TIMEOUT_SEC = 300;
|
|
18
|
-
var CLIENT_NAMES = {
|
|
19
|
-
codex: "Codex",
|
|
20
|
-
vscode: "VS Code",
|
|
21
|
-
gemini: "Gemini CLI"
|
|
22
|
-
};
|
|
23
|
-
function defaultScope(client) {
|
|
24
|
-
return client === "codex" ? "user" : "project";
|
|
25
|
-
}
|
|
26
|
-
function configPath(client, scope, where) {
|
|
27
|
-
const { cwd, home, platform, env } = where;
|
|
28
|
-
if (client === "codex") {
|
|
29
|
-
if (scope === "project") return resolve(cwd, ".codex", "config.toml");
|
|
30
|
-
return join(env.CODEX_HOME || join(home, ".codex"), "config.toml");
|
|
31
|
-
}
|
|
32
|
-
if (client === "gemini") {
|
|
33
|
-
return scope === "project" ? resolve(cwd, ".gemini", "settings.json") : join(home, ".gemini", "settings.json");
|
|
34
|
-
}
|
|
35
|
-
if (scope === "project") return resolve(cwd, ".vscode", "mcp.json");
|
|
36
|
-
if (platform === "darwin")
|
|
37
|
-
return join(home, "Library", "Application Support", "Code", "User", "mcp.json");
|
|
38
|
-
if (platform === "win32") {
|
|
39
|
-
return join(env.APPDATA || join(home, "AppData", "Roaming"), "Code", "User", "mcp.json");
|
|
40
|
-
}
|
|
41
|
-
return join(env.XDG_CONFIG_HOME || join(home, ".config"), "Code", "User", "mcp.json");
|
|
42
|
-
}
|
|
43
|
-
function entry(client, mcpUrl, withKey) {
|
|
44
|
-
if (client === "codex") {
|
|
45
|
-
return withKey ? {
|
|
46
|
-
url: mcpUrl,
|
|
47
|
-
bearer_token_env_var: KEY_VARIABLE,
|
|
48
|
-
tool_timeout_sec: CODEX_TOOL_TIMEOUT_SEC
|
|
49
|
-
} : { url: mcpUrl, tool_timeout_sec: CODEX_TOOL_TIMEOUT_SEC };
|
|
50
|
-
}
|
|
51
|
-
if (client === "gemini") {
|
|
52
|
-
return withKey ? { httpUrl: mcpUrl, headers: { Authorization: `Bearer \${${KEY_VARIABLE}}` } } : { httpUrl: mcpUrl };
|
|
53
|
-
}
|
|
54
|
-
return withKey ? {
|
|
55
|
-
type: "http",
|
|
56
|
-
url: mcpUrl,
|
|
57
|
-
headers: { Authorization: `Bearer \${input:${VSCODE_INPUT.id}}` }
|
|
58
|
-
} : { type: "http", url: mcpUrl };
|
|
59
|
-
}
|
|
60
|
-
function nextSteps(client, withKey) {
|
|
61
|
-
if (withKey) {
|
|
62
|
-
if (client === "codex") {
|
|
63
|
-
return [
|
|
64
|
-
`Codex reads the key from ${KEY_VARIABLE}, so keep it in the environment Codex starts in.`
|
|
65
|
-
];
|
|
66
|
-
}
|
|
67
|
-
if (client === "gemini") {
|
|
68
|
-
return [`Gemini CLI reads the key from ${KEY_VARIABLE} when it loads its settings.`];
|
|
69
|
-
}
|
|
70
|
-
return [
|
|
71
|
-
"VS Code asks for the key the first time the server starts, and keeps it in its secret storage."
|
|
72
|
-
];
|
|
73
|
-
}
|
|
74
|
-
if (client === "codex") return ["Sign in:", " codex mcp login pidgeon"];
|
|
75
|
-
if (client === "gemini") return ["Sign in, inside Gemini CLI:", " /mcp auth pidgeon"];
|
|
76
|
-
return ["When the server first starts, VS Code sends you to Pidgeon to sign in."];
|
|
77
|
-
}
|
|
78
|
-
function edit(client, path, current, block, force) {
|
|
79
|
-
return client === "codex" ? editToml(path, current, block, force) : editJson(client, path, current, block, force);
|
|
80
|
-
}
|
|
81
|
-
function writeClientConfig(client, path, block, force) {
|
|
82
|
-
let current = null;
|
|
83
|
-
try {
|
|
84
|
-
current = readFileSync(path, "utf8");
|
|
85
|
-
} catch (error) {
|
|
86
|
-
if (error.code !== "ENOENT") {
|
|
87
|
-
return { ok: false, message: `${path} could not be read, so nothing was written.` };
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const result = edit(client, path, current, block, force);
|
|
91
|
-
if (!result.ok) return result;
|
|
92
|
-
if (result.text === current) return { ok: true, changed: false, backup: null, text: result.text };
|
|
93
|
-
let backup = null;
|
|
94
|
-
if (current !== null) {
|
|
95
|
-
backup = `${path}.bak`;
|
|
96
|
-
copyFileSync(path, backup);
|
|
97
|
-
}
|
|
98
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
99
|
-
writeFileSync(path, result.text);
|
|
100
|
-
return { ok: true, changed: true, backup, text: result.text };
|
|
101
|
-
}
|
|
102
|
-
function differs(path) {
|
|
103
|
-
return `${path} already has a different "${SERVER_NAME}" server, so nothing was written.
|
|
104
|
-
Run again with --force to replace it, or edit the file by hand.`;
|
|
105
|
-
}
|
|
106
|
-
function same(a, b) {
|
|
107
|
-
if (a === b) return true;
|
|
108
|
-
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
109
|
-
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
110
|
-
const keysA = Object.keys(a);
|
|
111
|
-
const keysB = Object.keys(b);
|
|
112
|
-
if (keysA.length !== keysB.length) return false;
|
|
113
|
-
return keysA.every(
|
|
114
|
-
(key) => same(a[key], b[key])
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
function editJson(client, path, current, block, force) {
|
|
118
|
-
const text = current ?? "{}";
|
|
119
|
-
const errors = [];
|
|
120
|
-
const parsed = parse(text, errors, {
|
|
121
|
-
allowTrailingComma: true,
|
|
122
|
-
disallowComments: false
|
|
123
|
-
});
|
|
124
|
-
if (errors.length > 0 || typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
125
|
-
return { ok: false, message: `${path} exists and is not valid JSON, so nothing was written.` };
|
|
126
|
-
}
|
|
127
|
-
const root = parsed;
|
|
128
|
-
const key = client === "vscode" ? "servers" : "mcpServers";
|
|
129
|
-
const servers = root[key];
|
|
130
|
-
if (servers !== void 0 && (typeof servers !== "object" || servers === null || Array.isArray(servers))) {
|
|
131
|
-
return { ok: false, message: `"${key}" in ${path} is not an object, so nothing was written.` };
|
|
132
|
-
}
|
|
133
|
-
const existing = servers?.[SERVER_NAME];
|
|
134
|
-
if (existing !== void 0 && !same(existing, block) && !force) {
|
|
135
|
-
return { ok: false, message: differs(path) };
|
|
136
|
-
}
|
|
137
|
-
const formatting = formattingOf(text);
|
|
138
|
-
let next = text;
|
|
139
|
-
if (!same(existing, block)) {
|
|
140
|
-
next = applyEdits(
|
|
141
|
-
next,
|
|
142
|
-
modify(next, [key, SERVER_NAME], block, { formattingOptions: formatting })
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
if (client === "vscode" && JSON.stringify(block).includes("${input:")) {
|
|
146
|
-
const inputs = root.inputs;
|
|
147
|
-
if (inputs !== void 0 && !Array.isArray(inputs)) {
|
|
148
|
-
return { ok: false, message: `"inputs" in ${path} is not a list, so nothing was written.` };
|
|
149
|
-
}
|
|
150
|
-
const at = (inputs ?? []).findIndex(
|
|
151
|
-
(input) => input?.id === VSCODE_INPUT.id
|
|
152
|
-
);
|
|
153
|
-
if (at === -1) {
|
|
154
|
-
next = applyEdits(
|
|
155
|
-
next,
|
|
156
|
-
modify(next, ["inputs", -1], VSCODE_INPUT, {
|
|
157
|
-
formattingOptions: formatting,
|
|
158
|
-
isArrayInsertion: true
|
|
159
|
-
})
|
|
160
|
-
);
|
|
161
|
-
} else if (!same(inputs[at], VSCODE_INPUT)) {
|
|
162
|
-
if (!force) return { ok: false, message: differs(path) };
|
|
163
|
-
next = applyEdits(
|
|
164
|
-
next,
|
|
165
|
-
modify(next, ["inputs", at], VSCODE_INPUT, { formattingOptions: formatting })
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (current === null) next = `${next.trimEnd()}
|
|
170
|
-
`;
|
|
171
|
-
return { ok: true, text: next };
|
|
172
|
-
}
|
|
173
|
-
function formattingOf(text) {
|
|
174
|
-
const indent = /\n([ \t]+)\S/.exec(text)?.[1];
|
|
175
|
-
if (indent?.startsWith(" ")) return { insertSpaces: false, tabSize: 1, eol: "\n" };
|
|
176
|
-
return {
|
|
177
|
-
insertSpaces: true,
|
|
178
|
-
tabSize: indent ? indent.length : 2,
|
|
179
|
-
eol: text.includes("\r\n") ? "\r\n" : "\n"
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
var OUR_TABLE = /^\s*\[\s*mcp_servers\s*\.\s*(?:pidgeon|"pidgeon"|'pidgeon')\s*(?:\.[^\]]*)?\]\s*(?:#.*)?$/;
|
|
183
|
-
var ANY_TABLE = /^\s*\[/;
|
|
184
|
-
function editToml(path, current, block, force) {
|
|
185
|
-
const text = current ?? "";
|
|
186
|
-
let before;
|
|
187
|
-
try {
|
|
188
|
-
before = parseToml(text);
|
|
189
|
-
} catch {
|
|
190
|
-
return { ok: false, message: `${path} exists and is not valid TOML, so nothing was written.` };
|
|
191
|
-
}
|
|
192
|
-
const servers = before.mcp_servers;
|
|
193
|
-
const existing = servers?.[SERVER_NAME];
|
|
194
|
-
if (existing !== void 0 && same(existing, block)) return { ok: true, text };
|
|
195
|
-
if (existing !== void 0 && !force) return { ok: false, message: differs(path) };
|
|
196
|
-
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
197
|
-
const table = [
|
|
198
|
-
`[mcp_servers.${SERVER_NAME}]`,
|
|
199
|
-
...Object.entries(block).map(([k, v]) => `${k} = ${tomlValue(v)}`)
|
|
200
|
-
];
|
|
201
|
-
let next;
|
|
202
|
-
if (existing === void 0) {
|
|
203
|
-
const body = text.replace(/\s*$/, "");
|
|
204
|
-
next = `${body}${body ? `${eol}${eol}` : ""}${table.join(eol)}${eol}`;
|
|
205
|
-
} else {
|
|
206
|
-
const lines = text.split(/\r?\n/);
|
|
207
|
-
const start = lines.findIndex((line) => OUR_TABLE.test(line));
|
|
208
|
-
if (start === -1) {
|
|
209
|
-
return {
|
|
210
|
-
ok: false,
|
|
211
|
-
message: `${path} defines "${SERVER_NAME}" in a form this cannot edit safely, so nothing was written.`
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
let end = start + 1;
|
|
215
|
-
while (end < lines.length && (!ANY_TABLE.test(lines[end]) || OUR_TABLE.test(lines[end])))
|
|
216
|
-
end += 1;
|
|
217
|
-
let keep = end;
|
|
218
|
-
while (keep > start + 1 && lines[keep - 1].trim() === "") keep -= 1;
|
|
219
|
-
next = [...lines.slice(0, start), ...table, ...lines.slice(keep)].join(eol);
|
|
220
|
-
if (!next.endsWith(eol)) next = `${next}${eol}`;
|
|
221
|
-
}
|
|
222
|
-
let after;
|
|
223
|
-
try {
|
|
224
|
-
after = parseToml(next);
|
|
225
|
-
} catch {
|
|
226
|
-
return { ok: false, message: `Editing ${path} would have broken it, so nothing was written.` };
|
|
227
|
-
}
|
|
228
|
-
const expected = {
|
|
229
|
-
...before,
|
|
230
|
-
mcp_servers: { ...servers ?? {}, [SERVER_NAME]: block }
|
|
231
|
-
};
|
|
232
|
-
if (!same(after, expected)) {
|
|
233
|
-
return {
|
|
234
|
-
ok: false,
|
|
235
|
-
message: `${path} is laid out in a way this cannot edit safely, so nothing was written.`
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
return { ok: true, text: next };
|
|
239
|
-
}
|
|
240
|
-
function tomlValue(value) {
|
|
241
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
242
|
-
return JSON.stringify(String(value));
|
|
243
|
-
}
|
|
244
|
-
function render(client, block) {
|
|
245
|
-
if (client === "codex") {
|
|
246
|
-
return [
|
|
247
|
-
`[mcp_servers.${SERVER_NAME}]`,
|
|
248
|
-
...Object.entries(block).map(([k, v]) => `${k} = ${tomlValue(v)}`)
|
|
249
|
-
].join("\n");
|
|
250
|
-
}
|
|
251
|
-
const withKey = JSON.stringify(block).includes("${input:");
|
|
252
|
-
const shape = client === "vscode" ? { ...withKey ? { inputs: [VSCODE_INPUT] } : {}, servers: { [SERVER_NAME]: block } } : { mcpServers: { [SERVER_NAME]: block } };
|
|
253
|
-
return JSON.stringify(shape, null, 2);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export {
|
|
257
|
-
CLIENTS,
|
|
258
|
-
CLIENT_NAMES,
|
|
259
|
-
defaultScope,
|
|
260
|
-
configPath,
|
|
261
|
-
entry,
|
|
262
|
-
nextSteps,
|
|
263
|
-
edit,
|
|
264
|
-
writeClientConfig,
|
|
265
|
-
render
|
|
266
|
-
};
|
|
267
|
-
//# sourceMappingURL=chunk-67QGOBKE.js.map
|