sunpeak 0.2.6 → 0.3.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 +32 -17
- package/dist/chatgpt/chatgpt-simulator-types.d.ts +8 -0
- package/dist/chatgpt/chatgpt-simulator.d.ts +11 -0
- package/dist/chatgpt/conversation.d.ts +11 -0
- package/dist/chatgpt/index.d.ts +3 -0
- package/dist/chatgpt/mcp-provider.d.ts +25 -0
- package/dist/chatgpt/mock-openai.d.ts +61 -0
- package/dist/chatgpt/openai-provider.d.ts +19 -0
- package/dist/chatgpt/openai-types.d.ts +81 -0
- package/dist/chatgpt/simple-sidebar.d.ts +22 -0
- package/dist/chatgpt/theme-provider.d.ts +13 -0
- package/dist/hooks/index.d.ts +14 -0
- package/dist/hooks/use-display-mode.d.ts +2 -0
- package/dist/hooks/use-locale.d.ts +1 -0
- package/dist/hooks/use-max-height.d.ts +1 -0
- package/dist/hooks/use-mobile.d.ts +1 -0
- package/dist/hooks/use-safe-area.d.ts +2 -0
- package/dist/hooks/use-theme.d.ts +2 -0
- package/dist/hooks/use-tool-input.d.ts +2 -0
- package/dist/hooks/use-tool-response-metadata.d.ts +2 -0
- package/dist/hooks/use-user-agent.d.ts +2 -0
- package/dist/hooks/use-view.d.ts +2 -0
- package/dist/hooks/use-widget-api.d.ts +8 -0
- package/dist/hooks/use-widget-global.d.ts +9 -0
- package/dist/hooks/use-widget-props.d.ts +1 -0
- package/dist/hooks/use-widget-state.d.ts +4 -0
- package/dist/index.cjs +3310 -666
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -366
- package/dist/index.js +3325 -640
- package/dist/index.js.map +1 -1
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/media-queries.d.ts +3 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/mcp/index.cjs +799 -64
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.ts +1 -12
- package/dist/mcp/index.js +786 -44
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/server.d.ts +10 -0
- package/dist/mcp/types.d.ts +74 -0
- package/dist/providers/index.d.ts +40 -0
- package/dist/providers/types.d.ts +71 -0
- package/dist/style.css +5279 -0
- package/dist/test/setup.d.ts +0 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +15 -20
- package/template/README.md +3 -6
- package/template/dev/main.tsx +0 -1
- package/template/mcp/server.ts +1 -1
- package/template/package.json +4 -14
- package/template/src/App.tsx +7 -8
- package/template/src/components/index.ts +2 -2
- package/template/src/components/openai-card.test.tsx +73 -0
- package/template/src/components/openai-card.tsx +126 -0
- package/template/src/components/openai-carousel.test.tsx +84 -0
- package/template/src/components/openai-carousel.tsx +178 -0
- package/template/src/styles/globals.css +5 -216
- package/template/vite.config.build.ts +61 -0
- package/template/vite.config.ts +0 -2
- package/dist/index.d.cts +0 -366
- package/dist/mcp/index.d.cts +0 -12
- package/dist/styles/chatgpt/index.css +0 -146
- package/dist/styles/globals.css +0 -219
- package/template/components.json +0 -21
- package/template/dev/styles.css +0 -6
- package/template/postcss.config.js +0 -5
- package/template/src/components/shadcn/button.tsx +0 -60
- package/template/src/components/shadcn/card.tsx +0 -76
- package/template/src/components/shadcn/carousel.tsx +0 -260
- package/template/src/components/shadcn/index.ts +0 -5
- package/template/src/components/shadcn/label.tsx +0 -24
- package/template/src/components/shadcn/select.tsx +0 -157
- package/template/src/components/sunpeak-card.test.tsx +0 -76
- package/template/src/components/sunpeak-card.tsx +0 -171
- package/template/src/components/sunpeak-carousel.test.tsx +0 -42
- package/template/src/components/sunpeak-carousel.tsx +0 -160
- package/template/src/styles/chatgpt.css +0 -146
- package/template/tsup.config.ts +0 -50
package/dist/mcp/index.js
CHANGED
|
@@ -1,13 +1,705 @@
|
|
|
1
|
-
import { createServer } from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { URL } from "node:url";
|
|
3
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
|
+
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
const JSONRPC_VERSION = "2.0";
|
|
9
|
+
const ProgressTokenSchema = z.union([z.string(), z.number().int()]);
|
|
10
|
+
const CursorSchema = z.string();
|
|
11
|
+
const BaseRequestParamsSchema = z.object({
|
|
12
|
+
_meta: z.optional(z.object({
|
|
13
|
+
/**
|
|
14
|
+
* 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.
|
|
15
|
+
*/
|
|
16
|
+
progressToken: z.optional(ProgressTokenSchema)
|
|
17
|
+
}).passthrough())
|
|
18
|
+
}).passthrough();
|
|
19
|
+
const RequestSchema = z.object({
|
|
20
|
+
method: z.string(),
|
|
21
|
+
params: z.optional(BaseRequestParamsSchema)
|
|
22
|
+
});
|
|
23
|
+
const BaseNotificationParamsSchema = z.object({
|
|
24
|
+
/**
|
|
25
|
+
* This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications.
|
|
26
|
+
*/
|
|
27
|
+
_meta: z.optional(z.object({}).passthrough())
|
|
28
|
+
}).passthrough();
|
|
29
|
+
const NotificationSchema = z.object({
|
|
30
|
+
method: z.string(),
|
|
31
|
+
params: z.optional(BaseNotificationParamsSchema)
|
|
32
|
+
});
|
|
33
|
+
const ResultSchema = z.object({
|
|
34
|
+
/**
|
|
35
|
+
* This result property is reserved by the protocol to allow clients and servers to attach additional metadata to their responses.
|
|
36
|
+
*/
|
|
37
|
+
_meta: z.optional(z.object({}).passthrough())
|
|
38
|
+
}).passthrough();
|
|
39
|
+
const RequestIdSchema = z.union([z.string(), z.number().int()]);
|
|
40
|
+
const JSONRPCRequestSchema = z.object({
|
|
41
|
+
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
42
|
+
id: RequestIdSchema
|
|
43
|
+
}).merge(RequestSchema).strict();
|
|
44
|
+
const JSONRPCNotificationSchema = z.object({
|
|
45
|
+
jsonrpc: z.literal(JSONRPC_VERSION)
|
|
46
|
+
}).merge(NotificationSchema).strict();
|
|
47
|
+
const JSONRPCResponseSchema = z.object({
|
|
48
|
+
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
49
|
+
id: RequestIdSchema,
|
|
50
|
+
result: ResultSchema
|
|
51
|
+
}).strict();
|
|
52
|
+
var ErrorCode;
|
|
53
|
+
(function(ErrorCode2) {
|
|
54
|
+
ErrorCode2[ErrorCode2["ConnectionClosed"] = -1] = "ConnectionClosed";
|
|
55
|
+
ErrorCode2[ErrorCode2["ParseError"] = -32700] = "ParseError";
|
|
56
|
+
ErrorCode2[ErrorCode2["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
57
|
+
ErrorCode2[ErrorCode2["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
58
|
+
ErrorCode2[ErrorCode2["InvalidParams"] = -32602] = "InvalidParams";
|
|
59
|
+
ErrorCode2[ErrorCode2["InternalError"] = -32603] = "InternalError";
|
|
60
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
61
|
+
const JSONRPCErrorSchema = z.object({
|
|
62
|
+
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
63
|
+
id: RequestIdSchema,
|
|
64
|
+
error: z.object({
|
|
65
|
+
/**
|
|
66
|
+
* The error type that occurred.
|
|
67
|
+
*/
|
|
68
|
+
code: z.number().int(),
|
|
69
|
+
/**
|
|
70
|
+
* A short description of the error. The message SHOULD be limited to a concise single sentence.
|
|
71
|
+
*/
|
|
72
|
+
message: z.string(),
|
|
73
|
+
/**
|
|
74
|
+
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
|
|
75
|
+
*/
|
|
76
|
+
data: z.optional(z.unknown())
|
|
77
|
+
})
|
|
78
|
+
}).strict();
|
|
79
|
+
z.union([
|
|
80
|
+
JSONRPCRequestSchema,
|
|
81
|
+
JSONRPCNotificationSchema,
|
|
82
|
+
JSONRPCResponseSchema,
|
|
83
|
+
JSONRPCErrorSchema
|
|
84
|
+
]);
|
|
85
|
+
const EmptyResultSchema = ResultSchema.strict();
|
|
86
|
+
const CancelledNotificationSchema = NotificationSchema.extend({
|
|
87
|
+
method: z.literal("notifications/cancelled"),
|
|
88
|
+
params: BaseNotificationParamsSchema.extend({
|
|
89
|
+
/**
|
|
90
|
+
* The ID of the request to cancel.
|
|
91
|
+
*
|
|
92
|
+
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
93
|
+
*/
|
|
94
|
+
requestId: RequestIdSchema,
|
|
95
|
+
/**
|
|
96
|
+
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
97
|
+
*/
|
|
98
|
+
reason: z.string().optional()
|
|
99
|
+
})
|
|
100
|
+
});
|
|
101
|
+
const ImplementationSchema = z.object({
|
|
102
|
+
name: z.string(),
|
|
103
|
+
version: z.string()
|
|
104
|
+
}).passthrough();
|
|
105
|
+
const ClientCapabilitiesSchema = z.object({
|
|
106
|
+
/**
|
|
107
|
+
* Experimental, non-standard capabilities that the client supports.
|
|
108
|
+
*/
|
|
109
|
+
experimental: z.optional(z.object({}).passthrough()),
|
|
110
|
+
/**
|
|
111
|
+
* Present if the client supports sampling from an LLM.
|
|
112
|
+
*/
|
|
113
|
+
sampling: z.optional(z.object({}).passthrough()),
|
|
114
|
+
/**
|
|
115
|
+
* Present if the client supports listing roots.
|
|
116
|
+
*/
|
|
117
|
+
roots: z.optional(z.object({
|
|
118
|
+
/**
|
|
119
|
+
* Whether the client supports issuing notifications for changes to the roots list.
|
|
120
|
+
*/
|
|
121
|
+
listChanged: z.optional(z.boolean())
|
|
122
|
+
}).passthrough())
|
|
123
|
+
}).passthrough();
|
|
124
|
+
const InitializeRequestSchema = RequestSchema.extend({
|
|
125
|
+
method: z.literal("initialize"),
|
|
126
|
+
params: BaseRequestParamsSchema.extend({
|
|
127
|
+
/**
|
|
128
|
+
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
|
|
129
|
+
*/
|
|
130
|
+
protocolVersion: z.string(),
|
|
131
|
+
capabilities: ClientCapabilitiesSchema,
|
|
132
|
+
clientInfo: ImplementationSchema
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
const ServerCapabilitiesSchema = z.object({
|
|
136
|
+
/**
|
|
137
|
+
* Experimental, non-standard capabilities that the server supports.
|
|
138
|
+
*/
|
|
139
|
+
experimental: z.optional(z.object({}).passthrough()),
|
|
140
|
+
/**
|
|
141
|
+
* Present if the server supports sending log messages to the client.
|
|
142
|
+
*/
|
|
143
|
+
logging: z.optional(z.object({}).passthrough()),
|
|
144
|
+
/**
|
|
145
|
+
* Present if the server offers any prompt templates.
|
|
146
|
+
*/
|
|
147
|
+
prompts: z.optional(z.object({
|
|
148
|
+
/**
|
|
149
|
+
* Whether this server supports issuing notifications for changes to the prompt list.
|
|
150
|
+
*/
|
|
151
|
+
listChanged: z.optional(z.boolean())
|
|
152
|
+
}).passthrough()),
|
|
153
|
+
/**
|
|
154
|
+
* Present if the server offers any resources to read.
|
|
155
|
+
*/
|
|
156
|
+
resources: z.optional(z.object({
|
|
157
|
+
/**
|
|
158
|
+
* Whether this server supports clients subscribing to resource updates.
|
|
159
|
+
*/
|
|
160
|
+
subscribe: z.optional(z.boolean()),
|
|
161
|
+
/**
|
|
162
|
+
* Whether this server supports issuing notifications for changes to the resource list.
|
|
163
|
+
*/
|
|
164
|
+
listChanged: z.optional(z.boolean())
|
|
165
|
+
}).passthrough()),
|
|
166
|
+
/**
|
|
167
|
+
* Present if the server offers any tools to call.
|
|
168
|
+
*/
|
|
169
|
+
tools: z.optional(z.object({
|
|
170
|
+
/**
|
|
171
|
+
* Whether this server supports issuing notifications for changes to the tool list.
|
|
172
|
+
*/
|
|
173
|
+
listChanged: z.optional(z.boolean())
|
|
174
|
+
}).passthrough())
|
|
175
|
+
}).passthrough();
|
|
176
|
+
const InitializeResultSchema = ResultSchema.extend({
|
|
177
|
+
/**
|
|
178
|
+
* 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.
|
|
179
|
+
*/
|
|
180
|
+
protocolVersion: z.string(),
|
|
181
|
+
capabilities: ServerCapabilitiesSchema,
|
|
182
|
+
serverInfo: ImplementationSchema
|
|
183
|
+
});
|
|
184
|
+
const InitializedNotificationSchema = NotificationSchema.extend({
|
|
185
|
+
method: z.literal("notifications/initialized")
|
|
186
|
+
});
|
|
187
|
+
const PingRequestSchema = RequestSchema.extend({
|
|
188
|
+
method: z.literal("ping")
|
|
189
|
+
});
|
|
190
|
+
const ProgressSchema = z.object({
|
|
191
|
+
/**
|
|
192
|
+
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
193
|
+
*/
|
|
194
|
+
progress: z.number(),
|
|
195
|
+
/**
|
|
196
|
+
* Total number of items to process (or total progress required), if known.
|
|
197
|
+
*/
|
|
198
|
+
total: z.optional(z.number())
|
|
199
|
+
}).passthrough();
|
|
200
|
+
const ProgressNotificationSchema = NotificationSchema.extend({
|
|
201
|
+
method: z.literal("notifications/progress"),
|
|
202
|
+
params: BaseNotificationParamsSchema.merge(ProgressSchema).extend({
|
|
203
|
+
/**
|
|
204
|
+
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
|
|
205
|
+
*/
|
|
206
|
+
progressToken: ProgressTokenSchema
|
|
207
|
+
})
|
|
208
|
+
});
|
|
209
|
+
const PaginatedRequestSchema = RequestSchema.extend({
|
|
210
|
+
params: BaseRequestParamsSchema.extend({
|
|
211
|
+
/**
|
|
212
|
+
* An opaque token representing the current pagination position.
|
|
213
|
+
* If provided, the server should return results starting after this cursor.
|
|
214
|
+
*/
|
|
215
|
+
cursor: z.optional(CursorSchema)
|
|
216
|
+
}).optional()
|
|
217
|
+
});
|
|
218
|
+
const PaginatedResultSchema = ResultSchema.extend({
|
|
219
|
+
/**
|
|
220
|
+
* An opaque token representing the pagination position after the last returned result.
|
|
221
|
+
* If present, there may be more results available.
|
|
222
|
+
*/
|
|
223
|
+
nextCursor: z.optional(CursorSchema)
|
|
224
|
+
});
|
|
225
|
+
const ResourceContentsSchema = z.object({
|
|
226
|
+
/**
|
|
227
|
+
* The URI of this resource.
|
|
228
|
+
*/
|
|
229
|
+
uri: z.string(),
|
|
230
|
+
/**
|
|
231
|
+
* The MIME type of this resource, if known.
|
|
232
|
+
*/
|
|
233
|
+
mimeType: z.optional(z.string())
|
|
234
|
+
}).passthrough();
|
|
235
|
+
const TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
236
|
+
/**
|
|
237
|
+
* The text of the item. This must only be set if the item can actually be represented as text (not binary data).
|
|
238
|
+
*/
|
|
239
|
+
text: z.string()
|
|
240
|
+
});
|
|
241
|
+
const BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
242
|
+
/**
|
|
243
|
+
* A base64-encoded string representing the binary data of the item.
|
|
244
|
+
*/
|
|
245
|
+
blob: z.string().base64()
|
|
246
|
+
});
|
|
247
|
+
const ResourceSchema = z.object({
|
|
248
|
+
/**
|
|
249
|
+
* The URI of this resource.
|
|
250
|
+
*/
|
|
251
|
+
uri: z.string(),
|
|
252
|
+
/**
|
|
253
|
+
* A human-readable name for this resource.
|
|
254
|
+
*
|
|
255
|
+
* This can be used by clients to populate UI elements.
|
|
256
|
+
*/
|
|
257
|
+
name: z.string(),
|
|
258
|
+
/**
|
|
259
|
+
* A description of what this resource represents.
|
|
260
|
+
*
|
|
261
|
+
* 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.
|
|
262
|
+
*/
|
|
263
|
+
description: z.optional(z.string()),
|
|
264
|
+
/**
|
|
265
|
+
* The MIME type of this resource, if known.
|
|
266
|
+
*/
|
|
267
|
+
mimeType: z.optional(z.string())
|
|
268
|
+
}).passthrough();
|
|
269
|
+
const ResourceTemplateSchema = z.object({
|
|
270
|
+
/**
|
|
271
|
+
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
|
|
272
|
+
*/
|
|
273
|
+
uriTemplate: z.string(),
|
|
274
|
+
/**
|
|
275
|
+
* A human-readable name for the type of resource this template refers to.
|
|
276
|
+
*
|
|
277
|
+
* This can be used by clients to populate UI elements.
|
|
278
|
+
*/
|
|
279
|
+
name: z.string(),
|
|
280
|
+
/**
|
|
281
|
+
* A description of what this template is for.
|
|
282
|
+
*
|
|
283
|
+
* 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.
|
|
284
|
+
*/
|
|
285
|
+
description: z.optional(z.string()),
|
|
286
|
+
/**
|
|
287
|
+
* 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.
|
|
288
|
+
*/
|
|
289
|
+
mimeType: z.optional(z.string())
|
|
290
|
+
}).passthrough();
|
|
291
|
+
const ListResourcesRequestSchema = PaginatedRequestSchema.extend({
|
|
292
|
+
method: z.literal("resources/list")
|
|
293
|
+
});
|
|
294
|
+
const ListResourcesResultSchema = PaginatedResultSchema.extend({
|
|
295
|
+
resources: z.array(ResourceSchema)
|
|
296
|
+
});
|
|
297
|
+
const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({
|
|
298
|
+
method: z.literal("resources/templates/list")
|
|
299
|
+
});
|
|
300
|
+
const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({
|
|
301
|
+
resourceTemplates: z.array(ResourceTemplateSchema)
|
|
302
|
+
});
|
|
303
|
+
const ReadResourceRequestSchema = RequestSchema.extend({
|
|
304
|
+
method: z.literal("resources/read"),
|
|
305
|
+
params: BaseRequestParamsSchema.extend({
|
|
306
|
+
/**
|
|
307
|
+
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
|
|
308
|
+
*/
|
|
309
|
+
uri: z.string()
|
|
310
|
+
})
|
|
311
|
+
});
|
|
312
|
+
const ReadResourceResultSchema = ResultSchema.extend({
|
|
313
|
+
contents: z.array(z.union([TextResourceContentsSchema, BlobResourceContentsSchema]))
|
|
314
|
+
});
|
|
315
|
+
const ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
316
|
+
method: z.literal("notifications/resources/list_changed")
|
|
317
|
+
});
|
|
318
|
+
const SubscribeRequestSchema = RequestSchema.extend({
|
|
319
|
+
method: z.literal("resources/subscribe"),
|
|
320
|
+
params: BaseRequestParamsSchema.extend({
|
|
321
|
+
/**
|
|
322
|
+
* The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
|
|
323
|
+
*/
|
|
324
|
+
uri: z.string()
|
|
325
|
+
})
|
|
326
|
+
});
|
|
327
|
+
const UnsubscribeRequestSchema = RequestSchema.extend({
|
|
328
|
+
method: z.literal("resources/unsubscribe"),
|
|
329
|
+
params: BaseRequestParamsSchema.extend({
|
|
330
|
+
/**
|
|
331
|
+
* The URI of the resource to unsubscribe from.
|
|
332
|
+
*/
|
|
333
|
+
uri: z.string()
|
|
334
|
+
})
|
|
335
|
+
});
|
|
336
|
+
const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
|
|
337
|
+
method: z.literal("notifications/resources/updated"),
|
|
338
|
+
params: BaseNotificationParamsSchema.extend({
|
|
339
|
+
/**
|
|
340
|
+
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
|
|
341
|
+
*/
|
|
342
|
+
uri: z.string()
|
|
343
|
+
})
|
|
344
|
+
});
|
|
345
|
+
const PromptArgumentSchema = z.object({
|
|
346
|
+
/**
|
|
347
|
+
* The name of the argument.
|
|
348
|
+
*/
|
|
349
|
+
name: z.string(),
|
|
350
|
+
/**
|
|
351
|
+
* A human-readable description of the argument.
|
|
352
|
+
*/
|
|
353
|
+
description: z.optional(z.string()),
|
|
354
|
+
/**
|
|
355
|
+
* Whether this argument must be provided.
|
|
356
|
+
*/
|
|
357
|
+
required: z.optional(z.boolean())
|
|
358
|
+
}).passthrough();
|
|
359
|
+
const PromptSchema = z.object({
|
|
360
|
+
/**
|
|
361
|
+
* The name of the prompt or prompt template.
|
|
362
|
+
*/
|
|
363
|
+
name: z.string(),
|
|
364
|
+
/**
|
|
365
|
+
* An optional description of what this prompt provides
|
|
366
|
+
*/
|
|
367
|
+
description: z.optional(z.string()),
|
|
368
|
+
/**
|
|
369
|
+
* A list of arguments to use for templating the prompt.
|
|
370
|
+
*/
|
|
371
|
+
arguments: z.optional(z.array(PromptArgumentSchema))
|
|
372
|
+
}).passthrough();
|
|
373
|
+
const ListPromptsRequestSchema = PaginatedRequestSchema.extend({
|
|
374
|
+
method: z.literal("prompts/list")
|
|
375
|
+
});
|
|
376
|
+
const ListPromptsResultSchema = PaginatedResultSchema.extend({
|
|
377
|
+
prompts: z.array(PromptSchema)
|
|
378
|
+
});
|
|
379
|
+
const GetPromptRequestSchema = RequestSchema.extend({
|
|
380
|
+
method: z.literal("prompts/get"),
|
|
381
|
+
params: BaseRequestParamsSchema.extend({
|
|
382
|
+
/**
|
|
383
|
+
* The name of the prompt or prompt template.
|
|
384
|
+
*/
|
|
385
|
+
name: z.string(),
|
|
386
|
+
/**
|
|
387
|
+
* Arguments to use for templating the prompt.
|
|
388
|
+
*/
|
|
389
|
+
arguments: z.optional(z.record(z.string()))
|
|
390
|
+
})
|
|
391
|
+
});
|
|
392
|
+
const TextContentSchema = z.object({
|
|
393
|
+
type: z.literal("text"),
|
|
394
|
+
/**
|
|
395
|
+
* The text content of the message.
|
|
396
|
+
*/
|
|
397
|
+
text: z.string()
|
|
398
|
+
}).passthrough();
|
|
399
|
+
const ImageContentSchema = z.object({
|
|
400
|
+
type: z.literal("image"),
|
|
401
|
+
/**
|
|
402
|
+
* The base64-encoded image data.
|
|
403
|
+
*/
|
|
404
|
+
data: z.string().base64(),
|
|
405
|
+
/**
|
|
406
|
+
* The MIME type of the image. Different providers may support different image types.
|
|
407
|
+
*/
|
|
408
|
+
mimeType: z.string()
|
|
409
|
+
}).passthrough();
|
|
410
|
+
const EmbeddedResourceSchema = z.object({
|
|
411
|
+
type: z.literal("resource"),
|
|
412
|
+
resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema])
|
|
413
|
+
}).passthrough();
|
|
414
|
+
const PromptMessageSchema = z.object({
|
|
415
|
+
role: z.enum(["user", "assistant"]),
|
|
416
|
+
content: z.union([
|
|
417
|
+
TextContentSchema,
|
|
418
|
+
ImageContentSchema,
|
|
419
|
+
EmbeddedResourceSchema
|
|
420
|
+
])
|
|
421
|
+
}).passthrough();
|
|
422
|
+
const GetPromptResultSchema = ResultSchema.extend({
|
|
423
|
+
/**
|
|
424
|
+
* An optional description for the prompt.
|
|
425
|
+
*/
|
|
426
|
+
description: z.optional(z.string()),
|
|
427
|
+
messages: z.array(PromptMessageSchema)
|
|
428
|
+
});
|
|
429
|
+
const PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
430
|
+
method: z.literal("notifications/prompts/list_changed")
|
|
431
|
+
});
|
|
432
|
+
const ToolSchema = z.object({
|
|
433
|
+
/**
|
|
434
|
+
* The name of the tool.
|
|
435
|
+
*/
|
|
436
|
+
name: z.string(),
|
|
437
|
+
/**
|
|
438
|
+
* A human-readable description of the tool.
|
|
439
|
+
*/
|
|
440
|
+
description: z.optional(z.string()),
|
|
441
|
+
/**
|
|
442
|
+
* A JSON Schema object defining the expected parameters for the tool.
|
|
443
|
+
*/
|
|
444
|
+
inputSchema: z.object({
|
|
445
|
+
type: z.literal("object"),
|
|
446
|
+
properties: z.optional(z.object({}).passthrough())
|
|
447
|
+
}).passthrough()
|
|
448
|
+
}).passthrough();
|
|
449
|
+
const ListToolsRequestSchema = PaginatedRequestSchema.extend({
|
|
450
|
+
method: z.literal("tools/list")
|
|
451
|
+
});
|
|
452
|
+
const ListToolsResultSchema = PaginatedResultSchema.extend({
|
|
453
|
+
tools: z.array(ToolSchema)
|
|
454
|
+
});
|
|
455
|
+
const CallToolResultSchema = ResultSchema.extend({
|
|
456
|
+
content: z.array(z.union([TextContentSchema, ImageContentSchema, EmbeddedResourceSchema])),
|
|
457
|
+
isError: z.boolean().default(false).optional()
|
|
458
|
+
});
|
|
459
|
+
CallToolResultSchema.or(ResultSchema.extend({
|
|
460
|
+
toolResult: z.unknown()
|
|
461
|
+
}));
|
|
462
|
+
const CallToolRequestSchema = RequestSchema.extend({
|
|
463
|
+
method: z.literal("tools/call"),
|
|
464
|
+
params: BaseRequestParamsSchema.extend({
|
|
465
|
+
name: z.string(),
|
|
466
|
+
arguments: z.optional(z.record(z.unknown()))
|
|
467
|
+
})
|
|
468
|
+
});
|
|
469
|
+
const ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
470
|
+
method: z.literal("notifications/tools/list_changed")
|
|
471
|
+
});
|
|
472
|
+
const LoggingLevelSchema = z.enum([
|
|
473
|
+
"debug",
|
|
474
|
+
"info",
|
|
475
|
+
"notice",
|
|
476
|
+
"warning",
|
|
477
|
+
"error",
|
|
478
|
+
"critical",
|
|
479
|
+
"alert",
|
|
480
|
+
"emergency"
|
|
481
|
+
]);
|
|
482
|
+
const SetLevelRequestSchema = RequestSchema.extend({
|
|
483
|
+
method: z.literal("logging/setLevel"),
|
|
484
|
+
params: BaseRequestParamsSchema.extend({
|
|
485
|
+
/**
|
|
486
|
+
* 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.
|
|
487
|
+
*/
|
|
488
|
+
level: LoggingLevelSchema
|
|
489
|
+
})
|
|
490
|
+
});
|
|
491
|
+
const LoggingMessageNotificationSchema = NotificationSchema.extend({
|
|
492
|
+
method: z.literal("notifications/message"),
|
|
493
|
+
params: BaseNotificationParamsSchema.extend({
|
|
494
|
+
/**
|
|
495
|
+
* The severity of this log message.
|
|
496
|
+
*/
|
|
497
|
+
level: LoggingLevelSchema,
|
|
498
|
+
/**
|
|
499
|
+
* An optional name of the logger issuing this message.
|
|
500
|
+
*/
|
|
501
|
+
logger: z.optional(z.string()),
|
|
502
|
+
/**
|
|
503
|
+
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
|
|
504
|
+
*/
|
|
505
|
+
data: z.unknown()
|
|
506
|
+
})
|
|
507
|
+
});
|
|
508
|
+
const ModelHintSchema = z.object({
|
|
509
|
+
/**
|
|
510
|
+
* A hint for a model name.
|
|
511
|
+
*/
|
|
512
|
+
name: z.string().optional()
|
|
513
|
+
}).passthrough();
|
|
514
|
+
const ModelPreferencesSchema = z.object({
|
|
515
|
+
/**
|
|
516
|
+
* Optional hints to use for model selection.
|
|
517
|
+
*/
|
|
518
|
+
hints: z.optional(z.array(ModelHintSchema)),
|
|
519
|
+
/**
|
|
520
|
+
* How much to prioritize cost when selecting a model.
|
|
521
|
+
*/
|
|
522
|
+
costPriority: z.optional(z.number().min(0).max(1)),
|
|
523
|
+
/**
|
|
524
|
+
* How much to prioritize sampling speed (latency) when selecting a model.
|
|
525
|
+
*/
|
|
526
|
+
speedPriority: z.optional(z.number().min(0).max(1)),
|
|
527
|
+
/**
|
|
528
|
+
* How much to prioritize intelligence and capabilities when selecting a model.
|
|
529
|
+
*/
|
|
530
|
+
intelligencePriority: z.optional(z.number().min(0).max(1))
|
|
531
|
+
}).passthrough();
|
|
532
|
+
const SamplingMessageSchema = z.object({
|
|
533
|
+
role: z.enum(["user", "assistant"]),
|
|
534
|
+
content: z.union([TextContentSchema, ImageContentSchema])
|
|
535
|
+
}).passthrough();
|
|
536
|
+
const CreateMessageRequestSchema = RequestSchema.extend({
|
|
537
|
+
method: z.literal("sampling/createMessage"),
|
|
538
|
+
params: BaseRequestParamsSchema.extend({
|
|
539
|
+
messages: z.array(SamplingMessageSchema),
|
|
540
|
+
/**
|
|
541
|
+
* An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
|
|
542
|
+
*/
|
|
543
|
+
systemPrompt: z.optional(z.string()),
|
|
544
|
+
/**
|
|
545
|
+
* 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.
|
|
546
|
+
*/
|
|
547
|
+
includeContext: z.optional(z.enum(["none", "thisServer", "allServers"])),
|
|
548
|
+
temperature: z.optional(z.number()),
|
|
549
|
+
/**
|
|
550
|
+
* The maximum number of tokens to sample, as requested by the server. The client MAY choose to sample fewer tokens than requested.
|
|
551
|
+
*/
|
|
552
|
+
maxTokens: z.number().int(),
|
|
553
|
+
stopSequences: z.optional(z.array(z.string())),
|
|
554
|
+
/**
|
|
555
|
+
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
556
|
+
*/
|
|
557
|
+
metadata: z.optional(z.object({}).passthrough()),
|
|
558
|
+
/**
|
|
559
|
+
* The server's preferences for which model to select.
|
|
560
|
+
*/
|
|
561
|
+
modelPreferences: z.optional(ModelPreferencesSchema)
|
|
562
|
+
})
|
|
563
|
+
});
|
|
564
|
+
const CreateMessageResultSchema = ResultSchema.extend({
|
|
565
|
+
/**
|
|
566
|
+
* The name of the model that generated the message.
|
|
567
|
+
*/
|
|
568
|
+
model: z.string(),
|
|
569
|
+
/**
|
|
570
|
+
* The reason why sampling stopped.
|
|
571
|
+
*/
|
|
572
|
+
stopReason: z.optional(z.enum(["endTurn", "stopSequence", "maxTokens"]).or(z.string())),
|
|
573
|
+
role: z.enum(["user", "assistant"]),
|
|
574
|
+
content: z.discriminatedUnion("type", [
|
|
575
|
+
TextContentSchema,
|
|
576
|
+
ImageContentSchema
|
|
577
|
+
])
|
|
578
|
+
});
|
|
579
|
+
const ResourceReferenceSchema = z.object({
|
|
580
|
+
type: z.literal("ref/resource"),
|
|
581
|
+
/**
|
|
582
|
+
* The URI or URI template of the resource.
|
|
583
|
+
*/
|
|
584
|
+
uri: z.string()
|
|
585
|
+
}).passthrough();
|
|
586
|
+
const PromptReferenceSchema = z.object({
|
|
587
|
+
type: z.literal("ref/prompt"),
|
|
588
|
+
/**
|
|
589
|
+
* The name of the prompt or prompt template
|
|
590
|
+
*/
|
|
591
|
+
name: z.string()
|
|
592
|
+
}).passthrough();
|
|
593
|
+
const CompleteRequestSchema = RequestSchema.extend({
|
|
594
|
+
method: z.literal("completion/complete"),
|
|
595
|
+
params: BaseRequestParamsSchema.extend({
|
|
596
|
+
ref: z.union([PromptReferenceSchema, ResourceReferenceSchema]),
|
|
597
|
+
/**
|
|
598
|
+
* The argument's information
|
|
599
|
+
*/
|
|
600
|
+
argument: z.object({
|
|
601
|
+
/**
|
|
602
|
+
* The name of the argument
|
|
603
|
+
*/
|
|
604
|
+
name: z.string(),
|
|
605
|
+
/**
|
|
606
|
+
* The value of the argument to use for completion matching.
|
|
607
|
+
*/
|
|
608
|
+
value: z.string()
|
|
609
|
+
}).passthrough()
|
|
610
|
+
})
|
|
611
|
+
});
|
|
612
|
+
const CompleteResultSchema = ResultSchema.extend({
|
|
613
|
+
completion: z.object({
|
|
614
|
+
/**
|
|
615
|
+
* An array of completion values. Must not exceed 100 items.
|
|
616
|
+
*/
|
|
617
|
+
values: z.array(z.string()).max(100),
|
|
618
|
+
/**
|
|
619
|
+
* The total number of completion options available. This can exceed the number of values actually sent in the response.
|
|
620
|
+
*/
|
|
621
|
+
total: z.optional(z.number().int()),
|
|
622
|
+
/**
|
|
623
|
+
* Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
|
|
624
|
+
*/
|
|
625
|
+
hasMore: z.optional(z.boolean())
|
|
626
|
+
}).passthrough()
|
|
627
|
+
});
|
|
628
|
+
const RootSchema = z.object({
|
|
629
|
+
/**
|
|
630
|
+
* The URI identifying the root. This *must* start with file:// for now.
|
|
631
|
+
*/
|
|
632
|
+
uri: z.string().startsWith("file://"),
|
|
633
|
+
/**
|
|
634
|
+
* An optional name for the root.
|
|
635
|
+
*/
|
|
636
|
+
name: z.optional(z.string())
|
|
637
|
+
}).passthrough();
|
|
638
|
+
const ListRootsRequestSchema = RequestSchema.extend({
|
|
639
|
+
method: z.literal("roots/list")
|
|
640
|
+
});
|
|
641
|
+
const ListRootsResultSchema = ResultSchema.extend({
|
|
642
|
+
roots: z.array(RootSchema)
|
|
643
|
+
});
|
|
644
|
+
const RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
645
|
+
method: z.literal("notifications/roots/list_changed")
|
|
646
|
+
});
|
|
647
|
+
z.union([
|
|
648
|
+
PingRequestSchema,
|
|
649
|
+
InitializeRequestSchema,
|
|
650
|
+
CompleteRequestSchema,
|
|
651
|
+
SetLevelRequestSchema,
|
|
652
|
+
GetPromptRequestSchema,
|
|
653
|
+
ListPromptsRequestSchema,
|
|
654
|
+
ListResourcesRequestSchema,
|
|
655
|
+
ListResourceTemplatesRequestSchema,
|
|
656
|
+
ReadResourceRequestSchema,
|
|
657
|
+
SubscribeRequestSchema,
|
|
658
|
+
UnsubscribeRequestSchema,
|
|
659
|
+
CallToolRequestSchema,
|
|
660
|
+
ListToolsRequestSchema
|
|
661
|
+
]);
|
|
662
|
+
z.union([
|
|
663
|
+
CancelledNotificationSchema,
|
|
664
|
+
ProgressNotificationSchema,
|
|
665
|
+
InitializedNotificationSchema,
|
|
666
|
+
RootsListChangedNotificationSchema
|
|
667
|
+
]);
|
|
668
|
+
z.union([
|
|
669
|
+
EmptyResultSchema,
|
|
670
|
+
CreateMessageResultSchema,
|
|
671
|
+
ListRootsResultSchema
|
|
672
|
+
]);
|
|
673
|
+
z.union([
|
|
674
|
+
PingRequestSchema,
|
|
675
|
+
CreateMessageRequestSchema,
|
|
676
|
+
ListRootsRequestSchema
|
|
677
|
+
]);
|
|
678
|
+
z.union([
|
|
679
|
+
CancelledNotificationSchema,
|
|
680
|
+
ProgressNotificationSchema,
|
|
681
|
+
LoggingMessageNotificationSchema,
|
|
682
|
+
ResourceUpdatedNotificationSchema,
|
|
683
|
+
ResourceListChangedNotificationSchema,
|
|
684
|
+
ToolListChangedNotificationSchema,
|
|
685
|
+
PromptListChangedNotificationSchema
|
|
686
|
+
]);
|
|
687
|
+
z.union([
|
|
688
|
+
EmptyResultSchema,
|
|
689
|
+
InitializeResultSchema,
|
|
690
|
+
CompleteResultSchema,
|
|
691
|
+
GetPromptResultSchema,
|
|
692
|
+
ListPromptsResultSchema,
|
|
693
|
+
ListResourcesResultSchema,
|
|
694
|
+
ListResourceTemplatesResultSchema,
|
|
695
|
+
ReadResourceResultSchema,
|
|
696
|
+
CallToolResultSchema,
|
|
697
|
+
ListToolsResultSchema
|
|
698
|
+
]);
|
|
699
|
+
var MCPProvider = /* @__PURE__ */ ((MCPProvider2) => {
|
|
700
|
+
MCPProvider2["ChatGPT"] = "chatgpt";
|
|
701
|
+
return MCPProvider2;
|
|
702
|
+
})(MCPProvider || {});
|
|
11
703
|
function widgetDescriptorMeta() {
|
|
12
704
|
return {
|
|
13
705
|
"openai/outputTemplate": "ui://widget/app.html",
|
|
@@ -41,11 +733,62 @@ function readWidgetHtml(distPath) {
|
|
|
41
733
|
<div id="root"></div>
|
|
42
734
|
<script>
|
|
43
735
|
${jsContents}
|
|
44
|
-
|
|
736
|
+
<\/script>
|
|
45
737
|
</body>
|
|
46
738
|
</html>`;
|
|
47
739
|
}
|
|
48
|
-
|
|
740
|
+
class ChatGPTMCPProvider {
|
|
741
|
+
getWidgetDescriptorMeta() {
|
|
742
|
+
return widgetDescriptorMeta();
|
|
743
|
+
}
|
|
744
|
+
getWidgetInvocationMeta() {
|
|
745
|
+
return widgetInvocationMeta();
|
|
746
|
+
}
|
|
747
|
+
readWidgetContent(distPath) {
|
|
748
|
+
return readWidgetHtml(distPath);
|
|
749
|
+
}
|
|
750
|
+
getWidgetMimeType() {
|
|
751
|
+
return "text/html+skybridge";
|
|
752
|
+
}
|
|
753
|
+
getWidgetResourceUri() {
|
|
754
|
+
return "ui://widget/app.html";
|
|
755
|
+
}
|
|
756
|
+
createTool(config) {
|
|
757
|
+
return {
|
|
758
|
+
name: config.name,
|
|
759
|
+
description: config.description,
|
|
760
|
+
inputSchema: config.inputSchema,
|
|
761
|
+
title: config.description,
|
|
762
|
+
_meta: widgetDescriptorMeta(),
|
|
763
|
+
annotations: {
|
|
764
|
+
destructiveHint: false,
|
|
765
|
+
openWorldHint: false,
|
|
766
|
+
readOnlyHint: true
|
|
767
|
+
}
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
createResource(config) {
|
|
771
|
+
return {
|
|
772
|
+
uri: this.getWidgetResourceUri(),
|
|
773
|
+
name: config.name,
|
|
774
|
+
description: `${config.description} widget markup`,
|
|
775
|
+
mimeType: this.getWidgetMimeType(),
|
|
776
|
+
_meta: widgetDescriptorMeta()
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
function getChatGPTMCPProvider() {
|
|
781
|
+
return new ChatGPTMCPProvider();
|
|
782
|
+
}
|
|
783
|
+
function getProviderImplementation(provider) {
|
|
784
|
+
switch (provider) {
|
|
785
|
+
case MCPProvider.ChatGPT:
|
|
786
|
+
return getChatGPTMCPProvider();
|
|
787
|
+
default:
|
|
788
|
+
throw new Error(`Unknown provider: ${provider}`);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
function createAppServer(config, providerImpl) {
|
|
49
792
|
const {
|
|
50
793
|
name = "sunpeak-app",
|
|
51
794
|
version = "0.1.0",
|
|
@@ -53,32 +796,22 @@ function createAppServer(config) {
|
|
|
53
796
|
toolDescription = "Show the app",
|
|
54
797
|
dummyData = {}
|
|
55
798
|
} = config;
|
|
56
|
-
const
|
|
799
|
+
const widgetContent = providerImpl.readWidgetContent(config.distPath);
|
|
57
800
|
const toolInputSchema = {
|
|
58
801
|
type: "object",
|
|
59
802
|
properties: {},
|
|
60
803
|
additionalProperties: false
|
|
61
804
|
};
|
|
62
805
|
const toolInputParser = z.object({});
|
|
63
|
-
const tool = {
|
|
806
|
+
const tool = providerImpl.createTool({
|
|
64
807
|
name: toolName,
|
|
65
808
|
description: toolDescription,
|
|
66
|
-
inputSchema: toolInputSchema
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
annotations: {
|
|
70
|
-
destructiveHint: false,
|
|
71
|
-
openWorldHint: false,
|
|
72
|
-
readOnlyHint: true
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const resource = {
|
|
76
|
-
uri: "ui://widget/app.html",
|
|
809
|
+
inputSchema: toolInputSchema
|
|
810
|
+
});
|
|
811
|
+
const resource = providerImpl.createResource({
|
|
77
812
|
name: toolDescription,
|
|
78
|
-
description:
|
|
79
|
-
|
|
80
|
-
_meta: widgetDescriptorMeta()
|
|
81
|
-
};
|
|
813
|
+
description: toolDescription
|
|
814
|
+
});
|
|
82
815
|
const server = new Server(
|
|
83
816
|
{
|
|
84
817
|
name,
|
|
@@ -109,9 +842,9 @@ function createAppServer(config) {
|
|
|
109
842
|
contents: [
|
|
110
843
|
{
|
|
111
844
|
uri: resource.uri,
|
|
112
|
-
mimeType:
|
|
113
|
-
text:
|
|
114
|
-
_meta:
|
|
845
|
+
mimeType: providerImpl.getWidgetMimeType(),
|
|
846
|
+
text: widgetContent,
|
|
847
|
+
_meta: providerImpl.getWidgetDescriptorMeta()
|
|
115
848
|
}
|
|
116
849
|
]
|
|
117
850
|
};
|
|
@@ -127,7 +860,11 @@ function createAppServer(config) {
|
|
|
127
860
|
server.setRequestHandler(
|
|
128
861
|
CallToolRequestSchema,
|
|
129
862
|
async (request) => {
|
|
130
|
-
console.log(
|
|
863
|
+
console.log(
|
|
864
|
+
"[MCP] CallTool:",
|
|
865
|
+
request.params.name,
|
|
866
|
+
request.params.arguments
|
|
867
|
+
);
|
|
131
868
|
if (request.params.name !== toolName) {
|
|
132
869
|
throw new Error(`Unknown tool: ${request.params.name}`);
|
|
133
870
|
}
|
|
@@ -140,18 +877,18 @@ function createAppServer(config) {
|
|
|
140
877
|
}
|
|
141
878
|
],
|
|
142
879
|
structuredContent: dummyData,
|
|
143
|
-
_meta:
|
|
880
|
+
_meta: providerImpl.getWidgetInvocationMeta()
|
|
144
881
|
};
|
|
145
882
|
}
|
|
146
883
|
);
|
|
147
884
|
return server;
|
|
148
885
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
async function handleSseRequest(res, config) {
|
|
886
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
887
|
+
const ssePath = "/mcp";
|
|
888
|
+
const postPath = "/mcp/messages";
|
|
889
|
+
async function handleSseRequest(res, config, providerImpl) {
|
|
153
890
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
154
|
-
const server = createAppServer(config);
|
|
891
|
+
const server = createAppServer(config, providerImpl);
|
|
155
892
|
const transport = new SSEServerTransport(postPath, res);
|
|
156
893
|
const sessionId = transport.sessionId;
|
|
157
894
|
sessions.set(sessionId, { server, transport });
|
|
@@ -195,6 +932,8 @@ async function handlePostMessage(req, res, url) {
|
|
|
195
932
|
}
|
|
196
933
|
}
|
|
197
934
|
function runMCPServer(config) {
|
|
935
|
+
const provider = config.provider ?? MCPProvider.ChatGPT;
|
|
936
|
+
const providerImpl = getProviderImplementation(provider);
|
|
198
937
|
const portEnv = Number(process.env.PORT ?? 6766);
|
|
199
938
|
const port = config.port ?? (Number.isFinite(portEnv) ? portEnv : 6766);
|
|
200
939
|
const httpServer = createServer(
|
|
@@ -215,7 +954,7 @@ function runMCPServer(config) {
|
|
|
215
954
|
return;
|
|
216
955
|
}
|
|
217
956
|
if (req.method === "GET" && url.pathname === ssePath) {
|
|
218
|
-
await handleSseRequest(res, config);
|
|
957
|
+
await handleSseRequest(res, config, providerImpl);
|
|
219
958
|
return;
|
|
220
959
|
}
|
|
221
960
|
if (req.method === "POST" && url.pathname === postPath) {
|
|
@@ -230,14 +969,17 @@ function runMCPServer(config) {
|
|
|
230
969
|
socket.end("HTTP/1.1 400 Bad Request\r\n\r\n");
|
|
231
970
|
});
|
|
232
971
|
httpServer.listen(port, () => {
|
|
233
|
-
console.log(
|
|
972
|
+
console.log(
|
|
973
|
+
`Sunpeak MCP server (${provider}) listening on http://localhost:${port}`
|
|
974
|
+
);
|
|
234
975
|
console.log(` SSE stream: GET http://localhost:${port}${ssePath}`);
|
|
235
976
|
console.log(
|
|
236
977
|
` Message post endpoint: POST http://localhost:${port}${postPath}?sessionId=...`
|
|
237
978
|
);
|
|
238
979
|
});
|
|
239
980
|
}
|
|
240
|
-
|
|
241
|
-
|
|
981
|
+
export {
|
|
982
|
+
MCPProvider,
|
|
983
|
+
runMCPServer
|
|
984
|
+
};
|
|
242
985
|
//# sourceMappingURL=index.js.map
|
|
243
|
-
//# sourceMappingURL=index.js.map
|