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
| Name | Required | Description | Default |
|---|---|---|---|
| question | Yes | Question to ask |
Implementation Reference
- src/handlers/tools.ts:1221-1270 (handler)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 }; } } - src/handlers/tools.ts:222-229 (registration)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' } }, - src/handlers/tools.ts:295-296 (registration)Tool execution switch case for 'rag_query'.
case 'rag_query': return await this.handleRagQuery(args);