Skip to main content
Glama

list_environments

Retrieve all available environments for your current project to manage API testing and development workflows.

Instructions

List all environments for current project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectIdNoProject ID (optional, will use current project if not provided)
activeOnlyNoShow 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) } ] }; } }
  • 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 };
  • 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); },
  • 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 ];

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/martin-1103/mcp2'

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