Skip to main content
Glama

discover_agents

Find and register available CLI agents on your system to enable intelligent task delegation through specialized tools.

Instructions

Discover and register available CLI agents on the system

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
force_refreshNoForce re-discovery even if cache exists

Implementation Reference

  • MCP tool handler for 'discover_agents': invokes AgentDiscovery, auto-registers new agents, formats and returns discovery summary as text.
    elif name == "discover_agents":
        # Discover available agents
        force_refresh = arguments.get("force_refresh", False)
        discovered = await self.agent_discovery.discover_agents(force_refresh=force_refresh)
    
        # Register newly discovered agents
        registered_count = 0
        for agent_name, metadata in discovered.items():
            if metadata.available and agent_name not in self.config.orchestrators:
                agent_config = OrchestratorConfig(
                    name=agent_name,
                    command=metadata.command,
                    enabled=True,
                    timeout=300,
                )
                self.config.orchestrators[agent_name] = agent_config
                self.registry.register(agent_config)
                registered_count += 1
                logger.info(f"Registered new agent: {agent_name}")
    
        # Build response
        summary = self.agent_discovery.get_discovery_summary()
        text = f"Agent Discovery Results:\n\n"
        text += f"Total agents scanned: {summary['total_agents']}\n"
        text += f"Available: {summary['available']}\n"
        text += f"Unavailable: {summary['unavailable']}\n"
        text += f"Newly registered: {registered_count}\n\n"
    
        if summary['available_agents']:
            text += "Available Agents:\n"
            for agent in summary['available_agents']:
                text += f"  ✓ {agent['name']}: {agent['version']}\n"
                text += f"    Path: {agent['path']}\n"
    
        if summary['unavailable_agents']:
            text += "\nUnavailable Agents:\n"
            for agent in summary['unavailable_agents']:
                text += f"  ✗ {agent['name']}\n"
                text += f"    {agent['error']}\n"
    
        return [TextContent(type="text", text=text)]
  • Tool registration in list_tools() handler, defining name, description, and input schema for 'discover_agents'.
    Tool(
        name="discover_agents",
        description="Discover and register available CLI agents on the system",
        inputSchema={
            "type": "object",
            "properties": {
                "force_refresh": {
                    "type": "boolean",
                    "description": "Force re-discovery even if cache exists",
                    "default": False,
                },
            },
        },
    ),
  • Input schema definition for 'discover_agents' tool: optional boolean force_refresh.
    Tool(
        name="discover_agents",
        description="Discover and register available CLI agents on the system",
        inputSchema={
            "type": "object",
            "properties": {
                "force_refresh": {
                    "type": "boolean",
                    "description": "Force re-discovery even if cache exists",
                    "default": False,
                },
            },
        },
    ),
  • Core implementation of agent discovery logic (AgentDiscovery.discover_agents method), performing parallel discovery, verification, caching; invoked by MCP tool handler.
    async def discover_agents(
        self,
        force_refresh: bool = False,
        agents_to_check: list[str] | None = None,
    ) -> dict[str, AgentMetadata]:
        """Discover available agents on the system.
    
        Args:
            force_refresh: Force re-discovery even if cache exists
            agents_to_check: Specific agents to check (default: all known agents)
    
        Returns:
            Dictionary of agent name to metadata
        """
        if not force_refresh and self._discovered_agents:
            logger.info("Using cached agent discovery results")
            return self._discovered_agents
    
        logger.info("Starting agent discovery...")
    
        # Determine which agents to check
        agents = agents_to_check or list(self.KNOWN_AGENTS.keys())
    
        # Use a semaphore to limit concurrency on all platforms to avoid resource spikes
        # On Windows this is critical, on others it's just good practice
        concurrency_limit = 5 if platform.system() == "Windows" else 10
        semaphore = asyncio.Semaphore(concurrency_limit)
    
        async def _bounded_discover(name: str, config: dict[str, Any]) -> AgentMetadata | Exception:
            async with semaphore:
                try:
                    return await self._discover_single_agent(name, config)
                except Exception as e:
                    logger.error(f"Discovery task failed for {name}: {e}")
                    return e
    
        logger.debug(f"Running agent discovery in parallel (limit={concurrency_limit})")
        tasks = []
        for name in agents:
            if name not in self.KNOWN_AGENTS:
                logger.warning(f"Unknown agent: {name}")
                continue
    
            config = self.KNOWN_AGENTS[name]
            tasks.append(_bounded_discover(name, config))
    
        results = await asyncio.gather(*tasks, return_exceptions=True)
    
        # Process results
        for result in results:
            if isinstance(result, AgentMetadata):
                self._discovered_agents[result.name] = result
            elif isinstance(result, Exception):
                # Already logged in _bounded_discover
                pass
    
        # Save to cache
        self._save_cache()
    
        logger.info(
            f"Discovery complete: {sum(1 for a in self._discovered_agents.values() if a.available)}/{len(self._discovered_agents)} agents available"
        )
    
        return self._discovered_agents
  • Dataclass defining AgentMetadata structure used in discovery results.
    @dataclass
    class AgentMetadata:
        """Metadata for a discovered agent."""
    
        name: str
        command: str | list[str]
        version: str | None = None
        available: bool = False
        path: str | None = None
        error_message: str | None = None
        capabilities: list[str] | None = None
        verified_at: str | None = None
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'discover and register' which implies a write operation (registration), but doesn't clarify permissions, side effects, or what 'register' entails (e.g., updating a cache, adding to a database). This is a significant gap for a tool that appears to modify system state.

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 front-loads the core purpose without unnecessary words. Every part earns its place, making it highly concise and well-structured for quick comprehension.

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 tool's apparent complexity (involving discovery and registration of CLI agents), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what 'register' means, what the output looks like, or how it interacts with system state, leaving critical gaps for an agent to use it effectively.

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?

The schema description coverage is 100%, with the single parameter 'force_refresh' well-documented in the schema. The description doesn't add any parameter-specific details beyond what the schema provides, so it meets the baseline of 3 for adequate coverage without extra value.

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 tool's purpose with specific verbs ('discover and register') and resource ('available CLI agents on the system'), making it easy to understand what it does. However, it doesn't explicitly differentiate from sibling tools like 'list_agents', which might have overlapping 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 like 'list_agents' or 'get_routing_guidance'. There's no mention of prerequisites, typical use cases, or exclusions, leaving the agent with little context for 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/carlosduplar/multi-agent-mcp'

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