sunpeak 0.2.6 → 0.3.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.
- 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 +5014 -0
- package/dist/test/setup.d.ts +0 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +11 -19
- 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.cjs
CHANGED
|
@@ -1,20 +1,707 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const node_http = require("node:http");
|
|
4
|
+
const node_url = require("node:url");
|
|
5
|
+
const index_js = require("@modelcontextprotocol/sdk/server/index.js");
|
|
6
|
+
const sse_js = require("@modelcontextprotocol/sdk/server/sse.js");
|
|
7
|
+
const zod = require("zod");
|
|
8
|
+
const fs = require("node:fs");
|
|
9
|
+
const path = require("node:path");
|
|
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
|
+
var MCPProvider = /* @__PURE__ */ ((MCPProvider2) => {
|
|
702
|
+
MCPProvider2["ChatGPT"] = "chatgpt";
|
|
703
|
+
return MCPProvider2;
|
|
704
|
+
})(MCPProvider || {});
|
|
18
705
|
function widgetDescriptorMeta() {
|
|
19
706
|
return {
|
|
20
707
|
"openai/outputTemplate": "ui://widget/app.html",
|
|
@@ -31,13 +718,13 @@ function widgetInvocationMeta() {
|
|
|
31
718
|
};
|
|
32
719
|
}
|
|
33
720
|
function readWidgetHtml(distPath) {
|
|
34
|
-
const htmlPath =
|
|
35
|
-
if (!
|
|
721
|
+
const htmlPath = path.resolve(distPath);
|
|
722
|
+
if (!fs.existsSync(htmlPath)) {
|
|
36
723
|
throw new Error(
|
|
37
724
|
`Widget HTML not found at ${htmlPath}. Run "pnpm build" to generate the built app.`
|
|
38
725
|
);
|
|
39
726
|
}
|
|
40
|
-
const jsContents =
|
|
727
|
+
const jsContents = fs.readFileSync(htmlPath, "utf8");
|
|
41
728
|
return `<!DOCTYPE html>
|
|
42
729
|
<html>
|
|
43
730
|
<head>
|
|
@@ -48,11 +735,62 @@ function readWidgetHtml(distPath) {
|
|
|
48
735
|
<div id="root"></div>
|
|
49
736
|
<script>
|
|
50
737
|
${jsContents}
|
|
51
|
-
|
|
738
|
+
<\/script>
|
|
52
739
|
</body>
|
|
53
740
|
</html>`;
|
|
54
741
|
}
|
|
55
|
-
|
|
742
|
+
class ChatGPTMCPProvider {
|
|
743
|
+
getWidgetDescriptorMeta() {
|
|
744
|
+
return widgetDescriptorMeta();
|
|
745
|
+
}
|
|
746
|
+
getWidgetInvocationMeta() {
|
|
747
|
+
return widgetInvocationMeta();
|
|
748
|
+
}
|
|
749
|
+
readWidgetContent(distPath) {
|
|
750
|
+
return readWidgetHtml(distPath);
|
|
751
|
+
}
|
|
752
|
+
getWidgetMimeType() {
|
|
753
|
+
return "text/html+skybridge";
|
|
754
|
+
}
|
|
755
|
+
getWidgetResourceUri() {
|
|
756
|
+
return "ui://widget/app.html";
|
|
757
|
+
}
|
|
758
|
+
createTool(config) {
|
|
759
|
+
return {
|
|
760
|
+
name: config.name,
|
|
761
|
+
description: config.description,
|
|
762
|
+
inputSchema: config.inputSchema,
|
|
763
|
+
title: config.description,
|
|
764
|
+
_meta: widgetDescriptorMeta(),
|
|
765
|
+
annotations: {
|
|
766
|
+
destructiveHint: false,
|
|
767
|
+
openWorldHint: false,
|
|
768
|
+
readOnlyHint: true
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
createResource(config) {
|
|
773
|
+
return {
|
|
774
|
+
uri: this.getWidgetResourceUri(),
|
|
775
|
+
name: config.name,
|
|
776
|
+
description: `${config.description} widget markup`,
|
|
777
|
+
mimeType: this.getWidgetMimeType(),
|
|
778
|
+
_meta: widgetDescriptorMeta()
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function getChatGPTMCPProvider() {
|
|
783
|
+
return new ChatGPTMCPProvider();
|
|
784
|
+
}
|
|
785
|
+
function getProviderImplementation(provider) {
|
|
786
|
+
switch (provider) {
|
|
787
|
+
case MCPProvider.ChatGPT:
|
|
788
|
+
return getChatGPTMCPProvider();
|
|
789
|
+
default:
|
|
790
|
+
throw new Error(`Unknown provider: ${provider}`);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
function createAppServer(config, providerImpl) {
|
|
56
794
|
const {
|
|
57
795
|
name = "sunpeak-app",
|
|
58
796
|
version = "0.1.0",
|
|
@@ -60,32 +798,22 @@ function createAppServer(config) {
|
|
|
60
798
|
toolDescription = "Show the app",
|
|
61
799
|
dummyData = {}
|
|
62
800
|
} = config;
|
|
63
|
-
const
|
|
801
|
+
const widgetContent = providerImpl.readWidgetContent(config.distPath);
|
|
64
802
|
const toolInputSchema = {
|
|
65
803
|
type: "object",
|
|
66
804
|
properties: {},
|
|
67
805
|
additionalProperties: false
|
|
68
806
|
};
|
|
69
807
|
const toolInputParser = zod.z.object({});
|
|
70
|
-
const tool = {
|
|
808
|
+
const tool = providerImpl.createTool({
|
|
71
809
|
name: toolName,
|
|
72
810
|
description: toolDescription,
|
|
73
|
-
inputSchema: toolInputSchema
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
annotations: {
|
|
77
|
-
destructiveHint: false,
|
|
78
|
-
openWorldHint: false,
|
|
79
|
-
readOnlyHint: true
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const resource = {
|
|
83
|
-
uri: "ui://widget/app.html",
|
|
811
|
+
inputSchema: toolInputSchema
|
|
812
|
+
});
|
|
813
|
+
const resource = providerImpl.createResource({
|
|
84
814
|
name: toolDescription,
|
|
85
|
-
description:
|
|
86
|
-
|
|
87
|
-
_meta: widgetDescriptorMeta()
|
|
88
|
-
};
|
|
815
|
+
description: toolDescription
|
|
816
|
+
});
|
|
89
817
|
const server = new index_js.Server(
|
|
90
818
|
{
|
|
91
819
|
name,
|
|
@@ -99,14 +827,14 @@ function createAppServer(config) {
|
|
|
99
827
|
}
|
|
100
828
|
);
|
|
101
829
|
server.setRequestHandler(
|
|
102
|
-
|
|
830
|
+
ListResourcesRequestSchema,
|
|
103
831
|
async (_request) => {
|
|
104
832
|
console.log("[MCP] ListResources");
|
|
105
833
|
return { resources: [resource] };
|
|
106
834
|
}
|
|
107
835
|
);
|
|
108
836
|
server.setRequestHandler(
|
|
109
|
-
|
|
837
|
+
ReadResourceRequestSchema,
|
|
110
838
|
async (request) => {
|
|
111
839
|
console.log("[MCP] ReadResource:", request.params.uri);
|
|
112
840
|
if (request.params.uri !== resource.uri) {
|
|
@@ -116,25 +844,29 @@ function createAppServer(config) {
|
|
|
116
844
|
contents: [
|
|
117
845
|
{
|
|
118
846
|
uri: resource.uri,
|
|
119
|
-
mimeType:
|
|
120
|
-
text:
|
|
121
|
-
_meta:
|
|
847
|
+
mimeType: providerImpl.getWidgetMimeType(),
|
|
848
|
+
text: widgetContent,
|
|
849
|
+
_meta: providerImpl.getWidgetDescriptorMeta()
|
|
122
850
|
}
|
|
123
851
|
]
|
|
124
852
|
};
|
|
125
853
|
}
|
|
126
854
|
);
|
|
127
855
|
server.setRequestHandler(
|
|
128
|
-
|
|
856
|
+
ListToolsRequestSchema,
|
|
129
857
|
async (_request) => {
|
|
130
858
|
console.log("[MCP] ListTools");
|
|
131
859
|
return { tools: [tool] };
|
|
132
860
|
}
|
|
133
861
|
);
|
|
134
862
|
server.setRequestHandler(
|
|
135
|
-
|
|
863
|
+
CallToolRequestSchema,
|
|
136
864
|
async (request) => {
|
|
137
|
-
console.log(
|
|
865
|
+
console.log(
|
|
866
|
+
"[MCP] CallTool:",
|
|
867
|
+
request.params.name,
|
|
868
|
+
request.params.arguments
|
|
869
|
+
);
|
|
138
870
|
if (request.params.name !== toolName) {
|
|
139
871
|
throw new Error(`Unknown tool: ${request.params.name}`);
|
|
140
872
|
}
|
|
@@ -147,18 +879,18 @@ function createAppServer(config) {
|
|
|
147
879
|
}
|
|
148
880
|
],
|
|
149
881
|
structuredContent: dummyData,
|
|
150
|
-
_meta:
|
|
882
|
+
_meta: providerImpl.getWidgetInvocationMeta()
|
|
151
883
|
};
|
|
152
884
|
}
|
|
153
885
|
);
|
|
154
886
|
return server;
|
|
155
887
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
async function handleSseRequest(res, config) {
|
|
888
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
889
|
+
const ssePath = "/mcp";
|
|
890
|
+
const postPath = "/mcp/messages";
|
|
891
|
+
async function handleSseRequest(res, config, providerImpl) {
|
|
160
892
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
161
|
-
const server = createAppServer(config);
|
|
893
|
+
const server = createAppServer(config, providerImpl);
|
|
162
894
|
const transport = new sse_js.SSEServerTransport(postPath, res);
|
|
163
895
|
const sessionId = transport.sessionId;
|
|
164
896
|
sessions.set(sessionId, { server, transport });
|
|
@@ -202,17 +934,19 @@ async function handlePostMessage(req, res, url) {
|
|
|
202
934
|
}
|
|
203
935
|
}
|
|
204
936
|
function runMCPServer(config) {
|
|
937
|
+
const provider = config.provider ?? MCPProvider.ChatGPT;
|
|
938
|
+
const providerImpl = getProviderImplementation(provider);
|
|
205
939
|
const portEnv = Number(process.env.PORT ?? 6766);
|
|
206
940
|
const port = config.port ?? (Number.isFinite(portEnv) ? portEnv : 6766);
|
|
207
|
-
const httpServer =
|
|
941
|
+
const httpServer = node_http.createServer(
|
|
208
942
|
async (req, res) => {
|
|
209
943
|
if (!req.url) {
|
|
210
944
|
res.writeHead(400).end("Missing URL");
|
|
211
945
|
return;
|
|
212
946
|
}
|
|
213
|
-
const url
|
|
214
|
-
console.log(`[HTTP] ${req.method} ${url
|
|
215
|
-
if (req.method === "OPTIONS" && (url
|
|
947
|
+
const url = new node_url.URL(req.url, `http://${req.headers.host ?? "localhost"}`);
|
|
948
|
+
console.log(`[HTTP] ${req.method} ${url.pathname}`);
|
|
949
|
+
if (req.method === "OPTIONS" && (url.pathname === ssePath || url.pathname === postPath)) {
|
|
216
950
|
res.writeHead(204, {
|
|
217
951
|
"Access-Control-Allow-Origin": "*",
|
|
218
952
|
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
@@ -221,12 +955,12 @@ function runMCPServer(config) {
|
|
|
221
955
|
res.end();
|
|
222
956
|
return;
|
|
223
957
|
}
|
|
224
|
-
if (req.method === "GET" && url
|
|
225
|
-
await handleSseRequest(res, config);
|
|
958
|
+
if (req.method === "GET" && url.pathname === ssePath) {
|
|
959
|
+
await handleSseRequest(res, config, providerImpl);
|
|
226
960
|
return;
|
|
227
961
|
}
|
|
228
|
-
if (req.method === "POST" && url
|
|
229
|
-
await handlePostMessage(req, res, url
|
|
962
|
+
if (req.method === "POST" && url.pathname === postPath) {
|
|
963
|
+
await handlePostMessage(req, res, url);
|
|
230
964
|
return;
|
|
231
965
|
}
|
|
232
966
|
res.writeHead(404).end("Not Found");
|
|
@@ -237,14 +971,15 @@ function runMCPServer(config) {
|
|
|
237
971
|
socket.end("HTTP/1.1 400 Bad Request\r\n\r\n");
|
|
238
972
|
});
|
|
239
973
|
httpServer.listen(port, () => {
|
|
240
|
-
console.log(
|
|
974
|
+
console.log(
|
|
975
|
+
`Sunpeak MCP server (${provider}) listening on http://localhost:${port}`
|
|
976
|
+
);
|
|
241
977
|
console.log(` SSE stream: GET http://localhost:${port}${ssePath}`);
|
|
242
978
|
console.log(
|
|
243
979
|
` Message post endpoint: POST http://localhost:${port}${postPath}?sessionId=...`
|
|
244
980
|
);
|
|
245
981
|
});
|
|
246
982
|
}
|
|
247
|
-
|
|
983
|
+
exports.MCPProvider = MCPProvider;
|
|
248
984
|
exports.runMCPServer = runMCPServer;
|
|
249
985
|
//# sourceMappingURL=index.cjs.map
|
|
250
|
-
//# sourceMappingURL=index.cjs.map
|