Skip to main content
Glama

search_mcp_server

Discover and locate registered MCP servers using a search query, retrieving top results to simplify service discovery and routing for efficient MCP service execution.

Instructions

Search for registered MCP servers based on a query. Args: query: Search query top_k: Number of top results to return (default: 3)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
top_kNo

Implementation Reference

  • The MCP tool handler decorated with @mcp.tool(), which performs the search by calling the discovery service and formats the results as JSON.
    @mcp.tool() async def search_mcp_server(query: str, top_k: Optional[int] = 3) -> str: """ Search for registered MCP servers based on a query. Args: query: Search query top_k: Number of top results to return (default: 3) """ try: # Search for servers results = discovery_service.search_server(query, top_k) # Parse tools JSON strings back to objects for result in results: result["tools"] = json.loads(result["tools"]) return json.dumps(results, ensure_ascii=False) except Exception as e: return json.dumps({"error": str(e)}, ensure_ascii=False)
  • The supporting utility method in DiscoveryService that implements the vector search for MCP servers using DashVector embeddings.
    def search_server(self, query, top_k=3): """ Search for MCP servers based on a query. Args: query (str): Search query top_k (int): Number of top results to return (default: 3) Returns: list: List of matching servers with their metadata """ # Generate vector for the query query_vector = self._generate_embedding(query) # Perform vector search rsp = self.collection.query( query_vector, topk=top_k, output_fields=['server_description', 'server_endpoint', 'tools'] ) if not rsp: raise Exception("Failed to query DashVector") # Process results results = [] for doc in rsp.output: results.append({ "server_name": doc.id, "server_description": doc.fields['server_description'], "server_endpoint": doc.fields['server_endpoint'], "tools": doc.fields['tools'], # Still a JSON string "score": doc.score }) return results
  • mcp_router.py:61-61 (registration)
    The @mcp.tool() decorator that registers the search_mcp_server function as an MCP tool in the FastMCP server.
    @mcp.tool()

Other Tools

Related 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/Maverick-LjXuan/mcp-router'

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