Skip to content

fix(gitlab): handle undefined response in search_repositories#3600

Closed
nielskaspers wants to merge 1 commit intomodelcontextprotocol:mainfrom
nielskaspers:fix/issue-3454-gitlab-search-repositories
Closed

fix(gitlab): handle undefined response in search_repositories#3600
nielskaspers wants to merge 1 commit intomodelcontextprotocol:mainfrom
nielskaspers:fix/issue-3454-gitlab-search-repositories

Conversation

@nielskaspers
Copy link
Contributor

Summary

Fixes #3454

The search_repositories tool in server-gitlab crashes with McpError: Cannot read properties of undefined (reading 'map') when used against Enterprise self-hosted GitLab (v18.4).

Root cause: The /projects API endpoint on some Enterprise GitLab instances may return a non-array response body. When this undefined value is passed to Zod's z.array() validator, it internally calls .map() on undefined, causing the crash.

Fix: Add nullish coalescing (?? []) to default projects to an empty array when the API response is undefined or null.

-    items: projects
+    items: projects ?? []

Note: The src/gitlab/ directory was previously archived. This PR restores it to apply the fix. The actual code change is a single line in src/gitlab/index.ts.

…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
@nielskaspers
Copy link
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.

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.

Fix "McpError: Cannot read properties of undefined (reading 'map')" - in server-gitlab

1 participant