@prompt-optimizer/mcp-server 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +669 -0
  2. package/README.md +267 -0
  3. package/THIRD_PARTY_NOTICES.txt +4476 -0
  4. package/bin/prompt-optimizer-desktop-mcp.cjs +10 -0
  5. package/bin/prompt-optimizer-mcp.cjs +20 -0
  6. package/dist/browser.cjs +1 -0
  7. package/dist/browser.js +4202 -0
  8. package/dist/chunk-3FYJ3FRD.js +57 -0
  9. package/dist/chunk-E7Z4Y3F4.js +36402 -0
  10. package/dist/chunk-GBDJTSRW.js +298 -0
  11. package/dist/chunk-HLCN3DLS.js +19745 -0
  12. package/dist/chunk-HYVN7FZZ.js +4787 -0
  13. package/dist/chunk-MEUCFQGU.js +537 -0
  14. package/dist/chunk-N6AUTPPS.js +10647 -0
  15. package/dist/chunk-Q52SACHI.js +304 -0
  16. package/dist/chunk-Q5B3KFB3.js +31 -0
  17. package/dist/chunk-QSPNNVX3.js +49017 -0
  18. package/dist/chunk-SO4YJHYW.js +13450 -0
  19. package/dist/chunk-SV2GETJH.js +65 -0
  20. package/dist/chunk-TFH2LO2H.js +58 -0
  21. package/dist/chunk-TFJEYQ3G.js +786 -0
  22. package/dist/chunk-TLOFCHZI.js +70 -0
  23. package/dist/chunk-TQGHULC7.js +188 -0
  24. package/dist/chunk-UTOMPKTK.js +2209 -0
  25. package/dist/chunk-XXALDAL7.js +1838 -0
  26. package/dist/chunk-YT3U6B54.js +21 -0
  27. package/dist/desktop-business.cjs +1 -0
  28. package/dist/desktop-business.js +1227 -0
  29. package/dist/desktop-comparison-HDIQ6K45.js +22 -0
  30. package/dist/desktop-storage-YRABQCLF.js +14 -0
  31. package/dist/desktop.cjs +1 -0
  32. package/dist/desktop.js +26 -0
  33. package/dist/dist-O5VNBF5I.js +622 -0
  34. package/dist/dist-UMX52UME.js +481 -0
  35. package/dist/index.cjs +1 -0
  36. package/dist/index.js +12 -0
  37. package/dist/legacy.cjs +1 -0
  38. package/dist/legacy.js +26933 -0
  39. package/dist/multipart-parser-XE6WGDAU.js +373 -0
  40. package/dist/node-2RBNZOSK.js +2225 -0
  41. package/dist/node-4Z3USCHW.js +21 -0
  42. package/dist/node-QHGLD5ST.js +25 -0
  43. package/dist/registry-H5F4DGAM-UHR4F6LL.js +13 -0
  44. package/dist/src-7PBMYCGI.js +1398 -0
  45. package/dist/start.cjs +1 -0
  46. package/dist/start.js +16 -0
  47. package/package.json +30 -0
  48. package/preload-env.cjs +352 -0
  49. package/skills/prompt-optimizer-compare/SKILL.md +21 -0
