get_prompt
Retrieve AI prompts by ID from a community-curated library and fill template variables with custom values for use in coding assistants.
Instructions
Get a prompt by ID. If the prompt contains template variables (like ${variable} or ${variable:default}), you may need to provide values for them.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the prompt to retrieve |
Implementation Reference
- src/index.ts:187-212 (handler)Handler function that executes the 'get_prompt' tool logic by proxying the request to the prompts.chat API's tools/call endpoint with the provided prompt ID.async ({ id }) => { try { const response = await callPromptsChatMcp("tools/call", { name: "get_prompt", arguments: { id }, }); if (response.error) { return { content: [{ type: "text" as const, text: JSON.stringify({ error: response.error.message }) }], isError: true, }; } const result = response.result as { content: Array<{ type: string; text: string }> }; return { content: [{ type: "text" as const, text: result.content[0].text }], }; } catch (error) { const message = error instanceof Error ? error.message : String(error); return { content: [{ type: "text" as const, text: JSON.stringify({ error: message }) }], isError: true, }; } }
- src/index.ts:179-186 (schema)Input schema and metadata (title, description) for the 'get_prompt' tool, using Zod for validation.{ title: "Get Prompt", description: "Get a prompt by ID. If the prompt contains template variables (like ${variable} or ${variable:default}), you may need to provide values for them.", inputSchema: { id: z.string().describe("The ID of the prompt to retrieve"), }, },
- src/index.ts:177-213 (registration)Registration of the 'get_prompt' tool on the MCP server, including schema and handler.server.registerTool( "get_prompt", { title: "Get Prompt", description: "Get a prompt by ID. If the prompt contains template variables (like ${variable} or ${variable:default}), you may need to provide values for them.", inputSchema: { id: z.string().describe("The ID of the prompt to retrieve"), }, }, async ({ id }) => { try { const response = await callPromptsChatMcp("tools/call", { name: "get_prompt", arguments: { id }, }); if (response.error) { return { content: [{ type: "text" as const, text: JSON.stringify({ error: response.error.message }) }], isError: true, }; } const result = response.result as { content: Array<{ type: string; text: string }> }; return { content: [{ type: "text" as const, text: result.content[0].text }], }; } catch (error) { const message = error instanceof Error ? error.message : String(error); return { content: [{ type: "text" as const, text: JSON.stringify({ error: message }) }], isError: true, }; } } );
- src/index.ts:26-70 (helper)Utility function to make JSON-RPC calls to the prompts.chat API, handling both regular JSON and SSE responses. Used by the get_prompt tool handler.async function callPromptsChatMcp( method: string, params?: Record<string, unknown> ): Promise<McpResponse> { const response = await fetch(PROMPTS_CHAT_API, { method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json, text/event-stream", "User-Agent": USER_AGENT, ...(PROMPTS_API_KEY && { "PROMPTS-API-KEY": PROMPTS_API_KEY }), }, body: JSON.stringify({ jsonrpc: "2.0", id: Date.now(), method, params, }), }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const contentType = response.headers.get("content-type") || ""; // Handle SSE response format if (contentType.includes("text/event-stream")) { const text = await response.text(); const lines = text.split("\n"); for (const line of lines) { if (line.startsWith("data: ")) { const jsonStr = line.slice(6); if (jsonStr.trim()) { return JSON.parse(jsonStr) as McpResponse; } } } throw new Error("No valid JSON data found in SSE response"); } return (await response.json()) as McpResponse; }