fix(gitlab): guard against undefined response in search_repositories#3611
Open
joaquinhuigomez wants to merge 3 commits intomodelcontextprotocol:mainfrom
Open
fix(gitlab): guard against undefined response in search_repositories#3611joaquinhuigomez wants to merge 3 commits intomodelcontextprotocol:mainfrom
joaquinhuigomez wants to merge 3 commits intomodelcontextprotocol:mainfrom
Conversation
On Enterprise / self-hosted GitLab instances (e.g. v18.4) the `GET /projects?search=` endpoint may return a non-array response (e.g. an object wrapper) instead of the bare array that gitlab.com returns. The previous code passed the raw response directly into Zod schema validation, which calls `.map()` on the `items` field — crashing with `Cannot read properties of undefined (reading 'map')`. The fix normalises the API response before validation: if the response is already an array it is used as-is; otherwise the code looks for `.items` or `.projects` keys on the response object, falling back to an empty array. Note: The GitLab server source was moved to `servers-archived` (which is read-only), so this PR restores the `src/gitlab/` directory with the fix applied. The only functional change is in `searchProjects()` in `index.ts`. Fixes modelcontextprotocol#3454 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
npm ci was failing because package-lock.json was missing entries for @modelcontextprotocol/server-gitlab and its transitive dependencies after the src/gitlab directory was added to the src/* workspace. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The uv.lock file was stale, causing 'Build fetch' CI to fail with 'The lockfile needs to be updated, but --locked was provided'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cannot read properties of undefined (reading 'map')crash when callingsearch_repositoriesagainst Enterprise / self-hosted GitLab instances (e.g. v18.4)GET /projects?search=API returns a bare array on gitlab.com but may return an object wrapper on self-hosted instances. The code passed the raw response directly to Zod schema validation, which calls.map()onundefined..itemsor.projectsfrom the wrapper object, falling back to[].Note: The
src/gitlab/source was previously moved tomodelcontextprotocol/servers-archived(which is read-only and does not accept PRs). This PR restores the directory with the fix applied. The only functional change is insearchProjects()insrc/gitlab/index.ts— all other files are identical to the archived version. The same fix has also been pushed to my fork of servers-archived in case maintainers prefer to apply it there.Fixes #3454
Test plan
search_repositoriesworks against gitlab.com (bare array response)search_repositoriesworks against self-hosted GitLab Enterprise (object wrapper response){ count: 0, items: [] }instead of crashing🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com