@notifkit/mcp 0.1.0 → 0.1.2

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 CHANGED
@@ -14,22 +14,23 @@ Or skip the install and let your client run it with `npx -y @notifkit/mcp`.
14
14
 
15
15
  ## Configure
16
16
 
17
- Three environment variables:
17
+ Three environment variables, all of them required:
18
18
 
19
- | Variable | Required | Notes |
20
- | --------------------- | ---------------------- | ------------------------------------------ |
21
- | `NOTIFKIT_API_KEY` | yes | A project API key, or your `ADMIN_API_KEY` |
22
- | `NOTIFKIT_URL` | no | Defaults to `http://localhost:3000` |
23
- | `NOTIFKIT_PROJECT_ID` | only with an admin key | Which project the admin key should act on |
19
+ | Variable | Required | Notes |
20
+ | --------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
21
+ | `NOTIFKIT_API_KEY` | yes | Your `ADMIN_API_KEY`, or a project API key. The server exits without it |
22
+ | `NOTIFKIT_URL` | yes | Base URL of your notifkit API. Falls back to `http://localhost:3000`, so set it unless the API is there |
23
+ | `NOTIFKIT_PROJECT_ID` | yes | Which project the admin key acts on, sent as `x-project-id`. Without it an admin key gets `400` on everything except `/v1/projects` |
24
24
 
25
- A project-scoped key already carries its project, so it needs no `NOTIFKIT_PROJECT_ID`. Mint one with `POST /v1/projects/:id/keys`. Prefer that over the admin key — it is scoped to a single project and can be revoked on its own.
25
+ The examples below use your `ADMIN_API_KEY`, which carries no project of its own — it needs `NOTIFKIT_PROJECT_ID` to know which project to act on. A project-scoped key already carries its project, so if you swap one in, drop the `NOTIFKIT_PROJECT_ID` line. Prefer that where you can: it is scoped to a single project and can be revoked without rotating the admin key. Mint one with `create_project_key` or `POST /v1/projects/:id/keys`.
26
26
 
27
27
  ### Claude Code
28
28
 
29
29
  ```sh
30
30
  claude mcp add notifkit \
31
31
  --env NOTIFKIT_URL=http://localhost:3000 \
32
- --env NOTIFKIT_API_KEY=nk_your_project_key \
32
+ --env NOTIFKIT_API_KEY=your_admin_api_key \
33
+ --env NOTIFKIT_PROJECT_ID=6f1c9c1e-3b7a-4d2e-9f04-2c8a5b1d7e33 \
33
34
  -- npx -y @notifkit/mcp
34
35
  ```
35
36
 
@@ -45,7 +46,8 @@ In `claude_desktop_config.json`:
45
46
  "args": ["-y", "@notifkit/mcp"],
46
47
  "env": {
47
48
  "NOTIFKIT_URL": "http://localhost:3000",
48
- "NOTIFKIT_API_KEY": "nk_your_project_key"
49
+ "NOTIFKIT_API_KEY": "your_admin_api_key",
50
+ "NOTIFKIT_PROJECT_ID": "6f1c9c1e-3b7a-4d2e-9f04-2c8a5b1d7e33"
49
51
  }
50
52
  }
51
53
  }
@@ -62,38 +64,51 @@ The thing this exists for:
62
64
  > _(next day)_ **You:** "How did the spring sale do?"
63
65
  > **Agent:** → `list_campaigns` → `get_campaign_stats` → "194 delivered, 4 bounced, 2 suppressed. 71 opened (37%), 12 clicked (6%)."
64
66
 
65
- `send_campaign` takes raw email addresses — no user records needed up front. It creates one per address, keyed off the address itself, so re-sending to the same list updates those people rather than duplicating them. Duplicates and case differences within a list are collapsed before sending.
67
+ `send_campaign` takes raw email addresses, phone numbers, or push tokens — no user records needed up front. It creates one per recipient, keyed off the address itself, so re-sending to the same list updates those people rather than duplicating them. Duplicates and case differences within a list are collapsed before sending.
66
68
 
67
- ## Tools
69
+ ## The `raw_email` Pattern (One-off Sends from Terminal)
70
+
71
+ Instead of hardcoding a new template in backend code for every custom message, register a single generic pass-through template once:
68
72
 
