Skip to main content
Glama
jbccc

ZeroEntropy Zerank MCP Server

by jbccc

get_reranking

Reranks documents by relevance to a search query using the ZeroEntropy Zerank API, helping AI assistants prioritize the most pertinent information for users.

Instructions

Get the reranked document listing

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query
documentsYesArray of documents to rerank
api_keyYesAPI key for authentication

Implementation Reference

  • rerank.py:33-82 (handler)
    Standalone Python implementation of the get_reranking MCP tool handler using FastMCP. Calls ZeroRank API for reranking.
    async def get_reranking(request: RerankRequest) -> RerankResponse:
        """Get the reranked document listing
        Args:
            request: The RerankRequest object containing query, documents, and api_key
        Returns:
            The RerankResponse object containing the reranked document listing
        """
    
        headers = {
            "Authorization": f"Bearer {request.api_key}",
            "Content-Type": "application/json",
        }
    
        async with httpx.AsyncClient() as client:
            try:
                response = await client.post(
                    ZERANK_API_BASE,
                    json={
                        "query": request.query,
                        "documents": request.documents,
                    },
                    headers=headers,
                )
                response.raise_for_status()
    
                result = response.json()
                if "results" not in result:
                    raise ValueError("Invalid API response format")
    
                return RerankResponse(
                    results=[RerankResult(**result) for result in result["results"]]
                )
    
            except httpx.HTTPStatusError as e:
                if e.response.status_code == 401:
                    raise ValueError("Invalid API key")
                elif e.response.status_code == 429:
                    raise ValueError("Rate limit exceeded")
                else:
                    raise ValueError(f"API error: {e.response.status_code}")
    
            except httpx.TimeoutException:
                raise ValueError("Request timed out")
    
            except httpx.RequestError as e:
                raise ValueError(f"Request error: {str(e)}")
    
            except Exception as e:
                raise ValueError(f"Reranking failed: {str(e)}")
  • main.py:18-67 (handler)
    Python handler for get_reranking tool defined within FastMCPServer DurableObject class for Cloudflare Workers.
    async def get_reranking(request: RerankRequest) -> RerankResponse:
        """Get the reranked document listing
        Args:
            request: The RerankRequest object containing query, documents, and api_key
        Returns:
            The RerankResponse object containing the reranked document listing
        """
    
        headers = {
            "Authorization": f"Bearer {request.api_key}",
            "Content-Type": "application/json",
        }
    
        async with httpx.AsyncClient() as client:
            try:
                response = await client.post(
                    ZERANK_API_BASE,
                    json={
                        "query": request.query,
                        "documents": request.documents,
                    },
                    headers=headers,
                )
                response.raise_for_status()
    
                result = response.json()
                if "results" not in result:
                    raise ValueError("Invalid API response format")
    
                return RerankResponse(
                    results=[RerankResult(**result) for result in result["results"]]
                )
    
            except httpx.HTTPStatusError as e:
                if e.response.status_code == 401:
                    raise ValueError("Invalid API key")
                elif e.response.status_code == 429:
                    raise ValueError("Rate limit exceeded")
                else:
                    raise ValueError(f"API error: {e.response.status_code}")
    
            except httpx.TimeoutException:
                raise ValueError("Request timed out")
    
            except httpx.RequestError as e:
                raise ValueError(f"Request error: {str(e)}")
    
            except Exception as e:
                raise ValueError(f"Reranking failed: {str(e)}")
  • JavaScript handler logic within CallToolRequestSchema handler for the get_reranking tool in stdio MCP server.
    if (name === "get_reranking") {
      try {
        // Validate input
        const validatedArgs = RerankRequestSchema.parse(args);
        
        // Make API request
        const response = await makeRerankRequest(
          validatedArgs.query,
          validatedArgs.documents,
          validatedArgs.api_key
        );
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(response, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Error: ${error.message}`,
            },
          ],
          isError: true,
        };
      }
    }
  • JavaScript handler logic within callTool method for the get_reranking tool in Cloudflare Worker Durable Object.
    if (name === "get_reranking") {
      try {
        // Validate input
        const validatedArgs = RerankRequestSchema.parse(args);
        
        // Make API request
        const response = await this.makeRerankRequest(
          validatedArgs.query,
          validatedArgs.documents,
          validatedArgs.api_key
        );
    
        return new Response(JSON.stringify({
          jsonrpc: "2.0",
          id: id,
          result: {
            content: [
              {
                type: "text",
                text: JSON.stringify(response, null, 2),
              },
            ],
          },
        }), {
          headers: { "Content-Type": "application/json" },
        });
      } catch (error) {
        return this.createErrorResponse(error.message, id, MCP_ERROR_CODES.INVALID_PARAMS);
      }
    }
  • index.js:94-129 (registration)
    Registration of the get_reranking tool in the list tools handler for the JS MCP server.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "get_reranking",
            description: "Get the reranked document listing",
            inputSchema: {
              type: "object",
              properties: {
                query: {
                  type: "string",
                  description: "The search query",
                  minLength: 1,
                  maxLength: 10000,
                },
                documents: {
                  type: "array",
                  description: "Array of documents to rerank",
                  items: {
                    type: "string",
                  },
                  minItems: 1,
                  maxItems: 1000,
                },
                api_key: {
                  type: "string",
                  description: "API key for authentication",
                  minLength: 1,
                },
              },
              required: ["query", "documents", "api_key"],
            },
          },
        ],
      };
    });
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. It doesn't disclose behavioral traits like authentication needs (implied by api_key but not stated), rate limits, or what 'reranked' means in practice. The description is minimal and lacks operational details.

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

Conciseness4/5

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

The description is a single, concise sentence with no wasted words, making it front-loaded and efficient. However, it's so brief that it under-specifies the tool's purpose, slightly reducing its effectiveness.

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 of a reranking operation with 3 parameters and no annotations or output schema, the description is incomplete. It doesn't explain what 'reranked' means, the expected output format, or behavioral aspects, leaving significant gaps for an AI agent.

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 documents all parameters well. The description adds no meaning beyond the schema, as it doesn't explain how parameters interact or the semantics of reranking. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose3/5

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

The description 'Get the reranked document listing' states the action (get) and resource (reranked document listing), but it's vague about what reranking entails. It doesn't specify the algorithm or purpose of reranking, and with no sibling tools, differentiation isn't needed, but the purpose could be more specific.

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?

No guidance is provided on when to use this tool, such as scenarios for reranking documents or prerequisites. With no sibling tools, alternatives aren't mentioned, but the description lacks context for usage.

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/jbccc/zeroentropy-zerank-mcp'

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