promptlike-mcp 0.2.1 → 0.4.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.
- package/CHANGELOG.md +61 -0
- package/README.md +36 -4
- package/dist/index.js +4 -165
- package/dist/lib/api-client.js +115 -11
- package/dist/lib/constants.js +0 -1
- package/dist/lib/mcpPrompts.js +106 -0
- package/dist/lib/promptText.js +23 -0
- package/dist/lib/promptVariables.js +4 -2
- package/dist/lib/resources.js +71 -0
- package/dist/lib/writeGuard.js +126 -0
- package/dist/lib/writeTools.js +183 -0
- package/dist/server.js +464 -0
- package/package.json +8 -5
package/dist/server.js
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* promptlike-mcp sunucu kurulumu (transport'tan bağımsız → testte InMemory
|
|
4
|
+
* transport'la, üretimde stdio ile bağlanır).
|
|
5
|
+
*
|
|
6
|
+
* Üç yüzey:
|
|
7
|
+
* - tools: okuma (list_prompts / search_prompts / get_prompt / fill_variables
|
|
8
|
+
* / suggest_prompts) + yazma (v0.4+, W1-3: save_prompt / update_prompt)
|
|
9
|
+
* - prompts (v0.3+): kullanıcının kütüphanesi MCP prompt'u olarak — istemcinin
|
|
10
|
+
* `/` menüsünde görünür, {{değişkenler}} prompt argümanı olur. Yerleşik
|
|
11
|
+
* `save-this` prompt'u (v0.4+) konuşmadaki talimatı kaydettirir.
|
|
12
|
+
* - resources (v0.4+): `promptlike://<repo>/<prompt>` — Claude Code'da @-mention.
|
|
13
|
+
*
|
|
14
|
+
* Yazma kimliği her zaman `ple login` oturumunun token'ıdır; plan limitleri ve
|
|
15
|
+
* yetki API'de zorlanır. Silme aracı YOK (eski versiyon asla silinmez).
|
|
16
|
+
* MCP sampling kullanılmaz (2026-07-28 spec'inde deprecated).
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.SAVE_THIS_PROMPT = exports.PROMPT_CATALOG_MAX_PAGES = void 0;
|
|
20
|
+
exports.renderSaveThis = renderSaveThis;
|
|
21
|
+
exports.createServer = createServer;
|
|
22
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
23
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
24
|
+
const zod_1 = require("zod");
|
|
25
|
+
const constants_1 = require("./lib/constants");
|
|
26
|
+
const api_client_1 = require("./lib/api-client");
|
|
27
|
+
const resolver_1 = require("./lib/resolver");
|
|
28
|
+
const promptVariables_1 = require("./lib/promptVariables");
|
|
29
|
+
const promptText_1 = require("./lib/promptText");
|
|
30
|
+
const mcpPrompts_1 = require("./lib/mcpPrompts");
|
|
31
|
+
const resources_1 = require("./lib/resources");
|
|
32
|
+
const writeTools_1 = require("./lib/writeTools");
|
|
33
|
+
const writeGuard_1 = require("./lib/writeGuard");
|
|
34
|
+
function ok(payload) {
|
|
35
|
+
return { content: [{ type: 'text', text: JSON.stringify(payload, null, 2) }] };
|
|
36
|
+
}
|
|
37
|
+
function fail(message) {
|
|
38
|
+
return { content: [{ type: 'text', text: message }], isError: true };
|
|
39
|
+
}
|
|
40
|
+
function fromOutcome(outcome) {
|
|
41
|
+
if (outcome.ok)
|
|
42
|
+
return ok(outcome.payload);
|
|
43
|
+
if (outcome.payload) {
|
|
44
|
+
return { content: [{ type: 'text', text: JSON.stringify({ error: outcome.message, ...outcome.payload }, null, 2) }], isError: true };
|
|
45
|
+
}
|
|
46
|
+
return fail(outcome.message);
|
|
47
|
+
}
|
|
48
|
+
/** Tool gövdesi sarmalayıcı: auth guard + hataları temiz mesaja çevirir. */
|
|
49
|
+
async function guarded(fn) {
|
|
50
|
+
try {
|
|
51
|
+
await (0, api_client_1.ensureAuthed)();
|
|
52
|
+
return await fn();
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
return fail(err instanceof Error ? err.message : 'Unexpected error.');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Ambiguous/not-found çözümleme sonuçlarını tool yanıtına çevirir. */
|
|
59
|
+
function resolveFailure(name, result) {
|
|
60
|
+
if (result.status === 'ambiguous') {
|
|
61
|
+
return ok({
|
|
62
|
+
error: `'${name}' matched multiple prompts. Call again with the 'project' arg (each candidate lists its repo), a more specific name, or an id from the candidates.`,
|
|
63
|
+
candidates: result.candidates,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return fail(`No prompt matched '${name}'.`);
|
|
67
|
+
}
|
|
68
|
+
function summarize(p) {
|
|
69
|
+
return {
|
|
70
|
+
id: p.id,
|
|
71
|
+
title: p.title,
|
|
72
|
+
description: p.description ?? null,
|
|
73
|
+
updated_at: p.updated_at,
|
|
74
|
+
variables: (0, promptVariables_1.extractVariables)((0, promptText_1.versionText)(p.current_version)),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Prompt catalog (prompts/list + prompts/get)
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
/** prompts/list sayfa tavanı: 5 × 100 = 500 prompt (gecikmeyi sınırlar). */
|
|
81
|
+
exports.PROMPT_CATALOG_MAX_PAGES = 5;
|
|
82
|
+
const PROMPT_CATALOG_PAGE_SIZE = 100;
|
|
83
|
+
/** list → get arası aynı katalog kullanılsın; kütüphane değişikliği ≤30 sn'de yansır. */
|
|
84
|
+
const PROMPT_CATALOG_TTL_MS = 30000;
|
|
85
|
+
/**
|
|
86
|
+
* 2026-07-28 spec (SEP-2549) önbellek ipucu: liste yanıtları `ttlMs` +
|
|
87
|
+
* `cacheScope` taşır. Kütüphane kullanıcıya özel → `private`. Eski istemciler
|
|
88
|
+
* bilinmeyen alanı yok sayar.
|
|
89
|
+
*/
|
|
90
|
+
const CACHE_HINT = { ttlMs: PROMPT_CATALOG_TTL_MS, cacheScope: 'private' };
|
|
91
|
+
/** Sunucunun yerleşik prompt'u: konuşmadaki talimatı kütüphaneye kaydettirir. */
|
|
92
|
+
exports.SAVE_THIS_PROMPT = 'save-this';
|
|
93
|
+
const RESERVED_PROMPT_NAMES = new Set([exports.SAVE_THIS_PROMPT]);
|
|
94
|
+
async function fetchAllPrompts() {
|
|
95
|
+
const all = [];
|
|
96
|
+
for (let page = 1; page <= exports.PROMPT_CATALOG_MAX_PAGES; page++) {
|
|
97
|
+
const res = await (0, api_client_1.listPromptsPage)({ page, limit: PROMPT_CATALOG_PAGE_SIZE });
|
|
98
|
+
all.push(...res.prompts);
|
|
99
|
+
if (page >= res.totalPages || res.prompts.length < PROMPT_CATALOG_PAGE_SIZE)
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
return all;
|
|
103
|
+
}
|
|
104
|
+
function createCatalogCache(now) {
|
|
105
|
+
let cached = null;
|
|
106
|
+
return {
|
|
107
|
+
async get(forceFresh = false) {
|
|
108
|
+
if (!forceFresh && cached && now() - cached.at < PROMPT_CATALOG_TTL_MS) {
|
|
109
|
+
return cached.entries;
|
|
110
|
+
}
|
|
111
|
+
await (0, api_client_1.ensureAuthed)();
|
|
112
|
+
const entries = (0, mcpPrompts_1.buildPromptCatalog)(await fetchAllPrompts(), RESERVED_PROMPT_NAMES);
|
|
113
|
+
cached = { at: now(), entries };
|
|
114
|
+
return entries;
|
|
115
|
+
},
|
|
116
|
+
/** Yazmadan sonra: bir sonraki list/get taze kütüphaneyi görür. */
|
|
117
|
+
invalidate() {
|
|
118
|
+
cached = null;
|
|
119
|
+
},
|
|
120
|
+
/** Katalogda ada göre ara; yoksa (yeni prompt) bir kez taze liste. */
|
|
121
|
+
async find(match) {
|
|
122
|
+
return (await this.get()).find(match) ?? (await this.get(true)).find(match);
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** initialize'da istemcinin bildirdiği ad/sürüm → olay defterindeki `client`. */
|
|
127
|
+
function clientLabel(server) {
|
|
128
|
+
const info = server.server.getClientVersion();
|
|
129
|
+
if (!info?.name)
|
|
130
|
+
return undefined;
|
|
131
|
+
return info.version ? `${info.name}/${info.version}` : info.name;
|
|
132
|
+
}
|
|
133
|
+
function useOptions(server, surface, extra = {}) {
|
|
134
|
+
return { surface, client: clientLabel(server), ...extra };
|
|
135
|
+
}
|
|
136
|
+
function toMcpError(err) {
|
|
137
|
+
if (err instanceof types_js_1.McpError)
|
|
138
|
+
return err;
|
|
139
|
+
return new types_js_1.McpError(types_js_1.ErrorCode.InternalError, err instanceof Error ? err.message : 'Unexpected error.');
|
|
140
|
+
}
|
|
141
|
+
/** save-this: modele konuşmadaki yeniden kullanılabilir talimatı çıkarıp kaydettirir. */
|
|
142
|
+
function saveThisPrompt() {
|
|
143
|
+
return {
|
|
144
|
+
name: exports.SAVE_THIS_PROMPT,
|
|
145
|
+
title: 'Save this as a PromptLikeEngineer prompt',
|
|
146
|
+
description: 'Extract the reusable instruction from this conversation, mark {{variables}}, and save it to your library.',
|
|
147
|
+
arguments: [
|
|
148
|
+
{ name: 'title', description: 'Title to use (optional — otherwise one is proposed)', required: false },
|
|
149
|
+
{ name: 'project', description: 'Repo to save into (optional — default: your most recent repo)', required: false },
|
|
150
|
+
{ name: 'focus', description: 'What to capture, if not obvious (optional)', required: false },
|
|
151
|
+
],
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function renderSaveThis(args) {
|
|
155
|
+
const title = args?.title?.trim();
|
|
156
|
+
const project = args?.project?.trim();
|
|
157
|
+
const focus = args?.focus?.trim();
|
|
158
|
+
const lines = [
|
|
159
|
+
'Look back over this conversation and extract the reusable instruction worth keeping as a saved prompt — the part someone would run again on a different input, not the one-off details.',
|
|
160
|
+
'',
|
|
161
|
+
'1. Write it as a standalone prompt: imperative, self-contained, no references to "above" or to this chat.',
|
|
162
|
+
'2. Replace everything that changes between uses with {{snake_case}} variables (e.g. {{file}}, {{language}}, {{audience}}).',
|
|
163
|
+
'3. Never include secrets, API keys, tokens, passwords, personal data or private URLs — use a {{variable}} instead.',
|
|
164
|
+
`4. ${title ? `Use the title "${title}".` : 'Pick a short, specific title (at most 60 characters).'} Add a one-line description.`,
|
|
165
|
+
`5. Show the user the title, description and prompt, then call the promptlike save_prompt tool with title, content and description${project ? `, and project "${project}"` : ''}.`,
|
|
166
|
+
'6. If save_prompt says a prompt with that title already exists, ask the user whether to call update_prompt (adds a new version; nothing is deleted) or pick another title.',
|
|
167
|
+
];
|
|
168
|
+
if (focus)
|
|
169
|
+
lines.splice(1, 0, '', `Focus on: ${focus}`);
|
|
170
|
+
return lines.join('\n');
|
|
171
|
+
}
|
|
172
|
+
function registerPromptLibrary(server, catalog) {
|
|
173
|
+
// McpServer.registerPrompt statik kayıt içindir; kütüphane kullanıcıya göre
|
|
174
|
+
// dinamik olduğundan handler'lar alttaki Server'a doğrudan bağlanır.
|
|
175
|
+
// listChanged: save_prompt/update_prompt sonrası istemciye bildirilir.
|
|
176
|
+
server.server.registerCapabilities({
|
|
177
|
+
prompts: { listChanged: true },
|
|
178
|
+
resources: { listChanged: true },
|
|
179
|
+
});
|
|
180
|
+
server.server.setRequestHandler(types_js_1.ListPromptsRequestSchema, async () => {
|
|
181
|
+
try {
|
|
182
|
+
const entries = await catalog.get();
|
|
183
|
+
return { prompts: [saveThisPrompt(), ...entries.map(mcpPrompts_1.toMcpPrompt)], ...CACHE_HINT };
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
throw toMcpError(err);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
server.server.setRequestHandler(types_js_1.GetPromptRequestSchema, async (request) => {
|
|
190
|
+
const { name, arguments: args } = request.params;
|
|
191
|
+
if (name === exports.SAVE_THIS_PROMPT) {
|
|
192
|
+
return {
|
|
193
|
+
description: 'Save the reusable instruction from this conversation',
|
|
194
|
+
messages: [{ role: 'user', content: { type: 'text', text: renderSaveThis(args) } }],
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
let entry;
|
|
198
|
+
try {
|
|
199
|
+
entry = await catalog.find((e) => e.name === name);
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
throw toMcpError(err);
|
|
203
|
+
}
|
|
204
|
+
if (!entry) {
|
|
205
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Prompt '${name}' not found in your library.`);
|
|
206
|
+
}
|
|
207
|
+
let detail;
|
|
208
|
+
try {
|
|
209
|
+
detail = await (0, api_client_1.getPromptDetail)(entry.prompt.id);
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
throw toMcpError(err);
|
|
213
|
+
}
|
|
214
|
+
if (!detail) {
|
|
215
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Prompt '${name}' is no longer available.`);
|
|
216
|
+
}
|
|
217
|
+
const picked = (0, promptText_1.pickVersion)(detail);
|
|
218
|
+
const rendered = (0, mcpPrompts_1.renderPrompt)((0, promptText_1.versionText)(picked), args);
|
|
219
|
+
(0, api_client_1.recordPromptUse)(detail.id, useOptions(server, 'mcp_prompt', { version: picked?.version_number }));
|
|
220
|
+
const description = rendered.missing.length > 0
|
|
221
|
+
? `${detail.title} — unfilled: ${rendered.missing.join(', ')}`
|
|
222
|
+
: detail.title;
|
|
223
|
+
return {
|
|
224
|
+
description,
|
|
225
|
+
messages: [{ role: 'user', content: { type: 'text', text: rendered.text } }],
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
function registerResources(server, catalog) {
|
|
230
|
+
server.server.setRequestHandler(types_js_1.ListResourcesRequestSchema, async () => {
|
|
231
|
+
try {
|
|
232
|
+
const entries = await catalog.get();
|
|
233
|
+
return { resources: entries.map(resources_1.toMcpResource), ...CACHE_HINT };
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
throw toMcpError(err);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
server.server.setRequestHandler(types_js_1.ListResourceTemplatesRequestSchema, async () => ({
|
|
240
|
+
resourceTemplates: [
|
|
241
|
+
{
|
|
242
|
+
uriTemplate: resources_1.RESOURCE_TEMPLATE,
|
|
243
|
+
name: 'prompt',
|
|
244
|
+
title: 'Saved prompt',
|
|
245
|
+
description: 'A prompt from your PromptLikeEngineer library (current version, as Markdown).',
|
|
246
|
+
mimeType: resources_1.RESOURCE_MIME,
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
}));
|
|
250
|
+
server.server.setRequestHandler(types_js_1.ReadResourceRequestSchema, async (request) => {
|
|
251
|
+
const { uri } = request.params;
|
|
252
|
+
let entry;
|
|
253
|
+
try {
|
|
254
|
+
entry = await catalog.find((e) => (0, resources_1.findByUri)([e], uri) !== undefined);
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
throw toMcpError(err);
|
|
258
|
+
}
|
|
259
|
+
if (!entry) {
|
|
260
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Resource '${uri}' not found in your library.`);
|
|
261
|
+
}
|
|
262
|
+
let detail;
|
|
263
|
+
try {
|
|
264
|
+
detail = await (0, api_client_1.getPromptDetail)(entry.prompt.id);
|
|
265
|
+
}
|
|
266
|
+
catch (err) {
|
|
267
|
+
throw toMcpError(err);
|
|
268
|
+
}
|
|
269
|
+
if (!detail)
|
|
270
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Resource '${uri}' is no longer available.`);
|
|
271
|
+
const picked = (0, promptText_1.pickVersion)(detail);
|
|
272
|
+
(0, api_client_1.recordPromptUse)(detail.id, useOptions(server, 'mcp_resource', { version: picked?.version_number }));
|
|
273
|
+
return {
|
|
274
|
+
contents: [{ uri, mimeType: resources_1.RESOURCE_MIME, text: (0, promptText_1.versionText)(picked) }],
|
|
275
|
+
ttlMs: PROMPT_CATALOG_TTL_MS,
|
|
276
|
+
cacheScope: 'private',
|
|
277
|
+
};
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/** Yazma sonrası: önbelleği boşalt, istemciye liste değişti de (hata yutulur). */
|
|
281
|
+
function afterWrite(server, catalog) {
|
|
282
|
+
catalog.invalidate();
|
|
283
|
+
if (!server.isConnected())
|
|
284
|
+
return;
|
|
285
|
+
server.server.sendPromptListChanged().catch(() => undefined);
|
|
286
|
+
server.server.sendResourceListChanged().catch(() => undefined);
|
|
287
|
+
}
|
|
288
|
+
const READ_ONLY = { readOnlyHint: true, openWorldHint: false };
|
|
289
|
+
/** Yazma: yeni prompt/versiyon ekler, hiçbir şeyi silmez; aynı içerikle tekrar = no-op. */
|
|
290
|
+
const WRITE = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false };
|
|
291
|
+
function createServer(options = {}) {
|
|
292
|
+
const server = new mcp_js_1.McpServer({ name: constants_1.MCP_SERVER_NAME, version: constants_1.MCP_VERSION });
|
|
293
|
+
const catalog = createCatalogCache(options.now ?? Date.now);
|
|
294
|
+
server.registerTool('list_prompts', {
|
|
295
|
+
title: 'List prompts',
|
|
296
|
+
description: "List the user's saved prompts from their PromptLikeEngineer library. " +
|
|
297
|
+
'Optionally filter by tag. Returns id, title, description, updated_at and ' +
|
|
298
|
+
'the {{variable}} names each prompt expects.',
|
|
299
|
+
inputSchema: {
|
|
300
|
+
tag: zod_1.z.string().optional().describe('Filter by tag name'),
|
|
301
|
+
limit: zod_1.z.number().int().min(1).max(100).optional().describe('Max results (default 50)'),
|
|
302
|
+
},
|
|
303
|
+
annotations: READ_ONLY,
|
|
304
|
+
}, async ({ tag, limit }) => guarded(async () => {
|
|
305
|
+
const prompts = await (0, api_client_1.listPrompts)({ tag, limit: limit ?? 50 });
|
|
306
|
+
return ok({ total: prompts.length, prompts: prompts.map(summarize) });
|
|
307
|
+
}));
|
|
308
|
+
server.registerTool('search_prompts', {
|
|
309
|
+
title: 'Search prompts',
|
|
310
|
+
description: "Search the user's prompt library by title and description. " +
|
|
311
|
+
'Returns the same shape as list_prompts.',
|
|
312
|
+
inputSchema: {
|
|
313
|
+
query: zod_1.z.string().min(1).describe('Search text (matched against title + description)'),
|
|
314
|
+
limit: zod_1.z.number().int().min(1).max(100).optional().describe('Max results (default 20)'),
|
|
315
|
+
},
|
|
316
|
+
annotations: READ_ONLY,
|
|
317
|
+
}, async ({ query, limit }) => guarded(async () => {
|
|
318
|
+
const prompts = await (0, api_client_1.listPrompts)({ search: query, limit: limit ?? 20 });
|
|
319
|
+
return ok({ total: prompts.length, prompts: prompts.map(summarize) });
|
|
320
|
+
}));
|
|
321
|
+
server.registerTool('get_prompt', {
|
|
322
|
+
title: 'Get prompt content',
|
|
323
|
+
description: 'Fetch the full content of one prompt by name, title, id or short-id. ' +
|
|
324
|
+
'Optionally pin an exact version number. Returns the prompt text plus the ' +
|
|
325
|
+
'{{variable}} names it expects — if there are variables, either fill them ' +
|
|
326
|
+
'yourself or call fill_variables.',
|
|
327
|
+
inputSchema: {
|
|
328
|
+
name: zod_1.z.string().min(1).describe('Prompt title, id, or unique title fragment'),
|
|
329
|
+
version: zod_1.z.number().int().min(1).optional().describe('Exact version number to fetch (default: current)'),
|
|
330
|
+
project: zod_1.z.string().min(1).optional().describe('Repo name, slug, or id to scope resolution when titles collide'),
|
|
331
|
+
via: zod_1.z
|
|
332
|
+
.enum(['direct', 'suggestion'])
|
|
333
|
+
.optional()
|
|
334
|
+
.describe("Set 'suggestion' when fetching a prompt that suggest_prompts or a PromptLikeEngineer hint offered"),
|
|
335
|
+
},
|
|
336
|
+
annotations: READ_ONLY,
|
|
337
|
+
}, async ({ name, version, project, via }) => guarded(async () => {
|
|
338
|
+
const projectId = project ? await (0, resolver_1.resolveProjectId)(project) : undefined;
|
|
339
|
+
const result = await (0, resolver_1.resolvePromptByName)(name, { projectId });
|
|
340
|
+
if (result.status !== 'found')
|
|
341
|
+
return resolveFailure(name, result);
|
|
342
|
+
const prompt = result.prompt;
|
|
343
|
+
const picked = (0, promptText_1.pickVersion)(prompt, version);
|
|
344
|
+
if (!picked) {
|
|
345
|
+
const available = (prompt.versions ?? []).map((v) => v.version_number);
|
|
346
|
+
return fail(`Version ${version} not found for '${prompt.title}'. Available: ${available.join(', ') || 'none'}.`);
|
|
347
|
+
}
|
|
348
|
+
const text = (0, promptText_1.versionText)(picked);
|
|
349
|
+
(0, api_client_1.recordPromptUse)(prompt.id, useOptions(server, 'mcp_tool', { via, version: picked.version_number }));
|
|
350
|
+
return ok({
|
|
351
|
+
id: prompt.id,
|
|
352
|
+
title: prompt.title,
|
|
353
|
+
description: prompt.description ?? null,
|
|
354
|
+
version: picked.version_number ?? null,
|
|
355
|
+
updated_at: prompt.updated_at,
|
|
356
|
+
variables: (0, promptVariables_1.extractVariables)(text),
|
|
357
|
+
content: text,
|
|
358
|
+
});
|
|
359
|
+
}));
|
|
360
|
+
server.registerTool('fill_variables', {
|
|
361
|
+
title: 'Fill prompt variables',
|
|
362
|
+
description: 'Fetch a prompt and substitute its {{variable}} placeholders with the given ' +
|
|
363
|
+
'values, returning ready-to-use text. Unknown/empty values stay as {{name}} ' +
|
|
364
|
+
'in the output (listed in missing_variables).',
|
|
365
|
+
inputSchema: {
|
|
366
|
+
name: zod_1.z.string().min(1).describe('Prompt title, id, or unique title fragment'),
|
|
367
|
+
variables: zod_1.z.record(zod_1.z.string()).describe('Variable name → value map'),
|
|
368
|
+
version: zod_1.z.number().int().min(1).optional().describe('Exact version number (default: current)'),
|
|
369
|
+
project: zod_1.z.string().min(1).optional().describe('Repo name, slug, or id to scope resolution when titles collide'),
|
|
370
|
+
},
|
|
371
|
+
annotations: READ_ONLY,
|
|
372
|
+
}, async ({ name, variables, version, project }) => guarded(async () => {
|
|
373
|
+
const projectId = project ? await (0, resolver_1.resolveProjectId)(project) : undefined;
|
|
374
|
+
const result = await (0, resolver_1.resolvePromptByName)(name, { projectId });
|
|
375
|
+
if (result.status !== 'found')
|
|
376
|
+
return resolveFailure(name, result);
|
|
377
|
+
const prompt = result.prompt;
|
|
378
|
+
const picked = (0, promptText_1.pickVersion)(prompt, version);
|
|
379
|
+
if (!picked) {
|
|
380
|
+
const available = (prompt.versions ?? []).map((v) => v.version_number);
|
|
381
|
+
return fail(`Version ${version} not found for '${prompt.title}'. Available: ${available.join(', ') || 'none'}.`);
|
|
382
|
+
}
|
|
383
|
+
const raw = (0, promptText_1.versionText)(picked);
|
|
384
|
+
const filled = (0, promptVariables_1.fillVariables)(raw, variables);
|
|
385
|
+
const missing = (0, promptVariables_1.extractVariables)(filled);
|
|
386
|
+
(0, api_client_1.recordPromptUse)(prompt.id, useOptions(server, 'mcp_tool', { version: picked.version_number }));
|
|
387
|
+
return ok({
|
|
388
|
+
id: prompt.id,
|
|
389
|
+
title: prompt.title,
|
|
390
|
+
version: picked.version_number ?? null,
|
|
391
|
+
missing_variables: missing,
|
|
392
|
+
content: filled,
|
|
393
|
+
});
|
|
394
|
+
}));
|
|
395
|
+
server.registerTool('suggest_prompts', {
|
|
396
|
+
title: 'Suggest saved prompts',
|
|
397
|
+
description: "Call once at the start of a non-trivial task to check the user's saved prompts. " +
|
|
398
|
+
'Returns up to `limit` prompts from their own library that match the task (title/description ' +
|
|
399
|
+
"match, weighted by past use). If one fits, fetch it with get_prompt (via: 'suggestion'). " +
|
|
400
|
+
'An empty list means nothing fits — carry on normally. The task text is not stored.',
|
|
401
|
+
inputSchema: {
|
|
402
|
+
task: zod_1.z.string().min(1).max(2000).describe("A short description of the user's task"),
|
|
403
|
+
limit: zod_1.z.number().int().min(1).max(10).optional().describe('Max suggestions (default 3)'),
|
|
404
|
+
},
|
|
405
|
+
annotations: READ_ONLY,
|
|
406
|
+
}, async ({ task, limit }) => guarded(async () => {
|
|
407
|
+
const found = await (0, api_client_1.suggestPrompts)(task, limit ?? 3);
|
|
408
|
+
if (found.length === 0) {
|
|
409
|
+
return ok({ suggestions: [], note: 'No saved prompt fits this task — continue normally.' });
|
|
410
|
+
}
|
|
411
|
+
return ok({
|
|
412
|
+
suggestions: found.map((s) => ({
|
|
413
|
+
id: s.id,
|
|
414
|
+
title: s.title,
|
|
415
|
+
description: s.description,
|
|
416
|
+
used: s.use_count,
|
|
417
|
+
score: s.score,
|
|
418
|
+
})),
|
|
419
|
+
next_step: "If one fits, call get_prompt with its id and via: 'suggestion'.",
|
|
420
|
+
});
|
|
421
|
+
}));
|
|
422
|
+
server.registerTool('save_prompt', {
|
|
423
|
+
title: 'Save a new prompt',
|
|
424
|
+
description: "Save a new prompt to the user's PromptLikeEngineer library (use when the user asks to keep/save " +
|
|
425
|
+
'a prompt, or via the save-this prompt). Mark reusable parts as {{variables}}; never include secrets. ' +
|
|
426
|
+
'Saving the same title + content again is a no-op. If the title already exists with different ' +
|
|
427
|
+
'content, call update_prompt instead. Plan limits apply (the error says so).',
|
|
428
|
+
inputSchema: {
|
|
429
|
+
title: zod_1.z.string().min(1).max(writeGuard_1.MAX_TITLE).describe('Short, specific title'),
|
|
430
|
+
content: zod_1.z.string().min(1).max(writeGuard_1.MAX_CONTENT).describe('The prompt text; use {{variable}} placeholders'),
|
|
431
|
+
description: zod_1.z.string().max(writeGuard_1.MAX_DESCRIPTION).optional().describe('One-line description'),
|
|
432
|
+
project: zod_1.z.string().min(1).optional().describe('Repo name, slug, or id (default: most recently updated repo you can write to)'),
|
|
433
|
+
tags: zod_1.z.array(zod_1.z.string().min(1).max(writeGuard_1.MAX_TAG_LENGTH)).max(writeGuard_1.MAX_TAGS).optional().describe('Tag names'),
|
|
434
|
+
},
|
|
435
|
+
annotations: WRITE,
|
|
436
|
+
}, async (args) => guarded(async () => {
|
|
437
|
+
const outcome = await (0, writeTools_1.savePromptFlow)(args);
|
|
438
|
+
if (outcome.ok && outcome.payload.status === 'created')
|
|
439
|
+
afterWrite(server, catalog);
|
|
440
|
+
return fromOutcome(outcome);
|
|
441
|
+
}));
|
|
442
|
+
server.registerTool('update_prompt', {
|
|
443
|
+
title: 'Save a new version of a prompt',
|
|
444
|
+
description: 'Save new content for an existing prompt as a NEW version (the old version is kept; nothing is ' +
|
|
445
|
+
'deleted). `name` must be the exact title or the id. Content equal to the current version creates ' +
|
|
446
|
+
"no version. bump: 'patch' (default), 'minor' or 'major'.",
|
|
447
|
+
inputSchema: {
|
|
448
|
+
name: zod_1.z.string().min(1).describe('Exact prompt title, or its id / short id'),
|
|
449
|
+
content: zod_1.z.string().min(1).max(writeGuard_1.MAX_CONTENT).describe('The full new prompt text'),
|
|
450
|
+
changelog: zod_1.z.string().max(500).optional().describe('What changed, one line'),
|
|
451
|
+
bump: zod_1.z.enum(['patch', 'minor', 'major']).optional().describe('Semver bump (default patch)'),
|
|
452
|
+
project: zod_1.z.string().min(1).optional().describe('Repo name, slug, or id when titles collide'),
|
|
453
|
+
},
|
|
454
|
+
annotations: WRITE,
|
|
455
|
+
}, async (args) => guarded(async () => {
|
|
456
|
+
const outcome = await (0, writeTools_1.updatePromptFlow)(args);
|
|
457
|
+
if (outcome.ok && outcome.payload.status === 'updated')
|
|
458
|
+
afterWrite(server, catalog);
|
|
459
|
+
return fromOutcome(outcome);
|
|
460
|
+
}));
|
|
461
|
+
registerPromptLibrary(server, catalog);
|
|
462
|
+
registerResources(server, catalog);
|
|
463
|
+
return server;
|
|
464
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "promptlike-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"mcpName": "io.github.zeynepaslierhann/promptlike-mcp",
|
|
5
|
+
"description": "MCP server for PromptLikeEngineer - your prompt library as MCP tools, slash-command prompts and @-resources: list, search, get, fill {{variables}}, suggest, and save new prompts/versions (add-only).",
|
|
5
6
|
"bin": {
|
|
6
7
|
"promptlike-mcp": "dist/index.js",
|
|
7
8
|
"ple-mcp": "dist/index.js"
|
|
@@ -9,13 +10,15 @@
|
|
|
9
10
|
"main": "./dist/index.js",
|
|
10
11
|
"files": [
|
|
11
12
|
"dist",
|
|
12
|
-
"README.md"
|
|
13
|
+
"README.md",
|
|
14
|
+
"CHANGELOG.md"
|
|
13
15
|
],
|
|
14
16
|
"scripts": {
|
|
15
17
|
"build": "tsc && chmod +x dist/index.js",
|
|
16
18
|
"dev": "tsc --watch",
|
|
17
19
|
"typecheck": "tsc --noEmit",
|
|
18
20
|
"test": "vitest run",
|
|
21
|
+
"e2e:stdio": "npm run build && node scripts/e2e-stdio.mjs",
|
|
19
22
|
"start": "node dist/index.js",
|
|
20
23
|
"clean": "rm -rf dist",
|
|
21
24
|
"prepack": "npm run clean && npm run build"
|
|
@@ -45,8 +48,8 @@
|
|
|
45
48
|
"node": ">=18"
|
|
46
49
|
},
|
|
47
50
|
"dependencies": {
|
|
48
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
49
|
-
"zod": "^3.
|
|
51
|
+
"@modelcontextprotocol/sdk": "^1.30.1",
|
|
52
|
+
"zod": "^3.25.76"
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
52
55
|
"@types/node": "^20.10.0",
|