69
- **Campaigns**
73
+ ```json
74
+ {
75
+ "id": "raw_email",
76
+ "channel": "email",
77
+ "content": {
78
+ "subject": "{{subject}}",
79
+ "html": "{{{body}}}"
80
+ }
81
+ }
82
+ ```
70
83
 
71
- | Tool | What it does |
72
- | -------------------- | -------------------------------------------------------------------------------------------- |
73
- | `send_campaign` | Send a template to a list of email addresses, tagged with a label you can report on later |
74
- | `list_campaigns` | Recent campaign labels with size and last activity — how "the one from yesterday" gets found |
75
- | `get_campaign_stats` | Sent, delivered, failed, opened, clicked, bounced, complained, unsubscribed, with rates |
84
+ Because triple braces `{{{body}}}` preserve unescaped HTML, your agent in Claude Code or Cursor can dispatch arbitrary one-off formatted emails directly from terminal prompts:
76
85
 
77
- **Sending**
86
+ > **You:** "Send an email to alex@acme.corp saying their invoice is ready at https://app.acme.corp/inv/9481"
87
+ > **Agent:** → `send_campaign({ template: "raw_email", emails: ["alex@acme.corp"], data: { subject: "Invoice #9481 Ready", body: "<p>Download: <a href='...'>Invoice #9481</a></p>" } })`
78
88
 
79
- | Tool | What it does |
80
- | ------------------- | --------------------------------------------------------------------------------------------------------------- |
81
- | `send_notification` | Send to existing users, a segment, or a topic. Takes `sendAt` to schedule and `campaign` to make it reportable. |
82
- | `list_segments` | Every segment tag in use — the valid audiences to broadcast to |
83
- | `list_scheduled` | Sends queued for the future, including quiet-hours deferrals |
84
- | `get_delivery_logs` | Per-message detail, when the campaign totals are not enough |
89
+ ## Tools
85
90
 
86
- **Suppressions** — `list_suppressions`, `suppress_address`, `unsuppress_address`
91
+ **Campaigns & Sending**
87
92
 
88
- **Templates** — `list_templates`, `get_template`, `upsert_template`
93
+ | Tool | What it does |
94
+ | --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
95
+ | `send_campaign` | Send a template to a list of recipients across `email`, `sms`, `push`, `webhook`, `telegram`, `discord`, `whatsapp`, or `slack` with campaign tagging |
96
+ | `send_notification` | Send to existing users, a segment, or a topic with `sendAt` scheduling and priority lanes |
97
+ | `list_campaigns` | Recent campaign labels with size and last activity (supports `search`, `channel`, date range) |
98
+ | `get_campaign_stats` | Sent, delivered, failed, opened, clicked, bounced, complained, unsubscribed, with rates |
99
+ | `list_segments` | Every segment tag in use — the valid audiences to broadcast to |
100
+ | `list_scheduled` | Sends queued for the future, including quiet-hours deferrals |
101
+ | `get_delivery_logs` | Per-message detail with filters for template, channel, status, campaign, or user search |
102
+ | `get_notification` | Status and delivery attempts for a specific task |
103
+ | `cancel_notification` | Cancel a pending scheduled or quiet-hours deferred notification |
89
104
 
90
- **Users** — `list_users`, `get_user`, `upsert_user`, `add_user_contact`
105
+ **Templates** — `list_templates`, `get_template`, `upsert_template`, `delete_template`, `preview_template`, `render_template`
91
106
 
92
- **Workflows** — `create_workflow`, `list_workflows`, `trigger_workflow`, `get_workflow_run`, `cancel_workflow_run`, `ingest_event`
107
+ **Users** — `list_users` (with `search`, `segment`, `language`, `timezone`, `channel` filters), `get_user`, `upsert_user`, `update_user`, `delete_user`, `get_user_contacts`, `add_user_contact`, `delete_user_contact`, `get_user_preferences`, `update_user_preferences`
93
108
 
94
- **Operations** — `get_system_health`, `get_dead_letters`, `replay_dead_letter`
109
+ **Workflows** — `create_workflow`, `list_workflows` (with `search`), `trigger_workflow`, `get_workflow_run`, `cancel_workflow_run`, `ingest_event`
95
110
 
