Skip to main content
Glama

get-phrase-by-id

Retrieve a specific inspirational phrase by its unique ID from the Phrases MCP Server database for reference or editing.

Instructions

Returns a phrase by its ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesPhrase ID

Implementation Reference

  • The handler function for the 'get-phrase-by-id' tool. It fetches the phrase using makeMockAPIRequest with the given ID, formats a text response, and returns it in the MCP content format.
    async ({id}) => { const result = await makeMockAPIRequest<Phrase>("GET", { path: `/${id}`, }); const resultText = result ? `Phrase from ${result.name}: "${result.phrase}"` : `No phrase found with ID ${id}.`; return { content: [ { type: "text", text: resultText } ] } }
  • Zod input schema for the tool, defining the 'id' parameter as a non-negative number.
    { id: z.number().min(0).describe("Phrase ID"), },
  • src/index.ts:46-70 (registration)
    Registration of the 'get-phrase-by-id' tool on the MCP server, specifying name, description, input schema, and handler function.
    server.tool( "get-phrase-by-id", "Returns a phrase by its ID.", { id: z.number().min(0).describe("Phrase ID"), }, async ({id}) => { const result = await makeMockAPIRequest<Phrase>("GET", { path: `/${id}`, }); const resultText = result ? `Phrase from ${result.name}: "${result.phrase}"` : `No phrase found with ID ${id}.`; return { content: [ { type: "text", text: resultText } ] } } );
  • Generic helper function used by the tool handler to perform the actual HTTP GET request to the mock API endpoint for fetching the phrase by ID.
    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 definition for GetPhraseByIdParams, imported but not directly used in the tool schema (inline Zod is used instead).
    export type GetPhraseByIdParams = { id: number };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ronniemh/phrases-MCP-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server