Get Environment Variable (ESV)
getVariableRetrieve a specific environment variable (ESV) from PingOne Advanced Identity Cloud by its ID and return the decoded value.
Instructions
Retrieve a specific environment variable (ESV) by ID with decoded value
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| variableId | Yes | Variable ID (format: esv-*) |
Implementation Reference
- src/tools/esv/getVariable.ts:21-44 (handler)The main handler function 'toolFunction' that retrieves an environment variable by ID from the AIC API. It makes an authenticated request to /environment/variables/{variableId}, decodes the base64 value, and returns the result.
async toolFunction({ variableId }: { variableId: string }) { try { const url = `https://${aicBaseUrl}/environment/variables/${variableId}`; const { data, response } = await makeAuthenticatedRequest(url, SCOPES, { headers: { 'accept-api-version': 'resource=2.0' } }); // Decode the base64 value and replace the field const variableData = data as any; if (variableData.valueBase64) { const decodedValue = Buffer.from(variableData.valueBase64, 'base64').toString('utf-8'); delete variableData.valueBase64; variableData.value = decodedValue; } return createToolResponse(formatSuccess(variableData, response)); } catch (error: any) { return createToolResponse(`Failed to get variable '${variableId}': ${error.message}`); } } }; - src/tools/esv/getVariable.ts:18-20 (schema)Input schema validation for the getVariable tool. Expects a 'variableId' parameter validated by safePathSegmentSchema (format: esv-*).
inputSchema: { variableId: safePathSegmentSchema.describe('Variable ID (format: esv-*)') }, - src/index.ts:27-43 (registration)Tool registration loop where getVariableTool (along with all other tools) is registered with the MCP server via server.registerTool().
allTools.forEach((tool) => { const toolConfig: ToolConfig = { title: tool.title, description: tool.description }; // Only add inputSchema if it exists (some tools like getLogSources don't have one) if ('inputSchema' in tool && tool.inputSchema) { toolConfig.inputSchema = tool.inputSchema; } // Add annotations if present if ('annotations' in tool && tool.annotations) { toolConfig.annotations = tool.annotations; } server.registerTool(tool.name, toolConfig, tool.toolFunction as any); - src/utils/toolHelpers.ts:15-33 (registration)getAllTools() function that collects all tool objects including getVariableTool from the esvTool module and returns them for registration.
export function getAllTools(): Tool[] { const isDockerMode = process.env.DOCKER_CONTAINER === 'true'; const tools: Tool[] = [ ...(Object.values(managedObjectTools) as Tool[]), ...(Object.values(logTools) as Tool[]), ...(Object.values(themeTools) as Tool[]), ...(Object.values(esvTools) as Tool[]), ...(Object.values(featureManagementTools) as Tool[]) ]; // Only include AM tools in non-Docker mode (requires browser-based PKCE auth) if (!isDockerMode) { tools.push(...(Object.values(amTools) as Tool[])); tools.push(...(Object.values(applicationTools) as Tool[])); } return tools; } - src/tools/esv/getVariable.ts:1-44 (helper)The full getVariable.ts file containing the complete getVariable tool definition including imports, tool object with name/title/description/scopes/annotations, input schema, and handler function.
import { makeAuthenticatedRequest, createToolResponse } from '../../utils/apiHelpers.js'; import { formatSuccess } from '../../utils/responseHelpers.js'; import { safePathSegmentSchema } from '../../utils/validationHelpers.js'; const aicBaseUrl = process.env.AIC_BASE_URL; const SCOPES = ['fr:idc:esv:read']; export const getVariableTool = { name: 'getVariable', title: 'Get Environment Variable (ESV)', description: 'Retrieve a specific environment variable (ESV) by ID with decoded value', scopes: SCOPES, annotations: { readOnlyHint: true, openWorldHint: true }, inputSchema: { variableId: safePathSegmentSchema.describe('Variable ID (format: esv-*)') }, async toolFunction({ variableId }: { variableId: string }) { try { const url = `https://${aicBaseUrl}/environment/variables/${variableId}`; const { data, response } = await makeAuthenticatedRequest(url, SCOPES, { headers: { 'accept-api-version': 'resource=2.0' } }); // Decode the base64 value and replace the field const variableData = data as any; if (variableData.valueBase64) { const decodedValue = Buffer.from(variableData.valueBase64, 'base64').toString('utf-8'); delete variableData.valueBase64; variableData.value = decodedValue; } return createToolResponse(formatSuccess(variableData, response)); } catch (error: any) { return createToolResponse(`Failed to get variable '${variableId}': ${error.message}`); } } };