obsidian-sync-mcp 0.7.2 → 0.7.3

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
@@ -246,7 +246,7 @@ Without `MCP_AUTH_TOKEN`, the server runs without authentication — suitable fo
246
246
  | `COUCHDB_URL` | CouchDB mode | — | CouchDB server URL |
247
247
  | `COUCHDB_USER` | CouchDB mode | `admin` | CouchDB username |
248
248
  | `COUCHDB_PASSWORD` | CouchDB mode | — | CouchDB password (required) |
249
- | `COUCHDB_DATABASE` | CouchDB mode | `obsidian` | CouchDB database name |
249
+ | `COUCHDB_DATABASE` | CouchDB mode | `obsidian` | CouchDB database name. The server never creates it: if it doesn't exist, startup fails with an error |
250
250
  | `COUCHDB_PASSPHRASE` | CouchDB mode | — | LiveSync E2E encryption passphrase (must match plugin setting) |
251
251
  | `COUCHDB_OBFUSCATE_PROPERTIES` | CouchDB mode | `false` | Set to `true` if "Obfuscate Properties" is enabled in LiveSync (obfuscates file paths, sizes, dates in the database). For existing vaults the actual setting is auto-detected at startup; this value only decides the format for a brand-new empty database |
252
252
  | `VAULT_NAME` | Both | `MyVault` | Vault name (used for deep links and index storage) |
@@ -135,8 +135,52 @@ function maskInlineSpans(text) {
135
135
  return result + text.slice(from);
136
136
  }
137
137
 
138
+ // src/note-path.ts
139
+ var RESERVED_ROOT_FILES = /* @__PURE__ */ new Set([
140
+ "redflag.md",
141
+ "redflag2.md",
142
+ "redflag3.md",
143
+ "flag_rebuild.md",
144
+ "flag_fetch.md"
145
+ ]);
146
+ function validateNotePath(path) {
147
+ if (!path || path.length > 1e3) {
148
+ throw new Error("Invalid note path");
149
+ }
150
+ if (path.startsWith("/") || path.includes("\0") || path.includes("..")) {
151
+ throw new Error("Invalid note path");
152
+ }
153
+ if (path.includes(":")) {
154
+ throw new Error("Invalid note path: ':' is not allowed");
155
+ }
156
+ if (!path.endsWith(".md")) {
157
+ throw new Error("Invalid note path: must be a vault-relative path ending in .md");
158
+ }
159
+ for (const segment of path.split(/[/\\]/)) {
160
+ if (segment === "") {
161
+ throw new Error("Invalid note path: empty path segment");
162
+ }
163
+ if (segment.startsWith(".")) {
164
+ throw new Error("Invalid note path: dot-folders and hidden files (e.g. .obsidian) are not allowed");
165
+ }
166
+ }
167
+ if (!path.includes("/") && !path.includes("\\") && RESERVED_ROOT_FILES.has(path.toLowerCase())) {
168
+ throw new Error("Invalid note path: reserved LiveSync control file");
169
+ }
170
+ }
171
+ function isValidNotePath(path) {
172
+ try {
173
+ validateNotePath(path);
174
+ return true;
175
+ } catch {
176
+ return false;
177
+ }
178
+ }
179
+
138
180
  export {
139
181
  __reExport,
140
- parseFrontmatterAndLinks
182
+ parseFrontmatterAndLinks,
183
+ validateNotePath,
184
+ isValidNotePath
141
185
  };
