list_environments
Retrieve all available environments for your current project to manage API testing and development workflows.
Instructions
List all environments for current project
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "list_environments"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | No | Project ID (optional, will use current project if not provided) | |
| activeOnly | No | Show only active environments |
Implementation Reference
- Core handler function implementing the list_environments tool logic: detects project config, initializes backend client and EnvironmentService, fetches environments, formats them into a readable list with variable counts, handles errors.
export async function handleListEnvironments(args: any): Promise<McpToolResponse> { try { const { projectId, activeOnly } = args; const instances = await getInstances(); // Get project ID if not provided let targetProjectId = projectId; if (!targetProjectId) { const config = await instances.configManager.detectProjectConfig(); targetProjectId = config?.project?.id; if (!targetProjectId) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: 'Project ID not found in config and not provided in arguments' }, null, 2) } ] }; } } // Create environment service const envService = new EnvironmentService( instances.backendClient.getBaseUrl(), instances.backendClient.getToken() ); // List environments const request: ListEnvironmentsRequest = { projectId: targetProjectId, activeOnly: activeOnly !== false // default to true }; const response = await envService.listEnvironments(request); if (!response.success) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: response.error || 'Failed to list environments' }, null, 2) } ] }; } const environments = response.data || []; // Format response let envText = `🌍 Environments List (${environments.length}):\n\n`; if (environments.length === 0) { envText += 'No environments found for this project.\n'; envText += 'Use create_environment tool to add your first environment.\n'; } else { environments.forEach((env: any, index: number) => { const isDefault = env.is_default ? ' [Default]' : ''; const variables = parseVariables(env.variables); const varCount = Object.keys(variables).length; envText += `${index + 1}. ${env.name} (${env.id})${isDefault}\n`; envText += ` - ${varCount} variables\n`; if (env.description) { envText += ` - ${env.description}\n`; } envText += '\n'; }); } return { content: [ { type: 'text', text: envText } ] }; } catch (error: any) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: error.message || 'Unknown error occurred while listing environments' }, null, 2) } ] }; } } - src/tools/environment/tools.ts:14-32 (schema)MCP tool definition for list_environments including input schema with projectId and activeOnly parameters.
export const listEnvironmentsTool: McpTool = { name: 'list_environments', description: 'List all environments for current project', inputSchema: { type: 'object', properties: { projectId: { type: 'string', description: 'Project ID (optional, will use current project if not provided)' }, activeOnly: { type: 'boolean', description: 'Show only active environments', default: true } } }, handler: handleListEnvironments }; - src/tools/index.ts:85-88 (registration)Dynamic registration of the list_environments tool handler in the central tool handlers factory.
'list_environments': async (args: any) => { const { handleListEnvironments } = await import('./environment/handlers/listHandler.js'); return handleListEnvironments(args); }, - src/tools/environment/types.ts:22-32 (schema)TypeScript interfaces defining input (ListEnvironmentsRequest) and output (ListEnvironmentsResponse) for environment listing operations.
export interface ListEnvironmentsRequest { projectId?: string; activeOnly?: boolean; } export interface ListEnvironmentsResponse { success: boolean; data?: Environment[]; message?: string; error?: string; } - Export of all environment tools array, which includes listEnvironmentsTool and is imported into main tools index for complete toolset registration.
export const environmentTools = [ listEnvironmentsTool, getEnvironmentDetailsTool, createEnvironmentTool, updateEnvironmentVariablesTool, setDefaultEnvironmentTool, deleteEnvironmentTool ];