Skip to main content
Glama

get-phrase-by-id

Retrieve a specific phrase using its unique ID from the Phrases MCP Server, enabling quick access to stored inspirational content for direct use or management.

Instructions

Returns a phrase by its ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesPhrase ID

Implementation Reference

  • Handler function that fetches the phrase by ID using makeMockAPIRequest and formats a text response.
    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 defining the 'id' parameter as a non-negative number.
    { id: z.number().min(0).describe("Phrase ID"), },
  • src/index.ts:46-70 (registration)
    Registers the 'get-phrase-by-id' tool on the MCP server with name, description, 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 } ] } } );
  • Supporting utility function that performs HTTP requests to the mock API endpoint for managing 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; } }

Other Tools

Related Tools

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