Get tenant variables from Octopus Deploy
get_tenant_variablesRetrieve tenant variables filtered by type: all, common, or project-specific. Requires space name, tenant ID, and variable type.
Instructions
Get tenant variables by type
This tool retrieves different types of tenant variables. Use variableType parameter to specify which type:
"all": Get all tenant variables
"common": Get common variables only
"project": Get project-specific variables only
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| spaceName | Yes | The space name | |
| tenantId | Yes | The ID of the tenant to retrieve variables for | |
| variableType | Yes | Type of variables to retrieve | |
| includeMissingVariables | No | Include missing variables in the response (for common/project types) |
Implementation Reference
- src/tools/getTenantVariables.ts:9-85 (handler)The main handler function for the 'get_tenant_variables' tool. It registers the tool with the MCP server, defines the input schema (spaceName, tenantId, variableType, includeMissingVariables), and executes the logic to retrieve tenant variables via TenantRepository based on the variableType ('all', 'common', or 'project').
export function registerGetTenantVariablesTool(server: McpServer) { server.registerTool( "get_tenant_variables", { title: "Get tenant variables from Octopus Deploy", description: `Get tenant variables by type This tool retrieves different types of tenant variables. Use variableType parameter to specify which type: - "all": Get all tenant variables - "common": Get common variables only - "project": Get project-specific variables only`, inputSchema: { spaceName: z.string().describe("The space name"), tenantId: z.string().describe("The ID of the tenant to retrieve variables for"), variableType: z.enum(["all", "common", "project"]).describe("Type of variables to retrieve"), includeMissingVariables: z.boolean().optional().describe("Include missing variables in the response (for common/project types)") }, annotations: READ_ONLY_TOOL_ANNOTATIONS, }, async ({ spaceName, tenantId, variableType, includeMissingVariables = false }) => { validateEntityId(tenantId, 'tenant', ENTITY_PREFIXES.tenant); if (!variableType) { throw new Error( "Variable type is required. Valid values are: 'all', 'common', or 'project'. " + "'all' returns all variables, 'common' returns shared variables, 'project' returns project-specific variables." ); } try { const configuration = getClientConfigurationFromEnvironment(); const client = await Client.create(configuration); const tenantRepository = new TenantRepository(client, spaceName); let variables; switch (variableType) { case "all": { const tenant = await tenantRepository.get(tenantId); variables = await tenantRepository.getVariables(tenant); break; } case "common": variables = await tenantRepository.getCommonVariablesById(tenantId, includeMissingVariables); break; case "project": variables = await tenantRepository.getProjectVariablesById(tenantId, includeMissingVariables); break; default: throw new Error( `Invalid variable type '${variableType}'. Valid values are: 'all', 'common', or 'project'.` ); } return { content: [ { type: "text", text: JSON.stringify({ tenantId, variableType, includeMissingVariables, variables }), }, ], }; } catch (error) { handleOctopusApiError(error, { entityType: 'tenant', entityId: tenantId, spaceName }); } } ); } - Input schema definition using Zod for the get_tenant_variables tool. Parameters: spaceName (string), tenantId (string), variableType (enum: all/common/project), includeMissingVariables (optional boolean).
inputSchema: { spaceName: z.string().describe("The space name"), tenantId: z.string().describe("The ID of the tenant to retrieve variables for"), variableType: z.enum(["all", "common", "project"]).describe("Type of variables to retrieve"), includeMissingVariables: z.boolean().optional().describe("Include missing variables in the response (for common/project types)") }, annotations: READ_ONLY_TOOL_ANNOTATIONS, - src/tools/getTenantVariables.ts:87-91 (registration)Self-registration of the tool in the global TOOL_REGISTRY map, categorizing it under the 'tenants' toolset as a read-only tool.
registerToolDefinition({ toolName: "get_tenant_variables", config: { toolset: "tenants", readOnly: true }, registerFn: registerGetTenantVariablesTool, }); - src/tools/index.ts:14-14 (registration)Import statement in the tools index file that triggers the self-registration of the get_tenant_variables tool when the module is loaded.
import "./getTenantVariables.js"; - src/helpers/errorHandling.ts:108-123 (helper)Entity ID prefix constants used by validateEntityId, which is called in the handler to validate the tenantId starts with 'Tenants-'.
export const ENTITY_PREFIXES = { task: "ServerTasks-", project: "Projects-", environment: "Environments-", tenant: "Tenants-", release: "Releases-", runbook: "Runbooks-", machine: "Machines-", certificate: "Certificates-", account: "Accounts-", deployment: "Deployments-", deploymentProcess: "DeploymentProcesses-", interruption: "Interruptions-", event: "Events-", } as const;