env_get
Fetch environment variables for API testing; sensitive values are masked by default, but you can request a specific variable to see its full value.
Instructions
Obtiene una variable específica o todas las variables de un entorno. Los valores sensibles (token, password, secret, api_key...) se enmascaran por defecto. Pide una variable por nombre para ver su valor completo.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | No | Variable específica. Si se omite, retorna todas | |
| environment | No | Entorno a consultar (default: entorno activo) |
Implementation Reference
- src/tools/environment.ts:169-254 (handler)The env_get tool handler: retrieves variables from an environment. If 'key' is specified, returns its full value (unmasked). If no key, returns all variables with sensitive values masked via maskVariables(). Uses the active environment if none specified.
// ── env_get ── server.tool( 'env_get', 'Obtiene una variable específica o todas las variables de un entorno. Los valores sensibles (token, password, secret, api_key...) se enmascaran por defecto. Pide una variable por nombre para ver su valor completo.', { key: z .string() .optional() .describe('Variable específica. Si se omite, retorna todas'), environment: z .string() .optional() .describe('Entorno a consultar (default: entorno activo)'), }, async (params) => { try { const envName = params.environment ?? (await storage.getActiveEnvironment()) if (!envName) { return { content: [ { type: 'text' as const, text: 'No hay entorno activo. Usa env_switch para activar uno.', }, ], isError: true, } } const env = await storage.getEnvironment(envName) if (!env) { return { content: [ { type: 'text' as const, text: `Entorno '${envName}' no encontrado` }, ], isError: true, } } // Variable específica: mostrar valor completo (sin enmascarar) if (params.key) { const value = env.variables[params.key] if (value === undefined) { return { content: [ { type: 'text' as const, text: `Variable '${params.key}' no encontrada en entorno '${envName}'`, }, ], isError: true, } } return { content: [ { type: 'text' as const, text: JSON.stringify({ key: params.key, value, environment: envName }, null, 2), }, ], } } // Todas las variables: enmascarar sensibles return { content: [ { type: 'text' as const, text: JSON.stringify( { environment: envName, variables: maskVariables(env.variables) }, null, 2, ), }, ], } } catch (error) { const message = error instanceof Error ? error.message : String(error) return { content: [{ type: 'text' as const, text: `Error: ${message}` }], isError: true, } } }, ) - src/tools/environment.ts:174-182 (schema)Schema definition for env_get: accepts optional 'key' (specific variable name) and optional 'environment' (target env name, defaults to active).
key: z .string() .optional() .describe('Variable específica. Si se omite, retorna todas'), environment: z .string() .optional() .describe('Entorno a consultar (default: entorno activo)'), }, - src/server.ts:64-64 (registration)Registration of the environment tools (including env_get) via registerEnvironmentTools() called in the server setup.
registerEnvironmentTools(server, storage) - src/lib/storage.ts:14-36 (helper)Helper functions used by env_get: maskVariables() masks sensitive variables when returning all variables. maskSensitiveValue() checks key against SENSITIVE_PATTERNS regex.
const SENSITIVE_PATTERNS = /^(token|password|passwd|secret|api_key|apikey|api[-_]?secret|auth|credential|pat|app_password|access_token|refresh_token)$/i /** Enmascara un valor si el nombre de la variable indica que es sensible */ export function maskSensitiveValue( key: string, value: string, ): string { if (!SENSITIVE_PATTERNS.test(key)) return value if (value.length <= 12) return '***' return `${value.slice(0, 4)}...${value.slice(-4)}` } /** Enmascara todas las variables sensibles de un objeto */ export function maskVariables( variables: Record<string, string>, ): Record<string, string> { const masked: Record<string, string> = {} for (const [key, value] of Object.entries(variables)) { masked[key] = maskSensitiveValue(key, value) } return masked }