Skip to main content
Glama

list_prompts

Retrieve all available prompts from an MCP server with names, descriptions, and argument schemas for accurate invocation.

Instructions

List all prompts available on the connected MCP server.

Retrieves comprehensive information about all prompts exposed by the target server, including names, descriptions, and complete argument schemas to enable accurate prompt invocation.

Returns: Dictionary with prompt listing including: - success: True on successful retrieval - prompts: List of prompt objects with name, description, and arguments schema - metadata: Total count, server info, timing information

Raises: Returns error dict if not connected or retrieval fails

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The @mcp.tool decorated handler function that implements the list_prompts tool. It connects to a target MCP server, retrieves the list of prompts, processes their schemas, and returns structured data with success/error handling, logging, and progress updates.
    @mcp.tool
    async def list_prompts(ctx: Context) -> dict[str, Any]:
        """List all prompts available on the connected MCP server.
    
        Retrieves comprehensive information about all prompts exposed by the target
        server, including names, descriptions, and complete argument schemas to enable
        accurate prompt invocation.
    
        Returns:
            Dictionary with prompt listing including:
            - success: True on successful retrieval
            - prompts: List of prompt objects with name, description, and arguments schema
            - metadata: Total count, server info, timing information
    
        Raises:
            Returns error dict if not connected or retrieval fails
        """
        start_time = time.perf_counter()
    
        try:
            # Verify connection exists
            client, state = ConnectionManager.require_connection()
    
            # User-facing progress update
            await ctx.info("Listing prompts from connected MCP server")
            # Detailed technical log
            logger.info("Listing prompts from connected MCP server")
    
            # Get prompts from the server
            prompts_result = await client.list_prompts()
    
            elapsed_ms = (time.perf_counter() - start_time) * 1000
    
            # Convert prompts to dictionary format with full argument schemas
            # Note: client.list_prompts() returns a list directly, not an object with .prompts
            prompts_list = []
            for prompt in prompts_result:
                # Extract arguments schema
                arguments = []
                if hasattr(prompt, "arguments") and prompt.arguments:
                    for arg in prompt.arguments:
                        arg_dict = {
                            "name": arg.name,
                            "description": arg.description if arg.description else "",
                            "required": arg.required if hasattr(arg, "required") else False,
                        }
                        arguments.append(arg_dict)
    
                prompt_dict = {
                    "name": prompt.name,
                    "description": prompt.description if prompt.description else "",
                    "arguments": arguments,
                }
                prompts_list.append(prompt_dict)
    
            metadata = {
                "total_prompts": len(prompts_list),
                "server_url": state.server_url,
                "retrieved_at": time.time(),
                "request_time_ms": round(elapsed_ms, 2),
            }
    
            # Add server info if available
            if state.server_info:
                metadata["server_name"] = state.server_info.get("name", "unknown")
                metadata["server_version"] = state.server_info.get("version")
    
            # User-facing success update
            await ctx.info(f"Retrieved {len(prompts_list)} prompts from server")
            # Detailed technical log
            logger.info(
                f"Retrieved {len(prompts_list)} prompts from server",
                extra={
                    "prompt_count": len(prompts_list),
                    "server_url": state.server_url,
                    "duration_ms": elapsed_ms,
                },
            )
    
            return {
                "success": True,
                "prompts": prompts_list,
                "metadata": metadata,
            }
    
        except ConnectionError as e:
            elapsed_ms = (time.perf_counter() - start_time) * 1000
    
            # User-facing error update
            await ctx.error(f"Not connected: {str(e)}")
            # Detailed technical log
            logger.error(f"Not connected: {str(e)}", extra={"duration_ms": elapsed_ms})
    
            return {
                "success": False,
                "error": {
                    "error_type": "not_connected",
                    "message": str(e),
                    "details": {},
                    "suggestion": "Use connect_to_server() to establish a connection first",
                },
                "prompts": [],
                "metadata": {
                    "request_time_ms": round(elapsed_ms, 2),
                },
            }
    
        except Exception as e:
            elapsed_ms = (time.perf_counter() - start_time) * 1000
    
            # User-facing error update
            await ctx.error(f"Failed to list prompts: {str(e)}")
            # Detailed technical log
            logger.exception("Failed to list prompts", extra={"duration_ms": elapsed_ms})
    
            # Increment error counter
            ConnectionManager.increment_stat("errors")
    
            return {
                "success": False,
                "error": {
                    "error_type": "execution_error",
                    "message": f"Failed to list prompts: {str(e)}",
                    "details": {"exception_type": type(e).__name__},
                    "suggestion": "Check that the server supports the prompts capability and is responding correctly",
                },
                "prompts": [],
                "metadata": {
                    "request_time_ms": round(elapsed_ms, 2),
                },
            }
  • Import of the prompts module in the main server.py file, which triggers automatic tool registration via @mcp.tool decorators in prompts.py.
    from .tools import connection, tools, resources, prompts, llm
Behavior3/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 effectively describes the tool's read-only nature (retrieves information) and error conditions (connection failures), but lacks details on rate limits, pagination, or performance characteristics. It adds useful context beyond basic functionality but is not comprehensive.

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 well-structured with clear sections (purpose, returns, raises) and avoids redundancy. However, the 'Returns' section could be more concise, as some details (like 'success: True') might be inferred from context. Overall, it's efficient but has minor verbosity in the output description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (0 parameters, no annotations, but with an output schema), the description is complete. It explains what the tool does, what it returns, and error conditions, which is sufficient for a listing tool. The output schema will handle return value details, so the description doesn't need to duplicate that information.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description appropriately focuses on behavior and output rather than inputs, earning a baseline score of 4 for zero-parameter tools that avoid unnecessary parameter discussion.

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

Purpose5/5

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

The description clearly states the specific action ('List all prompts') and resource ('available on the connected MCP server'), distinguishing it from siblings like 'get_prompt' (which retrieves a single prompt) and 'list_tools' (which lists tools rather than prompts). The verb+resource combination is precise and unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying 'on the connected MCP server' and mentions prerequisites ('if not connected... returns error'), but does not explicitly state when to use this tool versus alternatives like 'get_prompt' or 'list_tools'. The guidance is clear but lacks explicit sibling differentiation.

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/rdwj/mcp-test-mcp'

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