142
- //# sourceMappingURL=chunk-43MP6CJE.js.map
186
+ //# sourceMappingURL=chunk-VR63UUCB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/parse.ts","../src/note-path.ts"],"sourcesContent":["/**\n * Parse Obsidian markdown content for frontmatter, tags, and links.\n */\n\nexport interface NoteMetadata {\n frontmatter: Record<string, string>;\n tags: string[];\n links: string[];\n}\n\nexport function parseFrontmatterAndLinks(content: string): NoteMetadata {\n const frontmatter: Record<string, any> = {};\n const tags = new Set<string>();\n const links: string[] = [];\n\n // Parse YAML frontmatter\n if (content.startsWith(\"---\\n\")) {\n const end = content.indexOf(\"\\n---\", 4);\n if (end !== -1) {\n const yaml = content.slice(4, end);\n let inTagsList = false;\n for (const line of yaml.split(\"\\n\")) {\n // Multi-line tags list item: \" - tagname\"\n if (inTagsList) {\n const listItem = line.match(/^\\s+-\\s+(.+)/);\n if (listItem) {\n const trimmed = listItem[1].trim();\n if (trimmed) tags.add(trimmed);\n continue;\n }\n inTagsList = false;\n }\n\n const match = line.match(/^([\\p{L}\\p{N}_][\\p{L}\\p{M}\\p{N}_-]*)\\s*:\\s*(.+)/u);\n if (match) {\n frontmatter[match[1]] = match[2].trim();\n }\n // Frontmatter tags (inline: [a, b] or start of multi-line list)\n if (/^tags\\s*:/.test(line)) {\n const value = line.replace(/^tags\\s*:\\s*/, \"\").trim();\n if (value) {\n // Inline: tags: [a, b] or tags: a, b\n const tagValues = value.replace(/[[\\]]/g, \"\");\n for (const t of tagValues.split(\",\")) {\n const trimmed = t.trim();\n if (trimmed) tags.add(trimmed);\n }\n } else {\n // Multi-line list follows\n inTagsList = true;\n }\n }\n }\n }\n }\n\n // Inline #tags. Obsidian does not read tags out of code, and a tag must\n // contain at least one non-numerical character (\"#1984 isn't a valid tag,\n // but #y1984 is\" — obsidian.md/help/tags), so code spans and fenced blocks\n // are masked out first and all-digit matches are dropped.\n for (const match of maskCode(content).matchAll(/(^|\\s)#([\\p{L}\\p{N}_/-][\\p{L}\\p{M}\\p{N}_/-]*)/gu)) {\n if (/^\\p{Nd}+$/u.test(match[2])) continue;\n tags.add(match[2]);\n }\n\n // [[wikilinks]]\n for (const match of content.matchAll(/\\[\\[([^\\]|]+)(?:\\|[^\\]]+)?\\]\\]/g)) {\n links.push(match[1]);\n }\n\n // [markdown links](path.md)\n for (const match of content.matchAll(/\\[([^\\]]+)\\]\\(([^)]+\\.md)\\)/g)) {\n links.push(match[2]);\n }\n\n return { frontmatter, tags: [...tags], links: [...new Set(links)] };\n}\n\n/**\n * Replace fenced code blocks (``` or ~~~, opener at line start with up to three\n * spaces of indent, closer of the same character and at least the same length;\n * an unclosed fence runs to the end) and inline code spans (a backtick run of\n * length n closes at the next run of exactly n within the same paragraph — a\n * span never crosses a blank line; an unmatched run is literal)\n * with dots, so offsets are preserved and nothing inside can start or extend a\n * tag. Indented code blocks, %% comments and math are not masked.\n */\nexport function maskCode(content: string): string {\n const lines = content.split(\"\\n\");\n const out: string[] = [];\n let fence: { char: string; len: number } | null = null;\n const inline: string[] = [];\n const flushInline = () => {\n if (inline.length === 0) return;\n out.push(...maskInlineSpans(inline.join(\"\\n\")).split(\"\\n\"));\n inline.length = 0;\n };\n for (const line of lines) {\n const open = line.match(/^ {0,3}(`{3,}|~{3,})/);\n if (fence) {\n const close = open && open[1][0] === fence.char && open[1].length >= fence.len && line.trim() === open[1];\n out.push(\".\".repeat(line.length));\n if (close) fence = null;\n continue;\n }\n if (open && (open[1][0] === \"~\" || !line.slice(open[0].length).includes(\"`\"))) {\n flushInline();\n fence = { char: open[1][0], len: open[1].length };\n out.push(\".\".repeat(line.length));\n continue;\n }\n if (line.trim() === \"\") {\n flushInline();\n out.push(line);\n continue;\n }\n inline.push(line);\n }\n flushInline();\n return out.join(\"\\n\");\n}\n\nfunction maskInlineSpans(text: string): string {\n // Collect backtick runs in one pass, then link each run to the next run of\n // the same length (scanning right to left) so matching stays linear.\n const runs: { at: number; len: number }[] = [];\n for (let i = 0; i < text.length; ) {\n if (text[i] !== \"`\") { i++; continue; }\n let n = 0;\n while (text[i + n] === \"`\") n++;\n runs.push({ at: i, len: n });\n i += n;\n }\n const next: number[] = [];\n const seen = new Map<number, number>();\n for (let r = runs.length - 1; r >= 0; r--) {\n next[r] = seen.get(runs[r].len) ?? -1;\n seen.set(runs[r].len, r);\n }\n let result = \"\";\n let from = 0;\n for (let r = 0; r < runs.length; ) {\n const c = next[r];\n if (c === -1) { r++; continue; }\n const start = runs[r].at;\n const end = runs[c].at + runs[c].len;\n result += text.slice(from, start) + text.slice(start, end).replace(/[^\\n]/g, \".\");\n from = end;\n r = c + 1;\n }\n return result + text.slice(from);\n}\n\nexport function extractSnippet(content: string, query: string, context = 80): string {\n const lower = content.toLowerCase();\n\n // Try exact phrase first\n let idx = lower.indexOf(query.toLowerCase());\n\n // Try to find the smallest span containing all query words\n if (idx === -1) {\n const words = query.split(/\\s+/).filter((w) => w.length >= 3).map((w) => w.toLowerCase());\n if (words.length > 1) {\n let bestStart = -1;\n let bestLen = Infinity;\n // For each occurrence of the first word, find the nearest span containing all words\n const first = words[0];\n let pos = 0;\n while (pos < lower.length) {\n const start = lower.indexOf(first, pos);\n if (start === -1) break;\n // Find last position needed to include all words from this start\n let spanEnd = start + first.length;\n let allFound = true;\n for (let i = 1; i < words.length; i++) {\n const wi = lower.indexOf(words[i], Math.max(0, start - 200));\n if (wi === -1) { allFound = false; break; }\n spanEnd = Math.max(spanEnd, wi + words[i].length);\n }\n if (allFound) {\n const spanStart = Math.min(start, ...words.map((w) => lower.indexOf(w, Math.max(0, start - 200))).filter((i) => i >= 0));\n const len = spanEnd - spanStart;\n if (len < bestLen) { bestStart = spanStart; bestLen = len; }\n }\n pos = start + 1;\n }\n if (bestStart >= 0 && bestLen <= 500) idx = bestStart;\n }\n }\n\n // Fall back to longest matching word\n if (idx === -1) {\n const words = query.split(/\\s+/).filter((w) => w.length >= 3).sort((a, b) => b.length - a.length);\n for (const word of words) {\n idx = lower.indexOf(word.toLowerCase());\n if (idx !== -1) break;\n }\n }\n\n if (idx === -1) {\n return content.slice(0, 160) + (content.length > 160 ? \"...\" : \"\");\n }\n const start = Math.max(0, idx - context);\n const end = Math.min(content.length, idx + query.length + context);\n return (start > 0 ? \"...\" : \"\") + content.slice(start, end) + (end < content.length ? \"...\" : \"\");\n}\n","/**\n * Shared validation for note paths, applied by both the CouchDB and local\n * backends before any read, write, delete or move.\n *\n * The note model is markdown-only: `list_notes` only ever surfaces `*.md`\n * files, and binary attachments are not supported. Enforcing that here keeps\n * the tools from reaching anything that isn't a note, which closes two real\n * problems:\n * - CouchDB mode: a path like `obsydian_livesync_version` or a `ix:`/`ps:`\n * prefixed id would otherwise become a document id and overwrite LiveSync's\n * own control documents, stopping sync on every device.\n * - Local mode: a path like `.obsidian/plugins/x/main.js` would otherwise\n * write executable plugin code into the vault, and `.obsidian/.../data.json`\n * would expose LiveSync credentials.\n *\n * Rules: vault-relative, ends in `.md`, no `..`, no leading `/`, no `:` (its\n * only use here is LiveSync's internal id prefixes), no NUL, and no path\n * segment (split on either slash) that starts with `.` (hidden files and the\n * `.obsidian` config dir). Root-level LiveSync control flag files are also\n * rejected even though they are `.md`.\n */\n\n// LiveSync's note-shaped control files, all at the vault root. Writing one and\n// letting it sync triggers a vault-wide rebuild/fetch on every device, so they\n// are not writable through the note tools. Compared lowercase because LiveSync\n// lowercases ids when case-insensitive handling is on.\nconst RESERVED_ROOT_FILES = new Set([\n \"redflag.md\",\n \"redflag2.md\",\n \"redflag3.md\",\n \"flag_rebuild.md\",\n \"flag_fetch.md\",\n]);\n\nexport function validateNotePath(path: string): void {\n if (!path || path.length > 1000) {\n throw new Error(\"Invalid note path\");\n }\n if (path.startsWith(\"/\") || path.includes(\"\\0\") || path.includes(\"..\")) {\n throw new Error(\"Invalid note path\");\n }\n if (path.includes(\":\")) {\n throw new Error(\"Invalid note path: ':' is not allowed\");\n }\n if (!path.endsWith(\".md\")) {\n throw new Error(\"Invalid note path: must be a vault-relative path ending in .md\");\n }\n for (const segment of path.split(/[/\\\\]/)) {\n if (segment === \"\") {\n throw new Error(\"Invalid note path: empty path segment\");\n }\n if (segment.startsWith(\".\")) {\n throw new Error(\"Invalid note path: dot-folders and hidden files (e.g. .obsidian) are not allowed\");\n }\n }\n // Root-level control flag files (no folder segment).\n if (!path.includes(\"/\") && !path.includes(\"\\\\\") && RESERVED_ROOT_FILES.has(path.toLowerCase())) {\n throw new Error(\"Invalid note path: reserved LiveSync control file\");\n }\n}\n\n/** Boolean form of validateNotePath, for filtering listings and the index. */\nexport function isValidNotePath(path: string): boolean {\n try {\n validateNotePath(path);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAUO,SAAS,yBAAyB,SAA+B;AACpE,QAAM,cAAmC,CAAC;AAC1C,QAAM,OAAO,oBAAI,IAAY;AAC7B,QAAM,QAAkB,CAAC;AAGzB,MAAI,QAAQ,WAAW,OAAO,GAAG;AAC7B,UAAM,MAAM,QAAQ,QAAQ,SAAS,CAAC;AACtC,QAAI,QAAQ,IAAI;AACZ,YAAM,OAAO,QAAQ,MAAM,GAAG,GAAG;AACjC,UAAI,aAAa;AACjB,iBAAW,QAAQ,KAA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B,UAAM,IAAI,MAAM,gEAAgE;AAAA,EACpF;AACA,aAAW,WAAW,KAAK,MAAM,OAAO,GAAG;AACvC,QAAI,YAAY,IAAI;AAChB,YAAM,IAAI,MAAM,uCAAuC;AAAA,IAC3D;AACA,QAAI,QAAQ,WAAW,GAAG,GAAG;AACzB,YAAM,IAAI,MAAM,kFAAkF;AAAA,IACtG;AAAA,EACJ;AAEA,MAAI,CAAC,KAAK,SAAS,GAAG,KAAK,CAAC,KAAK,SAAS,IAAI,KAAK,oBAAoB,IAAI,KAAK,YAAY,CAAC,GAAG;AAC5F,UAAM,IAAI,MAAM,mDAAmD;AAAA,EACvE;AACJ;AAGO,SAAS,gBAAgB,MAAuB;AACnD,MAAI;AACA,qBAAiB,IAAI;AACrB,WAAO;AAAA,EACX,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;","names":[]}
package/dist/main.js CHANGED
@@ -5,8 +5,9 @@ import {
5
5
  applyIndexChange
6
6
  } from "./chunk-SGLPTZJA.js";
