Skip to main content
Glama

gitlab_get_user_id_by_username

Retrieve the GitLab user ID for a given username to enable user identification and integration workflows in GitLab-Jira environments.

Instructions

Retrieves the GitLab user ID for a given username.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
usernameYesThe username of the GitLab user.

Implementation Reference

  • Core handler function that implements the tool logic: queries GitLab API for exact username match first, falls back to fuzzy search on username and name, returns the user ID or throws descriptive errors.
    async getUserIdByUsername(username: string): Promise<number> {
      // First try exact username match
      const exactUsers = await this.callGitLabApi<GitLabUser[]>(
        `users?username=${username}`,
      );
      if (exactUsers.length > 0) {
        return exactUsers[0].id;
      }
    
      // Fallback: search all users and filter by partial username (case-insensitive)
      const allUsers =
        await this.callGitLabApi<GitLabUser[]>(`users?per_page=100`);
      const lowerCaseUsername = username.toLowerCase();
    
      const matchingUsers = allUsers.filter(
        (user) =>
          user.username.toLowerCase().includes(lowerCaseUsername) ||
          user.name.toLowerCase().includes(lowerCaseUsername),
      );
    
      if (matchingUsers.length === 0) {
        throw new Error(`User with username containing '${username}' not found.`);
      }
    
      if (matchingUsers.length > 1) {
        const userList = matchingUsers
          .map((user) => `${user.username} (${user.name})`)
          .join(', ');
        throw new Error(
          `Multiple users found matching '${username}': ${userList}. Please be more specific.`,
        );
      }
    
      return matchingUsers[0].id;
    }
  • src/index.ts:1430-1444 (registration)
    Tool execution handler in the MCP server request handler switch statement: extracts username argument, calls the service method, and returns the userId in JSON format.
    case 'gitlab_get_user_id_by_username': {
      if (!gitlabService) {
        throw new Error('GitLab service is not initialized.');
      }
      const { username } = args as { username: string };
      const userId = await gitlabService.getUserIdByUsername(username);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({ userId }, null, 2),
          },
        ],
      };
    }
  • Tool registration in the allTools array, including the tool name, description, and input schema defining the required 'username' string parameter.
    {
      name: 'gitlab_get_user_id_by_username',
      description: 'Retrieves the GitLab user ID for a given username.',
      inputSchema: {
        type: 'object',
        properties: {
          username: {
            type: 'string',
            description: 'The username of the GitLab user.',
          },
        },
        required: ['username'],
      },
    },
  • TypeScript interface defining the GitLabUser object structure used by the handler for API responses.
    export interface GitLabUser {
      id: number;
      username: string;
      name: string;
      state: string;
      avatar_url: string;
      web_url: string;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the action ('retrieves') but lacks details on permissions required, rate limits, error handling, or output format. For a lookup tool with zero annotation coverage, this leaves significant behavioral gaps.

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?

The description is a single, efficient sentence with zero wasted words. It's front-loaded with the core action and resource, making it easy to parse. Every part of the sentence earns its place by conveying essential information.

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

Completeness3/5

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

Given the tool's low complexity (single parameter, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks details on usage, behavior, and output, which are needed for a complete understanding. The schema compensates for parameters, but other gaps remain.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents the 'username' parameter fully. The description adds no additional meaning beyond implying it maps to a GitLab user, which is redundant with the schema. Baseline 3 is appropriate as the schema handles parameter documentation.

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

Purpose4/5

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

The description clearly states the verb ('retrieves') and resource ('GitLab user ID'), making the purpose unambiguous. It distinguishes from siblings by focusing on user ID lookup rather than project, issue, or pipeline operations. However, it doesn't explicitly differentiate from potential user-related siblings like 'gitlab_get_user_activities', though that tool has a different scope.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a username), exclusions, or related tools for user management. The agent must infer usage from the description alone without explicit context.

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/HainanZhao/mcp-gitlab-jira'

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