nat.cli.commands.info.list_mcp#

Attributes#

Classes#

MCPPingResult

Result of an MCP server ping request.

Functions#

format_tool(→ dict[str, str | None])

Format an MCP tool into a dictionary for display.

print_tool(→ None)

Print a formatted tool to the console with optional detailed information.

list_tools_and_schemas(→ list[dict[str, str | None]])

List MCP tools using MCPBuilder with structured exception handling.

list_tools_direct(→ list[dict[str, str | None]])

List MCP tools using direct MCP protocol with exception conversion.

ping_mcp_server(→ MCPPingResult)

Ping an MCP server to check if it's responsive.

list_mcp(→ None)

List MCP tool names (default) or show detailed tool information.

ping(→ None)

Ping an MCP server to check if it's responsive.

Module Contents#

logger#
class MCPPingResult(/, **data: Any)#

Bases: pydantic.BaseModel

Result of an MCP server ping request.

Attributes:

url (str): The MCP server URL that was pinged status (str): Health status - ‘healthy’, ‘unhealthy’, or ‘unknown’ response_time_ms (float | None): Response time in milliseconds, None if request failed completely error (str | None): Error message if the ping failed, None if successful

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

url: str#
status: str#
response_time_ms: float | None#
error: str | None#
format_tool(tool: Any) dict[str, str | None]#

Format an MCP tool into a dictionary for display.

Extracts name, description, and input schema from various MCP tool object types and normalizes them into a consistent dictionary format for CLI display.

Args:

tool (Any): MCPToolClient or raw MCP Tool object (uses Any due to different types)

Returns:

dict[str, str | None]: Dictionary with name, description, and input_schema as keys

print_tool(
tool_dict: dict[str, str | None],
detail: bool = False,
) None#

Print a formatted tool to the console with optional detailed information.

Outputs tool information in a user-friendly format to stdout. When detail=True or when description/schema are available, shows full information with separator.

Args:

tool_dict (dict[str, str | None]): Dictionary containing tool information with name, description, and input_schema as keys detail (bool, optional): Whether to force detailed output. Defaults to False.

async list_tools_and_schemas(
url: str,
tool_name: str | None = None,
) list[dict[str, str | None]]#

List MCP tools using MCPBuilder with structured exception handling.

Args:

url (str): MCP server URL to connect to tool_name (str | None, optional): Specific tool name to retrieve. If None, retrieves all available tools. Defaults to None.

Returns:

list[dict[str, str | None]]: List of formatted tool dictionaries, each containing name, description, and input_schema as keys

Raises:

MCPError: Caught internally and logged, returns empty list instead

async list_tools_direct(
url: str,
tool_name: str | None = None,
) list[dict[str, str | None]]#

List MCP tools using direct MCP protocol with exception conversion.

Bypasses MCPBuilder and uses raw MCP ClientSession and SSE client directly. Converts raw exceptions to structured MCPErrors for consistent user experience. Used when –direct flag is specified in CLI.

Args:

url (str): MCP server URL to connect to tool_name (str | None, optional): Specific tool name to retrieve. If None, retrieves all available tools. Defaults to None.

Returns:

list[dict[str, str | None]]: List of formatted tool dictionaries, each containing name, description, and input_schema as keys

Note:

This function handles ExceptionGroup by extracting the most relevant exception and converting it to MCPError for consistent error reporting.

async ping_mcp_server(url: str, timeout: int) MCPPingResult#

Ping an MCP server to check if it’s responsive.

Args:

url (str): MCP server URL to ping timeout (int): Timeout in seconds for the ping request

Returns:

MCPPingResult: Structured result with status, response_time, and any error info

list_mcp(
ctx: click.Context,
direct: bool,
url: str,
tool: str | None,
detail: bool,
json_output: bool,
) None#

List MCP tool names (default) or show detailed tool information.

Use –detail for full output including descriptions and input schemas. If –tool is provided, always shows full output for that specific tool. Use –direct to bypass MCPBuilder and use raw MCP protocol. Use –json-output to get structured JSON data instead of formatted text.

Args:

ctx (click.Context): Click context object for command invocation direct (bool): Whether to bypass MCPBuilder and use direct MCP protocol url (str): MCP server URL to connect to (default: http://localhost:9901/sse) tool (str | None): Optional specific tool name to retrieve detailed info for detail (bool): Whether to show full details (description + schema) for all tools json_output (bool): Whether to output tool metadata in JSON format instead of text

Examples:

nat info mcp # List tool names only nat info mcp –detail # Show all tools with full details nat info mcp –tool my_tool # Show details for specific tool nat info mcp –json-output # Get JSON format output nat info mcp –direct –url http://… # Use direct protocol with custom URL

ping(url: str, timeout: int, json_output: bool) None#

Ping an MCP server to check if it’s responsive.

This command sends a ping request to the MCP server and measures the response time. It’s useful for health checks and monitoring server availability.

Args:

url (str): MCP server URL to ping (default: http://localhost:9901/sse) timeout (int): Timeout in seconds for the ping request (default: 60) json_output (bool): Whether to output the result in JSON format

Examples:

nat info mcp ping # Ping default server nat info mcp ping –url http://custom-server:9901/sse # Ping custom server nat info mcp ping –timeout 10 # Use 10 second timeout nat info mcp ping –json-output # Get JSON format output