7
7
  import {
8
+ isValidNotePath,
8
9
  parseFrontmatterAndLinks
9
- } from "./chunk-43MP6CJE.js";
10
+ } from "./chunk-VR63UUCB.js";
10
11
 
11
12
  // src/main.ts
12
13
  import { FastMCP } from "fastmcp";
@@ -184,7 +185,7 @@ function mountPasswordAuth(app, baseUrl, password, persistPath) {
184
185
  console.log(`Auth: /oauth/authorize accepted client_id=${clientId} redirect_uri=${JSON.stringify(redirectUri)}`);
185
186
  const csrf = randomBytes(32).toString("hex");
186
187
  csrfTokens.set(code, csrf);
187
- return c.html(renderPasswordPage(code, csrf));
188
+ return c.html(renderPasswordPage(code, csrf, hostOf(redirectUri), client.clientName));
188
189
  });
189
190
  app.post("/oauth/approve", async (c) => {
190
191
  const body = await c.req.parseBody();
@@ -204,7 +205,7 @@ function mountPasswordAuth(app, baseUrl, password, persistPath) {
204
205
  console.warn(`Auth: locked out, ${waitSec}s remaining`);
205
206
  const newCsrf = randomBytes(32).toString("hex");
206
207
  csrfTokens.set(code, newCsrf);
207
- return c.html(renderPasswordPage(code, newCsrf, `Too many attempts. Try again in ${waitSec} seconds.`), 429);
208
+ return c.html(renderPasswordPage(code, newCsrf, hostOf(pending.redirectUri), clients.get(pending.clientId)?.clientName, `Too many attempts. Try again in ${waitSec} seconds.`), 429);
208
209
  }
209
210
  if (typeof submittedPassword !== "string" || !safeEqual(submittedPassword, password)) {
210
211
  failedAttempts++;
@@ -216,9 +217,9 @@ function mountPasswordAuth(app, baseUrl, password, persistPath) {
216
217
  const lockoutMs = BASE_LOCKOUT_MS * Math.pow(2, lockoutCount - 1);
217
218
  lockedUntil = Date.now() + lockoutMs;
218
219
  console.warn(`Auth: lockout #${lockoutCount}, ${lockoutMs / 1e3}s`);
219
- return c.html(renderPasswordPage(code, newCsrf, `Too many attempts. Try again in ${Math.ceil(lockoutMs / 1e3)} seconds.`), 429);
220
+ return c.html(renderPasswordPage(code, newCsrf, hostOf(pending.redirectUri), clients.get(pending.clientId)?.clientName, `Too many attempts. Try again in ${Math.ceil(lockoutMs / 1e3)} seconds.`), 429);
220
221
  }
221
- return c.html(renderPasswordPage(code, newCsrf, "Wrong password."), 401);
222
+ return c.html(renderPasswordPage(code, newCsrf, hostOf(pending.redirectUri), clients.get(pending.clientId)?.clientName, "Wrong password."), 401);
222
223
  }
223
224
  failedAttempts = 0;
224
225
  lockoutCount = 0;
@@ -381,7 +382,16 @@ function mountPasswordAuth(app, baseUrl, password, persistPath) {
381
382
  }
382
383
  };
383
384
  }
