Conversation
|
Looks good and can fix the issue I raised |
…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>
132366d to
096169d
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes project ID resolution so an explicitly provided projectId argument takes precedence over GITLAB_PROJECT_ID when no allowlist is configured, enabling tools like get_project to query arbitrary accessible projects by ID/path.
Changes:
- Updated
getEffectiveProjectIdto prioritize the passedprojectIdoverGITLAB_PROJECT_ID, and to throw a clearer error when neither is provided. - Added a new test suite covering project ID resolution behavior across three configuration modes (no allowlist, single allowed project, multiple allowed projects).
- Ignored generated
test-results*.jsonartifacts.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
index.ts |
Changes getEffectiveProjectId precedence and adds explicit error when no project ID source exists. |
test/test-geteffectiveprojectid.ts |
Adds coverage for resolution behavior under different allowlist configurations via mock GitLab + MCP server. |
.gitignore |
Ignores JSON test result outputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| before(async () => { | ||
| // Start mock GitLab server | ||
| const mockPort = await findMockServerPort(9100); | ||
| mockGitLab = new MockGitLabServer({ | ||
| port: mockPort, | ||
| validTokens: [MOCK_TOKEN] | ||
| }); | ||
| await mockGitLab.start(); | ||
| const mockGitLabUrl = mockGitLab.getUrl(); | ||
|
|
||
| // Start MCP server WITHOUT GITLAB_ALLOWED_PROJECT_IDS | ||
| const mcpPort = await findAvailablePort(3100); | ||
| const server = await launchServer({ | ||
| mode: TransportMode.STREAMABLE_HTTP, | ||
| port: mcpPort, | ||
| timeout: 5000, | ||
| env: { | ||
| STREAMABLE_HTTP: 'true', | ||
| GITLAB_API_URL: `${mockGitLabUrl}/api/v4`, | ||
| GITLAB_PROJECT_ID: DEFAULT_PROJECT_ID, | ||
| GITLAB_READ_ONLY_MODE: 'true', | ||
| } | ||
| }); |
There was a problem hiding this comment.
This test suite is not hermetic: launchServer() reads process.env.GITLAB_TOKEN_TEST and process.env.TEST_PROJECT_ID (and passes through process.env.GITLAB_ALLOWED_PROJECT_IDS unless explicitly overridden). As written, these tests will fail on environments where those vars aren’t set (or will behave differently if GITLAB_ALLOWED_PROJECT_IDS is set in the parent env). Consider setting/restoring process.env.GITLAB_TOKEN_TEST + process.env.TEST_PROJECT_ID in the before/after hooks, and explicitly setting GITLAB_ALLOWED_PROJECT_IDS: '' for the “No GITLAB_ALLOWED_PROJECT_IDS” case to override any inherited value.
| description: "Get details of a specific commit", | ||
| inputSchema: toJSONSchema(GetCommitSchema), | ||
| }, | ||
| { | ||
| name: "get_commit_diff", | ||
| description: "Get changes/diffs of a specific commit", | ||
| inputSchema: toJSONSchema(GetCommitDiffSchema), |
There was a problem hiding this comment.
Now that the passed projectId takes precedence, callers that pass a URL-encoded path (which is documented for many project_id params) will start flowing through this branch more often. At least the get_project tool currently passes args.project_id straight into encodeURIComponent(...) without a prior decodeURIComponent, so an input like group%2Fproj will become double-encoded (group%252Fproj) and fail. Consider normalizing/decoding projectId before returning here (or ensuring all callers decode before calling this helper) so precedence changes don’t break URL-encoded project paths.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 132366d84f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Prioritize the passed projectId over GITLAB_PROJECT_ID to allow querying different projects | ||
| if (projectId) { | ||
| return projectId; |
There was a problem hiding this comment.
Unblock create/fork flows when GITLAB_PROJECT_ID is only a default
This helper now makes GITLAB_PROJECT_ID a fallback instead of a lock, but the fork_repository and create_repository handlers still reject whenever that env var is present (index.ts:5316-5318 and index.ts:5388-5391). In a deployment that keeps GITLAB_PROJECT_ID only to supply a default project, project-scoped tools can now target arbitrary project_ids while create/fork always fail, so the new semantics are only applied to part of the API surface.
Useful? React with 👍 / 👎.
| const server = await launchServer({ | ||
| mode: TransportMode.STREAMABLE_HTTP, | ||
| port: mcpPort, | ||
| timeout: 5000, | ||
| env: { | ||
| STREAMABLE_HTTP: 'true', | ||
| GITLAB_API_URL: `${mockGitLabUrl}/api/v4`, | ||
| GITLAB_PROJECT_ID: DEFAULT_PROJECT_ID, | ||
| GITLAB_READ_ONLY_MODE: 'true', | ||
| } |
There was a problem hiding this comment.
Seed launcher env before starting the new mock suites
These before() blocks call launchServer without first populating the parent GITLAB_TOKEN_TEST/TEST_PROJECT_ID, but test/utils/server-launcher.ts:40-57 reads both from process.env and throws if either is missing. Because this is a mock-only test, a clean local or CI run will fail before the MCP server starts unless the caller happens to have unrelated integration-test env vars exported.
Useful? React with 👍 / 👎.
When
GITLAB_ALLOWED_PROJECT_IDSis unset,getEffectiveProjectIdwas returningGITLAB_PROJECT_IDeven when a differentprojectIdwas explicitly passed, preventing users from querying other projects via tools likeget_project.Changes
projectIdparameter beforeGITLAB_PROJECT_IDenvironment variableBefore
After
This allows
get_projectand similar tools to accept any project ID/path when no allowlist is configured, while maintaining backward compatibility whenprojectIdis omitted.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.