update-phrase
Modify existing inspirational phrases by ID to update their text content within the Phrases MCP Server.
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:135-153 (handler)Handler function that performs the PATCH request to update the phrase by ID using the mock API and returns a success or failure message.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 for the tool inputs: phrase ID (number >=0) and new phrase text (string max 200 chars).{ id: z.number().min(0).describe("Phrase ID"), phrase: z.string().max(200).describe("New phrase text") },
- src/index.ts:128-154 (registration)Full registration of the 'update-phrase' tool on the MCP server, including name, description, input schema, and handler function.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 } ] } } );
- Shared helper function that makes HTTP requests to the mock API endpoint, used by all phrase tools including update-phrase.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; } }
- TypeScript type for update-phrase parameters: id and phrase.export type UpdatePhraseParams = { id: number } & Required<Pick<PhraseInput, "phrase">>;