update-phrase
Modify the text of a specific phrase by its ID using the Phrases MCP Server. Ensure accurate phrase updates with structured input for ID and new text.
Instructions
Updates the text of a phrase by its ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Phrase ID | |
| phrase | Yes | New phrase text |
Implementation Reference
- src/index.ts:128-154 (registration)Registers the 'update-phrase' MCP tool with input schema (Zod validation for id and phrase parameters) and the complete handler implementation that performs a PATCH request to the mock API endpoint to update the phrase text by ID, then formats and returns a text response.server.tool( "update-phrase", "Updates the text of a phrase by its ID.", { id: z.number().min(0).describe("Phrase ID"), phrase: z.string().max(200).describe("New phrase text") }, async ({id, phrase}) => { const result = await makeMockAPIRequest<Phrase>("PATCH", { path: `/${id}`, body: { phrase }, }); const resultText = result ? `Updated phrase for ${result.name}: "${result.phrase}"` : `Failed to update phrase with ID ${id}.`; return { content: [ { type: "text", text: resultText } ] } } );
- src/index.ts:131-134 (schema)Zod schema defining the input parameters for the update-phrase tool: id (positive number) and new phrase text (string up to 200 chars).{ id: z.number().min(0).describe("Phrase ID"), phrase: z.string().max(200).describe("New phrase text") },
- src/index.ts:135-153 (handler)The async handler function for update-phrase: calls makeMockAPIRequest with PATCH method, path /${id}, body {phrase}, formats success or failure message using the result, returns MCP text content.async ({id, phrase}) => { const result = await makeMockAPIRequest<Phrase>("PATCH", { path: `/${id}`, body: { phrase }, }); const resultText = result ? `Updated phrase for ${result.name}: "${result.phrase}"` : `Failed to update phrase with ID ${id}.`; return { content: [ { type: "text", text: resultText } ] } }
- Shared helper utility function that performs HTTP requests (including PATCH for updates) to the mock API at BASE_URL, used by the update-phrase handler.export async function makeMockAPIRequest<T>( method: HTTPMethod, options: RequestOptions = {} ): Promise<T | null> { const { path, queryParams, body } = options; let url = BASE_URL; if (path) url += path; if (method === "GET" && queryParams) { const query = new URLSearchParams(queryParams).toString(); url += `?${query}`; } const headers: HeadersInit = { "Content-Type": "application/json", }; const fetchOptions: RequestInit = { method, headers, body: body && method !== "GET" && method !== "DELETE" ? JSON.stringify(body) : undefined, }; try { const response = await fetch(url, fetchOptions); if (!response.ok) throw new Error(`HTTP error: ${response.status}`); if (method === "DELETE" || response.status === 204) return null; return await response.json(); } catch (err) { console.error(`Error on ${method} ${url}:`, err); return null; } }