sunpeak 0.15.4 → 0.16.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.
Files changed (105) hide show
  1. package/README.md +53 -49
  2. package/bin/commands/build.mjs +119 -6
  3. package/bin/commands/dev.mjs +168 -27
  4. package/bin/commands/new.mjs +13 -3
  5. package/bin/commands/start.mjs +215 -0
  6. package/bin/lib/extract-resource.mjs +1 -1
  7. package/bin/lib/extract-tool.mjs +78 -0
  8. package/bin/lib/patterns.mjs +2 -26
  9. package/bin/sunpeak.js +11 -1
  10. package/dist/chatgpt/index.cjs +3 -6
  11. package/dist/chatgpt/index.cjs.map +1 -1
  12. package/dist/chatgpt/index.d.ts +1 -1
  13. package/dist/chatgpt/index.js +6 -9
  14. package/dist/claude/index.cjs +1 -1
  15. package/dist/claude/index.js +1 -1
  16. package/dist/discovery-CH80W5l9.js +217 -0
  17. package/dist/discovery-CH80W5l9.js.map +1 -0
  18. package/dist/discovery-DmB8_4QL.cjs +216 -0
  19. package/dist/discovery-DmB8_4QL.cjs.map +1 -0
  20. package/dist/{index-Cngntkp2.cjs → index-Bll1bszc.cjs} +3 -6
  21. package/dist/{index-Cngntkp2.cjs.map → index-Bll1bszc.cjs.map} +1 -1
  22. package/dist/{index-Ce_5ZIdJ.js → index-CACtnwu2.js} +3 -6
  23. package/dist/{index-Ce_5ZIdJ.js.map → index-CACtnwu2.js.map} +1 -1
  24. package/dist/{index-CutQgPzR.js → index-CLcr8IyR.js} +3 -6
  25. package/dist/index-CLcr8IyR.js.map +1 -0
  26. package/dist/{index-B0dxRJvS.cjs → index-CaQmwZJc.cjs} +3 -6
  27. package/dist/index-CaQmwZJc.cjs.map +1 -0
  28. package/dist/index.cjs +49 -6
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.ts +3 -0
  31. package/dist/index.js +3405 -3362
  32. package/dist/index.js.map +1 -1
  33. package/dist/lib/discovery-cli.cjs +58 -5
  34. package/dist/lib/discovery-cli.cjs.map +1 -1
  35. package/dist/lib/discovery-cli.d.ts +3 -2
  36. package/dist/lib/discovery-cli.js +61 -8
  37. package/dist/lib/discovery-cli.js.map +1 -1
  38. package/dist/lib/discovery.d.ts +42 -43
  39. package/dist/lib/extract-tool.d.ts +12 -0
  40. package/dist/mcp/favicon.d.ts +1 -1
  41. package/dist/mcp/index.cjs +1582 -5
  42. package/dist/mcp/index.cjs.map +1 -1
  43. package/dist/mcp/index.d.ts +3 -1
  44. package/dist/mcp/index.js +1583 -6
  45. package/dist/mcp/index.js.map +1 -1
  46. package/dist/mcp/production-server.d.ts +156 -0
  47. package/dist/mcp/types.d.ts +24 -1
  48. package/dist/platform/chatgpt/index.cjs +1 -1
  49. package/dist/platform/chatgpt/index.js +1 -1
  50. package/dist/{protocol-DFbsCx7E.js → protocol-BD5jDQEx.js} +8 -1
  51. package/dist/{protocol-DFbsCx7E.js.map → protocol-BD5jDQEx.js.map} +1 -1
  52. package/dist/{protocol-CL4_Npj5.cjs → protocol-BOjXuK6l.cjs} +8 -1
  53. package/dist/{protocol-CL4_Npj5.cjs.map → protocol-BOjXuK6l.cjs.map} +1 -1
  54. package/dist/simulator/index.cjs +2 -5
  55. package/dist/simulator/index.cjs.map +1 -1
  56. package/dist/simulator/index.d.ts +1 -1
  57. package/dist/simulator/index.js +5 -8
  58. package/dist/simulator/simulator-url.d.ts +9 -9
  59. package/dist/{simulator-CxrtnguM.js → simulator-B7rw83zP.js} +9 -3
  60. package/dist/{simulator-CxrtnguM.js.map → simulator-B7rw83zP.js.map} +1 -1
  61. package/dist/{simulator-DcfQBRXE.cjs → simulator-DjZNa1MI.cjs} +9 -3
  62. package/dist/{simulator-DcfQBRXE.cjs.map → simulator-DjZNa1MI.cjs.map} +1 -1
  63. package/dist/simulator-url-CuLqtnSS.js.map +1 -1
  64. package/dist/simulator-url-rgg_KYOg.cjs.map +1 -1
  65. package/dist/types/resource-config.d.ts +7 -5
  66. package/dist/{use-app-BnoSPiUT.cjs → use-app-BpAJqzdE.cjs} +50 -21
  67. package/dist/{use-app-BnoSPiUT.cjs.map → use-app-BpAJqzdE.cjs.map} +1 -1
  68. package/dist/{use-app-D_TeaMFG.js → use-app-WOUdh1PR.js} +52 -23
  69. package/dist/{use-app-D_TeaMFG.js.map → use-app-WOUdh1PR.js.map} +1 -1
  70. package/package.json +1 -1
  71. package/template/.sunpeak/dev.tsx +8 -4
  72. package/template/.sunpeak/resource-loader.tsx +2 -1
  73. package/template/README.md +27 -22
  74. package/template/package.json +3 -1
  75. package/template/src/resources/albums/{albums-resource.test.tsx → albums.test.tsx} +1 -1
  76. package/template/src/resources/albums/{albums-resource.tsx → albums.tsx} +0 -1
  77. package/template/src/resources/carousel/{carousel-resource.test.tsx → carousel.test.tsx} +1 -1
  78. package/template/src/resources/carousel/{carousel-resource.tsx → carousel.tsx} +0 -1
  79. package/template/src/resources/index.ts +4 -4
  80. package/template/src/resources/map/{map-resource.test.tsx → map.test.tsx} +1 -1
  81. package/template/src/resources/map/{map-resource.tsx → map.tsx} +0 -1
  82. package/template/src/resources/review/{review-resource.test.tsx → review.test.tsx} +1 -1
  83. package/template/src/resources/review/{review-resource.tsx → review.tsx} +1 -2
  84. package/template/src/server.ts +17 -0
  85. package/template/src/tools/review-diff.ts +24 -0
  86. package/template/src/tools/review-post.ts +26 -0
  87. package/template/src/tools/review-purchase.ts +31 -0
  88. package/template/src/tools/show-albums.ts +22 -0
  89. package/template/src/tools/show-carousel.ts +25 -0
  90. package/template/src/tools/show-map.ts +29 -0
  91. package/template/tests/e2e/albums.spec.ts +6 -6
  92. package/template/tests/e2e/carousel.spec.ts +6 -6
  93. package/template/tests/e2e/map.spec.ts +11 -11
  94. package/template/tests/simulations/{review/review-diff-simulation.json → review-diff.json} +1 -31
  95. package/template/tests/simulations/{review/review-post-simulation.json → review-post.json} +1 -37
  96. package/template/tests/simulations/{review/review-purchase-simulation.json → review-purchase.json} +1 -38
  97. package/template/tests/simulations/{albums/albums-show-simulation.json → show-albums.json} +1 -24
  98. package/template/tests/simulations/{carousel/carousel-show-simulation.json → show-carousel.json} +1 -24
  99. package/template/tests/simulations/{map/map-show-simulation.json → show-map.json} +1 -35
  100. package/dist/discovery-CRR3SlyI.cjs +0 -156
  101. package/dist/discovery-CRR3SlyI.cjs.map +0 -1
  102. package/dist/discovery-DzV3HLXs.js +0 -157
  103. package/dist/discovery-DzV3HLXs.js.map +0 -1
  104. package/dist/index-B0dxRJvS.cjs.map +0 -1
  105. package/dist/index-CutQgPzR.js.map +0 -1
