Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 18, 2026

When GITLAB_ALLOWED_PROJECT_IDS is unset, getEffectiveProjectId was returning GITLAB_PROJECT_ID even when a different projectId was explicitly passed, preventing users from querying other projects via tools like get_project.

Changes

  • index.ts: Reversed priority order to check projectId parameter before GITLAB_PROJECT_ID environment variable
  • test/test-geteffectiveprojectid.ts: Added test coverage for all three configuration modes (no allowlist, single project, multiple projects)

Before

return GITLAB_PROJECT_ID || projectId;

After

if (projectId) {
  return projectId;
}
if (GITLAB_PROJECT_ID) {
  return GITLAB_PROJECT_ID;
}
throw new Error("No project ID provided and GITLAB_PROJECT_ID is not set");

This allows get_project and similar tools to accept any project ID/path when no allowlist is configured, while maintaining backward compatibility when projectId is omitted.

Original prompt

This section details on the original issue you should resolve

<issue_title>getEffectiveProjectId cannot return projectId passed into the function when GITLAB_ALLOWED_PROJECT_IDS is unspecified</issue_title>
<issue_description>I want to retrieve the project ID of another project (different from GITLAB_PROJECT_ID) by the project path with namespace using get_project. It's supported by Gitlab project API: https://docs.gitlab.com/18.6/api/projects/#get-a-single-project

However, getEffectiveProjectId always returns GITLAB_PROJECT_ID when GITLAB_ALLOWED_PROJECT_IDS is unspecified. Can it have an option to return projectId passed into the function, or even let projectId have precedence over GITLAB_PROJECT_ID at https://github.com/zereight/gitlab-mcp/blob/v2.0.21/index.ts#L1307 ? Thanks.
</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 18, 2026 14:08
…PROJECT_ID

- Changed the function to return projectId first if provided, then GITLAB_PROJECT_ID
- Added proper error handling when neither projectId nor GITLAB_PROJECT_ID is available
- Added comprehensive test suite to validate the fix

Co-authored-by: zereight <42544600+zereight@users.noreply.github.com>
Co-authored-by: zereight <42544600+zereight@users.noreply.github.com>
…checks

Co-authored-by: zereight <42544600+zereight@users.noreply.github.com>
Co-authored-by: zereight <42544600+zereight@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix getEffectiveProjectId to return specified projectId Fix getEffectiveProjectId to prioritize passed projectId over GITLAB_PROJECT_ID Jan 18, 2026
Copilot AI requested a review from zereight January 18, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getEffectiveProjectId cannot return projectId passed into the function when GITLAB_ALLOWED_PROJECT_IDS is unspecified

2 participants