Skip to content

Commit 4cf009a

Browse files
committed
refactor: migrate MCP prompt tools from raw fetchClient to typed API client methods
1 parent c5f88fe commit 4cf009a

File tree

1 file changed

+19
-75
lines changed

1 file changed

+19
-75
lines changed

packages/cli-v3/src/mcp/tools/prompts.ts

Lines changed: 19 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,6 @@ const ReactivateOverrideInput = CommonProjectsInput.extend({
4343
.describe("The dashboard-sourced version number to reactivate as override"),
4444
});
4545

46-
// ---------------------------------------------------------------------------
47-
// Helpers
48-
// ---------------------------------------------------------------------------
49-
50-
async function fetchPromptApi(
51-
apiClient: { fetchClient: typeof fetch; baseUrl: string },
52-
path: string,
53-
options?: RequestInit
54-
) {
55-
const res = await apiClient.fetchClient(`${apiClient.baseUrl}/api/v1/prompts${path}`, options);
56-
const data = await res.json();
57-
if (!res.ok) {
58-
throw new Error(data.error ?? `API error ${res.status}`);
59-
}
60-
return data;
61-
}
62-
6346
// ---------------------------------------------------------------------------
6447
// Read tools
6548
// ---------------------------------------------------------------------------
@@ -88,28 +71,17 @@ export const listPromptsTool = {
8871
branch: input.branch,
8972
});
9073

91-
const result = await fetchPromptApi(apiClient, "");
92-
93-
const prompts = result.data as Array<{
94-
slug: string;
95-
friendlyId: string;
96-
description?: string;
97-
defaultModel?: string;
98-
currentVersion: number | null;
99-
hasOverride: boolean;
100-
versionCount: number;
101-
tags: string[];
102-
}>;
74+
const result = await apiClient.listPrompts();
10375

104-
if (prompts.length === 0) {
76+
if (result.data.length === 0) {
10577
return { content: [{ type: "text" as const, text: "No prompts found." }] };
10678
}
10779

10880
const lines = ["## Prompts\n"];
109-
for (const p of prompts) {
81+
for (const p of result.data) {
11082
const status = p.hasOverride ? " (override active)" : "";
11183
const version = p.currentVersion != null ? `v${p.currentVersion}` : "no current";
112-
lines.push(`- **${p.slug}** — ${version}${status} · ${p.versionCount} versions`);
84+
lines.push(`- **${p.slug}** — ${version}${status}`);
11385
if (p.description) lines.push(` ${p.description}`);
11486
if (p.defaultModel) lines.push(` Model: ${p.defaultModel}`);
11587
}
@@ -142,24 +114,14 @@ export const getPromptVersionsTool = {
142114
branch: input.branch,
143115
});
144116

145-
const result = await fetchPromptApi(apiClient, `/${input.slug}/versions`);
117+
const result = await apiClient.listPromptVersions(input.slug);
146118

147-
const versions = result.data as Array<{
148-
version: number;
149-
labels: string[];
150-
source: string;
151-
model?: string;
152-
textContent?: string;
153-
commitMessage?: string;
154-
createdAt: string;
155-
}>;
156-
157-
if (versions.length === 0) {
119+
if (result.data.length === 0) {
158120
return { content: [{ type: "text" as const, text: "No versions found." }] };
159121
}
160122

161123
const lines = [`## Versions for "${input.slug}"\n`];
162-
for (const v of versions) {
124+
for (const v of result.data) {
163125
const labels = v.labels.length > 0 ? ` [${v.labels.join(", ")}]` : "";
164126
const model = v.model ? ` · ${v.model}` : "";
165127
const msg = v.commitMessage ? ` — "${v.commitMessage}"` : "";
@@ -203,11 +165,7 @@ export const promotePromptVersionTool = {
203165
branch: input.branch,
204166
});
205167

206-
await fetchPromptApi(apiClient, `/${input.slug}/promote`, {
207-
method: "POST",
208-
headers: { "Content-Type": "application/json" },
209-
body: JSON.stringify({ version: input.version }),
210-
});
168+
await apiClient.promotePromptVersion(input.slug, { version: input.version });
211169

212170
return {
213171
content: [
@@ -244,15 +202,11 @@ export const createPromptOverrideTool = {
244202
branch: input.branch,
245203
});
246204

247-
const result = await fetchPromptApi(apiClient, `/${input.slug}/override`, {
248-
method: "POST",
249-
headers: { "Content-Type": "application/json" },
250-
body: JSON.stringify({
251-
textContent: input.textContent,
252-
model: input.model,
253-
commitMessage: input.commitMessage,
254-
source: "mcp",
255-
}),
205+
const result = await apiClient.createPromptOverride(input.slug, {
206+
textContent: input.textContent,
207+
model: input.model,
208+
commitMessage: input.commitMessage,
209+
source: "mcp",
256210
});
257211

258212
return {
@@ -290,14 +244,10 @@ export const updatePromptOverrideTool = {
290244
branch: input.branch,
291245
});
292246

293-
await fetchPromptApi(apiClient, `/${input.slug}/override`, {
294-
method: "PUT",
295-
headers: { "Content-Type": "application/json" },
296-
body: JSON.stringify({
297-
textContent: input.textContent,
298-
model: input.model,
299-
commitMessage: input.commitMessage,
300-
}),
247+
await apiClient.updatePromptOverride(input.slug, {
248+
textContent: input.textContent,
249+
model: input.model,
250+
commitMessage: input.commitMessage,
301251
});
302252

303253
return {
@@ -332,9 +282,7 @@ export const removePromptOverrideTool = {
332282
branch: input.branch,
333283
});
334284

335-
await fetchPromptApi(apiClient, `/${input.slug}/override`, {
336-
method: "DELETE",
337-
});
285+
await apiClient.removePromptOverride(input.slug);
338286

339287
return {
340288
content: [
@@ -368,11 +316,7 @@ export const reactivatePromptOverrideTool = {
368316
branch: input.branch,
369317
});
370318

371-
await fetchPromptApi(apiClient, `/${input.slug}/override/reactivate`, {
372-
method: "POST",
373-
headers: { "Content-Type": "application/json" },
374-
body: JSON.stringify({ version: input.version }),
375-
});
319+
await apiClient.reactivatePromptOverride(input.slug, { version: input.version });
376320

377321
return {
378322
content: [

0 commit comments

Comments
 (0)