384
- function renderPasswordPage(code, csrf, error) {
385
+ function hostOf(uri) {
386
+ try {
387
+ return new URL(uri).host;
388
+ } catch {
389
+ return uri;
390
+ }
391
+ }
392
+ function renderPasswordPage(code, csrf, redirectHost, clientName, error) {
393
+ const esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
394
+ const who = clientName ? `<b>${esc(clientName)}</b> (name self-reported)` : "An application";
385
395
  return `<!DOCTYPE html>
386
396
  <html><head><title>Obsidian Sync MCP - Authorize</title>
387
397
  <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'">
@@ -391,10 +401,15 @@ function renderPasswordPage(code, csrf, error) {
391
401
  input[type=password] { width: 100%; padding: 10px; margin: 10px 0; box-sizing: border-box; font-size: 1em; }
392
402
  button { padding: 10px 20px; font-size: 1em; cursor: pointer; }
393
403
  .error { color: red; }
404
+ .dest { background: #f3f3f3; padding: 8px 10px; border-radius: 6px; word-break: break-all; }
405
+ .warn { color: #a15c00; }
394
406
  </style></head>
395
407
  <body>
396
408
  <h1>Obsidian Sync MCP</h1>
397
- ${error ? `<p class="error">${error.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")}</p>` : "<p>Enter the server password to authorize access to your vault.</p>"}
409
+ <p>${who} is requesting access to your vault. After you approve, your browser will be sent to:</p>
410
+ <p class="dest"><b>${esc(redirectHost)}</b></p>
411
+ <p class="warn">Only enter your password if you recognize this destination. If you did not start this sign-in, close this page.</p>
412
+ ${error ? `<p class="error">${esc(error)}</p>` : ""}
398
413
  <form method="POST" action="/oauth/approve" autocomplete="on">
399
414
  <input type="hidden" name="code" value="${code.replace(/&/g, "&amp;").replace(/"/g, "&quot;")}">
400
415
  <input type="hidden" name="csrf" value="${csrf.replace(/&/g, "&amp;").replace(/"/g, "&quot;")}">
