create-multicast 0.4.0 → 0.4.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-multicast",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Create a Multicast MCP gateway — one command to scaffold, configure, and deploy your parallel MCP server.",
5
5
  "type": "module",
6
6
  "bin": "./dist/cli.js",
@@ -73,6 +73,33 @@ function getRegisteredServers(env: Env): Map<string, RegisteredServer> {
73
73
  return servers;
74
74
  }
75
75
 
76
+ // ── SSE Response Parser ──────────────────────────────────────
77
+ // MCP Streamable HTTP servers may respond with either application/json
78
+ // or text/event-stream. This helper parses both formats.
79
+
80
+ async function parseJsonOrSse(response: Response): Promise<unknown> {
81
+ const contentType = response.headers.get("content-type") || "";
82
+
83
+ if (contentType.includes("text/event-stream")) {
84
+ // Parse SSE: extract the last JSON data line
85
+ const text = await response.text();
86
+ const lines = text.split("\n");
87
+ let lastData = "";
88
+ for (const line of lines) {
89
+ if (line.startsWith("data: ")) {
90
+ lastData = line.slice(6);
91
+ }
92
+ }
93
+ if (lastData) {
94
+ return JSON.parse(lastData);
95
+ }
96
+ throw new Error("No data in SSE response");
97
+ }
98
+
99
+ // Plain JSON
100
+ return response.json();
101
+ }
102
+
76
103
  // ── OAuth Token Management ───────────────────────────────────
77
104
  // Resolves auth for OAuth servers: checks D1 for cached token,
78
105
  // refreshes if expired, returns a valid Bearer header.
@@ -253,7 +280,7 @@ async function callMcpServer(
253
280
  };
254
281
  }
255
282
 
256
- const setupData = (await setupResponse.json()) as {
283
+ const setupData = (await parseJsonOrSse(setupResponse)) as {
257
284
  result?: { content?: Array<{ text?: string }>; isError?: boolean };
258
285
  error?: { message?: string };
259
286
  };
@@ -297,7 +324,7 @@ async function callMcpServer(
297
324
  };
298
325
  }
299
326
 
300
- const data = (await response.json()) as {
327
+ const data = (await parseJsonOrSse(response)) as {
301
328
  result?: unknown;
302
329
  error?: { message?: string; code?: number };
303
330
  };
@@ -391,7 +418,15 @@ async function discoverServerTools(
391
418
  "Content-Type": "application/json",
392
419
  "Accept": "application/json, text/event-stream",
393
420
  };
394
- if (server.auth) {
421
+
422
+ // Resolve auth: static header OR OAuth token from D1
423
+ if (server.isOAuth) {
424
+ const oauthResult = await resolveOAuthToken(server.name, db);
425
+ if (oauthResult.error) {
426
+ return { tool_count: 0, error: oauthResult.error };
427
+ }
428
+ headers["Authorization"] = oauthResult.auth!;
429
+ } else if (server.auth) {
395
430
  headers["Authorization"] = server.auth;
396
431
  }
397
432
 
@@ -445,7 +480,7 @@ async function discoverServerTools(
445
480
  return { tool_count: 0, error: errText };
446
481
  }
447
482
 
448
- const data = (await response.json()) as {
483
+ const data = (await parseJsonOrSse(response)) as {
449
484
  result?: { tools?: Array<{ name: string; description?: string; inputSchema?: unknown }> };
450
485
  error?: { message?: string };
451
486
  };