Skip to main content
Glama

rag_query

Ask questions using RAG-enhanced context from xAI Collections with LAZY-RAG cache for faster repeated queries.

Instructions

Ask a question with RAG-enhanced context from xAI Collections. Uses LAZY-RAG cache for 100,000x speedup on repeated queries.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
questionYesQuestion to ask

Implementation Reference

  • The handleRagQuery function implements the logic for the 'rag_query' MCP tool. It validates the input question, checks for API configuration, executes the RAG query, and formats the result.
    private async handleRagQuery(args: any): Promise<CallToolResult> {
      const { question } = args;
    
      if (!question) {
        return {
          content: [{
            type: 'text',
            text: '❌ Question is required'
          }],
          isError: true
        };
      }
    
      try {
        const rag = getRAGIntegrator();
    
        if (!rag.isConfigured()) {
          return {
            content: [{
              type: 'text',
              text: '❌ XAI_API_KEY not configured. Set the environment variable to enable RAG queries.'
            }],
            isError: true
          };
        }
    
        const result = await rag.query(question);
    
        const status = result.cached ? '⚡ CACHE HIT' : '🔄 API CALL';
        const elapsed = result.cached
          ? `${(result.elapsed * 1000).toFixed(3)}ms`
          : `${result.elapsed.toFixed(2)}s`;
    
        return {
          content: [{
            type: 'text',
            text: `${status} (${elapsed})\n\n${result.answer}`
          }]
        };
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : 'Unknown error';
        return {
          content: [{
            type: 'text',
            text: `❌ RAG Query Failed: ${errorMessage}`
          }],
          isError: true
        };
      }
    }
  • Tool definition and registration for 'rag_query' in the tool list.
    {
      name: 'rag_query',
      description: 'Ask a question with RAG-enhanced context from xAI Collections. Uses LAZY-RAG cache for 100,000x speedup on repeated queries.',
      inputSchema: {
        type: 'object',
        properties: {
          question: { type: 'string', description: 'Question to ask' }
        },
  • Tool execution switch case for 'rag_query'.
    case 'rag_query':
      return await this.handleRagQuery(args);

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/Wolfe-Jam/grok-faf-mcp'

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