@@ -548,7 +563,7 @@ var SearchIndex = class {
548
563
  /** List all indexed paths with mtimes, optionally filtered by folder prefix. */
549
564
  listWithMtime(folder) {
550
565
  const prefix = folder && !folder.endsWith("/") ? folder + "/" : folder;
551
- const entries = [...this.knownPaths].filter((p) => p.endsWith(".md")).filter((p) => !prefix || p.startsWith(prefix)).map((p) => ({ path: p, mtime: this.mtimes.get(p) ?? 0 }));
566
+ const entries = [...this.knownPaths].filter(isValidNotePath).filter((p) => !prefix || p.startsWith(prefix)).map((p) => ({ path: p, mtime: this.mtimes.get(p) ?? 0 }));
552
567
  return entries.sort((a, b) => a.path.localeCompare(b.path));
553
568
  }
554
569
  /** Get mtime for a path. */
@@ -1144,7 +1159,7 @@ if (MCP_INSTRUCTIONS_FILE) {
1144
1159
  }
1145
1160
  var vault;
1146
1161
  if (VAULT_PATH) {
1147
- const { LocalVault } = await import("./vault-local-S53KTNRT.js");
1162
+ const { LocalVault } = await import("./vault-local-OURGENR5.js");
1148
1163
  vault = new LocalVault(VAULT_PATH);
1149
1164
  console.log(`Local mode: ${VAULT_PATH}`);
1150
1165
  } else if (COUCHDB_URL) {
@@ -1152,7 +1167,7 @@ if (VAULT_PATH) {
1152
1167
  console.error("COUCHDB_PASSWORD is required in remote mode.");
1153
1168
  process.exit(1);
1154
1169
  }
1155
- const { Vault } = await import("./vault-YGHHZZZQ.js");
1170
+ const { Vault } = await import("./vault-EJSNMND5.js");
1156
1171
  vault = new Vault({
1157
1172
  couchdbUrl: COUCHDB_URL,
1158
1173
  couchdbUser: COUCHDB_USER,
@@ -1283,7 +1298,7 @@ if (VAULT_PATH) {
1283
1298
  var BASE_INSTRUCTIONS = "Access and manage an Obsidian vault. You can read, write, list, search, move, and delete markdown notes. Every tool response includes an Obsidian deep link. Always show this link to the user using the format [obsidian://open?vault=...&file=...](obsidian://open?vault=...&file=...) so it is both clickable and visible as a URL.";
1284
1299
  var serverOptions = {
1285
1300
  name: "obsidian-sync-mcp",
1286
- version: "0.7.2",
1301
+ version: "0.7.3",
1287
1302
  instructions: MCP_EXTRA_INSTRUCTIONS ? `${BASE_INSTRUCTIONS}
1288
1303
 
1289
1304
  ${MCP_EXTRA_INSTRUCTIONS}` : BASE_INSTRUCTIONS
@@ -1350,7 +1365,7 @@ server.start({
1350
1365
  transportType: "httpStream",
1351
1366
  httpStream: { port: PORT, endpoint: "/mcp", host: process.env.HOST ?? "0.0.0.0" }
1352
1367
  });
1353
- console.log(`obsidian-sync-mcp v${"0.7.2"} listening on port ${PORT}`);
1368
+ console.log(`obsidian-sync-mcp v${"0.7.3"} listening on port ${PORT}`);
1354
1369
  process.on("unhandledRejection", (err) => {
1355
1370
  console.error(`Unhandled rejection: ${describeError(err, debugLogging2)}`);
1356
1371
  });