fix(gitlab): handle undefined response in search_repositories#3600
Closed
nielskaspers wants to merge 1 commit intomodelcontextprotocol:mainfrom
Closed
fix(gitlab): handle undefined response in search_repositories#3600nielskaspers wants to merge 1 commit intomodelcontextprotocol:mainfrom
nielskaspers wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
…ontextprotocol#3454) On some Enterprise self-hosted GitLab instances (e.g. v18.4), the /projects API endpoint may return a non-array response body. This causes a crash when Zod's z.array() validator internally calls .map() on the undefined value. Add nullish coalescing to default to an empty array when the response is undefined or null. Fixes modelcontextprotocol#3454
Contributor
Author
|
Closing this PR — I missed that the gitlab server was archived in the main branch. The issue should be directed to the standalone gitlab server repo instead. |
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
Fixes #3454
The
search_repositoriestool inserver-gitlabcrashes withMcpError: Cannot read properties of undefined (reading 'map')when used against Enterprise self-hosted GitLab (v18.4).Root cause: The
/projectsAPI endpoint on some Enterprise GitLab instances may return a non-array response body. When thisundefinedvalue is passed to Zod'sz.array()validator, it internally calls.map()onundefined, causing the crash.Fix: Add nullish coalescing (
?? []) to defaultprojectsto an empty array when the API response isundefinedornull.Note: The
src/gitlab/directory was previously archived. This PR restores it to apply the fix. The actual code change is a single line insrc/gitlab/index.ts.