@@ -0,0 +1,156 @@
1
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { AuthInfo, CallToolResult, ToolHandlerExtra } from './types.js';
4
+ /**
5
+ * A tool loaded from a compiled tool module (`dist/tools/*.js`).
6
+ */
7
+ export interface ProductionTool {
8
+ /** Tool name (derived from filename, e.g. 'show-albums') */
9
+ name: string;
10
+ /** Tool config from the `tool` export */
11
+ tool: {
12
+ resource: string;
13
+ title?: string;
14
+ description?: string;
15
+ annotations?: Record<string, unknown>;
16
+ _meta?: Record<string, unknown>;
17
+ };
18
+ /** Zod shape from the `schema` export (passed to SDK as inputSchema) */
19
+ schema?: Record<string, unknown>;
20
+ /** Handler from the `default` export */
21
+ handler: (args: Record<string, unknown>, extra: ToolHandlerExtra) => CallToolResult | Promise<CallToolResult> | string | Promise<string>;
22
+ }
23
+ /**
24
+ * A resource loaded from the build output (`dist/{name}/{name}.html` + `.json`).
25
+ */
26
+ export interface ProductionResource {
27
+ /** Resource name (from .json metadata) */
28
+ name: string;
29
+ /** Resource URI (from .json metadata, includes cache-bust timestamp) */
30
+ uri: string;
31
+ /** Pre-built HTML content (self-contained, JS+CSS inlined) */
32
+ html: string;
33
+ /** Resource _meta (CSP, permissions, domain, etc.) */
34
+ _meta?: Record<string, unknown>;
35
+ /** Resource description */
36
+ description?: string;
37
+ }
38
+ /**
39
+ * Auth function signature for `src/server.ts` (Node.js).
40
+ * Called on every MCP request. Return AuthInfo to authenticate, null to reject (401).
41
+ */
42
+ export type AuthFunction = (req: IncomingMessage) => Promise<AuthInfo | null> | AuthInfo | null;
43
+ /**
44
+ * Auth function signature for Web Standard handlers (Cloudflare Workers, Deno, Bun).
45
+ */
46
+ export type WebAuthFunction = (req: Request) => Promise<AuthInfo | null> | AuthInfo | null;
47
+ /**
48
+ * Configuration for creating a production MCP server and Node.js handler.
49
+ */
50
+ export interface ProductionServerConfig {
51
+ /** Server name reported to hosts */
52
+ name?: string;
53
+ /** Server version reported to hosts */
54
+ version?: string;
55
+ /** Tool registrations with real handlers */
56
+ tools: ProductionTool[];
57
+ /** Resource registrations with pre-built HTML */
58
+ resources: ProductionResource[];
59
+ /** Auth function from server entry (populates extra.authInfo via req.auth) */
60
+ auth?: AuthFunction;
61
+ }
62
+ /**
63
+ * Configuration for creating a Web Standard MCP handler (serverless/edge).
64
+ */
65
+ export interface WebHandlerConfig {
66
+ /** Server name reported to hosts */
67
+ name?: string;
68
+ /** Server version reported to hosts */
69
+ version?: string;
70
+ /** Tool registrations with real handlers */
71
+ tools: ProductionTool[];
72
+ /** Resource registrations with pre-built HTML */
73
+ resources: ProductionResource[];
74
+ /** Auth function for Web Standard Request objects */
75
+ auth?: WebAuthFunction;
76
+ }
77
+ /**
78
+ * Create an MCP server with production tool handlers and pre-built resources.
79
+ *
80
+ * Tools are registered with real Zod schemas (input validation) and handlers.
81
+ * Resources serve pre-built HTML with their _meta preserved.
82
+ */
83
+ export declare function createProductionMcpServer(config: ProductionServerConfig): McpServer;
84
+ /**
85
+ * Create a request handler that manages MCP sessions over Streamable HTTP.
86
+ *
87
+ * The returned handler responds to:
88
+ * - `POST /mcp` — Initialize a session or send messages
89
+ * - `GET /mcp` — Open an SSE stream for server-initiated notifications
90
+ * - `DELETE /mcp` — Terminate a session
91
+ * - `OPTIONS /mcp` — CORS preflight
92
+ *
93
+ * For any other request, the handler does nothing (doesn't write to `res`),
94
+ * so callers can chain it with their own routing.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * import express from 'express';
99
+ * import { createMcpHandler } from 'sunpeak/mcp';
100
+ *
101
+ * const app = express();
102
+ * app.get('/health', (req, res) => res.json({ ok: true }));
103
+ *
104
+ * const mcpHandler = createMcpHandler({ tools, resources, auth });
105
+ * app.use((req, res, next) => {
106
+ * mcpHandler(req, res).then(() => {
107
+ * if (!res.headersSent) next();
108
+ * });
109
+ * });
110
+ *
111
+ * app.listen(3000);
112
+ * ```
113
+ */
114
+ export declare function createMcpHandler(config: ProductionServerConfig): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
115
+ /**
116
+ * Create a Web Standard request handler for MCP over Streamable HTTP.
117
+ *
118
+ * Returns a `(req: Request) => Promise<Response>` handler that works on any
119
+ * Web Standard runtime: Cloudflare Workers, Deno, Bun, Vercel Edge, etc.
120
+ *
121
+ * Unlike `createMcpHandler`, this handler does NOT do path matching — it handles
122
+ * every request it receives. Mount it behind your own router.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * // Cloudflare Worker
127
+ * import { createHandler } from 'sunpeak/mcp';
128
+ *
129
+ * const handler = createHandler({ tools, resources, auth });
130
+ * export default { fetch: handler };
131
+ * ```
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * // Hono
136
+ * import { Hono } from 'hono';
137
+ * import { createHandler } from 'sunpeak/mcp';
138
+ *
139
+ * const app = new Hono();
140
+ * const handler = createHandler({ tools, resources });
141
+ * app.all('/mcp', (c) => handler(c.req.raw));
142
+ * export default app;
143
+ * ```
144
+ */
145
+ export declare function createHandler(config: WebHandlerConfig): (req: Request) => Promise<Response>;
146
+ /**
147
+ * Start a production HTTP server with Streamable HTTP transport.
148
+ *
149
+ * This is a convenience wrapper around `createMcpHandler` that adds
150
+ * a root HTML page, favicon, and graceful shutdown. For custom HTTP
151
+ * servers (Express, Fastify, etc.), use `createMcpHandler` directly.
152
+ *
153
+ * @param config - Production server configuration (tools, resources, auth)
154
+ * @param port - HTTP port to listen on
155
+ */
156
+ export declare function startProductionHttpServer(config: ProductionServerConfig, port: number): void;
@@ -1,4 +1,27 @@
1
- import { Resource, Tool } from '@modelcontextprotocol/sdk/types.js';
1
+ import { Resource, Tool, ServerRequest, ServerNotification } from '@modelcontextprotocol/sdk/types.js';
2
+ import { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
+ import { ToolConfig } from '@modelcontextprotocol/ext-apps/server';
4
+ export type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
5
+ export type { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js';
6
+ /**
7
+ * Extra context passed to tool handlers as the second argument.
8
+ *
9
+ * This is a pre-applied alias for the MCP SDK's `RequestHandlerExtra` —
10
+ * no custom fields, just ergonomic generics so users don't need to parameterize it.
11
+ *
12
+ * Key fields: `authInfo`, `sessionId`, `signal`, `_meta`.
13
+ */
14
+ export type ToolHandlerExtra = RequestHandlerExtra<ServerRequest, ServerNotification>;
15
+ /**
16
+ * Configuration for a Sunpeak tool file's `tool` export.
17
+ *
18
+ * Extends the ext-apps `ToolConfig` with a `resource` field that links
19
+ * the tool to a resource by its unique name string.
20
+ */
21
+ export interface AppToolConfig extends ToolConfig {
22
+ /** The resource name (must match a directory in `src/resources/`, e.g. `'albums'`). */
23
+ resource: string;
24
+ }
2
25
  /**
3
26
  * Simulation configuration for MCP server.
4
27
  * Must include distPath for the built HTML file.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
- const useApp = require("../../use-app-BnoSPiUT.cjs");
4
+ const useApp = require("../../use-app-BpAJqzdE.cjs");
5
5
  function getOpenAIRuntime() {
6
6
  if (typeof window !== "undefined" && "openai" in window) {
7
7
  return window.openai;
@@ -1,5 +1,5 @@
1
1
  import { useCallback } from "react";
2
- import { u as useApp } from "../../use-app-D_TeaMFG.js";
2
+ import { u as useApp } from "../../use-app-WOUdh1PR.js";
3
3
  function getOpenAIRuntime() {
4
4
  if (typeof window !== "undefined" && "openai" in window) {
5
5
  return window.openai;
@@ -7863,6 +7863,7 @@ function preprocess(fn, schema) {
7863
7863
  return pipe(transform(fn), schema);
7864
7864
  }
7865
7865
  const LATEST_PROTOCOL_VERSION = "2025-11-25";
7866
+ const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = "2025-03-26";
7866
7867
  const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, "2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"];
7867
7868
  const RELATED_TASK_META_KEY = "io.modelcontextprotocol/related-task";
7868
7869
  const JSONRPC_VERSION = "2.0";
@@ -8188,6 +8189,7 @@ const InitializeRequestSchema = RequestSchema.extend({
8188
8189
  method: literal("initialize"),
8189
8190
  params: InitializeRequestParamsSchema
8190
8191
  });
8192
+ const isInitializeRequest = (value) => InitializeRequestSchema.safeParse(value).success;
8191
8193
  const ServerCapabilitiesSchema = object({
8192
8194
  /**
8193
8195
  * Experimental, non-standard capabilities that the server supports.
@@ -11557,6 +11559,7 @@ function mergeCapabilities(base, additional) {
11557
11559
  return result;
11558
11560
  }
11559
11561
  export {
11562
+ isJSONRPCRequest as $,
11560
11563
  ListRootsResultSchema as A,
11561
11564
  safeParse$1 as B,
11562
11565
  ContentBlockSchema as C,
@@ -11583,7 +11586,11 @@ export {
11583
11586
  getLiteralValue as X,
11584
11587
  getSchemaDescription as Y,
11585
11588
  isSchemaOptional as Z,
11589
+ isInitializeRequest as _,
11586
11590
  CallToolResultSchema as a,
11591
+ DEFAULT_NEGOTIATED_PROTOCOL_VERSION as a0,
11592
+ isJSONRPCResultResponse as a1,
11593
+ isJSONRPCErrorResponse as a2,
11587
11594
  PingRequestSchema as b,
11588
11595
  CallToolRequestSchema as c,
11589
11596
  LoggingMessageNotificationSchema as d,
@@ -11610,4 +11617,4 @@ export {
11610
11617
  ElicitResultSchema as y,
11611
11618
  ErrorCode as z
11612
11619
  };
11613
- //# sourceMappingURL=protocol-DFbsCx7E.js.map
11620
+ //# sourceMappingURL=protocol-BD5jDQEx.js.map