Skip to main content
Glama

search_onyx

Search the Onyx backend to find relevant documents by topic, retrieve matching chunks or full documents, and filter results by document sets.

Instructions

Search the Onyx backend for relevant documents

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe topic to search for
chunksAboveNoNumber of chunks to include above the matching chunk (default: 1)
chunksBelowNoNumber of chunks to include below the matching chunk (default: 1)
retrieveFullDocumentsNoWhether to retrieve full documents instead of just matching chunks (default: false)
documentSetsNoList of document set names to search within (empty for all)
maxResultsNoMaximum number of results to return (default: 5)

Implementation Reference

  • Main handler function that validates input, performs semantic search via OnyxApiService, retrieves relevant content, builds formatted context, and returns MCP tool response.
    export async function handleSearchOnyx(args: unknown, onyxApiService: OnyxApiService) {
      try {
        if (typeof args !== 'object' || args === null) {
          throw new McpError(ErrorCode.InvalidParams, 'Invalid arguments');
        }
    
        const { 
          query, 
          documentSets = [], 
          maxResults = 5,
          chunksAbove = 1,
          chunksBelow = 1,
          retrieveFullDocuments = false
        } = args as SearchParams;
        
        if (!query || typeof query !== 'string') {
          throw new McpError(ErrorCode.InvalidParams, 'Query is required');
        }
    
        // Step 1: Perform semantic search to find relevant documents
        const searchResults = await onyxApiService.searchOnyx(query, documentSets, chunksAbove, chunksBelow);
        
        // Step 2: Get the most relevant results
        const relevantResults = searchResults
          .sort((a, b) => b.score - a.score)
          .slice(0, maxResults);
        
        // Step 3: For each relevant document, fetch either the specific chunk or full document content
        const relevantContent = await Promise.all(
          relevantResults.map(result => 
            retrieveFullDocuments 
              ? onyxApiService.fetchDocumentContent(result.document_id)
              : onyxApiService.fetchDocumentChunk(result.document_id, result.chunk_ind)
          )
        );
        
        // Step 4: Combine into comprehensive context
        const context = onyxApiService.buildContext(relevantResults, relevantContent);
    
        return {
          content: [
            {
              type: 'text',
              text: context,
            },
          ],
        };
      } catch (error) {
        console.error('Error in handleSearchOnyx:', error);
        return {
          content: [
            {
              type: 'text',
              text: `Error searching Onyx: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • MCP tool schema definition including input schema for validation with properties like query, documentSets, maxResults, etc.
    search_onyx: {
      name: 'search_onyx',
      description: 'Search the Onyx backend for relevant documents',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'The topic to search for',
          },
          chunksAbove: {
            type: 'integer',
            description: 'Number of chunks to include above the matching chunk (default: 1)',
            default: 1
          },
          chunksBelow: {
            type: 'integer',
            description: 'Number of chunks to include below the matching chunk (default: 1)',
            default: 1
          },
          retrieveFullDocuments: {
            type: 'boolean',
            description: 'Whether to retrieve full documents instead of just matching chunks (default: false)',
            default: false
          },
          documentSets: {
            type: 'array',
            items: {
              type: 'string',
            },
            description: 'List of document set names to search within (empty for all)',
          },
          maxResults: {
            type: 'integer',
            description: 'Maximum number of results to return (default: 5)',
            minimum: 1,
            maximum: 10,
          },
        },
        required: ['query'],
      },
    },
  • src/server.ts:62-75 (registration)
    Registers the call_tool request handler that dispatches 'search_onyx' calls to the handleSearchOnyx function.
      this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
        switch (request.params.name) {
          case 'search_onyx':
            return handleSearchOnyx(request.params.arguments, this.onyxApiService);
          case 'chat_with_onyx':
            return handleChatWithOnyx(request.params.arguments, this.onyxApiService);
          default:
            throw new McpError(
              ErrorCode.MethodNotFound,
              `Unknown tool: ${request.params.name}`
            );
        }
      });
    }
  • src/server.ts:87-94 (registration)
    Registers the list_tools request handler that exposes the search_onyx schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          toolSchemas.search_onyx,
          toolSchemas.chat_with_onyx,
        ],
      };
    });
  • Core helper method in OnyxApiService that performs the actual API call to Onyx for semantic search.
    async searchOnyx(
      query: string,
      documentSets: string[] = [],
      chunksAbove = 0,
      chunksBelow = 0
    ): Promise<OnyxSearchResult[]> {
      try {
        const response = await axios.post(
          `${this.config.apiUrl}/admin/search`,
          {
            query,
            filters: {
              document_set: documentSets.length > 0 ? documentSets : null,
              source_type: null,
              time_cutoff: null,
              tags: null
            },
            chunks_above: chunksAbove,
            chunks_below: chunksBelow,
            evaluation_type: 'basic' // Enable LLM relevance filtering
          },
          {
            headers: {
              'Content-Type': 'application/json',
              'Authorization': `Bearer ${this.config.apiToken}`
            }
          }
        );
    
        return response.data.documents || [];
      } catch (error) {
        console.error('Error searching Onyx:', error);
        throw new Error(`Failed to search Onyx: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions searching for 'relevant documents' but doesn't describe what constitutes relevance, how results are ranked, whether there are rate limits, authentication requirements, or what the output format looks like. For a search tool with 6 parameters and no annotation coverage, this is insufficient.

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 a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for a tool with a clear primary function and is front-loaded with the essential information.

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 complexity (6 parameters, no annotations, no output schema), the description is inadequate. It doesn't explain what 'relevant' means, how results are returned, or provide any behavioral context. For a search tool that likely returns structured data, more completeness is needed to help an agent use it effectively.

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?

The schema description coverage is 100%, meaning all parameters are documented in the schema itself. The description adds no additional parameter semantics beyond what's already in the schema (e.g., it doesn't explain how 'chunksAbove' and 'chunksBelow' work together or what 'documentSets' represent). Baseline 3 is appropriate when the schema does the heavy lifting.

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 action ('Search') and target ('the Onyx backend for relevant documents'), providing a specific verb+resource combination. However, it doesn't differentiate from its sibling tool 'chat_with_onyx', which appears to be a related but distinct functionality, so it doesn't fully distinguish from alternatives.

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 the sibling 'chat_with_onyx' or any other alternatives. It lacks context about appropriate use cases, exclusions, or prerequisites, offering only a basic functional statement without usage direction.

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/lupuletic/onyx-mcp-server'

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