promptlike-mcp 0.2.1 → 0.3.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 +30 -0
- package/README.md +17 -2
- package/dist/index.js +4 -165
- package/dist/lib/api-client.js +8 -3
- package/dist/lib/constants.js +0 -1
- package/dist/lib/mcpPrompts.js +100 -0
- package/dist/lib/promptText.js +23 -0
- package/dist/server.js +243 -0
- package/package.json +7 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.0 — 2026-09-27
|
|
4
|
+
|
|
5
|
+
Your library in the `/` menu.
|
|
6
|
+
|
|
7
|
+
- **New: MCP `prompts` primitive.** Every prompt in your library is now also
|
|
8
|
+
exposed through `prompts/list` + `prompts/get`, so clients that support MCP
|
|
9
|
+
prompts show them as slash commands (Claude Code: `/mcp__promptlike__<name>`;
|
|
10
|
+
Cursor and Claude Desktop list them in their prompt pickers).
|
|
11
|
+
- Names are stable slugs of the prompt title (`Code Review` → `code-review`).
|
|
12
|
+
Titles that collide get an id suffix on every copy (`pr-review-aaaaaaaa`),
|
|
13
|
+
so a name never silently switches to a different prompt.
|
|
14
|
+
- Each `{{variable}}` becomes an optional prompt argument. Empty arguments
|
|
15
|
+
stay as `{{name}}` in the output — the same contract as `fill_variables`.
|
|
16
|
+
- Up to 500 prompts are listed; the list is cached for 30 seconds.
|
|
17
|
+
- **Unchanged:** the four tools (`list_prompts`, `search_prompts`, `get_prompt`,
|
|
18
|
+
`fill_variables`) keep their names, inputs and output shape.
|
|
19
|
+
- `package.json` carries `mcpName: io.github.zeynepaslierhann/promptlike-mcp`
|
|
20
|
+
for the official MCP Registry.
|
|
21
|
+
- `@modelcontextprotocol/sdk` 1.30.
|
|
22
|
+
|
|
23
|
+
## 0.2.1
|
|
24
|
+
|
|
25
|
+
- Server reports its real version (read from `package.json`).
|
|
26
|
+
|
|
27
|
+
## 0.2.0
|
|
28
|
+
|
|
29
|
+
- `project` argument on `get_prompt` / `fill_variables` to scope resolution
|
|
30
|
+
when titles collide; ambiguity candidates list their repo.
|
package/README.md
CHANGED
|
@@ -21,7 +21,22 @@ claude mcp add promptlike -- npx -y promptlike-mcp
|
|
|
21
21
|
|
|
22
22
|
Any other MCP client: run `npx -y promptlike-mcp` over stdio.
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## Prompts (v0.3+) — your library in the `/` menu
|
|
25
|
+
|
|
26
|
+
The server also implements the MCP **prompts** primitive (`prompts/list`, `prompts/get`), so clients that support it show your library as slash commands:
|
|
27
|
+
|
|
28
|
+
- **Claude Code:** type `/` → `/mcp__promptlike__code-review`
|
|
29
|
+
- **Cursor / Claude Desktop:** pick from the MCP prompt list
|
|
30
|
+
|
|
31
|
+
| Your prompt | MCP prompt |
|
|
32
|
+
|---|---|
|
|
33
|
+
| Title `Code Review` | name `code-review` (title slug; colliding titles get an id suffix on every copy, e.g. `pr-review-aaaaaaaa`) |
|
|
34
|
+
| `{{file}}`, `{{focus}}` in the body | optional arguments `file`, `focus` — empty ones stay as `{{name}}` |
|
|
35
|
+
| Repo + description | shown as the prompt description, e.g. `[ai-os] Reviews a diff` |
|
|
36
|
+
|
|
37
|
+
Up to 500 prompts are listed (most recently updated first); the list is cached for 30 seconds, so a prompt you just saved shows up within half a minute. The four tools below are unchanged.
|
|
38
|
+
|
|
39
|
+
## Tools (read-only)
|
|
25
40
|
|
|
26
41
|
| Tool | What it does |
|
|
27
42
|
|---|---|
|
|
@@ -30,7 +45,7 @@ Any other MCP client: run `npx -y promptlike-mcp` over stdio.
|
|
|
30
45
|
| `get_prompt` | Full content by name/id/short-id, optional `version` pin. |
|
|
31
46
|
| `fill_variables` | Fetch + substitute `{{variables}}`, returns ready-to-use text (unfilled ones reported in `missing_variables`). |
|
|
32
47
|
|
|
33
|
-
Writing/improving prompts is intentionally out of scope
|
|
48
|
+
Writing/improving prompts is intentionally out of scope — an agent can never burn your AI tokens or mutate your library through this server.
|
|
34
49
|
|
|
35
50
|
## Notes
|
|
36
51
|
|
package/dist/index.js
CHANGED
|
@@ -10,176 +10,15 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Kurulum (Claude Code):
|
|
12
12
|
* claude mcp add promptlike -- npx -y promptlike-mcp
|
|
13
|
+
*
|
|
14
|
+
* Tool + prompt tanımları: ./server.ts
|
|
13
15
|
*/
|
|
14
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
16
17
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
17
|
-
const zod_1 = require("zod");
|
|
18
18
|
const constants_1 = require("./lib/constants");
|
|
19
|
-
const
|
|
20
|
-
const resolver_1 = require("./lib/resolver");
|
|
21
|
-
const promptVariables_1 = require("./lib/promptVariables");
|
|
22
|
-
function ok(payload) {
|
|
23
|
-
return { content: [{ type: 'text', text: JSON.stringify(payload, null, 2) }] };
|
|
24
|
-
}
|
|
25
|
-
function fail(message) {
|
|
26
|
-
return { content: [{ type: 'text', text: message }], isError: true };
|
|
27
|
-
}
|
|
28
|
-
/** Tool gövdesi sarmalayıcı: auth guard + hataları temiz mesaja çevirir. */
|
|
29
|
-
async function guarded(fn) {
|
|
30
|
-
try {
|
|
31
|
-
await (0, api_client_1.ensureAuthed)();
|
|
32
|
-
return await fn();
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
return fail(err instanceof Error ? err.message : 'Unexpected error.');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/** Bir versiyonun kopyalanabilir düz metni. Yapısal parçalardan yeniden kurar ve
|
|
39
|
-
* BOŞ bölümleri atlar (E2E bulgusu F2: yalnız-description prompt'ta başıboş `---`
|
|
40
|
-
* çıkmasın). Stored `content` yalnız üç parça da boşken (legacy) yedek. */
|
|
41
|
-
function versionText(v) {
|
|
42
|
-
if (!v)
|
|
43
|
-
return '';
|
|
44
|
-
const parts = [v.role_text, v.description_text, v.context_text]
|
|
45
|
-
.map((s) => (s || '').trim())
|
|
46
|
-
.filter(Boolean);
|
|
47
|
-
if (parts.length > 0)
|
|
48
|
-
return parts.join('\n\n---\n\n');
|
|
49
|
-
return v.content && v.content.trim() ? v.content.trim() : '';
|
|
50
|
-
}
|
|
51
|
-
/** Ambiguous/not-found çözümleme sonuçlarını tool yanıtına çevirir. */
|
|
52
|
-
function resolveFailure(name, result) {
|
|
53
|
-
if (result.status === 'ambiguous') {
|
|
54
|
-
return ok({
|
|
55
|
-
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.`,
|
|
56
|
-
candidates: result.candidates,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
return fail(`No prompt matched '${name}'.`);
|
|
60
|
-
}
|
|
61
|
-
/** get_prompt / fill_variables ortak içerik seçimi (version pin dahil). */
|
|
62
|
-
function pickVersion(prompt, version) {
|
|
63
|
-
if (version === undefined)
|
|
64
|
-
return prompt.current_version ?? prompt.versions?.[0] ?? null;
|
|
65
|
-
return prompt.versions?.find((v) => v.version_number === version) ?? null;
|
|
66
|
-
}
|
|
67
|
-
// ---------------------------------------------------------------------------
|
|
68
|
-
// Server + tools
|
|
69
|
-
// ---------------------------------------------------------------------------
|
|
70
|
-
const server = new mcp_js_1.McpServer({ name: constants_1.MCP_SERVER_NAME, version: constants_1.MCP_VERSION });
|
|
71
|
-
server.registerTool('list_prompts', {
|
|
72
|
-
title: 'List prompts',
|
|
73
|
-
description: "List the user's saved prompts from their PromptLikeEngineer library. " +
|
|
74
|
-
'Optionally filter by tag. Returns id, title, description, updated_at and ' +
|
|
75
|
-
'the {{variable}} names each prompt expects.',
|
|
76
|
-
inputSchema: {
|
|
77
|
-
tag: zod_1.z.string().optional().describe('Filter by tag name'),
|
|
78
|
-
limit: zod_1.z.number().int().min(1).max(100).optional().describe('Max results (default 50)'),
|
|
79
|
-
},
|
|
80
|
-
}, async ({ tag, limit }) => guarded(async () => {
|
|
81
|
-
const prompts = await (0, api_client_1.listPrompts)({ tag, limit: limit ?? 50 });
|
|
82
|
-
return ok({
|
|
83
|
-
total: prompts.length,
|
|
84
|
-
prompts: prompts.map((p) => ({
|
|
85
|
-
id: p.id,
|
|
86
|
-
title: p.title,
|
|
87
|
-
description: p.description ?? null,
|
|
88
|
-
updated_at: p.updated_at,
|
|
89
|
-
variables: (0, promptVariables_1.extractVariables)(versionText(p.current_version)),
|
|
90
|
-
})),
|
|
91
|
-
});
|
|
92
|
-
}));
|
|
93
|
-
server.registerTool('search_prompts', {
|
|
94
|
-
title: 'Search prompts',
|
|
95
|
-
description: "Search the user's prompt library by title and description. " +
|
|
96
|
-
'Returns the same shape as list_prompts.',
|
|
97
|
-
inputSchema: {
|
|
98
|
-
query: zod_1.z.string().min(1).describe('Search text (matched against title + description)'),
|
|
99
|
-
limit: zod_1.z.number().int().min(1).max(100).optional().describe('Max results (default 20)'),
|
|
100
|
-
},
|
|
101
|
-
}, async ({ query, limit }) => guarded(async () => {
|
|
102
|
-
const prompts = await (0, api_client_1.listPrompts)({ search: query, limit: limit ?? 20 });
|
|
103
|
-
return ok({
|
|
104
|
-
total: prompts.length,
|
|
105
|
-
prompts: prompts.map((p) => ({
|
|
106
|
-
id: p.id,
|
|
107
|
-
title: p.title,
|
|
108
|
-
description: p.description ?? null,
|
|
109
|
-
updated_at: p.updated_at,
|
|
110
|
-
variables: (0, promptVariables_1.extractVariables)(versionText(p.current_version)),
|
|
111
|
-
})),
|
|
112
|
-
});
|
|
113
|
-
}));
|
|
114
|
-
server.registerTool('get_prompt', {
|
|
115
|
-
title: 'Get prompt content',
|
|
116
|
-
description: 'Fetch the full content of one prompt by name, title, id or short-id. ' +
|
|
117
|
-
'Optionally pin an exact version number. Returns the prompt text plus the ' +
|
|
118
|
-
'{{variable}} names it expects — if there are variables, either fill them ' +
|
|
119
|
-
'yourself or call fill_variables.',
|
|
120
|
-
inputSchema: {
|
|
121
|
-
name: zod_1.z.string().min(1).describe('Prompt title, id, or unique title fragment'),
|
|
122
|
-
version: zod_1.z.number().int().min(1).optional().describe('Exact version number to fetch (default: current)'),
|
|
123
|
-
project: zod_1.z.string().min(1).optional().describe('Repo name, slug, or id to scope resolution when titles collide'),
|
|
124
|
-
},
|
|
125
|
-
}, async ({ name, version, project }) => guarded(async () => {
|
|
126
|
-
const projectId = project ? await (0, resolver_1.resolveProjectId)(project) : undefined;
|
|
127
|
-
const result = await (0, resolver_1.resolvePromptByName)(name, { projectId });
|
|
128
|
-
if (result.status !== 'found')
|
|
129
|
-
return resolveFailure(name, result);
|
|
130
|
-
const prompt = result.prompt;
|
|
131
|
-
const picked = pickVersion(prompt, version);
|
|
132
|
-
if (!picked) {
|
|
133
|
-
const available = (prompt.versions ?? []).map((v) => v.version_number);
|
|
134
|
-
return fail(`Version ${version} not found for '${prompt.title}'. Available: ${available.join(', ') || 'none'}.`);
|
|
135
|
-
}
|
|
136
|
-
const text = versionText(picked);
|
|
137
|
-
(0, api_client_1.recordPromptUse)(prompt.id);
|
|
138
|
-
return ok({
|
|
139
|
-
id: prompt.id,
|
|
140
|
-
title: prompt.title,
|
|
141
|
-
description: prompt.description ?? null,
|
|
142
|
-
version: picked.version_number ?? null,
|
|
143
|
-
updated_at: prompt.updated_at,
|
|
144
|
-
variables: (0, promptVariables_1.extractVariables)(text),
|
|
145
|
-
content: text,
|
|
146
|
-
});
|
|
147
|
-
}));
|
|
148
|
-
server.registerTool('fill_variables', {
|
|
149
|
-
title: 'Fill prompt variables',
|
|
150
|
-
description: 'Fetch a prompt and substitute its {{variable}} placeholders with the given ' +
|
|
151
|
-
'values, returning ready-to-use text. Unknown/empty values stay as {{name}} ' +
|
|
152
|
-
'in the output (listed in missing_variables).',
|
|
153
|
-
inputSchema: {
|
|
154
|
-
name: zod_1.z.string().min(1).describe('Prompt title, id, or unique title fragment'),
|
|
155
|
-
variables: zod_1.z.record(zod_1.z.string()).describe('Variable name → value map'),
|
|
156
|
-
version: zod_1.z.number().int().min(1).optional().describe('Exact version number (default: current)'),
|
|
157
|
-
project: zod_1.z.string().min(1).optional().describe('Repo name, slug, or id to scope resolution when titles collide'),
|
|
158
|
-
},
|
|
159
|
-
}, async ({ name, variables, version, project }) => guarded(async () => {
|
|
160
|
-
const projectId = project ? await (0, resolver_1.resolveProjectId)(project) : undefined;
|
|
161
|
-
const result = await (0, resolver_1.resolvePromptByName)(name, { projectId });
|
|
162
|
-
if (result.status !== 'found')
|
|
163
|
-
return resolveFailure(name, result);
|
|
164
|
-
const prompt = result.prompt;
|
|
165
|
-
const picked = pickVersion(prompt, version);
|
|
166
|
-
if (!picked) {
|
|
167
|
-
const available = (prompt.versions ?? []).map((v) => v.version_number);
|
|
168
|
-
return fail(`Version ${version} not found for '${prompt.title}'. Available: ${available.join(', ') || 'none'}.`);
|
|
169
|
-
}
|
|
170
|
-
const raw = versionText(picked);
|
|
171
|
-
const filled = (0, promptVariables_1.fillVariables)(raw, variables);
|
|
172
|
-
const missing = (0, promptVariables_1.extractVariables)(filled);
|
|
173
|
-
(0, api_client_1.recordPromptUse)(prompt.id);
|
|
174
|
-
return ok({
|
|
175
|
-
id: prompt.id,
|
|
176
|
-
title: prompt.title,
|
|
177
|
-
version: picked.version_number ?? null,
|
|
178
|
-
missing_variables: missing,
|
|
179
|
-
content: filled,
|
|
180
|
-
});
|
|
181
|
-
}));
|
|
19
|
+
const server_1 = require("./server");
|
|
182
20
|
async function main() {
|
|
21
|
+
const server = (0, server_1.createServer)();
|
|
183
22
|
const transport = new stdio_js_1.StdioServerTransport();
|
|
184
23
|
await server.connect(transport);
|
|
185
24
|
// stdio sunucusunda stdout PROTOKOLE ait — insan-log'u stderr'e.
|
package/dist/lib/api-client.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.NOT_LOGGED_IN = void 0;
|
|
16
16
|
exports.ensureAuthed = ensureAuthed;
|
|
17
|
+
exports.listPromptsPage = listPromptsPage;
|
|
17
18
|
exports.listPrompts = listPrompts;
|
|
18
19
|
exports.listProjects = listProjects;
|
|
19
20
|
exports.getPromptDetail = getPromptDetail;
|
|
@@ -131,8 +132,8 @@ async function ensureAuthed() {
|
|
|
131
132
|
await refreshSession();
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
|
-
/** GET /api/prompts —
|
|
135
|
-
async function
|
|
135
|
+
/** GET /api/prompts — one page, with `totalPages` for callers that walk pages. */
|
|
136
|
+
async function listPromptsPage(params = {}) {
|
|
136
137
|
const res = await apiFetch('/api/prompts', {
|
|
137
138
|
query: {
|
|
138
139
|
tag: params.tag,
|
|
@@ -142,7 +143,11 @@ async function listPrompts(params = {}) {
|
|
|
142
143
|
projectId: params.projectId,
|
|
143
144
|
},
|
|
144
145
|
});
|
|
145
|
-
return res.prompts ?? [];
|
|
146
|
+
return { prompts: res.prompts ?? [], totalPages: res.totalPages ?? 1 };
|
|
147
|
+
}
|
|
148
|
+
/** GET /api/prompts — list the user's prompts (optionally by tag / search). */
|
|
149
|
+
async function listPrompts(params = {}) {
|
|
150
|
+
return (await listPromptsPage(params)).prompts;
|
|
146
151
|
}
|
|
147
152
|
/** GET /api/projects — accessible repos, for resolving a `project` argument. */
|
|
148
153
|
async function listProjects() {
|
package/dist/lib/constants.js
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MCP `prompts` primitive'i — kullanıcının kütüphanesini istemcinin `/` menüsüne
|
|
4
|
+
* (Claude Code: `/mcp__promptlike__<ad>`, Cursor/Claude Desktop prompt listesi)
|
|
5
|
+
* taşıyan SAF mantık. Ağ/SDK bağımlılığı yok → birim testlenebilir.
|
|
6
|
+
*
|
|
7
|
+
* Ad kuralı (deterministik, sıra-bağımsız):
|
|
8
|
+
* - başlık → küçük harf ASCII slug (Türkçe harfler çevrilir), `[a-z0-9-]`
|
|
9
|
+
* - aynı slug'a düşen HER prompt'a `-<id'nin ilk 8'i>` eklenir (yalnız
|
|
10
|
+
* ikinciye değil) → liste sırası değişse de ad değişmez, prompts/get aynı
|
|
11
|
+
* adı aynı prompt'a çözer.
|
|
12
|
+
* - `{{değişken}}` adları MCP prompt argümanı olur (required: false — boş
|
|
13
|
+
* bırakılan `{{ad}}` olarak kalır, fill_variables ile aynı sözleşme).
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.slugifyPromptName = slugifyPromptName;
|
|
17
|
+
exports.buildPromptCatalog = buildPromptCatalog;
|
|
18
|
+
exports.toMcpPrompt = toMcpPrompt;
|
|
19
|
+
exports.renderPrompt = renderPrompt;
|
|
20
|
+
const promptVariables_1 = require("./promptVariables");
|
|
21
|
+
const promptText_1 = require("./promptText");
|
|
22
|
+
/** Slug uzunluk tavanı — istemci menülerinde okunur kalsın. */
|
|
23
|
+
const MAX_SLUG_LENGTH = 48;
|
|
24
|
+
const TURKISH_MAP = {
|
|
25
|
+
ı: 'i',
|
|
26
|
+
İ: 'i',
|
|
27
|
+
ş: 's',
|
|
28
|
+
Ş: 's',
|
|
29
|
+
ğ: 'g',
|
|
30
|
+
Ğ: 'g',
|
|
31
|
+
ü: 'u',
|
|
32
|
+
Ü: 'u',
|
|
33
|
+
ö: 'o',
|
|
34
|
+
Ö: 'o',
|
|
35
|
+
ç: 'c',
|
|
36
|
+
Ç: 'c',
|
|
37
|
+
};
|
|
38
|
+
/** Başlığı MCP prompt adına çevirir. Boş kalırsa '' döner (çağıran id ile doldurur). */
|
|
39
|
+
function slugifyPromptName(title) {
|
|
40
|
+
const ascii = title
|
|
41
|
+
.replace(/[ıİşŞğĞüÜöÖçÇ]/g, (ch) => TURKISH_MAP[ch] ?? ch)
|
|
42
|
+
.normalize('NFKD')
|
|
43
|
+
.replace(/[̀-ͯ]/g, '')
|
|
44
|
+
.toLowerCase();
|
|
45
|
+
const slug = ascii
|
|
46
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
47
|
+
.replace(/^-+|-+$/g, '');
|
|
48
|
+
if (slug.length <= MAX_SLUG_LENGTH)
|
|
49
|
+
return slug;
|
|
50
|
+
return slug.slice(0, MAX_SLUG_LENGTH).replace(/-+$/g, '');
|
|
51
|
+
}
|
|
52
|
+
function shortId(id) {
|
|
53
|
+
return id.replace(/-/g, '').slice(0, 8).toLowerCase();
|
|
54
|
+
}
|
|
55
|
+
/** Prompt listesinden benzersiz, deterministik adlı katalog kurar. */
|
|
56
|
+
function buildPromptCatalog(prompts) {
|
|
57
|
+
const base = prompts.map((p) => {
|
|
58
|
+
const slug = slugifyPromptName(p.title);
|
|
59
|
+
return { prompt: p, slug: slug || `prompt-${shortId(p.id)}` };
|
|
60
|
+
});
|
|
61
|
+
const counts = new Map();
|
|
62
|
+
for (const { slug } of base)
|
|
63
|
+
counts.set(slug, (counts.get(slug) ?? 0) + 1);
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
const catalog = [];
|
|
66
|
+
for (const { prompt, slug } of base) {
|
|
67
|
+
const name = (counts.get(slug) ?? 0) > 1 ? `${slug}-${shortId(prompt.id)}` : slug;
|
|
68
|
+
// Aynı id iki sayfada gelirse (liste arası güncelleme) ikinciyi at.
|
|
69
|
+
if (seen.has(name))
|
|
70
|
+
continue;
|
|
71
|
+
seen.add(name);
|
|
72
|
+
catalog.push({ name, prompt });
|
|
73
|
+
}
|
|
74
|
+
return catalog;
|
|
75
|
+
}
|
|
76
|
+
/** Katalog girdisini prompts/list öğesine çevirir. */
|
|
77
|
+
function toMcpPrompt(entry) {
|
|
78
|
+
const { prompt } = entry;
|
|
79
|
+
const variables = (0, promptVariables_1.extractVariables)((0, promptText_1.versionText)(prompt.current_version));
|
|
80
|
+
const descParts = [
|
|
81
|
+
prompt.project_name ? `[${prompt.project_name}]` : '',
|
|
82
|
+
(prompt.description ?? '').trim(),
|
|
83
|
+
].filter(Boolean);
|
|
84
|
+
const out = { name: entry.name, title: prompt.title };
|
|
85
|
+
if (descParts.length > 0)
|
|
86
|
+
out.description = descParts.join(' ');
|
|
87
|
+
if (variables.length > 0) {
|
|
88
|
+
out.arguments = variables.map((v) => ({
|
|
89
|
+
name: v,
|
|
90
|
+
description: `Value for {{${v}}} (left as-is when empty)`,
|
|
91
|
+
required: false,
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
/** prompts/get gövdesi: {{değişken}}leri argümanlarla doldurur, eksikleri raporlar. */
|
|
97
|
+
function renderPrompt(text, args) {
|
|
98
|
+
const filled = (0, promptVariables_1.fillVariables)(text, args ?? {});
|
|
99
|
+
return { text: filled, missing: (0, promptVariables_1.extractVariables)(filled) };
|
|
100
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.versionText = versionText;
|
|
4
|
+
exports.pickVersion = pickVersion;
|
|
5
|
+
/** Bir versiyonun kopyalanabilir düz metni. Yapısal parçalardan yeniden kurar ve
|
|
6
|
+
* BOŞ bölümleri atlar (E2E bulgusu F2: yalnız-description prompt'ta başıboş `---`
|
|
7
|
+
* çıkmasın). Stored `content` yalnız üç parça da boşken (legacy) yedek. */
|
|
8
|
+
function versionText(v) {
|
|
9
|
+
if (!v)
|
|
10
|
+
return '';
|
|
11
|
+
const parts = [v.role_text, v.description_text, v.context_text]
|
|
12
|
+
.map((s) => (s || '').trim())
|
|
13
|
+
.filter(Boolean);
|
|
14
|
+
if (parts.length > 0)
|
|
15
|
+
return parts.join('\n\n---\n\n');
|
|
16
|
+
return v.content && v.content.trim() ? v.content.trim() : '';
|
|
17
|
+
}
|
|
18
|
+
/** Tool'lar + prompts/get ortak içerik seçimi (version pin dahil). */
|
|
19
|
+
function pickVersion(prompt, version) {
|
|
20
|
+
if (version === undefined)
|
|
21
|
+
return prompt.current_version ?? prompt.versions?.[0] ?? null;
|
|
22
|
+
return prompt.versions?.find((v) => v.version_number === version) ?? null;
|
|
23
|
+
}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
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
|
+
* İki yüzey:
|
|
7
|
+
* - tools (v0.1+): list_prompts / search_prompts / get_prompt / fill_variables
|
|
8
|
+
* - prompts (v0.3+): kullanıcının kütüphanesi MCP prompt'u olarak — istemcinin
|
|
9
|
+
* `/` menüsünde görünür, {{değişkenler}} prompt argümanı olur.
|
|
10
|
+
* İkisi de SALT-OKUNUR (REV-4 v1 kapsamı: yazma/improve yok).
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.PROMPT_CATALOG_MAX_PAGES = void 0;
|
|
14
|
+
exports.createServer = createServer;
|
|
15
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
16
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
17
|
+
const zod_1 = require("zod");
|
|
18
|
+
const constants_1 = require("./lib/constants");
|
|
19
|
+
const api_client_1 = require("./lib/api-client");
|
|
20
|
+
const resolver_1 = require("./lib/resolver");
|
|
21
|
+
const promptVariables_1 = require("./lib/promptVariables");
|
|
22
|
+
const promptText_1 = require("./lib/promptText");
|
|
23
|
+
const mcpPrompts_1 = require("./lib/mcpPrompts");
|
|
24
|
+
function ok(payload) {
|
|
25
|
+
return { content: [{ type: 'text', text: JSON.stringify(payload, null, 2) }] };
|
|
26
|
+
}
|
|
27
|
+
function fail(message) {
|
|
28
|
+
return { content: [{ type: 'text', text: message }], isError: true };
|
|
29
|
+
}
|
|
30
|
+
/** Tool gövdesi sarmalayıcı: auth guard + hataları temiz mesaja çevirir. */
|
|
31
|
+
async function guarded(fn) {
|
|
32
|
+
try {
|
|
33
|
+
await (0, api_client_1.ensureAuthed)();
|
|
34
|
+
return await fn();
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
return fail(err instanceof Error ? err.message : 'Unexpected error.');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Ambiguous/not-found çözümleme sonuçlarını tool yanıtına çevirir. */
|
|
41
|
+
function resolveFailure(name, result) {
|
|
42
|
+
if (result.status === 'ambiguous') {
|
|
43
|
+
return ok({
|
|
44
|
+
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.`,
|
|
45
|
+
candidates: result.candidates,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return fail(`No prompt matched '${name}'.`);
|
|
49
|
+
}
|
|
50
|
+
function summarize(p) {
|
|
51
|
+
return {
|
|
52
|
+
id: p.id,
|
|
53
|
+
title: p.title,
|
|
54
|
+
description: p.description ?? null,
|
|
55
|
+
updated_at: p.updated_at,
|
|
56
|
+
variables: (0, promptVariables_1.extractVariables)((0, promptText_1.versionText)(p.current_version)),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
// Prompt catalog (prompts/list + prompts/get)
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
/** prompts/list sayfa tavanı: 5 × 100 = 500 prompt (gecikmeyi sınırlar). */
|
|
63
|
+
exports.PROMPT_CATALOG_MAX_PAGES = 5;
|
|
64
|
+
const PROMPT_CATALOG_PAGE_SIZE = 100;
|
|
65
|
+
/** list → get arası aynı katalog kullanılsın; kütüphane değişikliği ≤30 sn'de yansır. */
|
|
66
|
+
const PROMPT_CATALOG_TTL_MS = 30000;
|
|
67
|
+
async function fetchAllPrompts() {
|
|
68
|
+
const all = [];
|
|
69
|
+
for (let page = 1; page <= exports.PROMPT_CATALOG_MAX_PAGES; page++) {
|
|
70
|
+
const res = await (0, api_client_1.listPromptsPage)({ page, limit: PROMPT_CATALOG_PAGE_SIZE });
|
|
71
|
+
all.push(...res.prompts);
|
|
72
|
+
if (page >= res.totalPages || res.prompts.length < PROMPT_CATALOG_PAGE_SIZE)
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
return all;
|
|
76
|
+
}
|
|
77
|
+
function createCatalogCache(now) {
|
|
78
|
+
let cached = null;
|
|
79
|
+
return {
|
|
80
|
+
async get(forceFresh = false) {
|
|
81
|
+
if (!forceFresh && cached && now() - cached.at < PROMPT_CATALOG_TTL_MS) {
|
|
82
|
+
return cached.entries;
|
|
83
|
+
}
|
|
84
|
+
await (0, api_client_1.ensureAuthed)();
|
|
85
|
+
const entries = (0, mcpPrompts_1.buildPromptCatalog)(await fetchAllPrompts());
|
|
86
|
+
cached = { at: now(), entries };
|
|
87
|
+
return entries;
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function toMcpError(err) {
|
|
92
|
+
if (err instanceof types_js_1.McpError)
|
|
93
|
+
return err;
|
|
94
|
+
return new types_js_1.McpError(types_js_1.ErrorCode.InternalError, err instanceof Error ? err.message : 'Unexpected error.');
|
|
95
|
+
}
|
|
96
|
+
function registerPromptLibrary(server, now) {
|
|
97
|
+
const catalog = createCatalogCache(now);
|
|
98
|
+
// McpServer.registerPrompt statik kayıt içindir; kütüphane kullanıcıya göre
|
|
99
|
+
// dinamik olduğundan handler'lar alttaki Server'a doğrudan bağlanır.
|
|
100
|
+
server.server.registerCapabilities({ prompts: { listChanged: false } });
|
|
101
|
+
server.server.setRequestHandler(types_js_1.ListPromptsRequestSchema, async () => {
|
|
102
|
+
try {
|
|
103
|
+
const entries = await catalog.get();
|
|
104
|
+
return { prompts: entries.map(mcpPrompts_1.toMcpPrompt) };
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
throw toMcpError(err);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
server.server.setRequestHandler(types_js_1.GetPromptRequestSchema, async (request) => {
|
|
111
|
+
const { name, arguments: args } = request.params;
|
|
112
|
+
let entry;
|
|
113
|
+
try {
|
|
114
|
+
entry = (await catalog.get()).find((e) => e.name === name);
|
|
115
|
+
// Önbellek bayat olabilir (yeni eklenen prompt) → bir kez taze liste.
|
|
116
|
+
if (!entry)
|
|
117
|
+
entry = (await catalog.get(true)).find((e) => e.name === name);
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
throw toMcpError(err);
|
|
121
|
+
}
|
|
122
|
+
if (!entry) {
|
|
123
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Prompt '${name}' not found in your library.`);
|
|
124
|
+
}
|
|
125
|
+
let detail;
|
|
126
|
+
try {
|
|
127
|
+
detail = await (0, api_client_1.getPromptDetail)(entry.prompt.id);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
throw toMcpError(err);
|
|
131
|
+
}
|
|
132
|
+
if (!detail) {
|
|
133
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Prompt '${name}' is no longer available.`);
|
|
134
|
+
}
|
|
135
|
+
const rendered = (0, mcpPrompts_1.renderPrompt)((0, promptText_1.versionText)((0, promptText_1.pickVersion)(detail)), args);
|
|
136
|
+
(0, api_client_1.recordPromptUse)(detail.id);
|
|
137
|
+
const description = rendered.missing.length > 0
|
|
138
|
+
? `${detail.title} — unfilled: ${rendered.missing.join(', ')}`
|
|
139
|
+
: detail.title;
|
|
140
|
+
return {
|
|
141
|
+
description,
|
|
142
|
+
messages: [{ role: 'user', content: { type: 'text', text: rendered.text } }],
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function createServer(options = {}) {
|
|
147
|
+
const server = new mcp_js_1.McpServer({ name: constants_1.MCP_SERVER_NAME, version: constants_1.MCP_VERSION });
|
|
148
|
+
server.registerTool('list_prompts', {
|
|
149
|
+
title: 'List prompts',
|
|
150
|
+
description: "List the user's saved prompts from their PromptLikeEngineer library. " +
|
|
151
|
+
'Optionally filter by tag. Returns id, title, description, updated_at and ' +
|
|
152
|
+
'the {{variable}} names each prompt expects.',
|
|
153
|
+
inputSchema: {
|
|
154
|
+
tag: zod_1.z.string().optional().describe('Filter by tag name'),
|
|
155
|
+
limit: zod_1.z.number().int().min(1).max(100).optional().describe('Max results (default 50)'),
|
|
156
|
+
},
|
|
157
|
+
}, async ({ tag, limit }) => guarded(async () => {
|
|
158
|
+
const prompts = await (0, api_client_1.listPrompts)({ tag, limit: limit ?? 50 });
|
|
159
|
+
return ok({ total: prompts.length, prompts: prompts.map(summarize) });
|
|
160
|
+
}));
|
|
161
|
+
server.registerTool('search_prompts', {
|
|
162
|
+
title: 'Search prompts',
|
|
163
|
+
description: "Search the user's prompt library by title and description. " +
|
|
164
|
+
'Returns the same shape as list_prompts.',
|
|
165
|
+
inputSchema: {
|
|
166
|
+
query: zod_1.z.string().min(1).describe('Search text (matched against title + description)'),
|
|
167
|
+
limit: zod_1.z.number().int().min(1).max(100).optional().describe('Max results (default 20)'),
|
|
168
|
+
},
|
|
169
|
+
}, async ({ query, limit }) => guarded(async () => {
|
|
170
|
+
const prompts = await (0, api_client_1.listPrompts)({ search: query, limit: limit ?? 20 });
|
|
171
|
+
return ok({ total: prompts.length, prompts: prompts.map(summarize) });
|
|
172
|
+
}));
|
|
173
|
+
server.registerTool('get_prompt', {
|
|
174
|
+
title: 'Get prompt content',
|
|
175
|
+
description: 'Fetch the full content of one prompt by name, title, id or short-id. ' +
|
|
176
|
+
'Optionally pin an exact version number. Returns the prompt text plus the ' +
|
|
177
|
+
'{{variable}} names it expects — if there are variables, either fill them ' +
|
|
178
|
+
'yourself or call fill_variables.',
|
|
179
|
+
inputSchema: {
|
|
180
|
+
name: zod_1.z.string().min(1).describe('Prompt title, id, or unique title fragment'),
|
|
181
|
+
version: zod_1.z.number().int().min(1).optional().describe('Exact version number to fetch (default: current)'),
|
|
182
|
+
project: zod_1.z.string().min(1).optional().describe('Repo name, slug, or id to scope resolution when titles collide'),
|
|
183
|
+
},
|
|
184
|
+
}, async ({ name, version, project }) => guarded(async () => {
|
|
185
|
+
const projectId = project ? await (0, resolver_1.resolveProjectId)(project) : undefined;
|
|
186
|
+
const result = await (0, resolver_1.resolvePromptByName)(name, { projectId });
|
|
187
|
+
if (result.status !== 'found')
|
|
188
|
+
return resolveFailure(name, result);
|
|
189
|
+
const prompt = result.prompt;
|
|
190
|
+
const picked = (0, promptText_1.pickVersion)(prompt, version);
|
|
191
|
+
if (!picked) {
|
|
192
|
+
const available = (prompt.versions ?? []).map((v) => v.version_number);
|
|
193
|
+
return fail(`Version ${version} not found for '${prompt.title}'. Available: ${available.join(', ') || 'none'}.`);
|
|
194
|
+
}
|
|
195
|
+
const text = (0, promptText_1.versionText)(picked);
|
|
196
|
+
(0, api_client_1.recordPromptUse)(prompt.id);
|
|
197
|
+
return ok({
|
|
198
|
+
id: prompt.id,
|
|
199
|
+
title: prompt.title,
|
|
200
|
+
description: prompt.description ?? null,
|
|
201
|
+
version: picked.version_number ?? null,
|
|
202
|
+
updated_at: prompt.updated_at,
|
|
203
|
+
variables: (0, promptVariables_1.extractVariables)(text),
|
|
204
|
+
content: text,
|
|
205
|
+
});
|
|
206
|
+
}));
|
|
207
|
+
server.registerTool('fill_variables', {
|
|
208
|
+
title: 'Fill prompt variables',
|
|
209
|
+
description: 'Fetch a prompt and substitute its {{variable}} placeholders with the given ' +
|
|
210
|
+
'values, returning ready-to-use text. Unknown/empty values stay as {{name}} ' +
|
|
211
|
+
'in the output (listed in missing_variables).',
|
|
212
|
+
inputSchema: {
|
|
213
|
+
name: zod_1.z.string().min(1).describe('Prompt title, id, or unique title fragment'),
|
|
214
|
+
variables: zod_1.z.record(zod_1.z.string()).describe('Variable name → value map'),
|
|
215
|
+
version: zod_1.z.number().int().min(1).optional().describe('Exact version number (default: current)'),
|
|
216
|
+
project: zod_1.z.string().min(1).optional().describe('Repo name, slug, or id to scope resolution when titles collide'),
|
|
217
|
+
},
|
|
218
|
+
}, async ({ name, variables, version, project }) => guarded(async () => {
|
|
219
|
+
const projectId = project ? await (0, resolver_1.resolveProjectId)(project) : undefined;
|
|
220
|
+
const result = await (0, resolver_1.resolvePromptByName)(name, { projectId });
|
|
221
|
+
if (result.status !== 'found')
|
|
222
|
+
return resolveFailure(name, result);
|
|
223
|
+
const prompt = result.prompt;
|
|
224
|
+
const picked = (0, promptText_1.pickVersion)(prompt, version);
|
|
225
|
+
if (!picked) {
|
|
226
|
+
const available = (prompt.versions ?? []).map((v) => v.version_number);
|
|
227
|
+
return fail(`Version ${version} not found for '${prompt.title}'. Available: ${available.join(', ') || 'none'}.`);
|
|
228
|
+
}
|
|
229
|
+
const raw = (0, promptText_1.versionText)(picked);
|
|
230
|
+
const filled = (0, promptVariables_1.fillVariables)(raw, variables);
|
|
231
|
+
const missing = (0, promptVariables_1.extractVariables)(filled);
|
|
232
|
+
(0, api_client_1.recordPromptUse)(prompt.id);
|
|
233
|
+
return ok({
|
|
234
|
+
id: prompt.id,
|
|
235
|
+
title: prompt.title,
|
|
236
|
+
version: picked.version_number ?? null,
|
|
237
|
+
missing_variables: missing,
|
|
238
|
+
content: filled,
|
|
239
|
+
});
|
|
240
|
+
}));
|
|
241
|
+
registerPromptLibrary(server, options.now ?? Date.now);
|
|
242
|
+
return server;
|
|
243
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "promptlike-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"mcpName": "io.github.zeynepaslierhann/promptlike-mcp",
|
|
5
|
+
"description": "MCP server for PromptLikeEngineer - read-only access to your prompt library as MCP tools and slash-command prompts (list, search, get, fill {{variables}}).",
|
|
5
6
|
"bin": {
|
|
6
7
|
"promptlike-mcp": "dist/index.js",
|
|
7
8
|
"ple-mcp": "dist/index.js"
|
|
@@ -9,7 +10,8 @@
|
|
|
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",
|
|
@@ -45,8 +47,8 @@
|
|
|
45
47
|
"node": ">=18"
|
|
46
48
|
},
|
|
47
49
|
"dependencies": {
|
|
48
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
49
|
-
"zod": "^3.
|
|
50
|
+
"@modelcontextprotocol/sdk": "^1.30.1",
|
|
51
|
+
"zod": "^3.25.76"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
54
|
"@types/node": "^20.10.0",
|