Skip to main content
Glama

chat

Send chat messages to AI models with optional RAG capabilities for retrieving information from documents. Configure parameters like temperature and system prompts to customize responses.

Instructions

Chat with Prem AI - supports chat completions with optional RAG capabilities.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe chat message to send
system_promptNoOptional system prompt to guide the model's behavior
modelNoOptional model to use for completion
temperatureNoOptional temperature for response generation
max_tokensNoOptional maximum tokens to generate
repository_idsNoOptional array of repository IDs for RAG
similarity_thresholdNoOptional similarity threshold for RAG
limitNoOptional limit of context chunks for RAG

Implementation Reference

  • The handler function for the 'chat' tool. It constructs a PremChatRequest, calls the Prem API chat.completions.create, and returns the response as text content or error.
    const requestId = `chat-${Date.now()}-${Math.random().toString(36).substring(2, 7)}`; this.activeRequests.add(requestId); try { const chatRequest = { project_id: PROJECT_ID as string, messages: [{ role: "user", content: query }], ...(model && { model }), ...(system_prompt && { system_prompt }), ...(temperature && { temperature }), ...(max_tokens && { max_tokens }), ...(repository_ids && { repositories: { ids: repository_ids, similarity_threshold: similarity_threshold || 0.65, limit: limit || 3 } }) }; const response = await this.client.chat.completions.create(chatRequest as any); const responseData = 'choices' in response ? response : { choices: [] }; return { content: [{ type: "text" as const, text: JSON.stringify(responseData, null, 2) }] }; } catch (error) { return { content: [{ type: "text" as const, text: `Chat error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } finally { this.activeRequests.delete(requestId); } }
  • src/index.ts:69-124 (registration)
    Registration of the 'chat' tool with the MCP server using this.server.toolcall.
    this.server.tool( "chat", "Chat with Prem AI - supports chat completions with optional RAG capabilities.", { query: z.string().describe("The chat message to send"), system_prompt: z.string().optional().describe("Optional system prompt to guide the model's behavior"), model: z.string().optional().describe("Optional model to use for completion"), temperature: z.number().optional().describe("Optional temperature for response generation"), max_tokens: z.number().optional().describe("Optional maximum tokens to generate"), repository_ids: z.array(z.number()).optional().describe("Optional array of repository IDs for RAG"), similarity_threshold: z.number().optional().describe("Optional similarity threshold for RAG"), limit: z.number().optional().describe("Optional limit of context chunks for RAG") }, async ({ query, system_prompt, model, temperature, max_tokens, repository_ids, similarity_threshold, limit }) => { const requestId = `chat-${Date.now()}-${Math.random().toString(36).substring(2, 7)}`; this.activeRequests.add(requestId); try { const chatRequest = { project_id: PROJECT_ID as string, messages: [{ role: "user", content: query }], ...(model && { model }), ...(system_prompt && { system_prompt }), ...(temperature && { temperature }), ...(max_tokens && { max_tokens }), ...(repository_ids && { repositories: { ids: repository_ids, similarity_threshold: similarity_threshold || 0.65, limit: limit || 3 } }) }; const response = await this.client.chat.completions.create(chatRequest as any); const responseData = 'choices' in response ? response : { choices: [] }; return { content: [{ type: "text" as const, text: JSON.stringify(responseData, null, 2) }] }; } catch (error) { return { content: [{ type: "text" as const, text: `Chat error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } finally { this.activeRequests.delete(requestId); } } );
  • Zod schema for validating inputs to the 'chat' tool.
    { query: z.string().describe("The chat message to send"), system_prompt: z.string().optional().describe("Optional system prompt to guide the model's behavior"), model: z.string().optional().describe("Optional model to use for completion"), temperature: z.number().optional().describe("Optional temperature for response generation"), max_tokens: z.number().optional().describe("Optional maximum tokens to generate"), repository_ids: z.array(z.number()).optional().describe("Optional array of repository IDs for RAG"), similarity_threshold: z.number().optional().describe("Optional similarity threshold for RAG"), limit: z.number().optional().describe("Optional limit of context chunks for RAG") }, async ({ query, system_prompt, model, temperature, max_tokens, repository_ids, similarity_threshold, limit }) => {
  • TypeScript interface defining the arguments for the chat tool.
    export interface ChatArgs { query: string; system_prompt?: string; model?: string; temperature?: number; max_tokens?: number; repository_ids?: number[]; similarity_threshold?: number; limit?: number; }
  • Type definition for the PremChatRequest used in the handler.
    export interface PremChatRequest { project_id: string; messages: PremMessage[]; model?: string; system_prompt?: string; session_id?: string; temperature?: number; max_tokens?: number; stream?: boolean; repositories?: PremRepository; }

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/ucalyptus/prem-mcp-server'

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