@@ -0,0 +1,304 @@
1
+ import { createRequire as __mcpCreateRequire } from "node:module";
2
+ const require = __mcpCreateRequire(import.meta.url);
3
+ import {
4
+ DesktopSourceError,
5
+ createDesktopComparisonRouter,
6
+ createDesktopReadonlyRouter,
7
+ publicDesktopError
8
+ } from "./chunk-GBDJTSRW.js";
9
+ import {
10
+ CallToolRequestSchema,
11
+ ListToolsRequestSchema,
12
+ Server,
13
+ StdioServerTransport
14
+ } from "./chunk-N6AUTPPS.js";
15
+
16
+ // src/desktop.ts
17
+ var string = { type: "string", minLength: 1 };
18
+ var pagination = { limit: { type: "integer", minimum: 1, maximum: 100 }, cursor: string };
19
+ var assetSelectionFields = { favoriteId: string, assetId: string, expectedRevision: string };
20
+ var readOnly = { readOnlyHint: true, destructiveHint: false };
21
+ var localAction = { readOnlyHint: false, destructiveHint: false, openWorldHint: false };
22
+ function object(properties, required) {
23
+ return { type: "object", properties, required, additionalProperties: false };
24
+ }
25
+ function connectionInput(properties, required) {
26
+ return object({ connectionId: string, ...properties }, ["connectionId", ...required]);
27
+ }
28
+ function tool(name, description, inputSchema, annotations = readOnly) {
29
+ return { name, description, inputSchema, annotations };
30
+ }
31
+ var prepareInput = connectionInput({
32
+ source: object(
33
+ { favoriteId: string, assetId: string, versionId: string, expectedRevision: string },
34
+ ["favoriteId", "assetId", "versionId", "expectedRevision"]
35
+ ),
36
+ variables: {
37
+ type: "object",
38
+ additionalProperties: { type: "string" },
39
+ propertyNames: { not: { enum: ["__proto__", "constructor", "prototype"] } }
40
+ },
41
+ candidatePrompt: object({
42
+ kind: { type: "string", enum: ["draft", "saved-version"] },
43
+ text: string,
44
+ versionId: string
45
+ }, ["kind"]),
46
+ candidates: {
47
+ type: "array",
48
+ minItems: 2,
49
+ maxItems: 2,
50
+ items: object(
51
+ { id: { type: "string", enum: ["a", "b"] }, configKey: string, expectedRevision: string },
52
+ ["id", "configKey", "expectedRevision"]
53
+ )
54
+ }
55
+ }, ["source", "variables", "candidates"]);
56
+ var comparisonTools = [
57
+ tool(
58
+ "po_tests_prepare",
59
+ "Preview a variable-workspace favorite with two different saved model configurations. To compare prompts under the same model, pass candidatePrompt as a draft with text or a saved-version with versionId and use the same model configuration and revision for A and B.",
60
+ prepareInput,
61
+ localAction
62
+ ),
63
+ tool(
64
+ "po_tests_execute",
65
+ "Start both prepared model requests. This sends the previewed prompt to the saved model endpoints using the MCP Node runtime network settings and can incur charges.",
66
+ connectionInput({ preparedId: string, previewRevision: string }, ["preparedId", "previewRevision"]),
67
+ { ...localAction, openWorldHint: true }
68
+ ),
69
+ tool(
70
+ "po_tests_get",
71
+ "Read the current state and outputs of both candidates for a prepared comparison.",
72
+ connectionInput({ preparedId: string }, ["preparedId"])
73
+ ),
74
+ tool(
75
+ "po_tests_cancel",
76
+ "Cancel an active comparison or a single candidate by runId. Any partial output already received is retained.",
77
+ connectionInput({ preparedId: string, runId: string }, ["preparedId"]),
78
+ localAction
79
+ ),
80
+ tool(
81
+ "po_comparisons_save",
82
+ "Save both completed results. Reuse the same saveKey after an uncertain response. The returned comparisonId opens the result in the desktop variable workspace.",
83
+ connectionInput({ preparedId: string, saveKey: string }, ["preparedId", "saveKey"]),
84
+ { ...localAction, idempotentHint: true }
85
+ ),
86
+ tool(
87
+ "po_comparisons_list",
88
+ "List saved comparison summaries for this desktop source.",
89
+ connectionInput({ ...pagination, favoriteId: string }, [])
90
+ ),
91
+ tool(
92
+ "po_comparisons_get",
93
+ "Read a saved comparison, including its frozen input and both outcomes.",
94
+ connectionInput({ comparisonId: string }, ["comparisonId"])
95
+ ),
96
+ tool(
97
+ "po_comparisons_delete",
98
+ "Permanently delete the selected saved comparison using its current revision.",
99
+ connectionInput({ comparisonId: string, expectedRevision: string }, ["comparisonId", "expectedRevision"]),
100
+ { ...localAction, destructiveHint: true, idempotentHint: true }
101
+ )
102
+ ];
103
+ function toolSpecs(access) {
104
+ const comparison = access === "compare";
105
+ const shared = [
106
+ tool("po_sources_list", "List configured desktop source labels without opening storage.", object({}, [])),
107
+ tool(
108
+ "po_sources_open",
109
+ comparison ? "Open one configured migrated desktop source with comparison execution and storage permissions." : "Open one configured migrated desktop source for reading only.",
110
+ object({ sourceId: string, access: { type: "string", enum: [access] } }, ["sourceId", "access"]),
111
+ comparison ? localAction : readOnly
112
+ ),
113
+ tool(
114
+ "po_sources_close",
115
+ comparison ? "Cancel active requests, release this source, and invalidate its prepared comparisons and revisions." : "Close this connection and invalidate its reader revisions.",
116
+ connectionInput({}, []),
117
+ comparison ? localAction : readOnly
118
+ ),
119
+ tool("po_models_list", comparison ? "List saved model descriptions and whether each can run a text comparison." : "List saved model descriptions; execution is unavailable.", connectionInput(pagination, [])),
120
+ tool(
121
+ "po_assets_list",
122
+ "List saved prompt assets without contents or private metadata.",
123
+ connectionInput({ ...pagination, modeKey: string, query: { type: "string" } }, [])
124
+ ),
125
+ tool(
126
+ "po_assets_list_versions",
127
+ "List the versions of a saved prompt in descending version order. Use the returned version ID and asset revision to read the requested version.",
128
+ connectionInput({ ...assetSelectionFields, ...pagination }, ["favoriteId", "assetId"])
129
+ ),
130
+ tool(
131
+ "po_assets_get_version",
132
+ "Read one exact saved or legacy current text version.",
133
+ connectionInput({ ...assetSelectionFields, versionId: string }, ["favoriteId", "assetId", "versionId"])
134
+ )
135
+ ];
136
+ return comparison ? [...shared, ...comparisonTools] : shared;
137
+ }
138
+ function isObject(value) {
139
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
140
+ const prototype = Object.getPrototypeOf(value);
141
+ return prototype === Object.prototype || prototype === null;
142
+ }
143
+ function matches(schema, value) {
144
+ switch (schema.type) {
145
+ case "string":
146
+ return typeof value === "string" && (!schema.minLength || value.trim().length >= schema.minLength) && (!schema.enum || schema.enum.includes(value));
147
+ case "integer":
148
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= schema.minimum && value <= schema.maximum;
149
+ case "array":
150
+ return Array.isArray(value) && value.length >= schema.minItems && value.length <= schema.maxItems && value.every((item) => matches(schema.items, item));
151
+ case "object":
152
+ if (!isObject(value)) return false;
153
+ if ("properties" in schema) {
154
+ return schema.required.every((key) => Object.hasOwn(value, key)) && Object.entries(value).every(([key, field]) => Object.hasOwn(schema.properties, key) && matches(schema.properties[key], field));
155
+ }
156
+ return Object.entries(value).every(([key, field]) => !schema.propertyNames.not.enum.includes(key) && matches(schema.additionalProperties, field));
157
+ }
158
+ }
159
+ function createDesktopToolDispatcher(access, router) {
160
+ const specs = toolSpecs(access);
161
+ const toolsByName = new Map(specs.map((spec) => [spec.name, spec]));
162
+ return {
163
+ specs,
164
+ has: (name) => toolsByName.has(name),
165
+ async call(name, args) {
166
+ const spec = toolsByName.get(name);
167
+ if (!spec) throw new DesktopSourceError("UNKNOWN_TOOL");
168
+ if (!matches(spec.inputSchema, args)) throw new DesktopSourceError("INVALID_INPUT");
169
+ const { connectionId, ...fields } = args;
170
+ const pagination2 = { limit: fields.limit, cursor: fields.cursor };
171
+ switch (name) {
172
+ case "po_sources_list":
173
+ return router.listSources();
174
+ case "po_sources_open":
175
+ return router.open(fields.sourceId, fields.access);
176
+ case "po_sources_close":
177
+ return router.close(connectionId);
178
+ case "po_models_list":
179
+ return router.listModels(connectionId, pagination2);
180
+ case "po_assets_list":
181
+ return router.listAssets(connectionId, {
182
+ ...pagination2,
183
+ modeKey: fields.modeKey,
184
+ query: fields.query
185
+ });
186
+ case "po_assets_list_versions":
187
+ return router.listAssetVersions(connectionId, {
188
+ favoriteId: fields.favoriteId,
189
+ assetId: fields.assetId,
190
+ expectedRevision: fields.expectedRevision
191
+ }, pagination2);
192
+ case "po_assets_get_version":
193
+ return router.getAssetVersion(connectionId, fields);
194
+ case "po_tests_prepare":
195
+ return router.prepare(connectionId, fields);
196
+ case "po_tests_execute":
197
+ return router.execute(connectionId, fields.preparedId, fields.previewRevision);
198
+ case "po_tests_get":
199
+ return router.getTest(connectionId, fields.preparedId);
200
+ case "po_tests_cancel":
201
+ return router.cancel(connectionId, fields.preparedId, fields.runId);
202
+ case "po_comparisons_save":
203
+ return router.saveComparison(connectionId, fields.preparedId, fields.saveKey);
204
+ case "po_comparisons_list":
205
+ return router.listComparisons(connectionId, { ...pagination2, favoriteId: fields.favoriteId });
206
+ case "po_comparisons_get":
207
+ return router.getComparison(connectionId, fields.comparisonId);
208
+ case "po_comparisons_delete":
209
+ return router.deleteComparison(connectionId, fields.comparisonId, fields.expectedRevision);
210
+ default:
211
+ throw new DesktopSourceError("UNKNOWN_TOOL");
212
+ }
213
+ }
214
+ };
215
+ }
216
+ function createDesktopServer(access, router) {
217
+ const dispatcher = createDesktopToolDispatcher(access, router);
218
+ const server = new Server({
219
+ name: access === "compare" ? "prompt-optimizer-desktop-comparison" : "prompt-optimizer-desktop-readonly",
220
+ version: "0.1.0"
221
+ }, { capabilities: { tools: {} } });
222
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: dispatcher.specs }));
223
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
224
+ try {
225
+ const { name, arguments: input } = request.params;
226
+ const payload = await dispatcher.call(name, input ?? {});
227
+ return { structuredContent: payload, content: [{ type: "text", text: JSON.stringify(payload) }] };
228
+ } catch (error) {
229
+ const payload = { error: publicDesktopError(error, access) };
230
+ return { isError: true, structuredContent: payload, content: [{ type: "text", text: JSON.stringify(payload) }] };
231
+ }
232
+ });
233
+ server.onclose = () => {
234
+ void router.dispose().catch(() => {
235
+ });
236
+ };
237
+ return { server, router };
238
+ }
239
+ function createDesktopReadonlyServer(profiles, opener) {
240
+ return createDesktopServer("read", createDesktopReadonlyRouter(profiles, opener));
241
+ }
242
+ function createDesktopComparisonServer(profiles, opener) {
243
+ return createDesktopServer("compare", createDesktopComparisonRouter(profiles, opener));
244
+ }
245
+ async function startDesktopStdio(access, { server, router }) {
246
+ let closing;
247
+ let reportedShutdownFailure = false;
248
+ const close = () => {
249
+ closing ??= (async () => {
250
+ process.stdin.off("end", onEnd);
251
+ process.stdin.off("close", onEnd);
252
+ process.off("SIGINT", onEnd);
253
+ process.off("SIGTERM", onEnd);
254
+ try {
255
+ await router.dispose();
256
+ } finally {
257
+ try {
258
+ await server.close();
259
+ } finally {
260
+ process.stdin.pause();
261
+ process.stdin.destroy();
262
+ }
263
+ }
264
+ })();
265
+ return closing;
266
+ };
267
+ const onEnd = () => {
268
+ void close().catch(() => {
269
+ const scope = access === "compare" ? "comparison" : "readonly";
270
+ if (!reportedShutdownFailure) process.stderr.write(`Desktop ${scope} shutdown failed (SOURCE_CLOSE_FAILED).
271
+ `);
272
+ reportedShutdownFailure = true;
273
+ process.exitCode = 1;
274
+ });
275
+ };
276
+ server.onclose = onEnd;
277
+ process.stdin.once("end", onEnd);
278
+ process.stdin.once("close", onEnd);
279
+ process.once("SIGINT", onEnd);
280
+ process.once("SIGTERM", onEnd);
281
+ try {
282
+ await server.connect(new StdioServerTransport());
283
+ } catch {
284
+ await close();
285
+ throw new DesktopSourceError("SOURCE_OPEN_FAILED");
286
+ }
287
+ return { server, router, close };
288
+ }
289
+ function startDesktopReadonlyStdio(profiles, opener) {
290
+ return startDesktopStdio("read", createDesktopReadonlyServer(profiles, opener));
291
+ }
292
+ function startDesktopComparisonStdio(profiles, opener) {
293
+ return startDesktopStdio("compare", createDesktopComparisonServer(profiles, opener));
294
+ }
295
+
296
+ export {
297
+ toolSpecs,
298
+ matches,
299
+ createDesktopToolDispatcher,
300
+ createDesktopReadonlyServer,
301
+ createDesktopComparisonServer,
302
+ startDesktopReadonlyStdio,
303
+ startDesktopComparisonStdio
304
+ };
@@ -0,0 +1,31 @@
1
+ import { createRequire as __mcpCreateRequire } from "node:module";
2
+ const require = __mcpCreateRequire(import.meta.url);
3
+ import {
4
+ STORAGE_ERROR_CODES,
5
+ __publicField
6
+ } from "./chunk-TQGHULC7.js";
7
+
8
+ // ../core/dist/chunk-YCXJMK6V.js
9
+ var STORAGE_OPERATION_TO_CODE = {
10
+ read: STORAGE_ERROR_CODES.READ_ERROR,
11
+ write: STORAGE_ERROR_CODES.WRITE_ERROR,
12
+ delete: STORAGE_ERROR_CODES.DELETE_ERROR,
13
+ clear: STORAGE_ERROR_CODES.CLEAR_ERROR,
14
+ config: STORAGE_ERROR_CODES.CONFIG_ERROR
15
+ };
16
+ var StorageError = class extends Error {
17
+ constructor(message, operation, params) {
18
+ const code = STORAGE_OPERATION_TO_CODE[operation];
19
+ super(message ? `[${code}] ${message}` : `[${code}]`);
20
+ __publicField(this, "operation", operation);
21
+ __publicField(this, "code");
22
+ __publicField(this, "params");
23
+ this.name = "StorageError";
24
+ this.code = code;
25
+ this.params = params ?? (message ? { details: message } : void 0);
26
+ }
27
+ };
28
+
29
+ export {
30
+ StorageError
31
+ };