96
- Project and API-key management is deliberately not exposed: minting and revoking credentials is not something an agent should do on your behalf. Use the HTTP API for that.
111
+ **Operations** — `get_system_health`, `get_system_metrics`, `get_dead_letters`, `replay_dead_letter`, `delete_dead_letter`, `list_projects`, `create_project`, `update_project`, `delete_project`, `list_project_keys`, `create_project_key`, `delete_project_key`
97
112
 
98
113
  ## Reading the numbers
99
114
 
package/dist/client.d.ts CHANGED
@@ -28,5 +28,7 @@ export declare class NotifkitApi {
28
28
  get<T>(path: string, query?: Record<string, string | number | undefined>): Promise<T>;
29
29
  post<T>(path: string, body?: unknown): Promise<T>;
30
30
  put<T>(path: string, body?: unknown): Promise<T>;
31
+ patch<T>(path: string, body?: unknown): Promise<T>;
32
+ delete<T>(path: string): Promise<T>;
31
33
  }
32
34
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,4FAA4F;IAC5F,SAAS,C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request("PUT", path, { body });
78
78
  }
79
+ patch(path, body) {
80
+ return this.request("PATCH", path, { body });
81
+ }
82
+ delete(path) {
83
+ return this.request("DELETE", path);
84
+ }
79
85
  }
80
86
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAG9B;IACA;IAHX,YACE,OAAe,EACN,MAAc,EACd,IAAa;QAEtB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAS;QAGtB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,MAAM,OAAO,WAAW;IACL,OAAO,CAAS;IAChB,OAAO,CAAyB;IAEjD,YAAY,OAA2B;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,OAAO,GAAG;YACb,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,OAAO,CAAC,MAAM,EAAE;YACzC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACpE,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CACX,MAAc,EACd,IAAY,EACZ,OAAiF;QAEjF,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,CAAC;QAEnC,IAAI,OAAO,EAAE,KAAK,EAAE,CAAC;YACnB,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;YACrC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,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O,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,CAAI,IAAY;QACpB,OAAO,IAAI,CAAC,OAAO,CAAI,QAAQ,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;CACF","sourcesContent":["/**\n * A minimal HTTP client for the notifkit API.\n *\n * Deliberately self-contained rather than importing `NotifkitClient` from the\n * root package: that entrypoint re-exports the db, redis, and config modules,\n * which would pull Postgres and Redis drivers into a process whose only job is\n * to speak JSON-RPC over stdio.\n */\n\nexport interface NotifkitApiOptions {\n baseUrl: string;\n apiKey: string;\n /** Required when `apiKey` is the admin key; project-scoped keys carry their own project. */\n projectId?: string;\n}\n\nexport class NotifkitApiError extends Error {\n constructor(\n message: string,\n readonly status: number,\n readonly body: unknown,\n ) {\n super(message);\n this.name = \"NotifkitApiError\";\n }\n}\n\nexport class NotifkitApi {\n private readonly baseUrl: string;\n private readonly headers: Record<string, string>;\n\n constructor(options: NotifkitApiOptions) {\n this.baseUrl = options.baseUrl.replace(/\\/$/, \"\");\n this.headers = {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${options.apiKey}`,\n ...(options.projectId ? { \"x-project-id\": options.projectId } : {}),\n };\n }\n\n async request<T>(\n method: string,\n path: string,\n options?: { body?: unknown; query?: Record<string, string | number | undefined> },\n ): Promise<T> {\n let url = `${this.baseUrl}${path}`;\n\n if (options?.query) {\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(options.query)) {\n if (value !== undefined) params.set(key, String(value));\n }\n const qs = params.toString();\n if (qs) url += `?${qs}`;\n }\n\n const res = await fetch(url, {\n method,\n headers: this.headers,\n body: options?.body === undefined ? undefined : JSON.stringify(options.body),\n });\n\n if (res.status === 204) return undefined as T;\n\n const text = await res.text();\n let data: unknown = undefined;\n if (text) {\n try {\n data = JSON.parse(text);\n } catch {\n data = text;\n }\n }\n\n if (!res.ok) {\n const record =\n typeof data === \"object\" && data !== null ? (data as Record<string, unknown>) : {};\n const message =\n typeof record[\"message\"] === \"string\"\n ? record[\"message\"]\n : typeof record[\"error\"] === \"string\"\n ? record[\"error\"]\n : `Request failed with status ${res.status}`;\n throw new NotifkitApiError(message, res.status, data);\n }\n\n return data as T;\n }\n\n get<T>(path: string, query?: Record<string, string | number | undefined>): Promise<T> {\n return this.request<T>(\"GET\", path, { query });\n }\n\n post<T>(path: string, body?: unknown): Promise<T> {\n return this.request<T>(\"POST\", path, { body });\n }\n\n put<T>(path: string, body?: unknown): Promise<T> {\n return this.request<T>(\"PUT\", path, { body });\n }\n\n patch<T>(path: string, body?: unknown): Promise<T> {\n return this.request<T>(\"PATCH\", path, { body });\n }\n\n delete<T>(path: string): Promise<T> {\n return this.request<T>(\"DELETE\", path);\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -13,4 +13,5 @@ export declare function createServer(options: {
13
13
  apiKey: string;
14
14
  projectId?: string;
15
15
  }): McpServer;
