sunpeak 0.5.20 → 0.5.23
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 +9 -4
- package/{cli → bin/commands}/build.mjs +1 -10
- package/bin/commands/dev.mjs +79 -0
- package/bin/commands/mcp.mjs +75 -0
- package/bin/sunpeak.js +28 -71
- package/bin/utils.mjs +12 -0
- package/dist/dev/entry.d.ts +0 -0
- package/dist/mcp/entry.cjs +29 -0
- package/dist/mcp/entry.cjs.map +1 -0
- package/dist/mcp/entry.d.ts +2 -0
- package/dist/mcp/entry.js +28 -0
- package/dist/mcp/entry.js.map +1 -0
- package/dist/mcp/index.cjs +2 -920
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.js +2 -920
- package/dist/mcp/index.js.map +1 -1
- package/dist/server-DpriZ4jT.cjs +922 -0
- package/dist/server-DpriZ4jT.cjs.map +1 -0
- package/dist/server-SBlanUcf.js +923 -0
- package/dist/server-SBlanUcf.js.map +1 -0
- package/package.json +5 -2
- package/{template/dev/main.tsx → src/dev/entry.tsx} +20 -8
- package/src/vite-env.d.ts +10 -0
- package/template/.sunpeak/dev.tsx +5 -0
- package/template/README.md +17 -35
- package/template/index.html +2 -2
- package/template/node_modules/.vite/deps/@openai_apps-sdk-ui_components_Button.js +3 -3
- package/template/node_modules/.vite/deps/@openai_apps-sdk-ui_components_SegmentedControl.js +1 -1
- package/template/node_modules/.vite/deps/@openai_apps-sdk-ui_components_Select.js +11 -11
- package/template/node_modules/.vite/deps/@openai_apps-sdk-ui_components_Textarea.js +3 -3
- package/template/node_modules/.vite/deps/_metadata.json +34 -34
- package/template/node_modules/.vite/deps/{chunk-EVJ3DVH5.js → chunk-LR7NKCX5.js} +7 -7
- package/template/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -1
- package/template/nodemon.json +1 -1
- package/template/package.json +3 -16
- package/template/src/components/album/albums.tsx +2 -2
- package/template/src/dev/entry.tsx +0 -0
- package/template/src/mcp/entry.ts +0 -0
- package/template/src/simulations/index.ts +3 -3
- package/cli/validate.mjs +0 -245
- package/template/_prettierignore +0 -4
- package/template/_prettierrc +0 -9
- package/template/eslint.config.cjs +0 -49
- package/template/mcp/server.ts +0 -19
- package/template/node_modules/.bin/eslint +0 -21
- package/template/node_modules/.bin/eslint-config-prettier +0 -21
- package/template/node_modules/.bin/prettier +0 -21
- package/template/node_modules/.bin/ts-node +0 -21
- package/template/node_modules/.bin/ts-node-cwd +0 -21
- package/template/node_modules/.bin/ts-node-esm +0 -21
- package/template/node_modules/.bin/ts-node-script +0 -21
- package/template/node_modules/.bin/ts-node-transpile-only +0 -21
- package/template/node_modules/.bin/ts-script +0 -21
- /package/template/node_modules/.vite/deps/{chunk-EVJ3DVH5.js.map → chunk-LR7NKCX5.js.map} +0 -0
- /package/template/{assets → public}/favicon.ico +0 -0
package/dist/mcp/index.cjs
CHANGED
|
@@ -1,923 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const fs = require("node:fs");
|
|
6
|
-
const path = require("node:path");
|
|
7
|
-
const index_js = require("@modelcontextprotocol/sdk/server/index.js");
|
|
8
|
-
const sse_js = require("@modelcontextprotocol/sdk/server/sse.js");
|
|
9
|
-
const zod = require("zod");
|
|
10
|
-
const JSONRPC_VERSION = "2.0";
|
|
11
|
-
const ProgressTokenSchema = zod.z.union([zod.z.string(), zod.z.number().int()]);
|
|
12
|
-
const CursorSchema = zod.z.string();
|
|
13
|
-
const BaseRequestParamsSchema = zod.z.object({
|
|
14
|
-
_meta: zod.z.optional(zod.z.object({
|
|
15
|
-
/**
|
|
16
|
-
* If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
|
|
17
|
-
*/
|
|
18
|
-
progressToken: zod.z.optional(ProgressTokenSchema)
|
|
19
|
-
}).passthrough())
|
|
20
|
-
}).passthrough();
|
|
21
|
-
const RequestSchema = zod.z.object({
|
|
22
|
-
method: zod.z.string(),
|
|
23
|
-
params: zod.z.optional(BaseRequestParamsSchema)
|
|
24
|
-
});
|
|
25
|
-
const BaseNotificationParamsSchema = zod.z.object({
|
|
26
|
-
/**
|
|
27
|
-
* This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications.
|
|
28
|
-
*/
|
|
29
|
-
_meta: zod.z.optional(zod.z.object({}).passthrough())
|
|
30
|
-
}).passthrough();
|
|
31
|
-
const NotificationSchema = zod.z.object({
|
|
32
|
-
method: zod.z.string(),
|
|
33
|
-
params: zod.z.optional(BaseNotificationParamsSchema)
|
|
34
|
-
});
|
|
35
|
-
const ResultSchema = zod.z.object({
|
|
36
|
-
/**
|
|
37
|
-
* This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses.
|
|
38
|
-
*/
|
|
39
|
-
_meta: zod.z.optional(zod.z.object({}).passthrough())
|
|
40
|
-
}).passthrough();
|
|
41
|
-
const RequestIdSchema = zod.z.union([zod.z.string(), zod.z.number().int()]);
|
|
42
|
-
const JSONRPCRequestSchema = zod.z.object({
|
|
43
|
-
jsonrpc: zod.z.literal(JSONRPC_VERSION),
|
|
44
|
-
id: RequestIdSchema
|
|
45
|
-
}).merge(RequestSchema).strict();
|
|
46
|
-
const JSONRPCNotificationSchema = zod.z.object({
|
|
47
|
-
jsonrpc: zod.z.literal(JSONRPC_VERSION)
|
|
48
|
-
}).merge(NotificationSchema).strict();
|
|
49
|
-
const JSONRPCResponseSchema = zod.z.object({
|
|
50
|
-
jsonrpc: zod.z.literal(JSONRPC_VERSION),
|
|
51
|
-
id: RequestIdSchema,
|
|
52
|
-
result: ResultSchema
|
|
53
|
-
}).strict();
|
|
54
|
-
var ErrorCode;
|
|
55
|
-
(function(ErrorCode2) {
|
|
56
|
-
ErrorCode2[ErrorCode2["ConnectionClosed"] = -1] = "ConnectionClosed";
|
|
57
|
-
ErrorCode2[ErrorCode2["ParseError"] = -32700] = "ParseError";
|
|
58
|
-
ErrorCode2[ErrorCode2["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
59
|
-
ErrorCode2[ErrorCode2["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
60
|
-
ErrorCode2[ErrorCode2["InvalidParams"] = -32602] = "InvalidParams";
|
|
61
|
-
ErrorCode2[ErrorCode2["InternalError"] = -32603] = "InternalError";
|
|
62
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
63
|
-
const JSONRPCErrorSchema = zod.z.object({
|
|
64
|
-
jsonrpc: zod.z.literal(JSONRPC_VERSION),
|
|
65
|
-
id: RequestIdSchema,
|
|
66
|
-
error: zod.z.object({
|
|
67
|
-
/**
|
|
68
|
-
* The error type that occurred.
|
|
69
|
-
*/
|
|
70
|
-
code: zod.z.number().int(),
|
|
71
|
-
/**
|
|
72
|
-
* A short description of the error. The message SHOULD be limited to a concise single sentence.
|
|
73
|
-
*/
|
|
74
|
-
message: zod.z.string(),
|
|
75
|
-
/**
|
|
76
|
-
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
|
|
77
|
-
*/
|
|
78
|
-
data: zod.z.optional(zod.z.unknown())
|
|
79
|
-
})
|
|
80
|
-
}).strict();
|
|
81
|
-
zod.z.union([
|
|
82
|
-
JSONRPCRequestSchema,
|
|
83
|
-
JSONRPCNotificationSchema,
|
|
84
|
-
JSONRPCResponseSchema,
|
|
85
|
-
JSONRPCErrorSchema
|
|
86
|
-
]);
|
|
87
|
-
const EmptyResultSchema = ResultSchema.strict();
|
|
88
|
-
const CancelledNotificationSchema = NotificationSchema.extend({
|
|
89
|
-
method: zod.z.literal("notifications/cancelled"),
|
|
90
|
-
params: BaseNotificationParamsSchema.extend({
|
|
91
|
-
/**
|
|
92
|
-
* The ID of the request to cancel.
|
|
93
|
-
*
|
|
94
|
-
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
95
|
-
*/
|
|
96
|
-
requestId: RequestIdSchema,
|
|
97
|
-
/**
|
|
98
|
-
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
99
|
-
*/
|
|
100
|
-
reason: zod.z.string().optional()
|
|
101
|
-
})
|
|
102
|
-
});
|
|
103
|
-
const ImplementationSchema = zod.z.object({
|
|
104
|
-
name: zod.z.string(),
|
|
105
|
-
version: zod.z.string()
|
|
106
|
-
}).passthrough();
|
|
107
|
-
const ClientCapabilitiesSchema = zod.z.object({
|
|
108
|
-
/**
|
|
109
|
-
* Experimental, non-standard capabilities that the client supports.
|
|
110
|
-
*/
|
|
111
|
-
experimental: zod.z.optional(zod.z.object({}).passthrough()),
|
|
112
|
-
/**
|
|
113
|
-
* Present if the client supports sampling from an LLM.
|
|
114
|
-
*/
|
|
115
|
-
sampling: zod.z.optional(zod.z.object({}).passthrough()),
|
|
116
|
-
/**
|
|
117
|
-
* Present if the client supports listing roots.
|
|
118
|
-
*/
|
|
119
|
-
roots: zod.z.optional(zod.z.object({
|
|
120
|
-
/**
|
|
121
|
-
* Whether the client supports issuing notifications for changes to the roots list.
|
|
122
|
-
*/
|
|
123
|
-
listChanged: zod.z.optional(zod.z.boolean())
|
|
124
|
-
}).passthrough())
|
|
125
|
-
}).passthrough();
|
|
126
|
-
const InitializeRequestSchema = RequestSchema.extend({
|
|
127
|
-
method: zod.z.literal("initialize"),
|
|
128
|
-
params: BaseRequestParamsSchema.extend({
|
|
129
|
-
/**
|
|
130
|
-
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
|
|
131
|
-
*/
|
|
132
|
-
protocolVersion: zod.z.string(),
|
|
133
|
-
capabilities: ClientCapabilitiesSchema,
|
|
134
|
-
clientInfo: ImplementationSchema
|
|
135
|
-
})
|
|
136
|
-
});
|
|
137
|
-
const ServerCapabilitiesSchema = zod.z.object({
|
|
138
|
-
/**
|
|
139
|
-
* Experimental, non-standard capabilities that the server supports.
|
|
140
|
-
*/
|
|
141
|
-
experimental: zod.z.optional(zod.z.object({}).passthrough()),
|
|
142
|
-
/**
|
|
143
|
-
* Present if the server supports sending log messages to the client.
|
|
144
|
-
*/
|
|
145
|
-
logging: zod.z.optional(zod.z.object({}).passthrough()),
|
|
146
|
-
/**
|
|
147
|
-
* Present if the server offers any prompt templates.
|
|
148
|
-
*/
|
|
149
|
-
prompts: zod.z.optional(zod.z.object({
|
|
150
|
-
/**
|
|
151
|
-
* Whether this server supports issuing notifications for changes to the prompt list.
|
|
152
|
-
*/
|
|
153
|
-
listChanged: zod.z.optional(zod.z.boolean())
|
|
154
|
-
}).passthrough()),
|
|
155
|
-
/**
|
|
156
|
-
* Present if the server offers any resources to read.
|
|
157
|
-
*/
|
|
158
|
-
resources: zod.z.optional(zod.z.object({
|
|
159
|
-
/**
|
|
160
|
-
* Whether this server supports clients subscribing to resource updates.
|
|
161
|
-
*/
|
|
162
|
-
subscribe: zod.z.optional(zod.z.boolean()),
|
|
163
|
-
/**
|
|
164
|
-
* Whether this server supports issuing notifications for changes to the resource list.
|
|
165
|
-
*/
|
|
166
|
-
listChanged: zod.z.optional(zod.z.boolean())
|
|
167
|
-
}).passthrough()),
|
|
168
|
-
/**
|
|
169
|
-
* Present if the server offers any tools to call.
|
|
170
|
-
*/
|
|
171
|
-
tools: zod.z.optional(zod.z.object({
|
|
172
|
-
/**
|
|
173
|
-
* Whether this server supports issuing notifications for changes to the tool list.
|
|
174
|
-
*/
|
|
175
|
-
listChanged: zod.z.optional(zod.z.boolean())
|
|
176
|
-
}).passthrough())
|
|
177
|
-
}).passthrough();
|
|
178
|
-
const InitializeResultSchema = ResultSchema.extend({
|
|
179
|
-
/**
|
|
180
|
-
* The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect.
|
|
181
|
-
*/
|
|
182
|
-
protocolVersion: zod.z.string(),
|
|
183
|
-
capabilities: ServerCapabilitiesSchema,
|
|
184
|
-
serverInfo: ImplementationSchema
|
|
185
|
-
});
|
|
186
|
-
const InitializedNotificationSchema = NotificationSchema.extend({
|
|
187
|
-
method: zod.z.literal("notifications/initialized")
|
|
188
|
-
});
|
|
189
|
-
const PingRequestSchema = RequestSchema.extend({
|
|
190
|
-
method: zod.z.literal("ping")
|
|
191
|
-
});
|
|
192
|
-
const ProgressSchema = zod.z.object({
|
|
193
|
-
/**
|
|
194
|
-
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
195
|
-
*/
|
|
196
|
-
progress: zod.z.number(),
|
|
197
|
-
/**
|
|
198
|
-
* Total number of items to process (or total progress required), if known.
|
|
199
|
-
*/
|
|
200
|
-
total: zod.z.optional(zod.z.number())
|
|
201
|
-
}).passthrough();
|
|
202
|
-
const ProgressNotificationSchema = NotificationSchema.extend({
|
|
203
|
-
method: zod.z.literal("notifications/progress"),
|
|
204
|
-
params: BaseNotificationParamsSchema.merge(ProgressSchema).extend({
|
|
205
|
-
/**
|
|
206
|
-
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
|
|
207
|
-
*/
|
|
208
|
-
progressToken: ProgressTokenSchema
|
|
209
|
-
})
|
|
210
|
-
});
|
|
211
|
-
const PaginatedRequestSchema = RequestSchema.extend({
|
|
212
|
-
params: BaseRequestParamsSchema.extend({
|
|
213
|
-
/**
|
|
214
|
-
* An opaque token representing the current pagination position.
|
|
215
|
-
* If provided, the server should return results starting after this cursor.
|
|
216
|
-
*/
|
|
217
|
-
cursor: zod.z.optional(CursorSchema)
|
|
218
|
-
}).optional()
|
|
219
|
-
});
|
|
220
|
-
const PaginatedResultSchema = ResultSchema.extend({
|
|
221
|
-
/**
|
|
222
|
-
* An opaque token representing the pagination position after the last returned result.
|
|
223
|
-
* If present, there may be more results available.
|
|
224
|
-
*/
|
|
225
|
-
nextCursor: zod.z.optional(CursorSchema)
|
|
226
|
-
});
|
|
227
|
-
const ResourceContentsSchema = zod.z.object({
|
|
228
|
-
/**
|
|
229
|
-
* The URI of this resource.
|
|
230
|
-
*/
|
|
231
|
-
uri: zod.z.string(),
|
|
232
|
-
/**
|
|
233
|
-
* The MIME type of this resource, if known.
|
|
234
|
-
*/
|
|
235
|
-
mimeType: zod.z.optional(zod.z.string())
|
|
236
|
-
}).passthrough();
|
|
237
|
-
const TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
238
|
-
/**
|
|
239
|
-
* The text of the item. This must only be set if the item can actually be represented as text (not binary data).
|
|
240
|
-
*/
|
|
241
|
-
text: zod.z.string()
|
|
242
|
-
});
|
|
243
|
-
const BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
244
|
-
/**
|
|
245
|
-
* A base64-encoded string representing the binary data of the item.
|
|
246
|
-
*/
|
|
247
|
-
blob: zod.z.string().base64()
|
|
248
|
-
});
|
|
249
|
-
const ResourceSchema = zod.z.object({
|
|
250
|
-
/**
|
|
251
|
-
* The URI of this resource.
|
|
252
|
-
*/
|
|
253
|
-
uri: zod.z.string(),
|
|
254
|
-
/**
|
|
255
|
-
* A human-readable name for this resource.
|
|
256
|
-
*
|
|
257
|
-
* This can be used by clients to populate UI elements.
|
|
258
|
-
*/
|
|
259
|
-
name: zod.z.string(),
|
|
260
|
-
/**
|
|
261
|
-
* A description of what this resource represents.
|
|
262
|
-
*
|
|
263
|
-
* This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
|
|
264
|
-
*/
|
|
265
|
-
description: zod.z.optional(zod.z.string()),
|
|
266
|
-
/**
|
|
267
|
-
* The MIME type of this resource, if known.
|
|
268
|
-
*/
|
|
269
|
-
mimeType: zod.z.optional(zod.z.string())
|
|
270
|
-
}).passthrough();
|
|
271
|
-
const ResourceTemplateSchema = zod.z.object({
|
|
272
|
-
/**
|
|
273
|
-
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
|
|
274
|
-
*/
|
|
275
|
-
uriTemplate: zod.z.string(),
|
|
276
|
-
/**
|
|
277
|
-
* A human-readable name for the type of resource this template refers to.
|
|
278
|
-
*
|
|
279
|
-
* This can be used by clients to populate UI elements.
|
|
280
|
-
*/
|
|
281
|
-
name: zod.z.string(),
|
|
282
|
-
/**
|
|
283
|
-
* A description of what this template is for.
|
|
284
|
-
*
|
|
285
|
-
* This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
|
|
286
|
-
*/
|
|
287
|
-
description: zod.z.optional(zod.z.string()),
|
|
288
|
-
/**
|
|
289
|
-
* The MIME type for all resources that match this template. This should only be included if all resources matching this template have the same type.
|
|
290
|
-
*/
|
|
291
|
-
mimeType: zod.z.optional(zod.z.string())
|
|
292
|
-
}).passthrough();
|
|
293
|
-
const ListResourcesRequestSchema = PaginatedRequestSchema.extend({
|
|
294
|
-
method: zod.z.literal("resources/list")
|
|
295
|
-
});
|
|
296
|
-
const ListResourcesResultSchema = PaginatedResultSchema.extend({
|
|
297
|
-
resources: zod.z.array(ResourceSchema)
|
|
298
|
-
});
|
|
299
|
-
const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({
|
|
300
|
-
method: zod.z.literal("resources/templates/list")
|
|
301
|
-
});
|
|
302
|
-
const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({
|
|
303
|
-
resourceTemplates: zod.z.array(ResourceTemplateSchema)
|
|
304
|
-
});
|
|
305
|
-
const ReadResourceRequestSchema = RequestSchema.extend({
|
|
306
|
-
method: zod.z.literal("resources/read"),
|
|
307
|
-
params: BaseRequestParamsSchema.extend({
|
|
308
|
-
/**
|
|
309
|
-
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
|
|
310
|
-
*/
|
|
311
|
-
uri: zod.z.string()
|
|
312
|
-
})
|
|
313
|
-
});
|
|
314
|
-
const ReadResourceResultSchema = ResultSchema.extend({
|
|
315
|
-
contents: zod.z.array(zod.z.union([TextResourceContentsSchema, BlobResourceContentsSchema]))
|
|
316
|
-
});
|
|
317
|
-
const ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
318
|
-
method: zod.z.literal("notifications/resources/list_changed")
|
|
319
|
-
});
|
|
320
|
-
const SubscribeRequestSchema = RequestSchema.extend({
|
|
321
|
-
method: zod.z.literal("resources/subscribe"),
|
|
322
|
-
params: BaseRequestParamsSchema.extend({
|
|
323
|
-
/**
|
|
324
|
-
* The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
|
|
325
|
-
*/
|
|
326
|
-
uri: zod.z.string()
|
|
327
|
-
})
|
|
328
|
-
});
|
|
329
|
-
const UnsubscribeRequestSchema = RequestSchema.extend({
|
|
330
|
-
method: zod.z.literal("resources/unsubscribe"),
|
|
331
|
-
params: BaseRequestParamsSchema.extend({
|
|
332
|
-
/**
|
|
333
|
-
* The URI of the resource to unsubscribe from.
|
|
334
|
-
*/
|
|
335
|
-
uri: zod.z.string()
|
|
336
|
-
})
|
|
337
|
-
});
|
|
338
|
-
const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
|
|
339
|
-
method: zod.z.literal("notifications/resources/updated"),
|
|
340
|
-
params: BaseNotificationParamsSchema.extend({
|
|
341
|
-
/**
|
|
342
|
-
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
|
|
343
|
-
*/
|
|
344
|
-
uri: zod.z.string()
|
|
345
|
-
})
|
|
346
|
-
});
|
|
347
|
-
const PromptArgumentSchema = zod.z.object({
|
|
348
|
-
/**
|
|
349
|
-
* The name of the argument.
|
|
350
|
-
*/
|
|
351
|
-
name: zod.z.string(),
|
|
352
|
-
/**
|
|
353
|
-
* A human-readable description of the argument.
|
|
354
|
-
*/
|
|
355
|
-
description: zod.z.optional(zod.z.string()),
|
|
356
|
-
/**
|
|
357
|
-
* Whether this argument must be provided.
|
|
358
|
-
*/
|
|
359
|
-
required: zod.z.optional(zod.z.boolean())
|
|
360
|
-
}).passthrough();
|
|
361
|
-
const PromptSchema = zod.z.object({
|
|
362
|
-
/**
|
|
363
|
-
* The name of the prompt or prompt template.
|
|
364
|
-
*/
|
|
365
|
-
name: zod.z.string(),
|
|
366
|
-
/**
|
|
367
|
-
* An optional description of what this prompt provides
|
|
368
|
-
*/
|
|
369
|
-
description: zod.z.optional(zod.z.string()),
|
|
370
|
-
/**
|
|
371
|
-
* A list of arguments to use for templating the prompt.
|
|
372
|
-
*/
|
|
373
|
-
arguments: zod.z.optional(zod.z.array(PromptArgumentSchema))
|
|
374
|
-
}).passthrough();
|
|
375
|
-
const ListPromptsRequestSchema = PaginatedRequestSchema.extend({
|
|
376
|
-
method: zod.z.literal("prompts/list")
|
|
377
|
-
});
|
|
378
|
-
const ListPromptsResultSchema = PaginatedResultSchema.extend({
|
|
379
|
-
prompts: zod.z.array(PromptSchema)
|
|
380
|
-
});
|
|
381
|
-
const GetPromptRequestSchema = RequestSchema.extend({
|
|
382
|
-
method: zod.z.literal("prompts/get"),
|
|
383
|
-
params: BaseRequestParamsSchema.extend({
|
|
384
|
-
/**
|
|
385
|
-
* The name of the prompt or prompt template.
|
|
386
|
-
*/
|
|
387
|
-
name: zod.z.string(),
|
|
388
|
-
/**
|
|
389
|
-
* Arguments to use for templating the prompt.
|
|
390
|
-
*/
|
|
391
|
-
arguments: zod.z.optional(zod.z.record(zod.z.string()))
|
|
392
|
-
})
|
|
393
|
-
});
|
|
394
|
-
const TextContentSchema = zod.z.object({
|
|
395
|
-
type: zod.z.literal("text"),
|
|
396
|
-
/**
|
|
397
|
-
* The text content of the message.
|
|
398
|
-
*/
|
|
399
|
-
text: zod.z.string()
|
|
400
|
-
}).passthrough();
|
|
401
|
-
const ImageContentSchema = zod.z.object({
|
|
402
|
-
type: zod.z.literal("image"),
|
|
403
|
-
/**
|
|
404
|
-
* The base64-encoded image data.
|
|
405
|
-
*/
|
|
406
|
-
data: zod.z.string().base64(),
|
|
407
|
-
/**
|
|
408
|
-
* The MIME type of the image. Different providers may support different image types.
|
|
409
|
-
*/
|
|
410
|
-
mimeType: zod.z.string()
|
|
411
|
-
}).passthrough();
|
|
412
|
-
const EmbeddedResourceSchema = zod.z.object({
|
|
413
|
-
type: zod.z.literal("resource"),
|
|
414
|
-
resource: zod.z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
|
|
415
|
-
}).passthrough();
|
|
416
|
-
const PromptMessageSchema = zod.z.object({
|
|
417
|
-
role: zod.z.enum(["user", "assistant"]),
|
|
418
|
-
content: zod.z.union([
|
|
419
|
-
TextContentSchema,
|
|
420
|
-
ImageContentSchema,
|
|
421
|
-
EmbeddedResourceSchema
|
|
422
|
-
])
|
|
423
|
-
}).passthrough();
|
|
424
|
-
const GetPromptResultSchema = ResultSchema.extend({
|
|
425
|
-
/**
|
|
426
|
-
* An optional description for the prompt.
|
|
427
|
-
*/
|
|
428
|
-
description: zod.z.optional(zod.z.string()),
|
|
429
|
-
messages: zod.z.array(PromptMessageSchema)
|
|
430
|
-
});
|
|
431
|
-
const PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
432
|
-
method: zod.z.literal("notifications/prompts/list_changed")
|
|
433
|
-
});
|
|
434
|
-
const ToolSchema = zod.z.object({
|
|
435
|
-
/**
|
|
436
|
-
* The name of the tool.
|
|
437
|
-
*/
|
|
438
|
-
name: zod.z.string(),
|
|
439
|
-
/**
|
|
440
|
-
* A human-readable description of the tool.
|
|
441
|
-
*/
|
|
442
|
-
description: zod.z.optional(zod.z.string()),
|
|
443
|
-
/**
|
|
444
|
-
* A JSON Schema object defining the expected parameters for the tool.
|
|
445
|
-
*/
|
|
446
|
-
inputSchema: zod.z.object({
|
|
447
|
-
type: zod.z.literal("object"),
|
|
448
|
-
properties: zod.z.optional(zod.z.object({}).passthrough())
|
|
449
|
-
}).passthrough()
|
|
450
|
-
}).passthrough();
|
|
451
|
-
const ListToolsRequestSchema = PaginatedRequestSchema.extend({
|
|
452
|
-
method: zod.z.literal("tools/list")
|
|
453
|
-
});
|
|
454
|
-
const ListToolsResultSchema = PaginatedResultSchema.extend({
|
|
455
|
-
tools: zod.z.array(ToolSchema)
|
|
456
|
-
});
|
|
457
|
-
const CallToolResultSchema = ResultSchema.extend({
|
|
458
|
-
content: zod.z.array(zod.z.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])),
|
|
459
|
-
isError: zod.z.boolean().default(false).optional()
|
|
460
|
-
});
|
|
461
|
-
CallToolResultSchema.or(ResultSchema.extend({
|
|
462
|
-
toolResult: zod.z.unknown()
|
|
463
|
-
}));
|
|
464
|
-
const CallToolRequestSchema = RequestSchema.extend({
|
|
465
|
-
method: zod.z.literal("tools/call"),
|
|
466
|
-
params: BaseRequestParamsSchema.extend({
|
|
467
|
-
name: zod.z.string(),
|
|
468
|
-
arguments: zod.z.optional(zod.z.record(zod.z.unknown()))
|
|
469
|
-
})
|
|
470
|
-
});
|
|
471
|
-
const ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
472
|
-
method: zod.z.literal("notifications/tools/list_changed")
|
|
473
|
-
});
|
|
474
|
-
const LoggingLevelSchema = zod.z.enum([
|
|
475
|
-
"debug",
|
|
476
|
-
"info",
|
|
477
|
-
"notice",
|
|
478
|
-
"warning",
|
|
479
|
-
"error",
|
|
480
|
-
"critical",
|
|
481
|
-
"alert",
|
|
482
|
-
"emergency"
|
|
483
|
-
]);
|
|
484
|
-
const SetLevelRequestSchema = RequestSchema.extend({
|
|
485
|
-
method: zod.z.literal("logging/setLevel"),
|
|
486
|
-
params: BaseRequestParamsSchema.extend({
|
|
487
|
-
/**
|
|
488
|
-
* The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.
|
|
489
|
-
*/
|
|
490
|
-
level: LoggingLevelSchema
|
|
491
|
-
})
|
|
492
|
-
});
|
|
493
|
-
const LoggingMessageNotificationSchema = NotificationSchema.extend({
|
|
494
|
-
method: zod.z.literal("notifications/message"),
|
|
495
|
-
params: BaseNotificationParamsSchema.extend({
|
|
496
|
-
/**
|
|
497
|
-
* The severity of this log message.
|
|
498
|
-
*/
|
|
499
|
-
level: LoggingLevelSchema,
|
|
500
|
-
/**
|
|
501
|
-
* An optional name of the logger issuing this message.
|
|
502
|
-
*/
|
|
503
|
-
logger: zod.z.optional(zod.z.string()),
|
|
504
|
-
/**
|
|
505
|
-
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
|
|
506
|
-
*/
|
|
507
|
-
data: zod.z.unknown()
|
|
508
|
-
})
|
|
509
|
-
});
|
|
510
|
-
const ModelHintSchema = zod.z.object({
|
|
511
|
-
/**
|
|
512
|
-
* A hint for a model name.
|
|
513
|
-
*/
|
|
514
|
-
name: zod.z.string().optional()
|
|
515
|
-
}).passthrough();
|
|
516
|
-
const ModelPreferencesSchema = zod.z.object({
|
|
517
|
-
/**
|
|
518
|
-
* Optional hints to use for model selection.
|
|
519
|
-
*/
|
|
520
|
-
hints: zod.z.optional(zod.z.array(ModelHintSchema)),
|
|
521
|
-
/**
|
|
522
|
-
* How much to prioritize cost when selecting a model.
|
|
523
|
-
*/
|
|
524
|
-
costPriority: zod.z.optional(zod.z.number().min(0).max(1)),
|
|
525
|
-
/**
|
|
526
|
-
* How much to prioritize sampling speed (latency) when selecting a model.
|
|
527
|
-
*/
|
|
528
|
-
speedPriority: zod.z.optional(zod.z.number().min(0).max(1)),
|
|
529
|
-
/**
|
|
530
|
-
* How much to prioritize intelligence and capabilities when selecting a model.
|
|
531
|
-
*/
|
|
532
|
-
intelligencePriority: zod.z.optional(zod.z.number().min(0).max(1))
|
|
533
|
-
}).passthrough();
|
|
534
|
-
const SamplingMessageSchema = zod.z.object({
|
|
535
|
-
role: zod.z.enum(["user", "assistant"]),
|
|
536
|
-
content: zod.z.union([TextContentSchema, ImageContentSchema])
|
|
537
|
-
}).passthrough();
|
|
538
|
-
const CreateMessageRequestSchema = RequestSchema.extend({
|
|
539
|
-
method: zod.z.literal("sampling/createMessage"),
|
|
540
|
-
params: BaseRequestParamsSchema.extend({
|
|
541
|
-
messages: zod.z.array(SamplingMessageSchema),
|
|
542
|
-
/**
|
|
543
|
-
* An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
|
|
544
|
-
*/
|
|
545
|
-
systemPrompt: zod.z.optional(zod.z.string()),
|
|
546
|
-
/**
|
|
547
|
-
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.
|
|
548
|
-
*/
|
|
549
|
-
includeContext: zod.z.optional(zod.z.enum(["none", "thisServer", "allServers"])),
|
|
550
|
-
temperature: zod.z.optional(zod.z.number()),
|
|
551
|
-
/**
|
|
552
|
-
* The maximum number of tokens to sample, as requested by the server. The client MAY choose to sample fewer tokens than requested.
|
|
553
|
-
*/
|
|
554
|
-
maxTokens: zod.z.number().int(),
|
|
555
|
-
stopSequences: zod.z.optional(zod.z.array(zod.z.string())),
|
|
556
|
-
/**
|
|
557
|
-
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
558
|
-
*/
|
|
559
|
-
metadata: zod.z.optional(zod.z.object({}).passthrough()),
|
|
560
|
-
/**
|
|
561
|
-
* The server's preferences for which model to select.
|
|
562
|
-
*/
|
|
563
|
-
modelPreferences: zod.z.optional(ModelPreferencesSchema)
|
|
564
|
-
})
|
|
565
|
-
});
|
|
566
|
-
const CreateMessageResultSchema = ResultSchema.extend({
|
|
567
|
-
/**
|
|
568
|
-
* The name of the model that generated the message.
|
|
569
|
-
*/
|
|
570
|
-
model: zod.z.string(),
|
|
571
|
-
/**
|
|
572
|
-
* The reason why sampling stopped.
|
|
573
|
-
*/
|
|
574
|
-
stopReason: zod.z.optional(zod.z.enum(["endTurn", "stopSequence", "maxTokens"]).or(zod.z.string())),
|
|
575
|
-
role: zod.z.enum(["user", "assistant"]),
|
|
576
|
-
content: zod.z.discriminatedUnion("type", [
|
|
577
|
-
TextContentSchema,
|
|
578
|
-
ImageContentSchema
|
|
579
|
-
])
|
|
580
|
-
});
|
|
581
|
-
const ResourceReferenceSchema = zod.z.object({
|
|
582
|
-
type: zod.z.literal("ref/resource"),
|
|
583
|
-
/**
|
|
584
|
-
* The URI or URI template of the resource.
|
|
585
|
-
*/
|
|
586
|
-
uri: zod.z.string()
|
|
587
|
-
}).passthrough();
|
|
588
|
-
const PromptReferenceSchema = zod.z.object({
|
|
589
|
-
type: zod.z.literal("ref/prompt"),
|
|
590
|
-
/**
|
|
591
|
-
* The name of the prompt or prompt template
|
|
592
|
-
*/
|
|
593
|
-
name: zod.z.string()
|
|
594
|
-
}).passthrough();
|
|
595
|
-
const CompleteRequestSchema = RequestSchema.extend({
|
|
596
|
-
method: zod.z.literal("completion/complete"),
|
|
597
|
-
params: BaseRequestParamsSchema.extend({
|
|
598
|
-
ref: zod.z.union([PromptReferenceSchema, ResourceReferenceSchema]),
|
|
599
|
-
/**
|
|
600
|
-
* The argument's information
|
|
601
|
-
*/
|
|
602
|
-
argument: zod.z.object({
|
|
603
|
-
/**
|
|
604
|
-
* The name of the argument
|
|
605
|
-
*/
|
|
606
|
-
name: zod.z.string(),
|
|
607
|
-
/**
|
|
608
|
-
* The value of the argument to use for completion matching.
|
|
609
|
-
*/
|
|
610
|
-
value: zod.z.string()
|
|
611
|
-
}).passthrough()
|
|
612
|
-
})
|
|
613
|
-
});
|
|
614
|
-
const CompleteResultSchema = ResultSchema.extend({
|
|
615
|
-
completion: zod.z.object({
|
|
616
|
-
/**
|
|
617
|
-
* An array of completion values. Must not exceed 100 items.
|
|
618
|
-
*/
|
|
619
|
-
values: zod.z.array(zod.z.string()).max(100),
|
|
620
|
-
/**
|
|
621
|
-
* The total number of completion options available. This can exceed the number of values actually sent in the response.
|
|
622
|
-
*/
|
|
623
|
-
total: zod.z.optional(zod.z.number().int()),
|
|
624
|
-
/**
|
|
625
|
-
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
|
|
626
|
-
*/
|
|
627
|
-
hasMore: zod.z.optional(zod.z.boolean())
|
|
628
|
-
}).passthrough()
|
|
629
|
-
});
|
|
630
|
-
const RootSchema = zod.z.object({
|
|
631
|
-
/**
|
|
632
|
-
* The URI identifying the root. This *must* start with file:// for now.
|
|
633
|
-
*/
|
|
634
|
-
uri: zod.z.string().startsWith("file://"),
|
|
635
|
-
/**
|
|
636
|
-
* An optional name for the root.
|
|
637
|
-
*/
|
|
638
|
-
name: zod.z.optional(zod.z.string())
|
|
639
|
-
}).passthrough();
|
|
640
|
-
const ListRootsRequestSchema = RequestSchema.extend({
|
|
641
|
-
method: zod.z.literal("roots/list")
|
|
642
|
-
});
|
|
643
|
-
const ListRootsResultSchema = ResultSchema.extend({
|
|
644
|
-
roots: zod.z.array(RootSchema)
|
|
645
|
-
});
|
|
646
|
-
const RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
647
|
-
method: zod.z.literal("notifications/roots/list_changed")
|
|
648
|
-
});
|
|
649
|
-
zod.z.union([
|
|
650
|
-
PingRequestSchema,
|
|
651
|
-
InitializeRequestSchema,
|
|
652
|
-
CompleteRequestSchema,
|
|
653
|
-
SetLevelRequestSchema,
|
|
654
|
-
GetPromptRequestSchema,
|
|
655
|
-
ListPromptsRequestSchema,
|
|
656
|
-
ListResourcesRequestSchema,
|
|
657
|
-
ListResourceTemplatesRequestSchema,
|
|
658
|
-
ReadResourceRequestSchema,
|
|
659
|
-
SubscribeRequestSchema,
|
|
660
|
-
UnsubscribeRequestSchema,
|
|
661
|
-
CallToolRequestSchema,
|
|
662
|
-
ListToolsRequestSchema
|
|
663
|
-
]);
|
|
664
|
-
zod.z.union([
|
|
665
|
-
CancelledNotificationSchema,
|
|
666
|
-
ProgressNotificationSchema,
|
|
667
|
-
InitializedNotificationSchema,
|
|
668
|
-
RootsListChangedNotificationSchema
|
|
669
|
-
]);
|
|
670
|
-
zod.z.union([
|
|
671
|
-
EmptyResultSchema,
|
|
672
|
-
CreateMessageResultSchema,
|
|
673
|
-
ListRootsResultSchema
|
|
674
|
-
]);
|
|
675
|
-
zod.z.union([
|
|
676
|
-
PingRequestSchema,
|
|
677
|
-
CreateMessageRequestSchema,
|
|
678
|
-
ListRootsRequestSchema
|
|
679
|
-
]);
|
|
680
|
-
zod.z.union([
|
|
681
|
-
CancelledNotificationSchema,
|
|
682
|
-
ProgressNotificationSchema,
|
|
683
|
-
LoggingMessageNotificationSchema,
|
|
684
|
-
ResourceUpdatedNotificationSchema,
|
|
685
|
-
ResourceListChangedNotificationSchema,
|
|
686
|
-
ToolListChangedNotificationSchema,
|
|
687
|
-
PromptListChangedNotificationSchema
|
|
688
|
-
]);
|
|
689
|
-
zod.z.union([
|
|
690
|
-
EmptyResultSchema,
|
|
691
|
-
InitializeResultSchema,
|
|
692
|
-
CompleteResultSchema,
|
|
693
|
-
GetPromptResultSchema,
|
|
694
|
-
ListPromptsResultSchema,
|
|
695
|
-
ListResourcesResultSchema,
|
|
696
|
-
ListResourceTemplatesResultSchema,
|
|
697
|
-
ReadResourceResultSchema,
|
|
698
|
-
CallToolResultSchema,
|
|
699
|
-
ListToolsResultSchema
|
|
700
|
-
]);
|
|
701
|
-
function readToolHtml(distPath) {
|
|
702
|
-
const htmlPath = path.resolve(distPath);
|
|
703
|
-
if (!fs.existsSync(htmlPath)) {
|
|
704
|
-
throw new Error(
|
|
705
|
-
`Widget file not found at ${htmlPath}. Run "pnpm build" to generate the built app.`
|
|
706
|
-
);
|
|
707
|
-
}
|
|
708
|
-
const jsContents = fs.readFileSync(htmlPath, "utf8");
|
|
709
|
-
return `<!DOCTYPE html>
|
|
710
|
-
<html>
|
|
711
|
-
<head>
|
|
712
|
-
<meta charset="UTF-8">
|
|
713
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
714
|
-
</head>
|
|
715
|
-
<body>
|
|
716
|
-
<div id="root"></div>
|
|
717
|
-
<script>
|
|
718
|
-
${jsContents}
|
|
719
|
-
<\/script>
|
|
720
|
-
</body>
|
|
721
|
-
</html>`;
|
|
722
|
-
}
|
|
723
|
-
function createAppServer(config) {
|
|
724
|
-
const { name = "sunpeak-app", version = "0.1.0", simulations } = config;
|
|
725
|
-
const toolInputParser = zod.z.object({});
|
|
726
|
-
const widgetContentMap = new Map(
|
|
727
|
-
simulations.map((simulation) => [simulation.tool.name, readToolHtml(simulation.distPath)])
|
|
728
|
-
);
|
|
729
|
-
const timestamp = Date.now().toString(36);
|
|
730
|
-
const tools = simulations.map((simulation) => {
|
|
731
|
-
const tool = simulation.tool;
|
|
732
|
-
const meta = tool._meta;
|
|
733
|
-
const outputTemplate = meta == null ? void 0 : meta["openai/outputTemplate"];
|
|
734
|
-
if (outputTemplate && typeof outputTemplate === "string") {
|
|
735
|
-
const timestampedUri = outputTemplate.includes(".") ? outputTemplate.replace(/(\.[^.]+)$/, `-${timestamp}$1`) : `${outputTemplate}-${timestamp}`;
|
|
736
|
-
return {
|
|
737
|
-
...tool,
|
|
738
|
-
_meta: {
|
|
739
|
-
...meta ?? {},
|
|
740
|
-
"openai/outputTemplate": timestampedUri
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
return tool;
|
|
745
|
-
});
|
|
746
|
-
const resources = simulations.map((simulation) => simulation.resource);
|
|
747
|
-
const toolCallDataMap = new Map(
|
|
748
|
-
simulations.map((simulation) => [
|
|
749
|
-
simulation.tool.name,
|
|
750
|
-
simulation.toolCall ?? { structuredContent: null, _meta: {} }
|
|
751
|
-
])
|
|
752
|
-
);
|
|
753
|
-
const resourceMap = new Map(
|
|
754
|
-
resources.map((resource, index) => [
|
|
755
|
-
resource.uri,
|
|
756
|
-
{
|
|
757
|
-
content: widgetContentMap.get(simulations[index].tool.name),
|
|
758
|
-
resource
|
|
759
|
-
}
|
|
760
|
-
])
|
|
761
|
-
);
|
|
762
|
-
const server = new index_js.Server(
|
|
763
|
-
{
|
|
764
|
-
name,
|
|
765
|
-
version
|
|
766
|
-
},
|
|
767
|
-
{
|
|
768
|
-
capabilities: {
|
|
769
|
-
resources: {},
|
|
770
|
-
tools: {}
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
);
|
|
774
|
-
server.setRequestHandler(ListResourcesRequestSchema, async (_request) => {
|
|
775
|
-
console.log("[MCP] ListResources");
|
|
776
|
-
return { resources };
|
|
777
|
-
});
|
|
778
|
-
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
779
|
-
console.log("[MCP] ReadResource:", request.params.uri);
|
|
780
|
-
const requestedUri = request.params.uri;
|
|
781
|
-
const cleanedUri = requestedUri.includes(".") ? requestedUri.replace(/-[a-z0-9]+(\.[^.]+)$/, "$1") : requestedUri.replace(/-[a-z0-9]+$/, "");
|
|
782
|
-
const resourceData = resourceMap.get(cleanedUri);
|
|
783
|
-
if (!resourceData) {
|
|
784
|
-
throw new Error(`Unknown resource: ${request.params.uri} (cleaned: ${cleanedUri})`);
|
|
785
|
-
}
|
|
786
|
-
return {
|
|
787
|
-
contents: [
|
|
788
|
-
{
|
|
789
|
-
uri: resourceData.resource.uri,
|
|
790
|
-
mimeType: resourceData.resource.mimeType,
|
|
791
|
-
text: resourceData.content,
|
|
792
|
-
_meta: resourceData.resource._meta
|
|
793
|
-
}
|
|
794
|
-
]
|
|
795
|
-
};
|
|
796
|
-
});
|
|
797
|
-
server.setRequestHandler(ListToolsRequestSchema, async (_request) => {
|
|
798
|
-
console.log("[MCP] ListTools");
|
|
799
|
-
return { tools };
|
|
800
|
-
});
|
|
801
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
802
|
-
console.log("[MCP] CallTool:", request.params.name, request.params.arguments);
|
|
803
|
-
const simulation = simulations.find((s) => s.tool.name === request.params.name);
|
|
804
|
-
if (!simulation) {
|
|
805
|
-
throw new Error(`Simulation not found: ${request.params.name}`);
|
|
806
|
-
}
|
|
807
|
-
const toolCallData = toolCallDataMap.get(request.params.name);
|
|
808
|
-
toolInputParser.parse(request.params.arguments ?? {});
|
|
809
|
-
return {
|
|
810
|
-
content: [
|
|
811
|
-
{
|
|
812
|
-
type: "text",
|
|
813
|
-
text: `Rendered ${simulation.tool.description}!`
|
|
814
|
-
}
|
|
815
|
-
],
|
|
816
|
-
structuredContent: (toolCallData == null ? void 0 : toolCallData.structuredContent) ?? void 0,
|
|
817
|
-
_meta: (toolCallData == null ? void 0 : toolCallData._meta) ?? {}
|
|
818
|
-
};
|
|
819
|
-
});
|
|
820
|
-
return server;
|
|
821
|
-
}
|
|
822
|
-
const sessions = /* @__PURE__ */ new Map();
|
|
823
|
-
const ssePath = "/mcp";
|
|
824
|
-
const postPath = "/mcp/messages";
|
|
825
|
-
async function handleSseRequest(res, config) {
|
|
826
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
827
|
-
const server = createAppServer(config);
|
|
828
|
-
const transport = new sse_js.SSEServerTransport(postPath, res);
|
|
829
|
-
const sessionId = transport.sessionId;
|
|
830
|
-
sessions.set(sessionId, { server, transport });
|
|
831
|
-
transport.onclose = async () => {
|
|
832
|
-
sessions.delete(sessionId);
|
|
833
|
-
await server.close();
|
|
834
|
-
};
|
|
835
|
-
transport.onerror = (error) => {
|
|
836
|
-
console.error("SSE transport error", error);
|
|
837
|
-
};
|
|
838
|
-
try {
|
|
839
|
-
await server.connect(transport);
|
|
840
|
-
} catch (error) {
|
|
841
|
-
sessions.delete(sessionId);
|
|
842
|
-
console.error("Failed to start SSE session", error);
|
|
843
|
-
if (!res.headersSent) {
|
|
844
|
-
res.writeHead(500).end("Failed to establish SSE connection");
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
async function handlePostMessage(req, res, url) {
|
|
849
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
850
|
-
res.setHeader("Access-Control-Allow-Headers", "content-type");
|
|
851
|
-
const sessionId = url.searchParams.get("sessionId");
|
|
852
|
-
if (!sessionId) {
|
|
853
|
-
res.writeHead(400).end("Missing sessionId query parameter");
|
|
854
|
-
return;
|
|
855
|
-
}
|
|
856
|
-
const session = sessions.get(sessionId);
|
|
857
|
-
if (!session) {
|
|
858
|
-
res.writeHead(404).end("Unknown session");
|
|
859
|
-
return;
|
|
860
|
-
}
|
|
861
|
-
try {
|
|
862
|
-
await session.transport.handlePostMessage(req, res);
|
|
863
|
-
} catch (error) {
|
|
864
|
-
console.error("Failed to process message", error);
|
|
865
|
-
if (!res.headersSent) {
|
|
866
|
-
res.writeHead(500).end("Failed to process message");
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
function runMCPServer(config) {
|
|
871
|
-
const portEnv = Number(process.env.PORT ?? 6766);
|
|
872
|
-
const port = config.port ?? (Number.isFinite(portEnv) ? portEnv : 6766);
|
|
873
|
-
const httpServer = node_http.createServer(async (req, res) => {
|
|
874
|
-
if (!req.url) {
|
|
875
|
-
res.writeHead(400).end("Missing URL");
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
const url = new node_url.URL(req.url, `http://${req.headers.host ?? "localhost"}`);
|
|
879
|
-
console.log(`[HTTP] ${req.method} ${url.pathname}`);
|
|
880
|
-
if (req.method === "OPTIONS" && (url.pathname === ssePath || url.pathname === postPath)) {
|
|
881
|
-
res.writeHead(204, {
|
|
882
|
-
"Access-Control-Allow-Origin": "*",
|
|
883
|
-
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
884
|
-
"Access-Control-Allow-Headers": "content-type"
|
|
885
|
-
});
|
|
886
|
-
res.end();
|
|
887
|
-
return;
|
|
888
|
-
}
|
|
889
|
-
if (req.method === "GET" && url.pathname === ssePath) {
|
|
890
|
-
await handleSseRequest(res, config);
|
|
891
|
-
return;
|
|
892
|
-
}
|
|
893
|
-
if (req.method === "POST" && url.pathname === postPath) {
|
|
894
|
-
await handlePostMessage(req, res, url);
|
|
895
|
-
return;
|
|
896
|
-
}
|
|
897
|
-
res.writeHead(404).end("Not Found");
|
|
898
|
-
});
|
|
899
|
-
httpServer.on("clientError", (err, socket) => {
|
|
900
|
-
console.error("HTTP client error", err);
|
|
901
|
-
socket.end("HTTP/1.1 400 Bad Request\r\n\r\n");
|
|
902
|
-
});
|
|
903
|
-
httpServer.listen(port, () => {
|
|
904
|
-
console.log(`Sunpeak MCP server listening on http://localhost:${port}`);
|
|
905
|
-
console.log(` SSE stream: GET http://localhost:${port}${ssePath}`);
|
|
906
|
-
console.log(` Message post endpoint: POST http://localhost:${port}${postPath}?sessionId=...`);
|
|
907
|
-
});
|
|
908
|
-
const shutdown = () => {
|
|
909
|
-
console.log("\nShutting down MCP server...");
|
|
910
|
-
httpServer.close(() => {
|
|
911
|
-
console.log("MCP server closed");
|
|
912
|
-
process.exit(0);
|
|
913
|
-
});
|
|
914
|
-
setTimeout(() => {
|
|
915
|
-
console.error("Force closing MCP server");
|
|
916
|
-
process.exit(1);
|
|
917
|
-
}, 5e3);
|
|
918
|
-
};
|
|
919
|
-
process.on("SIGTERM", shutdown);
|
|
920
|
-
process.on("SIGINT", shutdown);
|
|
921
|
-
}
|
|
922
|
-
exports.runMCPServer = runMCPServer;
|
|
3
|
+
const server = require("../server-DpriZ4jT.cjs");
|
|
4
|
+
exports.runMCPServer = server.runMCPServer;
|
|
923
5
|
//# sourceMappingURL=index.cjs.map
|