Skip to main content
Glama
njlnaet
by njlnaet

CoderSwap Hybrid Search

coderswap_search

Execute hybrid search queries against CoderSwap projects using DSL-powered ranking to find relevant code snippets and information from vector knowledge bases.

Instructions

Execute a hybrid search query against a CoderSwap project using DSL-powered ranking

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes
queryYes
top_kNo
snippet_lengthNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
resultsYes
result_countYes

Implementation Reference

  • src/index.ts:486-565 (registration)
    Full registration of the 'coderswap_search' MCP tool, including schema definitions and handler function.
    server.registerTool(
      'coderswap_search',
      {
        title: 'CoderSwap Hybrid Search',
        description: 'Execute a hybrid search query against a CoderSwap project using DSL-powered ranking',
        inputSchema: {
          project_id: z.string().min(1, 'project_id is required'),
          query: z.string().min(1, 'query is required'),
          top_k: z.number().min(1).max(50).default(10),
          snippet_length: z.number().min(50).max(1000).default(200)
        },
        outputSchema: {
          query: z.string(),
          result_count: z.number(),
          results: z.array(z.object({
            score: z.number(),
            title: z.string().optional(),
            snippet: z.string().optional()
          }))
        }
      },
      async ({ project_id, query, top_k = 10, snippet_length = 200 }) => {
        try {
          log('debug', 'Executing search', { project_id, query, top_k })
          const result = await client.search({ project_id, query, top_k, snippet_length })
    
          const output = {
            query,
            result_count: result.results.length,
            results: result.results.slice(0, top_k).map(r => ({
              score: r.score,
              title: r.title,
              snippet: r.snippet
            }))
          }
    
          if (result.results.length === 0) {
            return {
              content: [{
                type: 'text',
                text: `No results found for: "${query}"`
              }],
              structuredContent: output
            }
          }
    
          // Format results with rich detail
          const formattedResults = result.results
            .slice(0, top_k)
            .map((r, i) => {
              const medal = i === 0 ? '🥇' : i === 1 ? '🥈' : i === 2 ? '🥉' : `${i + 1}.`
              const score = ((r.score ?? 0) * 100).toFixed(1)
              let text = `${medal} Score: ${score}%`
              if (r.title) text += `\n   ${r.title}`
              if (r.snippet) text += `\n   ${r.snippet.substring(0, 150)}...`
              return text
            })
            .join('\n\n')
    
          log('info', `Search returned ${result.results.length} results`)
    
          return {
            content: [{
              type: 'text',
              text: `Found ${result.results.length} result(s) for: "${query}"\n\n${formattedResults}`
            }],
            structuredContent: output
          }
        } catch (error) {
          log('error', 'Search failed', { project_id, query, error: error instanceof Error ? error.message : error })
          return {
            content: [{
              type: 'text',
              text: `✗ Search failed: ${error instanceof Error ? error.message : 'Unknown error'}`
            }],
            isError: true
          }
        }
      }
    )
  • The core handler function for the coderswap_search tool. It invokes the CoderSwapClient.search method, processes and formats the results with scores and medals, and returns structured content.
    async ({ project_id, query, top_k = 10, snippet_length = 200 }) => {
      try {
        log('debug', 'Executing search', { project_id, query, top_k })
        const result = await client.search({ project_id, query, top_k, snippet_length })
    
        const output = {
          query,
          result_count: result.results.length,
          results: result.results.slice(0, top_k).map(r => ({
            score: r.score,
            title: r.title,
            snippet: r.snippet
          }))
        }
    
        if (result.results.length === 0) {
          return {
            content: [{
              type: 'text',
              text: `No results found for: "${query}"`
            }],
            structuredContent: output
          }
        }
    
        // Format results with rich detail
        const formattedResults = result.results
          .slice(0, top_k)
          .map((r, i) => {
            const medal = i === 0 ? '🥇' : i === 1 ? '🥈' : i === 2 ? '🥉' : `${i + 1}.`
            const score = ((r.score ?? 0) * 100).toFixed(1)
            let text = `${medal} Score: ${score}%`
            if (r.title) text += `\n   ${r.title}`
            if (r.snippet) text += `\n   ${r.snippet.substring(0, 150)}...`
            return text
          })
          .join('\n\n')
    
        log('info', `Search returned ${result.results.length} results`)
    
        return {
          content: [{
            type: 'text',
            text: `Found ${result.results.length} result(s) for: "${query}"\n\n${formattedResults}`
          }],
          structuredContent: output
        }
      } catch (error) {
        log('error', 'Search failed', { project_id, query, error: error instanceof Error ? error.message : error })
        return {
          content: [{
            type: 'text',
            text: `✗ Search failed: ${error instanceof Error ? error.message : 'Unknown error'}`
          }],
          isError: true
        }
      }
    }
  • Implementation of the search method in CoderSwapClient class, which makes the HTTP POST request to the /v1/search API endpoint.
    async search(input: SearchInput) {
      const res = await fetch(`${this.baseUrl}/v1/search`, {
        method: 'POST',
        headers: this.headers,
        body: JSON.stringify({
          project_id: input.project_id,
          query: input.query,
          snippet_length: input.snippet_length ?? 200,
          settings: {
            k: input.top_k ?? 5
          }
        })
      })
      return this.handleResponse<{ results: SearchResult[]; request_id?: string }>(res)
    }
  • Zod schema definition for SearchInput type used by the CoderSwapClient.search method.
    export const searchSchema = z.object({
      project_id: z.string().min(1, 'project_id is required'),
      query: z.string().min(1, 'query is required'),
      top_k: z.number().min(1).max(50).optional(),
      snippet_length: z.number().min(50).max(1000).optional()
    })
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'DSL-powered ranking' which hints at ranking behavior, but doesn't explain what 'hybrid search' entails, whether it's read-only or has side effects, authentication requirements, rate limits, or what the output contains. This leaves significant gaps for a search operation.

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 description and front-loads the essential information about what the tool does.

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

Completeness3/5

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

Given that there's an output schema (which reduces the need to describe return values), but with 4 parameters having 0% schema coverage and no annotations, the description is incomplete. It covers the basic purpose but lacks crucial details about parameter meanings, behavioral characteristics, and usage context that would make it fully adequate for this search tool.

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

Parameters2/5

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

With 0% schema description coverage for all 4 parameters, the description provides no information about parameter meanings beyond what's in the schema. It doesn't explain what 'project_id' refers to, what format 'query' should take, what 'top_k' controls, or what 'snippet_length' affects in the results. The description fails to compensate for the complete lack of schema 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 action ('execute a hybrid search query') and target resource ('against a CoderSwap project'), which provides a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like coderswap_validate_search or coderswap_research_ingest, which might have overlapping search-related functionality.

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. There's no mention of prerequisites, appropriate contexts, or comparisons to sibling tools like coderswap_validate_search (which might be for validation) or coderswap_research_ingest (which might involve data ingestion).

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

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