get_variables
Retrieve project variables and shared library variable sets for Octopus Deploy projects to manage configuration data across deployments.
Instructions
This tool gets all project and library variable set variables for a given project. Projects can contain variables (specific to a project), library variable sets (shared collections of variables associated with many projects), and tenant variables (variables related to a tenants connected to the project) If you want to retrieve tenant variables for a tenant connected to the project, use the get_tenant_variables tool.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| spaceName | Yes | The space name | |
| projectId | Yes | The ID of the project to retrieve the variables for | |
| gitRef | No | The gitRef to retrieve the variables from, if the project is a config-as-code project |
Implementation Reference
- src/tools/getVariables.ts:30-53 (handler)The inline handler function for the "get_variables" MCP tool. It initializes the Octopus Deploy client, resolves the space ID, retrieves all variables using getAllVariables helper, and formats the response as MCP text content with JSON.async ({ spaceName, projectId, gitRef }) => { const configuration = getClientConfigurationFromEnvironment(); const client = await Client.create(configuration); const spaceId = await resolveSpaceId(client, spaceName); const variables = await getAllVariables({ projectId: projectId, spaceName: spaceName, spaceId: spaceId, gitRef: gitRef }, client) return { content: [ { type: "text", text: JSON.stringify({ variables }), }, ], }; }
- src/tools/getVariables.ts:13-55 (registration)Registers the "get_variables" tool on the MCP server, providing the tool name, description, Zod input schema, output metadata, and the handler function.export function registerGetVariablesTool(server: McpServer) { server.tool( "get_variables", `This tool gets all project and library variable set variables for a given project. Projects can contain variables (specific to a project), library variable sets (shared collections of variables associated with many projects), and tenant variables (variables related to a tenants connected to the project) If you want to retrieve tenant variables for a tenant connected to the project, use the get_tenant_variables tool. `, { spaceName: z.string().describe("The space name"), projectId: z.string().describe("The ID of the project to retrieve the variables for"), gitRef: z.string().describe("The gitRef to retrieve the variables from, if the project is a config-as-code project").optional(), }, { title: "Get variables for a Project from Octopus Deploy", readOnlyHint: true, }, async ({ spaceName, projectId, gitRef }) => { const configuration = getClientConfigurationFromEnvironment(); const client = await Client.create(configuration); const spaceId = await resolveSpaceId(client, spaceName); const variables = await getAllVariables({ projectId: projectId, spaceName: spaceName, spaceId: spaceId, gitRef: gitRef }, client) return { content: [ { type: "text", text: JSON.stringify({ variables }), }, ], }; } ); }
- src/tools/getVariables.ts:21-25 (schema)Zod schema defining the input parameters for the get_variables tool: required spaceName and projectId, optional gitRef.{ spaceName: z.string().describe("The space name"), projectId: z.string().describe("The ID of the project to retrieve the variables for"), gitRef: z.string().describe("The gitRef to retrieve the variables from, if the project is a config-as-code project").optional(), },
- src/tools/getVariables.ts:147-163 (helper)Helper function that orchestrates fetching the project's variable set and associated library variable sets using Octopus Deploy repositories and API calls.export async function getAllVariables( params: GetAllVariablesParams, apiClient: Client ): Promise<AllVariablesForProject> { const { spaceId, spaceName, gitRef, projectId } = params; const projectRepository = new ProjectRepository(apiClient, spaceName); const project = await projectRepository.get(projectId); const projectVariableSet = await loadProjectVariableSet(project, gitRef, apiClient, spaceId); const libraryVariableSets = await loadLibraryVariableSetVariables(project.IncludedLibraryVariableSetIds, apiClient, spaceId); return { projectVariableSet, libraryVariableSets }; }
- src/tools/getVariables.ts:57-61 (registration)Self-registration of the get_variables tool into the global TOOL_REGISTRY, enabling conditional registration via src/tools/index.ts.registerToolDefinition({ toolName: "get_variables", config: { toolset: "projects", readOnly: true }, registerFn: registerGetVariablesTool, });