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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.4.0 — unreleased (2026-09-27)
|
|
4
|
+
|
|
5
|
+
Save from the agent.
|
|
6
|
+
|
|
7
|
+
- **New: `save_prompt`** (`title`, `content`, `description?`, `project?`,
|
|
8
|
+
`tags?`) and **`update_prompt`** (`name`, `content`, `changelog?`,
|
|
9
|
+
`bump?: patch|minor|major`, `project?`). Add-only: a new prompt or a new
|
|
10
|
+
version — nothing is ever deleted. Saving the same title + content again, or
|
|
11
|
+
updating with the current content, changes nothing (safe to retry).
|
|
12
|
+
`update_prompt` needs the exact title or id; it never guesses. Plan limits
|
|
13
|
+
apply as on the web and come back as a plain message with the upgrade link.
|
|
14
|
+
Content that looks like a live key/token is refused. Writes use your
|
|
15
|
+
`ple login` session; without it, the tools say so.
|
|
16
|
+
- **New: `save-this` prompt** — `/mcp__promptlike__save-this` asks the agent to
|
|
17
|
+
pull the reusable instruction out of the conversation, mark `{{variables}}`,
|
|
18
|
+
show it to you and call `save_prompt`.
|
|
19
|
+
- **New: resources** — every prompt as `promptlike://<repo>/<prompt>`
|
|
20
|
+
(`text/markdown`, current version), plus a resource template. In Claude Code
|
|
21
|
+
they are `@`-mentionable.
|
|
22
|
+
- **New: `suggest_prompts(task)`** — best matches from your own library for a
|
|
23
|
+
task, for agents without hooks. `get_prompt` accepts `via: "suggestion"`.
|
|
24
|
+
- List/read responses carry the 2026-07-28 cache hints (`ttlMs`,
|
|
25
|
+
`cacheScope: private`); prompts/resources announce `listChanged` after a save.
|
|
26
|
+
- Uses are recorded with their surface (tool / slash prompt / resource) and the
|
|
27
|
+
client name, so Insights can tell agents apart.
|
|
28
|
+
- Tool annotations: read tools `readOnlyHint`; write tools
|
|
29
|
+
`destructiveHint: false`, `idempotentHint: true`.
|
|
30
|
+
- **Fixed:** `{{constructor}}` and similar names no longer fill from JavaScript
|
|
31
|
+
built-ins when left empty.
|
|
32
|
+
- MCP sampling is not used (deprecated in the 2026-07-28 spec).
|
|
33
|
+
|
|
34
|
+
## 0.3.0 — 2026-09-27
|
|
35
|
+
|
|
36
|
+
Your library in the `/` menu.
|
|
37
|
+
|
|
38
|
+
- **New: MCP `prompts` primitive.** Every prompt in your library is now also
|
|
39
|
+
exposed through `prompts/list` + `prompts/get`, so clients that support MCP
|
|
40
|
+
prompts show them as slash commands (Claude Code: `/mcp__promptlike__<name>`;
|
|
41
|
+
Cursor and Claude Desktop list them in their prompt pickers).
|
|
42
|
+
- Names are stable slugs of the prompt title (`Code Review` → `code-review`).
|
|
43
|
+
Titles that collide get an id suffix on every copy (`pr-review-aaaaaaaa`),
|
|
44
|
+
so a name never silently switches to a different prompt.
|
|
45
|
+
- Each `{{variable}}` becomes an optional prompt argument. Empty arguments
|
|
46
|
+
stay as `{{name}}` in the output — the same contract as `fill_variables`.
|
|
47
|
+
- Up to 500 prompts are listed; the list is cached for 30 seconds.
|
|
48
|
+
- **Unchanged:** the four tools (`list_prompts`, `search_prompts`, `get_prompt`,
|
|
49
|
+
`fill_variables`) keep their names, inputs and output shape.
|
|
50
|
+
- `package.json` carries `mcpName: io.github.zeynepaslierhann/promptlike-mcp`
|
|
51
|
+
for the official MCP Registry.
|
|
52
|
+
- `@modelcontextprotocol/sdk` 1.30.
|
|
53
|
+
|
|
54
|
+
## 0.2.1
|
|
55
|
+
|
|
56
|
+
- Server reports its real version (read from `package.json`).
|
|
57
|
+
|
|
58
|
+
## 0.2.0
|
|
59
|
+
|
|
60
|
+
- `project` argument on `get_prompt` / `fill_variables` to scope resolution
|
|
61
|
+
when titles collide; ambiguity candidates list their repo.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# promptlike-mcp
|
|
2
2
|
|
|
3
|
-
MCP (Model Context Protocol) server for [PromptLikeEngineer](https://promptlikeengineer.com) — gives AI agents **
|
|
3
|
+
MCP (Model Context Protocol) server for [PromptLikeEngineer](https://promptlikeengineer.com) — gives AI agents your prompt library: read it, fill it, get suggestions from it, and save good prompts back to it (**add-only**: a new prompt or a new version, never a delete).
|
|
4
4
|
|
|
5
5
|
Your prompts stay where you saved them; your agent pulls them by name at the moment it needs them. No copy-paste, no stale duplicates in system prompts.
|
|
6
6
|
|
|
@@ -21,16 +21,48 @@ 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, and a save through this server refreshes it at once.
|
|
38
|
+
|
|
39
|
+
One built-in prompt sits next to yours: **`save-this`** (`/mcp__promptlike__save-this`). It asks the agent to pull the reusable instruction out of the conversation, mark `{{variables}}`, show it to you and save it with `save_prompt`.
|
|
40
|
+
|
|
41
|
+
## Resources (v0.4+) — `@`-mention a prompt
|
|
42
|
+
|
|
43
|
+
Every prompt is also a resource, `promptlike://<repo>/<prompt>` (`text/markdown`, current version). Clients with resource support let you attach one directly — in Claude Code, type `@` and pick it. List and read responses carry cache hints (`ttlMs`, `cacheScope: private`).
|
|
44
|
+
|
|
45
|
+
## Tools
|
|
25
46
|
|
|
26
47
|
| Tool | What it does |
|
|
27
48
|
|---|---|
|
|
28
49
|
| `list_prompts` | List your prompts (optional `tag` filter). Includes each prompt's `{{variable}}` names. |
|
|
29
50
|
| `search_prompts` | Search by title/description. |
|
|
30
|
-
| `get_prompt` | Full content by name/id/short-id, optional `version` pin. |
|
|
51
|
+
| `get_prompt` | Full content by name/id/short-id, optional `version` pin. `via: "suggestion"` when fetching a suggested prompt. |
|
|
31
52
|
| `fill_variables` | Fetch + substitute `{{variables}}`, returns ready-to-use text (unfilled ones reported in `missing_variables`). |
|
|
53
|
+
| `suggest_prompts` | Up to 3 prompts from your own library that fit a task (call once at the start of a non-trivial task). |
|
|
54
|
+
| `save_prompt` | **Write.** New prompt: `title`, `content`, optional `description`, `project` (repo; default: your most recent repo you can edit), `tags`. |
|
|
55
|
+
| `update_prompt` | **Write.** New version of an existing prompt: exact title or id, full new `content`, optional `changelog`, `bump` (`patch`/`minor`/`major`). |
|
|
56
|
+
|
|
57
|
+
### How writes behave
|
|
58
|
+
|
|
59
|
+
- **Add-only.** There is no delete tool; `update_prompt` keeps every earlier version (roll back on the web or with `ple rollback`).
|
|
60
|
+
- **Safe to retry.** Same title + content → "already saved"; content equal to the current version → no new version. A title that exists with different content is reported instead of duplicated.
|
|
61
|
+
- **Your account, your limits.** Writes use your `ple login` session and the same plan limits as the web; hitting one returns a plain message with the upgrade link and saves nothing. Viewer access to a shared repo cannot write.
|
|
62
|
+
- **No secrets.** Content that looks like an API key or token is refused — use a `{{variable}}`.
|
|
63
|
+
- **Exact names only for updates.** A fuzzy match is answered with "did you mean…", never written to.
|
|
32
64
|
|
|
33
|
-
|
|
65
|
+
The server never spends your AI tokens (no improve), and it does not use MCP sampling.
|
|
34
66
|
|
|
35
67
|
## Notes
|
|
36
68
|
|
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
|
@@ -12,16 +12,41 @@
|
|
|
12
12
|
* refresh, 429/hata gövdelerini temiz mesajlara map'leme.
|
|
13
13
|
*/
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.NOT_LOGGED_IN = void 0;
|
|
15
|
+
exports.ApiError = 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;
|
|
21
|
+
exports.buildUseEventBody = buildUseEventBody;
|
|
22
|
+
exports.sanitizeClientName = sanitizeClientName;
|
|
20
23
|
exports.recordPromptUse = recordPromptUse;
|
|
24
|
+
exports.createPrompt = createPrompt;
|
|
25
|
+
exports.savePromptVersion = savePromptVersion;
|
|
26
|
+
exports.addPromptTag = addPromptTag;
|
|
27
|
+
exports.suggestPrompts = suggestPrompts;
|
|
21
28
|
const constants_1 = require("./constants");
|
|
22
29
|
const config_1 = require("./config");
|
|
23
30
|
exports.NOT_LOGGED_IN = 'Not logged in. Run `ple login` in a terminal first (install: npm i -g promptlike).';
|
|
24
31
|
const SESSION_EXPIRED = 'Session expired. Run `ple login` in a terminal to sign in again.';
|
|
32
|
+
/**
|
|
33
|
+
* HTTP error with the status kept, so write tools can tell a plan limit
|
|
34
|
+
* (403 + upgradeUrl / 429 LIMIT_EXCEEDED) from a real failure.
|
|
35
|
+
*/
|
|
36
|
+
class ApiError extends Error {
|
|
37
|
+
constructor(message, status, code, upgradeUrl) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = 'ApiError';
|
|
40
|
+
this.status = status;
|
|
41
|
+
this.code = code;
|
|
42
|
+
this.upgradeUrl = upgradeUrl;
|
|
43
|
+
}
|
|
44
|
+
/** True for plan-limit responses (prompt / version / project caps). */
|
|
45
|
+
get isPlanLimit() {
|
|
46
|
+
return Boolean(this.upgradeUrl) || this.code === 'LIMIT_EXCEEDED';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.ApiError = ApiError;
|
|
25
50
|
function buildUrl(path, query) {
|
|
26
51
|
const u = new URL(constants_1.API_BASE_URL + path);
|
|
27
52
|
if (query) {
|
|
@@ -41,9 +66,8 @@ async function toError(res) {
|
|
|
41
66
|
catch {
|
|
42
67
|
// Non-JSON error body — generic message below.
|
|
43
68
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return new Error(`Request failed (${res.status}).`);
|
|
69
|
+
const message = body.error || `Request failed (${res.status}).`;
|
|
70
|
+
return new ApiError(message, res.status, body.code, body.upgradeUrl);
|
|
47
71
|
}
|
|
48
72
|
function getAccessTokenOrThrow() {
|
|
49
73
|
const config = (0, config_1.readConfig)();
|
|
@@ -106,6 +130,14 @@ async function apiFetch(path, opts = {}) {
|
|
|
106
130
|
await refreshSession();
|
|
107
131
|
return apiFetch(path, { ...opts, _retried: true });
|
|
108
132
|
}
|
|
133
|
+
if (res.status === 429 && !res.headers.get('retry-after')) {
|
|
134
|
+
// 429 without Retry-After can be a plan limit body (import route) —
|
|
135
|
+
// surface its message instead of a misleading "rate limited".
|
|
136
|
+
const err = await toError(res);
|
|
137
|
+
if (err.isPlanLimit)
|
|
138
|
+
throw err;
|
|
139
|
+
throw new ApiError('Rate limited. Retry in a few seconds.', 429, err.code);
|
|
140
|
+
}
|
|
109
141
|
if (res.status === 429) {
|
|
110
142
|
const retryAfter = res.headers.get('retry-after');
|
|
111
143
|
// Agent'lar back-off yapabilsin diye süre mesajda açık.
|
|
@@ -131,8 +163,8 @@ async function ensureAuthed() {
|
|
|
131
163
|
await refreshSession();
|
|
132
164
|
}
|
|
133
165
|
}
|
|
134
|
-
/** GET /api/prompts —
|
|
135
|
-
async function
|
|
166
|
+
/** GET /api/prompts — one page, with `totalPages` for callers that walk pages. */
|
|
167
|
+
async function listPromptsPage(params = {}) {
|
|
136
168
|
const res = await apiFetch('/api/prompts', {
|
|
137
169
|
query: {
|
|
138
170
|
tag: params.tag,
|
|
@@ -142,7 +174,11 @@ async function listPrompts(params = {}) {
|
|
|
142
174
|
projectId: params.projectId,
|
|
143
175
|
},
|
|
144
176
|
});
|
|
145
|
-
return res.prompts ?? [];
|
|
177
|
+
return { prompts: res.prompts ?? [], totalPages: res.totalPages ?? 1 };
|
|
178
|
+
}
|
|
179
|
+
/** GET /api/prompts — list the user's prompts (optionally by tag / search). */
|
|
180
|
+
async function listPrompts(params = {}) {
|
|
181
|
+
return (await listPromptsPage(params)).prompts;
|
|
146
182
|
}
|
|
147
183
|
/** GET /api/projects — accessible repos, for resolving a `project` argument. */
|
|
148
184
|
async function listProjects() {
|
|
@@ -163,12 +199,80 @@ async function getPromptDetail(id) {
|
|
|
163
199
|
throw err;
|
|
164
200
|
}
|
|
165
201
|
}
|
|
202
|
+
/** POST /use body. Client is trimmed to the server's charset/length. */
|
|
203
|
+
function buildUseEventBody(opts) {
|
|
204
|
+
const body = {
|
|
205
|
+
surface: opts.surface,
|
|
206
|
+
client: sanitizeClientName(opts.client) ?? `promptlike-mcp/${constants_1.MCP_VERSION}`,
|
|
207
|
+
via: opts.via === 'suggestion' ? 'suggestion' : 'direct',
|
|
208
|
+
};
|
|
209
|
+
if (typeof opts.version === 'number' && Number.isInteger(opts.version) && opts.version > 0) {
|
|
210
|
+
body.version = opts.version;
|
|
211
|
+
}
|
|
212
|
+
return body;
|
|
213
|
+
}
|
|
214
|
+
/** Same charset/length rule as the server (`sanitizeClient`): ≤64, `[A-Za-z0-9._@/ -]`. */
|
|
215
|
+
function sanitizeClientName(v) {
|
|
216
|
+
if (!v)
|
|
217
|
+
return null;
|
|
218
|
+
const cleaned = v.replace(/[^A-Za-z0-9._@/ -]/g, '').slice(0, 64).trim();
|
|
219
|
+
return cleaned || null;
|
|
220
|
+
}
|
|
166
221
|
/**
|
|
167
|
-
* Kullanım kaydı — get_prompt/fill_variables
|
|
168
|
-
* (CLI copy/get/show ile aynı desen).
|
|
222
|
+
* Kullanım kaydı — get_prompt/fill_variables/prompts.get/resources.read
|
|
223
|
+
* sonrası fire-and-forget (CLI copy/get/show ile aynı desen). Gövde yüzeyi,
|
|
224
|
+
* istemciyi ve `via`yı taşır (W1-1 olay defteri). Hata YUTULUR.
|
|
169
225
|
*/
|
|
170
|
-
function recordPromptUse(promptId) {
|
|
171
|
-
apiFetch(`/api/prompts/${promptId}/use`, { method: 'POST' }).catch(() => {
|
|
226
|
+
function recordPromptUse(promptId, opts = { surface: 'mcp_tool' }) {
|
|
227
|
+
apiFetch(`/api/prompts/${promptId}/use`, { method: 'POST', body: buildUseEventBody(opts) }).catch(() => {
|
|
172
228
|
/* sessiz — telemetri */
|
|
173
229
|
});
|
|
174
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* A single-body prompt goes into `contextText` — the same slot `ple sync` and
|
|
233
|
+
* the import route use — with the other two parts empty, so `versionText()`
|
|
234
|
+
* returns exactly what the agent saved.
|
|
235
|
+
*/
|
|
236
|
+
async function createPrompt(input) {
|
|
237
|
+
return apiFetch('/api/prompts', {
|
|
238
|
+
method: 'POST',
|
|
239
|
+
body: {
|
|
240
|
+
isNew: true,
|
|
241
|
+
projectId: input.projectId,
|
|
242
|
+
title: input.title,
|
|
243
|
+
description: input.description ?? '',
|
|
244
|
+
roleText: '',
|
|
245
|
+
descriptionText: '',
|
|
246
|
+
contextText: input.content,
|
|
247
|
+
changelog: input.changelog ?? 'Saved from an agent via MCP',
|
|
248
|
+
source: 'mcp',
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
/** New version of an existing prompt (never deletes the old one). */
|
|
253
|
+
async function savePromptVersion(input) {
|
|
254
|
+
return apiFetch('/api/prompts', {
|
|
255
|
+
method: 'POST',
|
|
256
|
+
body: {
|
|
257
|
+
id: input.promptId,
|
|
258
|
+
roleText: '',
|
|
259
|
+
descriptionText: '',
|
|
260
|
+
contextText: input.content,
|
|
261
|
+
changelog: input.changelog ?? 'Updated from an agent via MCP',
|
|
262
|
+
source: 'mcp',
|
|
263
|
+
bumpMajor: input.bump === 'major',
|
|
264
|
+
bumpMinor: input.bump === 'minor',
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
/** Attach a tag by name (found or created in the prompt's repo). */
|
|
269
|
+
async function addPromptTag(promptId, tagName) {
|
|
270
|
+
await apiFetch(`/api/prompts/${promptId}/tags`, { method: 'POST', body: { tagName } });
|
|
271
|
+
}
|
|
272
|
+
/** Best matches for a task from the user's OWN library (server-side full text). */
|
|
273
|
+
async function suggestPrompts(task, limit = 3) {
|
|
274
|
+
const res = await apiFetch('/api/prompts/suggest', {
|
|
275
|
+
query: { task, limit },
|
|
276
|
+
});
|
|
277
|
+
return res.suggestions ?? [];
|
|
278
|
+
}
|
package/dist/lib/constants.js
CHANGED
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
/**
|
|
56
|
+
* Prompt listesinden benzersiz, deterministik adlı katalog kurar.
|
|
57
|
+
* `reserved`: sunucunun kendi prompt adları (ör. `save-this`) — kullanıcının
|
|
58
|
+
* aynı slug'a düşen prompt'u çakışma sayılır ve id soneki alır.
|
|
59
|
+
*/
|
|
60
|
+
function buildPromptCatalog(prompts, reserved = new Set()) {
|
|
61
|
+
const base = prompts.map((p) => {
|
|
62
|
+
const slug = slugifyPromptName(p.title);
|
|
63
|
+
return { prompt: p, slug: slug || `prompt-${shortId(p.id)}` };
|
|
64
|
+
});
|
|
65
|
+
const counts = new Map();
|
|
66
|
+
for (const r of reserved)
|
|
67
|
+
counts.set(r, 1);
|
|
68
|
+
for (const { slug } of base)
|
|
69
|
+
counts.set(slug, (counts.get(slug) ?? 0) + 1);
|
|
70
|
+
const seen = new Set();
|
|
71
|
+
const catalog = [];
|
|
72
|
+
for (const { prompt, slug } of base) {
|
|
73
|
+
const name = (counts.get(slug) ?? 0) > 1 ? `${slug}-${shortId(prompt.id)}` : slug;
|
|
74
|
+
// Aynı id iki sayfada gelirse (liste arası güncelleme) ikinciyi at.
|
|
75
|
+
if (seen.has(name))
|
|
76
|
+
continue;
|
|
77
|
+
seen.add(name);
|
|
78
|
+
catalog.push({ name, prompt });
|
|
79
|
+
}
|
|
80
|
+
return catalog;
|
|
81
|
+
}
|
|
82
|
+
/** Katalog girdisini prompts/list öğesine çevirir. */
|
|
83
|
+
function toMcpPrompt(entry) {
|
|
84
|
+
const { prompt } = entry;
|
|
85
|
+
const variables = (0, promptVariables_1.extractVariables)((0, promptText_1.versionText)(prompt.current_version));
|
|
86
|
+
const descParts = [
|
|
87
|
+
prompt.project_name ? `[${prompt.project_name}]` : '',
|
|
88
|
+
(prompt.description ?? '').trim(),
|
|
89
|
+
].filter(Boolean);
|
|
90
|
+
const out = { name: entry.name, title: prompt.title };
|
|
91
|
+
if (descParts.length > 0)
|
|
92
|
+
out.description = descParts.join(' ');
|
|
93
|
+
if (variables.length > 0) {
|
|
94
|
+
out.arguments = variables.map((v) => ({
|
|
95
|
+
name: v,
|
|
96
|
+
description: `Value for {{${v}}} (left as-is when empty)`,
|
|
97
|
+
required: false,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
/** prompts/get gövdesi: {{değişken}}leri argümanlarla doldurur, eksikleri raporlar. */
|
|
103
|
+
function renderPrompt(text, args) {
|
|
104
|
+
const filled = (0, promptVariables_1.fillVariables)(text, args ?? {});
|
|
105
|
+
return { text: filled, missing: (0, promptVariables_1.extractVariables)(filled) };
|
|
106
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -36,7 +36,9 @@ function fillVariables(text, values) {
|
|
|
36
36
|
if (!text)
|
|
37
37
|
return '';
|
|
38
38
|
return text.replace(VARIABLE_PATTERN, (whole, name) => {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
// Yalnız kendi anahtarları: {{constructor}} / {{toString}} gibi adlar
|
|
40
|
+
// Object.prototype'tan fonksiyon çekip metne "function Object()…" basmasın.
|
|
41
|
+
const value = Object.prototype.hasOwnProperty.call(values, name) ? values[name] : undefined;
|
|
42
|
+
return typeof value === 'string' && value !== '' ? value : whole;
|
|
41
43
|
});
|
|
42
44
|
}
|