list_namespaces
Retrieve all namespaces in a Nacos cluster for service discovery and configuration management, enabling efficient organization and access control across services.
Instructions
Retrieves the list of namespaces in the current Nacos cluster.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp_server_nacos/server.py:92-95 (handler)Handler logic for the 'list_namespaces' tool. Retrieves the Nacos API URL from the tool class and executes a GET request using the NacosServer instance, returning the result as text content.case nacos_tools.NacosToolNames.LIST_NAMESPACES: url = nacos_tools.NacosListNamespacesTool().url result = nacos.get(name, url, arguments) return [types.TextContent(type="text", text=result)]
- Schema and metadata definition for the 'list_namespaces' tool, including name, description, empty input schema (no parameters required), and the specific Nacos API endpoint URL.class NacosListNamespacesTool(NacosTool): def __init__(self): super().__init__( name=NacosToolNames.LIST_NAMESPACES, description="Retrieves the list of namespaces in the current Nacos cluster.", inputSchema={ "type": "object", "properties": {} }, url="/nacos/v3/admin/core/namespace/list" )
- src/mcp_server_nacos/server.py:71-86 (registration)Registration of the 'list_namespaces' tool (as NacosListNamespacesTool) in the MCP server's list_tools handler, making it available to clients.@server.list_tools() async def handle_list_tools() -> list[types.Tool]: """List available tools""" return [ nacos_tools.NacosListNamespacesTool(), nacos_tools.NacosListServices(), nacos_tools.NacosGetService(), nacos_tools.NacosListInstances(), nacos_tools.NacosListServiceSubscribers(), nacos_tools.NacosListConfigs(), nacos_tools.NacosGetConfig(), nacos_tools.NacosListConfigHistory(), nacos_tools.NacosGetConfigHistory(), nacos_tools.NacosListConfigListeners(), nacos_tools.NacosListListenedConfigs(), ]
- src/mcp_server_nacos/server.py:37-46 (helper)Helper method in NacosServer class that constructs the full API URL, performs the HTTP GET request to Nacos with authentication, and formats the response or error.def get(self, name:str, url: str, params: Any = None) -> str: url = f'http://{self.host}:{self.port}{url}' logger.debug(f'GET {url} with params {params}') result = self._request(url, params=params) if result is None: return "Unexpected error: None result handled." if result.is_success(): return str(result.data) return f'Do {name} failed with message: {result.message}'
- Enum defining the string constants for tool names, including LIST_NAMESPACES = "list_namespaces" used throughout for matching and identification.class NacosToolNames(str, Enum): LIST_NAMESPACES = "list_namespaces", LIST_SERVICES = "list_services", GET_SERVICE = "get_service", LIST_INSTANCES = "list_service_instances", LIST_SERVICE_SUBSCRIBERS = "list_service_subscribers", LIST_CONFIGS = "list_configs", GET_CONFIG = "get_config", LIST_CONFIG_HISTORY = "list_config_history", GET_CONFIG_HISTORY = "get_config_history", LIST_CONFIG_LISTENERS = "list_config_listeners", LIST_LISTENED_CONFIGS = "list_listened_configs",