Skip to main content
Glama

search_mcp_server

Find registered MCP servers by query to discover available tools and services for routing requests.

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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'search_mcp_server' tool, decorated with @mcp.tool() for registration. It calls the discovery_service to search for MCP servers and returns 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)
  • Supporting helper method in DiscoveryService that performs the actual semantic search using text embeddings from DashScope and vector similarity search in DashVector.
    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
Behavior2/5

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

With no annotations provided, the description carries full burden but lacks behavioral details. It doesn't disclose whether this is a read-only operation, what the search scope is (e.g., local vs. remote), performance characteristics, or error handling. The mention of 'registered MCP servers' hints at a database query, but specifics are missing.

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 front-loaded with the core purpose in the first sentence, followed by a structured 'Args:' section. It avoids unnecessary words, but the 'Args:' formatting could be more integrated. Overall, it's efficient with minimal waste.

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 2 parameters with 0% schema coverage and an output schema present, the description provides basic parameter semantics but lacks behavioral context. It doesn't explain search mechanics or result format, relying on the output schema for return values. This is adequate for a simple search tool but misses operational details.

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 0%, so the description must compensate. It adds basic semantics by explaining 'query' as a 'Search query' and 'top_k' as 'Number of top results to return', which clarifies intent beyond schema types. However, it doesn't detail query syntax, result ranking, or default behavior beyond the default value, leaving gaps.

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 verb ('Search') and resource ('registered MCP servers'), making the purpose immediately understandable. It distinguishes from sibling tools like 'add_mcp_server' (creation) and 'exec_mcp_tool' (execution) by focusing on discovery. However, it doesn't specify what aspects of servers are searched (e.g., names, descriptions, capabilities), keeping it from a perfect score.

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 versus alternatives. The description doesn't mention prerequisites, typical use cases, or how it relates to sibling tools like 'add_mcp_server' for adding servers or 'exec_mcp_tool' for using them. This leaves the agent without context for tool selection.

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

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