env_set_default
Set an environment as the default for its group, automatically activating it when you enter a project.
Instructions
Marca un entorno como el default de su grupo. El default se activa automaticamente al entrar al proyecto.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Nombre del entorno a marcar como default |
Implementation Reference
- src/tools/environment.ts:611-637 (handler)The 'env_set_default' tool handler: validates the environment exists, checks it belongs to a group, sets it as the group default via storage.setGroupDefault, and clears active sessions for the group so the new default takes effect immediately.
server.tool( 'env_set_default', 'Marca un entorno como el default de su grupo. El default se activa automaticamente al entrar al proyecto.', { name: z.string().describe('Nombre del entorno a marcar como default'), }, async (params) => { try { const env = await storage.getEnvironment(params.name) if (!env) { return { content: [{ type: 'text' as const, text: `Error: Entorno '${params.name}' no encontrado` }], isError: true } } if (!env.group) { return { content: [{ type: 'text' as const, text: `Error: El entorno '${params.name}' es global y no pertenece a ningun grupo. Solo los entornos de un grupo pueden ser default.` }], isError: true } } await storage.setGroupDefault(env.group, params.name) // Limpiar todas las sesiones activas del grupo para que el nuevo default tome efecto inmediato await storage.clearGroupSessionActives(env.group) return { content: [{ type: 'text' as const, text: `Entorno '${params.name}' marcado como default del grupo '${env.group}'` }], } } 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:614-616 (schema)Input schema for env_set_default: requires a 'name' string describing the environment to mark as default.
{ name: z.string().describe('Nombre del entorno a marcar como default'), }, - src/tools/environment.ts:611-637 (registration)Registration of 'env_set_default' tool on the MCP server via server.tool() inside registerEnvironmentTools.
server.tool( 'env_set_default', 'Marca un entorno como el default de su grupo. El default se activa automaticamente al entrar al proyecto.', { name: z.string().describe('Nombre del entorno a marcar como default'), }, async (params) => { try { const env = await storage.getEnvironment(params.name) if (!env) { return { content: [{ type: 'text' as const, text: `Error: Entorno '${params.name}' no encontrado` }], isError: true } } if (!env.group) { return { content: [{ type: 'text' as const, text: `Error: El entorno '${params.name}' es global y no pertenece a ningun grupo. Solo los entornos de un grupo pueden ser default.` }], isError: true } } await storage.setGroupDefault(env.group, params.name) // Limpiar todas las sesiones activas del grupo para que el nuevo default tome efecto inmediato await storage.clearGroupSessionActives(env.group) return { content: [{ type: 'text' as const, text: `Entorno '${params.name}' marcado como default del grupo '${env.group}'` }], } } catch (error) { const message = error instanceof Error ? error.message : String(error) return { content: [{ type: 'text' as const, text: `Error: ${message}` }], isError: true } } }, ) - src/lib/storage.ts:468-483 (helper)Storage.setGroupDefault: loads the group, validates the environment belongs to it, sets group.default to envName, and persists the group.
async setGroupDefault(groupName: string, envName: string): Promise<void> { const group = await this.getGroup(groupName) if (!group) { throw new Error(`Grupo '${groupName}' no encontrado`) } const env = await this.getEnvironment(envName) if (!env) { throw new Error(`Entorno '${envName}' no encontrado`) } if (env.group !== groupName) { throw new Error(`El entorno '${envName}' no pertenece al grupo '${groupName}'`) } group.default = envName group.updatedAt = new Date().toISOString() await this.saveGroup(group) } - src/lib/storage.ts:229-247 (helper)Storage.clearGroupSessionActives: clears all project-level active environment entries for scopes belonging to the specified group, ensuring the new default takes effect immediately.
async clearGroupSessionActives(groupName: string): Promise<void> { const group = await this.getGroup(groupName) if (!group) return const projectEnvs = await this.getProjectEnvs() let changed = false for (const key of Object.keys(projectEnvs)) { const normalized = key.replace(/\\/g, '/') for (const scope of group.scopes) { if (normalized === scope || normalized.startsWith(scope + '/')) { delete projectEnvs[key] changed = true break } } } if (changed) { await this.writeJson(this.projectEnvsFile, projectEnvs) } }