Skip to main content
Glama
f

prompts.chat MCP Server

by f

get_prompt

Retrieve AI prompts by ID from prompts.chat, with support for template variables that can be customized for specific use cases.

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
NameRequiredDescriptionDefault
idYesThe ID of the prompt to retrieve

Implementation Reference

  • The handler function that implements the core logic of the 'get_prompt' tool. It forwards the prompt ID to the upstream prompts.chat MCP server using the 'tools/call' method, handles errors, and returns the prompt content.
    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,
        };
      }
    }
  • The input schema for the 'get_prompt' tool, defining the required 'id' parameter using Zod.
    inputSchema: {
      id: z.string().describe("The ID of the prompt to retrieve"),
    },
  • src/index.ts:177-213 (registration)
    The registration of the 'get_prompt' tool using server.registerTool, including title, description, input schema, and handler reference.
    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,
          };
        }
      }
    );
  • Helper utility function used by the get_prompt handler to communicate with the upstream prompts.chat MCP server.
    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;
    }
Install Server

Other 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/f/prompts.chat-mcp'

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