Skip to main content
Glama
OctopusDeploy

Octopus Deploy MCP Server

Official

List all environments in an Octopus Deploy space

list_environments
Read-onlyIdempotent

List all environments in a specified Octopus Deploy space. Optionally filter by partial name to find specific environments quickly.

Instructions

List environments in a space

This tool lists all environments in a given space. The space name is required. Use this tool as early as possible to understand which environments are configured. Optionally filter by partial name match using partialName parameter.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
spaceNameYes
partialNameNo
skipNo
takeNo

Implementation Reference

  • The async handler function that executes the list_environments tool logic: creates an Octopus API client, queries environments via EnvironmentRepository, and returns formatted results.
    async ({ spaceName, partialName, skip, take }) => {
      try {
        const configuration = getClientConfigurationFromEnvironment();
        const client = await Client.create(configuration);
        const environmentRepository = new EnvironmentRepository(
          client,
          spaceName,
        );
    
        const environmentsResponse = await environmentRepository.list({
          partialName,
          skip,
          take,
        });
    
        if (environmentsResponse.Items.length === 0) {
          const message = partialName
            ? `No environments found matching '${partialName}' in space '${spaceName}'. Environment names are case-sensitive.`
            : `No environments found in space '${spaceName}'. This space may not have any environments configured.`;
    
          return {
            content: [
              {
                type: "text",
                text: message,
              },
            ],
          };
        }
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                totalResults: environmentsResponse.TotalResults,
                itemsPerPage: environmentsResponse.ItemsPerPage,
                numberOfPages: environmentsResponse.NumberOfPages,
                lastPageNumber: environmentsResponse.LastPageNumber,
                items: environmentsResponse.Items.map(
                  (environment: DeploymentEnvironment) => ({
                    spaceId: environment.SpaceId,
                    id: environment.Id,
                    name: environment.Name,
                    description: environment.Description,
                    sortOrder: environment.SortOrder,
                    useGuidedFailure: environment.UseGuidedFailure,
                    allowDynamicInfrastructure:
                      environment.AllowDynamicInfrastructure,
                    extensionSettings: environment.ExtensionSettings,
                  }),
                ),
              }),
            },
          ],
        };
      } catch (error) {
        handleOctopusApiError(error, { spaceName });
      }
    },
  • Input schema definition for list_environments tool: validates spaceName (required string), partialName (optional string), skip (optional number), and take (optional number).
      {
        title: "List all environments in an Octopus Deploy space",
        description: `List environments in a space
    
    This tool lists all environments in a given space. The space name is required. Use this tool as early as possible to understand which environments are configured. Optionally filter by partial name match using partialName parameter.`,
        inputSchema: {
          spaceName: z.string(),
          partialName: z.string().optional(),
          skip: z.number().optional(),
          take: z.number().optional(),
        },
        annotations: READ_ONLY_TOOL_ANNOTATIONS,
  • Self-registration call added to the global TOOL_REGISTRY map with toolset 'core' and readOnly: true.
    registerToolDefinition({
      toolName: "list_environments",
      config: { toolset: "core", readOnly: true },
      registerFn: registerListEnvironmentsTool,
    });
  • The public registration function registerListEnvironmentsTool that calls server.registerTool with the name 'list_environments'.
    export function registerListEnvironmentsTool(server: McpServer) {
      server.registerTool(
        "list_environments",
        {
          title: "List all environments in an Octopus Deploy space",
          description: `List environments in a space
    
      This tool lists all environments in a given space. The space name is required. Use this tool as early as possible to understand which environments are configured. Optionally filter by partial name match using partialName parameter.`,
          inputSchema: {
            spaceName: z.string(),
            partialName: z.string().optional(),
            skip: z.number().optional(),
            take: z.number().optional(),
          },
          annotations: READ_ONLY_TOOL_ANNOTATIONS,
        },
        async ({ spaceName, partialName, skip, take }) => {
          try {
            const configuration = getClientConfigurationFromEnvironment();
            const client = await Client.create(configuration);
            const environmentRepository = new EnvironmentRepository(
              client,
              spaceName,
            );
    
            const environmentsResponse = await environmentRepository.list({
              partialName,
              skip,
              take,
            });
    
            if (environmentsResponse.Items.length === 0) {
              const message = partialName
                ? `No environments found matching '${partialName}' in space '${spaceName}'. Environment names are case-sensitive.`
                : `No environments found in space '${spaceName}'. This space may not have any environments configured.`;
    
              return {
                content: [
                  {
                    type: "text",
                    text: message,
                  },
                ],
              };
            }
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify({
                    totalResults: environmentsResponse.TotalResults,
                    itemsPerPage: environmentsResponse.ItemsPerPage,
                    numberOfPages: environmentsResponse.NumberOfPages,
                    lastPageNumber: environmentsResponse.LastPageNumber,
                    items: environmentsResponse.Items.map(
                      (environment: DeploymentEnvironment) => ({
                        spaceId: environment.SpaceId,
                        id: environment.Id,
                        name: environment.Name,
                        description: environment.Description,
                        sortOrder: environment.SortOrder,
                        useGuidedFailure: environment.UseGuidedFailure,
                        allowDynamicInfrastructure:
                          environment.AllowDynamicInfrastructure,
                        extensionSettings: environment.ExtensionSettings,
                      }),
                    ),
                  }),
                },
              ],
            };
          } catch (error) {
            handleOctopusApiError(error, { spaceName });
          }
        },
      );
    }
  • Error handling utility imported and used in the list_environments handler via handleOctopusApiError.
    /**
     * Enhanced error handling utilities for Octopus Deploy MCP Server tools
     */
    
    /**
     * Checks if the error is an Error instance and has a message containing the specified text
     */
    export function isErrorWithMessage(
      error: unknown,
      messageFragment: string,
    ): error is Error {
      return (
        error instanceof Error && error.message?.includes(messageFragment) === true
      );
    }
    
    /**
     * Common error handler for Octopus Deploy API errors with actionable messages
     */
    export function handleOctopusApiError(
      error: unknown,
      context: {
        entityType?: string;
        entityId?: string;
        spaceName?: string;
        helpText?: string;
      },
    ): never {
      const { entityType, entityId, spaceName, helpText } = context;
    
      // Handle 404/not found errors
      if (
        isErrorWithMessage(error, "not found") ||
        isErrorWithMessage(error, "404")
      ) {
        if (entityType && entityId && spaceName) {
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already mark the tool as read-only, idempotent, and non-destructive. The description adds context about filtering by partialName but does not mention pagination or other behavioral traits. With annotations covering the core safety profile, a 3 is appropriate for the added value.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences, efficient and front-loaded with the main action. It could be slightly more structured but is concise and readable.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema and 4 parameters, the description is incomplete. It covers the required parameter and one optional, but ignores pagination (skip, take), leaving gaps for an agent to understand full usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must add meaning. It explains spaceName (required) and partialName (optional filter) but omits skip and take entirely, leaving two parameters undocumented. This is insufficient for a 4-parameter tool.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool lists all environments in a space, with a specific verb ('list') and resource ('environments'). It also notes the required spaceName, making the purpose unambiguous and distinct from sibling tools like list_deployments or list_projects.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description advises using this tool early to understand configured environments, providing clear context. However, it lacks guidance on when not to use it or alternatives, which is acceptable given there are no direct siblings for listing environments.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/OctopusDeploy/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server