16
+ export declare function runServer(): Promise<void>;
16
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAOpE,wBAAgB,YAAY,CAAC,OAAO,EAAE;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,SAAS,CAwBZ"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AASpE,wBAAgB,YAAY,CAAC,OAAO,EAAE;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,SAAS,CAwBZ;AAED,wBAAsB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAkB/C"}
package/dist/index.js CHANGED
@@ -11,9 +11,10 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
11
11
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
12
12
  import { NotifkitApi } from "./client.js";
13
13
  import { registerTools } from "./tools.js";
14
+ import { fileURLToPath } from "node:url";
14
15
  const DEFAULT_URL = "http://localhost:3000";
15
16
  export function createServer(options) {
16
- const server = new McpServer({ name: "notifkit", version: "0.0.1" }, {
17
+ const server = new McpServer({ name: "notifkit", version: "0.1.1" }, {
17
18
  instructions: "Tools for notifkit, a self-hosted notification service.\n\n" +
18
19
  "Sending: send_campaign takes a list of email addresses directly and is the right tool when the " +
19
20
  "user supplies recipients themselves. send_notification targets existing users, a segment, or a " +
@@ -32,7 +33,7 @@ export function createServer(options) {
32
33
  registerTools(server, new NotifkitApi(options));
33
34
  return server;
34
35
  }
35
- async function main() {
36
+ export async function runServer() {
36
37
  const baseUrl = process.env["NOTIFKIT_URL"] ?? DEFAULT_URL;
37
38
  const apiKey = process.env["NOTIFKIT_API_KEY"];
38
39
  const projectId = process.env["NOTIFKIT_PROJECT_ID"];
@@ -46,8 +47,17 @@ async function main() {
46
47
  await server.connect(new StdioServerTransport());
47
48
  console.error(`notifkit-mcp: connected, talking to ${baseUrl}`);
48
49
  }
49
- main().catch((error) => {
50
- console.error("notifkit-mcp: fatal:", error instanceof Error ? error.message : error);
51
- process.exit(1);
52
- });
50
+ const entryFile = process.argv[1];
51
+ const isDirectRun = Boolean(entryFile) &&
52
+ !process.env["VITEST"] &&
53
+ (fileURLToPath(import.meta.url) === entryFile ||
54
+ entryFile?.endsWith("notifkit-mcp") ||
55
+ entryFile?.endsWith("dist/index.js") ||
56
+ entryFile?.endsWith("src/index.ts"));
57
+ if (isDirectRun) {
58
+ runServer().catch((error) => {
59
+ console.error("notifkit-mcp: fatal:", error instanceof Error ? error.message : error);
60
+ process.exit(1);
61
+ });
62
+ }
53
63
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAE5C,MAAM,UAAU,YAAY,CAAC,OAI5B;IACC,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,EACtC;QACE,YAAY,EACV,6DAA6D;YAC7D,iGAAiG;YACjG,iGAAiG;YACjG,iGAAiG;YACjG,wFAAwF;YACxF,iGAAiG;YACjG,qDAAqD;YACrD,mGAAmG;YACnG,qDAAqD;YACrD,kGAAkG;YAClG,oBAAoB;YACpB,wFAAwF;YACxF,kGAAkG;YAClG,qCAAqC;KACxC,CACF,CAAC;IAEF,aAAa,CAAC,MAAM,EAAE,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IAChD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,KAAK,UAAU,IAAI;IACjB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,WAAW,CAAC;IAC3D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAErD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CACX,8CAA8C;YAC5C,8FAA8F;YAC9F,8BAA8B,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C,cAAc,CAAC,CAAC,CAAC;AAEzC,IAAI,WAAW,EAAE,CAAC;IAChB,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACnC,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACtF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["#!/usr/bin/env node\n/**\n * notifkit MCP server (stdio).\n *\n * Exposes the notifkit HTTP API as MCP tools so a terminal agent can send\n * notifications, manage templates and users, and drive workflows.\n *\n * stdout is the JSON-RPC transport — never write to it. Diagnostics go to stderr.\n */\n\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { NotifkitApi } from \"./client.js\";\nimport { registerTools } from \"./tools.js\";\n\nimport { fileURLToPath } from \"node:url\";\n\nconst DEFAULT_URL = \"http://localhost:3000\";\n\nexport function createServer(options: {\n baseUrl: string;\n apiKey: string;\n projectId?: string;\n}): McpServer {\n const server = new McpServer(\n { name: \"notifkit\", version: \"0.1.1\" },\n {\n instructions:\n \"Tools for notifkit, a self-hosted notification service.\\n\\n\" +\n \"Sending: send_campaign takes a list of email addresses directly and is the right tool when the \" +\n \"user supplies recipients themselves. send_notification targets existing users, a segment, or a \" +\n \"topic. Both accept a `campaign` label — set one on any send whose results might be asked about \" +\n \"later, and tell the user the label, because without it the send cannot be reported on \" +\n \"afterwards. Multi-step sequences (drips, onboarding, reminders) are workflows: create_workflow \" +\n \"defines one, trigger_workflow runs it per user.\\n\\n\" +\n \"Reporting: get_campaign_stats answers 'how did that send do?'. Pass on its `warnings` verbatim — \" +\n \"an untracked open rate is not a zero open rate.\\n\\n\" +\n \"Discover ids with list_campaigns, list_segments, list_templates, and list_workflows rather than \" +\n \"guessing them.\\n\\n\" +\n \"Every send reaches real people and cannot be recalled, so confirm the audience before \" +\n \"broadcasting. Never remove a suppression to improve a delivery figure: suppressions record that \" +\n \"somebody asked not to be contacted.\",\n },\n );\n\n registerTools(server, new NotifkitApi(options));\n return server;\n}\n\nexport async function runServer(): Promise<void> {\n const baseUrl = process.env[\"NOTIFKIT_URL\"] ?? DEFAULT_URL;\n const apiKey = process.env[\"NOTIFKIT_API_KEY\"];\n const projectId = process.env[\"NOTIFKIT_PROJECT_ID\"];\n\n if (!apiKey) {\n console.error(\n \"notifkit-mcp: NOTIFKIT_API_KEY is not set.\\n\" +\n \" Set it to a project API key, or to your ADMIN_API_KEY together with NOTIFKIT_PROJECT_ID.\\n\" +\n ` NOTIFKIT_URL defaults to ${DEFAULT_URL}.`,\n );\n process.exit(1);\n }\n\n const server = createServer({ baseUrl, apiKey, projectId });\n await server.connect(new StdioServerTransport());\n\n console.error(`notifkit-mcp: connected, talking to ${baseUrl}`);\n}\n\nconst entryFile = process.argv[1];\nconst isDirectRun =\n Boolean(entryFile) &&\n !process.env[\"VITEST\"] &&\n (fileURLToPath(import.meta.url) === entryFile ||\n entryFile?.endsWith(\"notifkit-mcp\") ||\n entryFile?.endsWith(\"dist/index.js\") ||\n entryFile?.endsWith(\"src/index.ts\"));\n\nif (isDirectRun) {\n runServer().catch((error: unknown) => {\n console.error(\"notifkit-mcp: fatal:\", error instanceof Error ? error.message : error);\n process.exit(1);\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AA+C/C,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAyrBvE"}
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AA2I/C,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CA2zCvE"}