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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'chat completions with optional RAG capabilities' but doesn't describe key behavioral traits like whether this is a read-only or mutating operation, authentication requirements, rate limits, response format, or error handling. For a chat tool with 8 parameters and no annotations, this leaves significant gaps in understanding how the tool behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise and front-loaded: a single sentence that captures the core functionality. Every word earns its place with no redundancy or unnecessary elaboration. The structure efficiently communicates the tool's purpose without wasting space.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (8 parameters, no output schema, no annotations), the description is incomplete. It doesn't address behavioral aspects, usage context, or output expectations. While the schema covers parameters well, the description fails to provide the additional context needed for an agent to understand when and how to use this tool effectively, especially compared to siblings.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 8 parameters thoroughly. The description adds minimal value beyond the schema by mentioning 'optional RAG capabilities', which loosely relates to parameters like repository_ids, similarity_threshold, and limit. However, it doesn't provide additional semantic context or usage examples beyond what's in the parameter descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Chat with Prem AI - supports chat completions with optional RAG capabilities.' It specifies the verb ('Chat with'), resource ('Prem AI'), and key capabilities (chat completions with optional RAG). However, it doesn't explicitly differentiate from sibling tools like 'prem_chat_with_template' beyond mentioning RAG capabilities.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'prem_chat_with_template' or 'prem_upload_document'. It mentions optional RAG capabilities but doesn't specify scenarios where RAG is beneficial or when to choose this tool over siblings. No explicit when/when-not statements or alternative recommendations are included.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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

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