Skip to main content
Glama
Tiberriver256

Azure DevOps MCP Server

list_organizations

Retrieve a list of all Azure DevOps organizations you have access to, enabling quick identification and selection for further management actions.

Instructions

List all Azure DevOps organizations accessible to the current authentication

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function `listOrganizations` that executes the tool logic. It authenticates (PAT or Azure Identity), fetches user profile, retrieves organizations via the Azure DevOps REST API, and returns transformed Organization objects.
    export async function listOrganizations(
      config: AzureDevOpsConfig,
    ): Promise<Organization[]> {
      try {
        if (!isAzureDevOpsServicesUrl(config.organizationUrl)) {
          throw new AzureDevOpsValidationError(
            'The list_organizations endpoint is only available for Azure DevOps Services',
          );
        }
    
        // Determine auth method and create appropriate authorization header
        let authHeader: string;
    
        if (config.authMethod === AuthenticationMethod.PersonalAccessToken) {
          // PAT authentication
          if (!config.personalAccessToken) {
            throw new AzureDevOpsAuthenticationError(
              'Personal Access Token (PAT) is required when using PAT authentication',
            );
          }
          authHeader = createBasicAuthHeader(config.personalAccessToken);
        } else {
          // Azure Identity authentication (DefaultAzureCredential or AzureCliCredential)
          const credential =
            config.authMethod === AuthenticationMethod.AzureCli
              ? new AzureCliCredential()
              : new DefaultAzureCredential();
    
          const token = await credential.getToken(
            `${AZURE_DEVOPS_RESOURCE_ID}/.default`,
          );
    
          if (!token || !token.token) {
            throw new AzureDevOpsAuthenticationError(
              'Failed to acquire Azure Identity token',
            );
          }
    
          authHeader = `Bearer ${token.token}`;
        }
    
        // Step 1: Get the user profile to get the publicAlias
        const profileResponse = await axios.get(
          'https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=6.0',
          {
            headers: {
              Authorization: authHeader,
              'Content-Type': 'application/json',
            },
          },
        );
    
        // Extract the publicAlias
        const publicAlias = profileResponse.data.publicAlias;
        if (!publicAlias) {
          throw new AzureDevOpsAuthenticationError(
            'Unable to get user publicAlias from profile',
          );
        }
    
        // Step 2: Get organizations using the publicAlias
        const orgsResponse = await axios.get(
          `https://app.vssps.visualstudio.com/_apis/accounts?memberId=${publicAlias}&api-version=6.0`,
          {
            headers: {
              Authorization: authHeader,
              'Content-Type': 'application/json',
            },
          },
        );
    
        // Define the shape of the API response
        interface AzureDevOpsOrganization {
          accountId: string;
          accountName: string;
          accountUri: string;
        }
    
        // Transform the response
        return orgsResponse.data.value.map((org: AzureDevOpsOrganization) => ({
          id: org.accountId,
          name: org.accountName,
          url: org.accountUri,
        }));
      } catch (error) {
        // Handle profile API errors as authentication errors
        if (axios.isAxiosError(error) && error.config?.url?.includes('profile')) {
          throw new AzureDevOpsAuthenticationError(
            `Authentication failed: ${error.toJSON()}`,
          );
        } else if (
          error instanceof Error &&
          (error.message.includes('profile') ||
            error.message.includes('Unauthorized') ||
            error.message.includes('Authentication'))
        ) {
          throw new AzureDevOpsAuthenticationError(
            `Authentication failed: ${error.message}`,
          );
        }
    
        if (error instanceof AzureDevOpsError) {
          throw error;
        }
    
        throw new AzureDevOpsAuthenticationError(
          `Failed to list organizations: ${error instanceof Error ? error.message : String(error)}`,
        );
      }
    }
  • Zod schema `ListOrganizationsSchema` - an empty object schema since list_organizations requires no input parameters.
    import { z } from 'zod';
    
    /**
     * Schema for the list organizations request
     * Note: This is an empty schema because the operation doesn't require any parameters
     */
    export const ListOrganizationsSchema = z.object({});
  • Tool definition registration for `list_organizations` with name, description, and JSON Schema input schema.
    export const organizationsTools: ToolDefinition[] = [
      {
        name: 'list_organizations',
        description:
          'List all Azure DevOps organizations accessible to the current authentication',
        inputSchema: zodToJsonSchema(ListOrganizationsSchema),
      },
    ];
  • Request routing: `isOrganizationsRequest` checks if the tool name matches 'list_organizations', and `handleOrganizationsRequest` dispatches to the handler, building the config from environment variables.
    export const isOrganizationsRequest: RequestIdentifier = (
      request: CallToolRequest,
    ): boolean => {
      const toolName = request.params.name;
      return ['list_organizations'].includes(toolName);
    };
    
    /**
     * Handles organizations feature requests
     */
    export const handleOrganizationsRequest: RequestHandler = async (
      connection: WebApi,
      request: CallToolRequest,
    ): Promise<{ content: Array<{ type: string; text: string }> }> => {
      switch (request.params.name) {
        case 'list_organizations': {
          // Use environment variables for authentication method and PAT
          // This matches how other features handle authentication
          const config: AzureDevOpsConfig = {
            authMethod:
              process.env.AZURE_DEVOPS_AUTH_METHOD?.toLowerCase() === 'pat'
                ? AuthenticationMethod.PersonalAccessToken
                : process.env.AZURE_DEVOPS_AUTH_METHOD?.toLowerCase() ===
                    'azure-cli'
                  ? AuthenticationMethod.AzureCli
                  : AuthenticationMethod.AzureIdentity,
            personalAccessToken: process.env.AZURE_DEVOPS_PAT,
            organizationUrl: connection.serverUrl || '',
          };
    
          const result = await listOrganizations(config);
          return {
            content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
          };
        }
        default:
          throw new Error(`Unknown organizations tool: ${request.params.name}`);
      }
    };
  • Helper function `createBasicAuthHeader` that creates a Basic Auth header from a PAT.
    function createBasicAuthHeader(pat: string): string {
      const token = Buffer.from(`:${pat}`).toString('base64');
      return `Basic ${token}`;
    }
Behavior2/5

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

No annotations provided; description merely states it lists organizations. Does not disclose authentication requirements, rate limits, or behavior when no organizations exist. For a read operation, more transparency is needed.

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

Conciseness5/5

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

Single sentence, front-loaded with verb and resource, no superfluous words. Perfectly concise and structured.

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

Completeness4/5

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

Description covers the purpose and scope adequately for a simple list tool. Could mention return format (e.g., array of organization names) or pagination, but not essential given no output schema.

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

Parameters4/5

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

No parameters exist (0 params), so description does not need to add parameter info. Baseline 4 is appropriate as there are no gaps.

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?

Description clearly states it lists Azure DevOps organizations, specifies scope 'accessible to the current authentication', and is distinct from sibling tools like '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 Guidelines3/5

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

No explicit guidance on when to use or alternatives, but the tool is straightforward with no parameters. Usage is implied, but lacks exclusionary conditions.

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/Tiberriver256/mcp-server-azure-devops'

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