create-phrase
Generate and store new inspirational phrases with author attribution using the Phrases MCP Server. Ideal for managing motivational content directly from Claude for Desktop.
Instructions
Creates a new phrase for an author.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Author name | |
| phrase | Yes | Phrase text |
Implementation Reference
- src/index.ts:107-124 (handler)The handler function for the "create-phrase" tool. It performs a POST request using makeMockAPIRequest with the provided author name and phrase, formats the result into a text response, and returns it as MCP content.async ({name, phrase}) => { const created = await makeMockAPIRequest<Phrase>("POST", { body: { name, phrase }, }); const resultText = created ? `Created phrase for ${created.name}: "${created.phrase}" (ID: ${created.id})` : "Failed to create the phrase."; return { content: [ { type: "text", text: resultText } ] } }
- src/index.ts:103-106 (schema)Input schema for the "create-phrase" tool using Zod to validate the 'name' (author) and 'phrase' parameters.{ name: z.string().max(50).describe("Author name"), phrase: z.string().max(200).describe("Phrase text") },
- src/index.ts:100-125 (registration)Registration of the "create-phrase" tool using server.tool(), including name, description, input schema, and handler function.server.tool( "create-phrase", "Creates a new phrase for an author.", { name: z.string().max(50).describe("Author name"), phrase: z.string().max(200).describe("Phrase text") }, async ({name, phrase}) => { const created = await makeMockAPIRequest<Phrase>("POST", { body: { name, phrase }, }); const resultText = created ? `Created phrase for ${created.name}: "${created.phrase}" (ID: ${created.id})` : "Failed to create the phrase."; return { content: [ { type: "text", text: resultText } ] } } );
- Supporting helper function used by the tool handler to make HTTP requests to the MockAPI endpoint for creating phrases.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; } }