postmark-mcp 1.0.13 → 1.0.15

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/index.js CHANGED
@@ -22,6 +22,12 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
22
22
  import { z } from "zod";
23
23
  import postmark from "postmark";
24
24
 
25
+ // Ensure fetch is available (Node < 18)
26
+ if (typeof fetch === 'undefined') {
27
+ const nf = await import('node-fetch');
28
+ globalThis.fetch = nf.default;
29
+ }
30
+
25
31
  // Postmark configuration
26
32
  const serverToken = process.env.POSTMARK_SERVER_TOKEN;
27
33
  const defaultSender = process.env.DEFAULT_SENDER_EMAIL;
@@ -162,7 +168,7 @@ function registerTools(server, postmarkClient) {
162
168
  from: z.string().optional().describe("Sender email address (optional, uses default if not provided)"),
163
169
  tag: z.string().optional().describe("Optional tag for categorization"),
164
170
  inReplyTo: z.string().optional().describe("SMTP Message-ID this email replies to (e.g. <id@host>)"),
165
- attachmentUrls: z.array(z.string().url()).optional().describe("Array of attachment URLs (optional)")
171
+ attachmentUrls: z.array(z.string()).optional().describe("Array of attachment URLs (optional)")
166
172
  },
167
173
  async ({ to, subject, textBody, htmlBody, from, tag, inReplyTo, attachmentUrls }) => {
168
174
  const emailData = {
@@ -187,10 +193,38 @@ function registerTools(server, postmarkClient) {
187
193
  let attachmentsSize = 0;
188
194
  const attachments = [];
189
195
 
190
- for (const url of attachmentUrls) {
191
- const response = await fetch(url);
196
+ for (const rawUrl of attachmentUrls) {
197
+ const cleanedUrl = String(rawUrl)
198
+ .trim()
199
+ .replace(/^@+/, '') // allow @https://... style inputs
200
+ .replace(/^<([^>]+)>$/, '$1'); // strip surrounding angle brackets
201
+
202
+ let parsed;
203
+ try {
204
+ parsed = new URL(cleanedUrl);
205
+ } catch {
206
+ throw new Error(`Invalid attachment URL: ${rawUrl}`);
207
+ }
208
+
209
+ let response;
210
+ try {
211
+ response = await fetch(parsed.toString(), {
212
+ redirect: 'follow',
213
+ headers: {
214
+ 'User-Agent': 'Mozilla/5.0 (compatible; Postmark-MCP/1.0)'
215
+ }
216
+ });
217
+ } catch (err) {
218
+ const cause = err && err.cause ? ` | cause: ${err.cause.code || ''} ${err.cause.message || ''}` : '';
219
+ throw new Error(`Attachment fetch failed for ${cleanedUrl}: ${err && err.message ? err.message : err}${cause}`);
220
+ }
192
221
  if (!response.ok) {
193
- throw new Error(`Failed to fetch attachment from ${url}: ${response.status} ${response.statusText}`);
222
+ let snippet = '';
223
+ try {
224
+ const text = await response.text();
225
+ snippet = text ? ` | body: ${text.slice(0, 200)}${text.length > 200 ? '...' : ''}` : '';
226
+ } catch { }
227
+ throw new Error(`Failed to fetch attachment from ${cleanedUrl}: ${response.status} ${response.statusText}${snippet}`);
194
228
  }
195
229
 
196
230
  const arrayBuf = await response.arrayBuffer();
@@ -199,7 +233,7 @@ function registerTools(server, postmarkClient) {
199
233
 
200
234
  const contentType = response.headers.get("content-type") || "application/octet-stream";
201
235
  const contentDisposition = response.headers.get("content-disposition") || "";
202
- const filename = pickFilename(url, contentDisposition);
236
+ const filename = pickFilename(cleanedUrl, contentDisposition);
203
237
 
204
238
  if (isForbiddenExt(filename)) {
205
239
  throw new Error(`Attachment "${filename}" has a forbidden file extension.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postmark-mcp",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Universal Postmark MCP server using official SDK",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -0,0 +1,10 @@
1
+ {
2
+ "url": "https://www.mckinsey.com/~/media/mckinsey/featured%20insights/mckinsey%20global%20surveys/mckinsey-global-surveys-2021-a-year-in-review.pdf",
3
+ "filename": "mckinsey-global-surveys-2021-a-year-in-review.pdf",
4
+ "contentType": "application/pdf",
5
+ "bytesRaw": 3987886,
6
+ "bytesBase64": 5317184,
7
+ "isPdf": true,
8
+ "roundTripIdentical": true,
9
+ "usedCustomHeaders": false
10
+ }