@pidgeon-ai/mcp 0.1.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 +70 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +230 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @pidgeon-ai/mcp
|
|
2
|
+
|
|
3
|
+
Pidgeon as a [Model Context Protocol](https://modelcontextprotocol.io) server:
|
|
4
|
+
a real mailbox your agent can read, answer and create addresses in.
|
|
5
|
+
|
|
6
|
+
## The credential is the whole of the access control
|
|
7
|
+
|
|
8
|
+
This hands an API key to a model. Nothing in this package decides what may be
|
|
9
|
+
reached — the key's own ceiling and the addresses it was granted do all of it,
|
|
10
|
+
server-side, exactly as for any other caller.
|
|
11
|
+
|
|
12
|
+
So **give it the narrowest key the agent needs**. A key created with `read`
|
|
13
|
+
access can never send, however generously it is granted a mailbox, and an
|
|
14
|
+
agent that only has to triage should have one.
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
PIDGEON_API_KEY=pgn_live_… npx @pidgeon-ai/mcp
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Claude Desktop, or any other MCP client:
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"mcpServers": {
|
|
25
|
+
"pidgeon": {
|
|
26
|
+
"command": "npx",
|
|
27
|
+
"args": ["-y", "@pidgeon-ai/mcp"],
|
|
28
|
+
"env": { "PIDGEON_API_KEY": "pgn_live_…" }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`PIDGEON_BASE_URL` points it somewhere else, which is how you run it against a
|
|
35
|
+
local checkout.
|
|
36
|
+
|
|
37
|
+
## Tools
|
|
38
|
+
|
|
39
|
+
| Tool | What it does |
|
|
40
|
+
| ----------------- | ----------------------------------------------------------- |
|
|
41
|
+
| `list_addresses` | The addresses the key can reach; filter by `tenant_id` |
|
|
42
|
+
| `create_address` | A new address, optionally `reply_only` and with an end date |
|
|
43
|
+
| `get_address` | One address, its capabilities and its send policy |
|
|
44
|
+
| `list_threads` | Conversations in one address |
|
|
45
|
+
| `get_thread` | One conversation, by the `thread_id` a webhook gave you |
|
|
46
|
+
| `list_messages` | The messages of a conversation |
|
|
47
|
+
| `search_messages` | Full-text within one mailbox |
|
|
48
|
+
| `send_message` | Send, subject to the address's send policy |
|
|
49
|
+
| `list_send_rules` | Why a send was refused |
|
|
50
|
+
|
|
51
|
+
## Two settings worth knowing about
|
|
52
|
+
|
|
53
|
+
An agent's address should usually be created **`reply_only`**: it can answer
|
|
54
|
+
anybody who has written to it and start a conversation with nobody, which is a
|
|
55
|
+
structural limit rather than a quantity. `create_address` takes it.
|
|
56
|
+
|
|
57
|
+
It can also be given an **end date**. An address per ticket or per invoice
|
|
58
|
+
stops accepting mail when the thing is over; expiry suspends the address and
|
|
59
|
+
keeps the correspondence.
|
|
60
|
+
|
|
61
|
+
## What this is not
|
|
62
|
+
|
|
63
|
+
A protocol adapter over an API that already exists, and nothing else. No
|
|
64
|
+
business logic, no database, no model, no state.
|
|
65
|
+
|
|
66
|
+
Every tool **is** an endpoint: the dispatcher works off the endpoint each tool
|
|
67
|
+
declares rather than off its name, so there is nowhere to put behaviour the
|
|
68
|
+
API does not have, and a test asserts each one exists in the published
|
|
69
|
+
OpenAPI document. If something is missing here, it is missing from the API,
|
|
70
|
+
and that is where it gets built.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The tools this server offers, and the endpoint each one is.
|
|
6
|
+
*
|
|
7
|
+
* **This is an adapter, and this file is where that stays true.** Every tool
|
|
8
|
+
* names the `METHOD /path` it calls, and `tests/unit/mcp-adapter.test.ts`
|
|
9
|
+
* asserts that pair exists in `public/openapi.json`. So a tool cannot be
|
|
10
|
+
* added for behaviour the API does not have — if one needs logic that is not
|
|
11
|
+
* an endpoint, **the API is missing it**, and it gets built there.
|
|
12
|
+
*
|
|
13
|
+
* That constraint is the whole reason this package is allowed to exist.
|
|
14
|
+
* `architecture.md` §7 put MCP on the do-not-build list when this product was
|
|
15
|
+
* email hosting, and the premise changed rather than the judgement: what is
|
|
16
|
+
* sold now is a programmable mailbox, and the buyer is somebody building an
|
|
17
|
+
* agent. A protocol adapter over an API already at parity is thin. An agent
|
|
18
|
+
* runtime is not, and this file is what keeps the second from growing out of
|
|
19
|
+
* the first. `decisions.md` §153.
|
|
20
|
+
*/
|
|
21
|
+
interface ToolDefinition {
|
|
22
|
+
name: string;
|
|
23
|
+
title: string;
|
|
24
|
+
description: string;
|
|
25
|
+
/** The endpoint this tool *is*. Checked against the published contract. */
|
|
26
|
+
endpoint: `${'GET' | 'POST' | 'PATCH' | 'DELETE'} ${string}`;
|
|
27
|
+
inputSchema: z.ZodRawShape;
|
|
28
|
+
/** Whether it changes anything. MCP clients surface this before confirming. */
|
|
29
|
+
readOnly: boolean;
|
|
30
|
+
}
|
|
31
|
+
declare const TOOLS: ToolDefinition[];
|
|
32
|
+
|
|
33
|
+
declare function createServer(context: {
|
|
34
|
+
baseUrl: string;
|
|
35
|
+
apiKey: string;
|
|
36
|
+
}): McpServer;
|
|
37
|
+
declare function main(): Promise<void>;
|
|
38
|
+
|
|
39
|
+
export { TOOLS, type ToolDefinition, createServer, main };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
|
|
7
|
+
// src/call.ts
|
|
8
|
+
var PidgeonHttpError = class extends Error {
|
|
9
|
+
status;
|
|
10
|
+
code;
|
|
11
|
+
constructor(message, status, code) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "PidgeonHttpError";
|
|
14
|
+
this.status = status;
|
|
15
|
+
this.code = code;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var PATH_PARAM = /\{([^}]+)\}/g;
|
|
19
|
+
async function callEndpoint(tool, input, context) {
|
|
20
|
+
const [method, template] = splitEndpoint(tool.endpoint);
|
|
21
|
+
const remaining = { ...input };
|
|
22
|
+
const path = template.replace(PATH_PARAM, (_match, name) => {
|
|
23
|
+
const value = remaining[name];
|
|
24
|
+
if (value === void 0 || value === null || value === "") {
|
|
25
|
+
throw new PidgeonHttpError(`\`${name}\` is required.`, 400, "validation");
|
|
26
|
+
}
|
|
27
|
+
delete remaining[name];
|
|
28
|
+
return encodeURIComponent(String(value));
|
|
29
|
+
});
|
|
30
|
+
const url = new URL(`${context.baseUrl}${path}`);
|
|
31
|
+
const sendsBody = method === "POST" || method === "PATCH";
|
|
32
|
+
if (!sendsBody) {
|
|
33
|
+
for (const [key, value] of Object.entries(remaining)) {
|
|
34
|
+
if (value !== void 0 && value !== null) url.searchParams.set(key, String(value));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const doFetch = context.fetch ?? globalThis.fetch;
|
|
38
|
+
const response = await doFetch(url, {
|
|
39
|
+
method,
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: `Bearer ${context.apiKey}`,
|
|
42
|
+
...sendsBody ? { "Content-Type": "application/json" } : {}
|
|
43
|
+
},
|
|
44
|
+
body: sendsBody ? JSON.stringify(remaining) : void 0
|
|
45
|
+
});
|
|
46
|
+
const payload = await response.json().catch(() => null);
|
|
47
|
+
if (!response.ok || payload?.error) {
|
|
48
|
+
throw new PidgeonHttpError(
|
|
49
|
+
payload?.error?.message ?? `Request failed with ${response.status}.`,
|
|
50
|
+
response.status,
|
|
51
|
+
payload?.error?.code ?? "internal"
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return payload?.data ?? payload;
|
|
55
|
+
}
|
|
56
|
+
function splitEndpoint(endpoint) {
|
|
57
|
+
const space = endpoint.indexOf(" ");
|
|
58
|
+
return [endpoint.slice(0, space), endpoint.slice(space + 1)];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/tools.ts
|
|
62
|
+
import { z } from "zod";
|
|
63
|
+
var TOOLS = [
|
|
64
|
+
{
|
|
65
|
+
name: "list_addresses",
|
|
66
|
+
title: "List addresses",
|
|
67
|
+
description: "The addresses this credential can reach. Use `tenant_id` to list the addresses belonging to one of your own customers.",
|
|
68
|
+
endpoint: "GET /identities",
|
|
69
|
+
readOnly: true,
|
|
70
|
+
inputSchema: {
|
|
71
|
+
limit: z.number().int().min(1).max(200).optional(),
|
|
72
|
+
cursor: z.string().optional(),
|
|
73
|
+
tenant_id: z.string().optional()
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "create_address",
|
|
78
|
+
title: "Create an address",
|
|
79
|
+
description: 'Create an address your software owns. `send_policy: "reply_only"` makes it unable to write to anybody who has not written to it first, which is the right default for an agent. `expires_at` gives it an end date, after which it stops accepting mail.',
|
|
80
|
+
endpoint: "POST /identities",
|
|
81
|
+
readOnly: false,
|
|
82
|
+
inputSchema: {
|
|
83
|
+
domain_id: z.string(),
|
|
84
|
+
local_part: z.string(),
|
|
85
|
+
display_name: z.string().nullish(),
|
|
86
|
+
type: z.enum(["human", "team", "application", "workflow", "agent"]).optional(),
|
|
87
|
+
send_policy: z.enum(["open", "reply_only", "list"]).optional(),
|
|
88
|
+
expires_at: z.string().optional(),
|
|
89
|
+
tenant_id: z.string().optional()
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "get_address",
|
|
94
|
+
title: "Read one address",
|
|
95
|
+
description: "One address, by id. Answers its type, its capabilities, its send policy and its end date, which is how to check what an address is allowed to do before using it.",
|
|
96
|
+
endpoint: "GET /identities/{id}",
|
|
97
|
+
readOnly: true,
|
|
98
|
+
inputSchema: { id: z.string() }
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "list_threads",
|
|
102
|
+
title: "List conversations",
|
|
103
|
+
description: "Conversations in one address, newest first. Filter by `status` for the queue an agent should be working, or by `assignee_id` for what one person has taken.",
|
|
104
|
+
endpoint: "GET /threads",
|
|
105
|
+
readOnly: true,
|
|
106
|
+
inputSchema: {
|
|
107
|
+
identity_id: z.string(),
|
|
108
|
+
limit: z.number().int().min(1).max(200).optional(),
|
|
109
|
+
cursor: z.string().optional()
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "get_thread",
|
|
114
|
+
title: "Read a conversation",
|
|
115
|
+
description: "One conversation, by id. Every webhook payload carries a `thread_id`, so this is how a handler turns an event into the conversation it is about.",
|
|
116
|
+
endpoint: "GET /threads/{id}",
|
|
117
|
+
readOnly: true,
|
|
118
|
+
inputSchema: { id: z.string() }
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "list_messages",
|
|
122
|
+
title: "List messages in a conversation",
|
|
123
|
+
description: "The messages of one conversation, oldest first \u2014 the text to read before replying. Bodies are here; attachments are metadata only.",
|
|
124
|
+
endpoint: "GET /messages",
|
|
125
|
+
readOnly: true,
|
|
126
|
+
inputSchema: {
|
|
127
|
+
thread_id: z.string(),
|
|
128
|
+
limit: z.number().int().min(1).max(200).optional(),
|
|
129
|
+
cursor: z.string().optional()
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "search_messages",
|
|
134
|
+
title: "Search one mailbox",
|
|
135
|
+
description: "Full-text search within a single address, ranked by relevance. One mailbox at a time, because searching across addresses somebody cannot all read is not a thing to offer.",
|
|
136
|
+
endpoint: "GET /messages/search",
|
|
137
|
+
readOnly: true,
|
|
138
|
+
inputSchema: {
|
|
139
|
+
identity_id: z.string(),
|
|
140
|
+
q: z.string(),
|
|
141
|
+
limit: z.number().int().min(1).max(200).optional()
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "send_message",
|
|
146
|
+
title: "Send a message",
|
|
147
|
+
description: "Send from an address this credential may send as. Refused if the address\u2019s send policy does not permit the recipient, or if the recipient previously bounced or reported mail as spam.",
|
|
148
|
+
endpoint: "POST /messages",
|
|
149
|
+
readOnly: false,
|
|
150
|
+
inputSchema: {
|
|
151
|
+
identity_id: z.string(),
|
|
152
|
+
to: z.union([z.string(), z.array(z.string())]),
|
|
153
|
+
cc: z.union([z.string(), z.array(z.string())]).optional(),
|
|
154
|
+
subject: z.string().optional(),
|
|
155
|
+
text: z.string().optional(),
|
|
156
|
+
html: z.string().optional(),
|
|
157
|
+
thread_id: z.string().optional(),
|
|
158
|
+
in_reply_to: z.string().optional()
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: "list_send_rules",
|
|
163
|
+
title: "What an address may write to",
|
|
164
|
+
description: "The allow and block list of one address, and the send policy it hangs off. Read this when a send was refused.",
|
|
165
|
+
endpoint: "GET /identities/{id}/send-rules",
|
|
166
|
+
readOnly: true,
|
|
167
|
+
inputSchema: { id: z.string() }
|
|
168
|
+
}
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
// src/index.ts
|
|
172
|
+
var DEFAULT_BASE_URL = "https://pidgeon.ai/api/v1";
|
|
173
|
+
function createServer(context) {
|
|
174
|
+
const server = new McpServer({ name: "pidgeon", version: "0.1.0" });
|
|
175
|
+
for (const tool of TOOLS) {
|
|
176
|
+
server.registerTool(
|
|
177
|
+
tool.name,
|
|
178
|
+
{
|
|
179
|
+
title: tool.title,
|
|
180
|
+
description: tool.description,
|
|
181
|
+
inputSchema: tool.inputSchema,
|
|
182
|
+
annotations: {
|
|
183
|
+
readOnlyHint: tool.readOnly,
|
|
184
|
+
/*
|
|
185
|
+
* Sending mail is not undoable and reaches somebody who did not ask
|
|
186
|
+
* to be part of this. A client that asks before a destructive call
|
|
187
|
+
* should be asking before that one.
|
|
188
|
+
*/
|
|
189
|
+
destructiveHint: !tool.readOnly,
|
|
190
|
+
openWorldHint: true
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
async (input) => {
|
|
194
|
+
try {
|
|
195
|
+
const result = await callEndpoint(tool, input, context);
|
|
196
|
+
return {
|
|
197
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
198
|
+
};
|
|
199
|
+
} catch (error) {
|
|
200
|
+
const message = error instanceof PidgeonHttpError ? `${error.code}: ${error.message}` : error instanceof Error ? error.message : "The request failed.";
|
|
201
|
+
return { isError: true, content: [{ type: "text", text: message }] };
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return server;
|
|
207
|
+
}
|
|
208
|
+
async function main() {
|
|
209
|
+
const apiKey = process.env.PIDGEON_API_KEY;
|
|
210
|
+
if (!apiKey) {
|
|
211
|
+
process.stderr.write(
|
|
212
|
+
"PIDGEON_API_KEY is not set. Create a key at https://pidgeon.ai/app/developers/keys \u2014 and give it the narrowest access the agent needs, because this hands it to a model.\n"
|
|
213
|
+
);
|
|
214
|
+
process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
const server = createServer({
|
|
217
|
+
baseUrl: process.env.PIDGEON_BASE_URL ?? DEFAULT_BASE_URL,
|
|
218
|
+
apiKey
|
|
219
|
+
});
|
|
220
|
+
await server.connect(new StdioServerTransport());
|
|
221
|
+
}
|
|
222
|
+
if (process.env.PIDGEON_MCP_NO_MAIN !== "1") {
|
|
223
|
+
void main();
|
|
224
|
+
}
|
|
225
|
+
export {
|
|
226
|
+
TOOLS,
|
|
227
|
+
createServer,
|
|
228
|
+
main
|
|
229
|
+
};
|
|
230
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/call.ts","../src/tools.ts"],"sourcesContent":["import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\n\nimport { callEndpoint, PidgeonHttpError } from './call.js';\nimport { TOOLS } from './tools.js';\n\n/**\n * Pidgeon, as a Model Context Protocol server.\n *\n * A **protocol adapter over an API already at parity**, and nothing else. No\n * business logic, no database, no LLM, no state of its own. Every tool is an\n * endpoint — `call.ts` dispatches on the endpoint the tool declares rather\n * than on its name, so there is nowhere to put behaviour the API does not\n * have. `tests/unit/mcp-adapter.test.ts` holds the other half: every declared\n * endpoint exists in `public/openapi.json`.\n *\n * `architecture.md` §7 listed MCP as deliberately absent, beside \"no LLM, no\n * RAG, no agent runtime\". That entry was written when this product was email\n * hosting; what it sells now is a programmable mailbox, and the person who\n * wants one is building an agent. The premise changed rather than the\n * judgement — an agent runtime is still not being built, and the constraints\n * above are what keep this from becoming one. `decisions.md` §154.\n *\n * ## Authorization is the key, and only the key\n *\n * The credential comes from `PIDGEON_API_KEY` and every call carries it.\n * Nothing here decides what may be reached: the key's own ceiling and the\n * addresses it was granted do all of it, server-side, exactly as they do for\n * any other caller.\n *\n * That matters more here than anywhere else, because this is the single most\n * likely place for a broad credential to be handed to a model. A key created\n * with `access: 'read'` can be given to an agent that must never send, and\n * `decisions.md` §143 is why that holds however generously the key is\n * granted. The README says so in the first paragraph.\n */\n\nconst DEFAULT_BASE_URL = 'https://pidgeon.ai/api/v1';\n\nexport function createServer(context: { baseUrl: string; apiKey: string }): McpServer {\n const server = new McpServer({ name: 'pidgeon', version: '0.1.0' });\n\n for (const tool of TOOLS) {\n server.registerTool(\n tool.name,\n {\n title: tool.title,\n description: tool.description,\n inputSchema: tool.inputSchema,\n annotations: {\n readOnlyHint: tool.readOnly,\n /*\n * Sending mail is not undoable and reaches somebody who did not ask\n * to be part of this. A client that asks before a destructive call\n * should be asking before that one.\n */\n destructiveHint: !tool.readOnly,\n openWorldHint: true,\n },\n },\n async (input: Record<string, unknown>) => {\n try {\n const result = await callEndpoint(tool, input, context);\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }],\n };\n } catch (error) {\n /*\n * Reported as a tool error rather than thrown, which is what lets a\n * model read the reason and act on it — \"that address can only\n * reply to people who have written to it\" is a sentence it can do\n * something about, where a transport-level failure is not.\n */\n const message =\n error instanceof PidgeonHttpError\n ? `${error.code}: ${error.message}`\n : error instanceof Error\n ? error.message\n : 'The request failed.';\n\n return { isError: true, content: [{ type: 'text' as const, text: message }] };\n }\n },\n );\n }\n\n return server;\n}\n\nexport async function main(): Promise<void> {\n const apiKey = process.env.PIDGEON_API_KEY;\n\n if (!apiKey) {\n /*\n * To stderr and a non-zero exit. stdout is the protocol channel on a\n * stdio server, so a message written there is a parse error at the other\n * end rather than something a person reads.\n */\n process.stderr.write(\n 'PIDGEON_API_KEY is not set. Create a key at https://pidgeon.ai/app/developers/keys — ' +\n 'and give it the narrowest access the agent needs, because this hands it to a model.\\n',\n );\n process.exit(1);\n }\n\n const server = createServer({\n baseUrl: process.env.PIDGEON_BASE_URL ?? DEFAULT_BASE_URL,\n apiKey,\n });\n\n await server.connect(new StdioServerTransport());\n}\n\nexport { TOOLS } from './tools.js';\nexport type { ToolDefinition } from './tools.js';\n\n/*\n * Run when executed, not when imported — the tests import `createServer` and\n * must not open a transport on stdio while doing it.\n */\nif (process.env.PIDGEON_MCP_NO_MAIN !== '1') {\n void main();\n}\n","import type { ToolDefinition } from './tools.js';\n\n/**\n * Calling the endpoint a tool declares.\n *\n * **The tool's `endpoint` is its implementation**, not a label beside one.\n * That is deliberate and it is what makes \"this package is an adapter\" a\n * structural fact rather than a promise: there is no place to put behaviour\n * the API does not have, because nothing here dispatches on the tool's name.\n *\n * Path parameters come out of the input by name, and what is left becomes the\n * query string on a `GET` or `DELETE` and the body on a `POST` or `PATCH`.\n * The API's own schemas then validate it — this does not re-declare their\n * rules, because two copies of a validation rule is one copy that is wrong.\n *\n * It does not use `@pidgeon-ai/sdk` at runtime, only its types. The SDK is a\n * thin wrapper over the same requests, and going through it would add a layer\n * whose only job is to be a second place a path can be spelled wrong.\n */\n\nexport interface CallContext {\n baseUrl: string;\n apiKey: string;\n fetch?: typeof globalThis.fetch;\n}\n\nexport class PidgeonHttpError extends Error {\n readonly status: number;\n readonly code: string;\n\n constructor(message: string, status: number, code: string) {\n super(message);\n this.name = 'PidgeonHttpError';\n this.status = status;\n this.code = code;\n }\n}\n\nconst PATH_PARAM = /\\{([^}]+)\\}/g;\n\nexport async function callEndpoint(\n tool: ToolDefinition,\n input: Record<string, unknown>,\n context: CallContext,\n): Promise<unknown> {\n const [method, template] = splitEndpoint(tool.endpoint);\n\n const remaining = { ...input };\n\n /*\n * `{id}` is filled from the input and removed from it, so it cannot also\n * arrive as a query parameter — where the API would reject it as an unknown\n * field, since every request schema here is `.strict()`.\n */\n const path = template.replace(PATH_PARAM, (_match, name: string) => {\n const value = remaining[name];\n\n if (value === undefined || value === null || value === '') {\n throw new PidgeonHttpError(`\\`${name}\\` is required.`, 400, 'validation');\n }\n\n delete remaining[name];\n return encodeURIComponent(String(value));\n });\n\n const url = new URL(`${context.baseUrl}${path}`);\n const sendsBody = method === 'POST' || method === 'PATCH';\n\n if (!sendsBody) {\n for (const [key, value] of Object.entries(remaining)) {\n if (value !== undefined && value !== null) url.searchParams.set(key, String(value));\n }\n }\n\n const doFetch = context.fetch ?? globalThis.fetch;\n\n const response = await doFetch(url, {\n method,\n headers: {\n Authorization: `Bearer ${context.apiKey}`,\n ...(sendsBody ? { 'Content-Type': 'application/json' } : {}),\n },\n body: sendsBody ? JSON.stringify(remaining) : undefined,\n });\n\n const payload = (await response.json().catch(() => null)) as {\n data?: unknown;\n error?: { code: string; message: string };\n } | null;\n\n if (!response.ok || payload?.error) {\n /*\n * The API's own sentence, passed through rather than rewritten. It is\n * written for somebody debugging an integration — \"that address is on\n * this address's block list\" — and a model relaying it to a person is\n * better served by the real reason than by \"the request failed\".\n */\n throw new PidgeonHttpError(\n payload?.error?.message ?? `Request failed with ${response.status}.`,\n response.status,\n payload?.error?.code ?? 'internal',\n );\n }\n\n return payload?.data ?? payload;\n}\n\nexport function splitEndpoint(endpoint: string): [string, string] {\n const space = endpoint.indexOf(' ');\n return [endpoint.slice(0, space), endpoint.slice(space + 1)];\n}\n","import { z } from 'zod';\n\n/**\n * The tools this server offers, and the endpoint each one is.\n *\n * **This is an adapter, and this file is where that stays true.** Every tool\n * names the `METHOD /path` it calls, and `tests/unit/mcp-adapter.test.ts`\n * asserts that pair exists in `public/openapi.json`. So a tool cannot be\n * added for behaviour the API does not have — if one needs logic that is not\n * an endpoint, **the API is missing it**, and it gets built there.\n *\n * That constraint is the whole reason this package is allowed to exist.\n * `architecture.md` §7 put MCP on the do-not-build list when this product was\n * email hosting, and the premise changed rather than the judgement: what is\n * sold now is a programmable mailbox, and the buyer is somebody building an\n * agent. A protocol adapter over an API already at parity is thin. An agent\n * runtime is not, and this file is what keeps the second from growing out of\n * the first. `decisions.md` §153.\n */\n\nexport interface ToolDefinition {\n name: string;\n title: string;\n description: string;\n /** The endpoint this tool *is*. Checked against the published contract. */\n endpoint: `${'GET' | 'POST' | 'PATCH' | 'DELETE'} ${string}`;\n inputSchema: z.ZodRawShape;\n /** Whether it changes anything. MCP clients surface this before confirming. */\n readOnly: boolean;\n}\n\n/*\n * Deliberately not every endpoint.\n *\n * A tool list is a menu a model reads on every call, so length is a real\n * cost, and the ones left out are left out for reasons rather than by\n * omission: minting API keys and granting mailbox access are credential\n * operations that should be done by a person who can see what they are\n * agreeing to, and the raw attachment and export endpoints move bytes a\n * model has no use for. Anything here is something an agent doing the job\n * this product is for actually needs.\n */\nexport const TOOLS: ToolDefinition[] = [\n {\n name: 'list_addresses',\n title: 'List addresses',\n description:\n 'The addresses this credential can reach. Use `tenant_id` to list the addresses ' +\n 'belonging to one of your own customers.',\n endpoint: 'GET /identities',\n readOnly: true,\n inputSchema: {\n limit: z.number().int().min(1).max(200).optional(),\n cursor: z.string().optional(),\n tenant_id: z.string().optional(),\n },\n },\n {\n name: 'create_address',\n title: 'Create an address',\n description:\n 'Create an address your software owns. `send_policy: \"reply_only\"` makes it unable to ' +\n 'write to anybody who has not written to it first, which is the right default for an ' +\n 'agent. `expires_at` gives it an end date, after which it stops accepting mail.',\n endpoint: 'POST /identities',\n readOnly: false,\n inputSchema: {\n domain_id: z.string(),\n local_part: z.string(),\n display_name: z.string().nullish(),\n type: z.enum(['human', 'team', 'application', 'workflow', 'agent']).optional(),\n send_policy: z.enum(['open', 'reply_only', 'list']).optional(),\n expires_at: z.string().optional(),\n tenant_id: z.string().optional(),\n },\n },\n {\n name: 'get_address',\n title: 'Read one address',\n description:\n 'One address, by id. Answers its type, its capabilities, its send policy and its end ' +\n 'date, which is how to check what an address is allowed to do before using it.',\n endpoint: 'GET /identities/{id}',\n readOnly: true,\n inputSchema: { id: z.string() },\n },\n {\n name: 'list_threads',\n title: 'List conversations',\n description:\n 'Conversations in one address, newest first. Filter by `status` for the queue an agent ' +\n 'should be working, or by `assignee_id` for what one person has taken.',\n endpoint: 'GET /threads',\n readOnly: true,\n inputSchema: {\n identity_id: z.string(),\n limit: z.number().int().min(1).max(200).optional(),\n cursor: z.string().optional(),\n },\n },\n {\n name: 'get_thread',\n title: 'Read a conversation',\n description:\n 'One conversation, by id. Every webhook payload carries a `thread_id`, so this is how a ' +\n 'handler turns an event into the conversation it is about.',\n endpoint: 'GET /threads/{id}',\n readOnly: true,\n inputSchema: { id: z.string() },\n },\n {\n name: 'list_messages',\n title: 'List messages in a conversation',\n description:\n 'The messages of one conversation, oldest first — the text to read before replying. ' +\n 'Bodies are here; attachments are metadata only.',\n endpoint: 'GET /messages',\n readOnly: true,\n inputSchema: {\n thread_id: z.string(),\n limit: z.number().int().min(1).max(200).optional(),\n cursor: z.string().optional(),\n },\n },\n {\n name: 'search_messages',\n title: 'Search one mailbox',\n description:\n 'Full-text search within a single address, ranked by relevance. One mailbox at a time, ' +\n 'because searching across addresses somebody cannot all read is not a thing to offer.',\n endpoint: 'GET /messages/search',\n readOnly: true,\n inputSchema: {\n identity_id: z.string(),\n q: z.string(),\n limit: z.number().int().min(1).max(200).optional(),\n },\n },\n {\n name: 'send_message',\n title: 'Send a message',\n description:\n 'Send from an address this credential may send as. Refused if the address’s send ' +\n 'policy does not permit the recipient, or if the recipient previously bounced or ' +\n 'reported mail as spam.',\n endpoint: 'POST /messages',\n readOnly: false,\n inputSchema: {\n identity_id: z.string(),\n to: z.union([z.string(), z.array(z.string())]),\n cc: z.union([z.string(), z.array(z.string())]).optional(),\n subject: z.string().optional(),\n text: z.string().optional(),\n html: z.string().optional(),\n thread_id: z.string().optional(),\n in_reply_to: z.string().optional(),\n },\n },\n {\n name: 'list_send_rules',\n title: 'What an address may write to',\n description:\n 'The allow and block list of one address, and the send policy it hangs off. Read this ' +\n 'when a send was refused.',\n endpoint: 'GET /identities/{id}/send-rules',\n readOnly: true,\n inputSchema: { id: z.string() },\n },\n];\n"],"mappings":";;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,4BAA4B;;;ACyB9B,IAAM,mBAAN,cAA+B,MAAM;AAAA,EACjC;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,QAAgB,MAAc;AACzD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AACF;AAEA,IAAM,aAAa;AAEnB,eAAsB,aACpB,MACA,OACA,SACkB;AAClB,QAAM,CAAC,QAAQ,QAAQ,IAAI,cAAc,KAAK,QAAQ;AAEtD,QAAM,YAAY,EAAE,GAAG,MAAM;AAO7B,QAAM,OAAO,SAAS,QAAQ,YAAY,CAAC,QAAQ,SAAiB;AAClE,UAAM,QAAQ,UAAU,IAAI;AAE5B,QAAI,UAAU,UAAa,UAAU,QAAQ,UAAU,IAAI;AACzD,YAAM,IAAI,iBAAiB,KAAK,IAAI,mBAAmB,KAAK,YAAY;AAAA,IAC1E;AAEA,WAAO,UAAU,IAAI;A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AA,EACF,CAAC;AAED,QAAM,OAAO,QAAQ,IAAI,qBAAqB,CAAC;AACjD;AASA,IAAI,QAAQ,IAAI,wBAAwB,KAAK;AAC3C,OAAK,KAAK;AACZ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pidgeon-ai/mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Model Context Protocol server for Pidgeon. A protocol adapter over the API, and nothing more.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pidgeon",
|
|
7
|
+
"email",
|
|
8
|
+
"mcp",
|
|
9
|
+
"model-context-protocol"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/patrickcneuhaus/pidgeon.git",
|
|
15
|
+
"directory": "packages/mcp"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://pidgeon.ai",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"bin": {
|
|
20
|
+
"pidgeon-mcp": "dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"prepublishOnly": "pnpm build"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@modelcontextprotocol/sdk": "^1.30.1",
|
|
48
|
+
"@pidgeon-ai/sdk": "workspace:*",
|
|
49
|
+
"zod": "^4.6.5"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"tsup": "^8.5.0",
|
|
53
|
+
"typescript": "^5",
|
|
54
|
+
"@types/node": "^24"
|
|
55
|
+
}
|
|
56
|
+
}
|