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"], }, }, ], }; });
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