@zereight/mcp-gitlab 2.3.23-next.209 → 2.3.23-next.211

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ import { pipeline } from "node:stream/promises";
3
3
  import { parseProjectScopeHeader } from "../server/request-helpers.js";
4
4
  import { decryptDownloadToken } from "../utils/download-token.js";
5
5
  import { fetchWithValidatedRedirects, UnsafeRedirectError } from "../utils/safe-redirect-fetch.js";
6
+ import { uploadFilenameForms } from "../utils/url.js";
6
7
  const DEFAULT_DOWNLOAD_TIMEOUT_MS = 120_000;
7
8
  function canonicalizeQueryParams(params) {
8
9
  const sortedKeys = Object.keys(params).sort();
@@ -147,6 +148,8 @@ export function registerDownloadProxy(app, deps) {
147
148
  }
148
149
  const { type } = req.params;
149
150
  let gitlabUrl;
151
+ // Tried in turn while GitLab answers 404: an upload's name in its other Unicode forms.
152
+ let retryUrls = [];
150
153
  try {
151
154
  switch (type) {
152
155
  case "job-artifacts": {
@@ -168,7 +171,8 @@ export function registerDownloadProxy(app, deps) {
168
171
  const effectiveProjectId = resolveDownloadProjectId(deps, project_id, sealedProjectIds, requestScope.projectIds);
169
172
  // The uploads route takes one filename segment; a slash inside the name must
170
173
  // stay inside that segment instead of turning into another route level.
171
- gitlabUrl = `${apiUrl}/projects/${deps.encodeGitLabPathSegment(effectiveProjectId)}/uploads/${deps.encodeGitLabPathSegment(secret)}/${deps.encodeGitLabPathSegment(filename)}`;
174
+ const uploadUrl = (name) => `${apiUrl}/projects/${deps.encodeGitLabPathSegment(effectiveProjectId)}/uploads/${deps.encodeGitLabPathSegment(secret)}/${deps.encodeGitLabPathSegment(name)}`;
175
+ [gitlabUrl, ...retryUrls] = uploadFilenameForms(filename).map(uploadUrl);
172
176
  break;
173
177
  }
174
178
  case "release-asset": {
@@ -197,13 +201,21 @@ export function registerDownloadProxy(app, deps) {
197
201
  const controller = new AbortController();
198
202
  const timeout = setTimeout(() => controller.abort(), downloadTimeoutMs);
199
203
  try {
200
- const gitlabResponse = await fetchWithValidatedRedirects(gitlabUrl, {
204
+ const fetchOptions = {
201
205
  headers,
202
206
  dispatcher: deps.getDispatcherForUrl(apiUrl),
203
207
  signal: controller.signal,
204
208
  fetchImpl: deps.fetch,
205
209
  isTrustedRedirectHost: deps.isTrustedRedirectHost,
206
- });
210
+ };
211
+ let gitlabResponse = await fetchWithValidatedRedirects(gitlabUrl, fetchOptions);
212
+ for (const retryUrl of retryUrls) {
213
+ if (gitlabResponse.status !== 404) {
214
+ break;
215
+ }
216
+ await gitlabResponse.body?.cancel();
217
+ gitlabResponse = await fetchWithValidatedRedirects(retryUrl, fetchOptions);
218
+ }
207
219
  if (!gitlabResponse.ok) {
208
220
  res.status(gitlabResponse.status).json({
209
221
  error: `GitLab API error: ${gitlabResponse.status} ${gitlabResponse.statusText}`,
package/build/index.js CHANGED
@@ -106,7 +106,7 @@ import { formatUnknownHelpTopic, getWorkflowGuide, readHelpTopic } from "./serve
106
106
  import { isInitializationRequestBody, isUnauthenticatedDiscoveryRequestBody, parseProjectScopeHeader, readAcceptHeader, readMcpSessionIdHeader, redactSessionIdForLog, } from "./server/request-helpers.js";
107
107
  export { readMcpSessionIdHeader } from "./server/request-helpers.js";
108
108
  import { authBySession, BASE_HEADERS, bindSessionProjectScope, buildAuthHeaders, configureGitLabRequestContext, getEffectiveAllowedProjectIds, getEffectiveApiUrl, getFetchConfig, SESSION_PROJECT_SCOPE_MISMATCH, sessionAuthStore, updateSessionPublicBaseUrl, usesJobTokenHeader, withPublicBaseUrl, } from "./server/gitlab-request-context.js";
109
- import { apiUrlUserinfoWarning, commaSplitHint, configuredApiUrlErrors, encodeGitLabPath, encodeGitLabPathSegment, invalidListEntryError, isCleartextRemoteUrl, normalizeGitLabApiUrl, parseConfiguredGitLabApiUrls, } from "./utils/url.js";
109
+ import { apiUrlUserinfoWarning, commaSplitHint, configuredApiUrlErrors, encodeGitLabPath, encodeGitLabPathSegment, invalidListEntryError, isCleartextRemoteUrl, normalizeGitLabApiUrl, parseConfiguredGitLabApiUrls, uploadFilenameForms, } from "./utils/url.js";
110
110
  import { estimateMergeCommitCount, filterDiffsByPatterns, openSafeOutputWriteStream, resolveDownloadRoot, readSafeExistingFile, summarizeWebhookEvents, } from "./utils/helpers.js";
111
111
  import { graphqlQueryContainsWriteOperation, graphqlQueryContainsDeleteOperation, } from "./utils/graphql-query.js";
112
112
  import { encodeRepoFilePayloadContent, fileOperationsIncludeDeleteOrMove, toGitLabCommitActions, } from "./utils/gitlab-commit-actions.js";
@@ -7456,9 +7456,22 @@ function getSafeAttachmentFilename(filename) {
7456
7456
  }
7457
7457
  async function downloadAttachment(projectId, secret, filename, localPath, metadataOnly = false) {
7458
7458
  const effectiveProjectId = getEffectiveProjectId(projectId);
7459
- const safeFilename = getSafeAttachmentFilename(filename);
7460
- const url = new URL(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(effectiveProjectId)}/uploads/${encodeGitLabPathSegment(secret)}/${encodeGitLabPathSegment(safeFilename)}`);
7461
- const response = await fetchWithValidatedRedirects(url.toString(), downloadRedirectOptions());
7459
+ const requestedFilename = getSafeAttachmentFilename(filename);
7460
+ const fetchUpload = (name) => fetchWithValidatedRedirects(new URL(`${getEffectiveApiUrl()}/projects/${encodeGitLabPathSegment(effectiveProjectId)}/uploads/${encodeGitLabPathSegment(secret)}/${encodeGitLabPathSegment(name)}`).toString(), downloadRedirectOptions());
7461
+ // GitLab answers 404 when the name's accents are in another Unicode form than the
7462
+ // stored one. The result and a saved file take the name decoded, as GitLab stores it,
7463
+ // so no form may hold a separator.
7464
+ const [firstName = requestedFilename, ...alternatives] = uploadFilenameForms(requestedFilename).filter(name => !name.includes("/") && !name.includes("\\"));
7465
+ let safeFilename = firstName;
7466
+ let response = await fetchUpload(safeFilename);
7467
+ for (const candidate of alternatives) {
7468
+ if (response.status !== 404) {
7469
+ break;
7470
+ }
7471
+ await response.body?.cancel();
7472
+ safeFilename = candidate;
7473
+ response = await fetchUpload(candidate);
7474
+ }
7462
7475
  if (!response.ok) {
7463
7476
  await handleGitLabError(response);
7464
7477
  }
package/build/schemas.js CHANGED
@@ -3468,7 +3468,9 @@ export const MarkdownUploadRemoteSchema = z.object({
3468
3468
  export const DownloadAttachmentSchema = z.object({
3469
3469
  project_id: z.string().describe("Project ID or URL-encoded path of the project"),
3470
3470
  secret: z.string().describe("The 32-character secret of the upload"),
3471
- filename: z.string().describe("The filename of the upload"),
3471
+ filename: z
3472
+ .string()
3473
+ .describe("The filename of the upload, copied from its URL as is, percent-encoding included (e.g. `Capture_d_e%CC%81cran.png` from `/uploads/<secret>/Capture_d_e%CC%81cran.png`): retyping accented characters can change their bytes"),
3472
3474
  local_path: z
3473
3475
  .string()
3474
3476
  .optional()
@@ -3481,7 +3483,9 @@ export const DownloadAttachmentSchema = z.object({
3481
3483
  export const DownloadAttachmentRemoteSchema = z.object({
3482
3484
  project_id: z.string().describe("Project ID or URL-encoded path of the project"),
3483
3485
  secret: z.string().describe("The 32-character secret of the upload"),
3484
- filename: z.string().describe("The filename of the upload"),
3486
+ filename: z
3487
+ .string()
3488
+ .describe("The filename of the upload, copied from its URL as is, percent-encoding included (e.g. `Capture_d_e%CC%81cran.png` from `/uploads/<secret>/Capture_d_e%CC%81cran.png`): retyping accented characters can change their bytes"),
3485
3489
  });
3486
3490
  export const GroupIteration = z.object({
3487
3491
  id: z.coerce.string(),
@@ -227,6 +227,20 @@ function decodeFully(value) {
227
227
  }
228
228
  return null;
229
229
  }
230
+ /**
231
+ * An upload's filename percent-decoded, as `encodeGitLabPathSegment` does, then its
232
+ * other Unicode forms, to try in turn while GitLab answers 404.
233
+ *
234
+ * GitLab matches the name byte for byte. macOS writes accents decomposed (e + U+0301)
235
+ * and GitLab keeps the name as uploaded, while clients usually send it composed.
236
+ */
237
+ export function uploadFilenameForms(filename) {
238
+ const decoded = decodeFully(filename);
239
+ if (decoded === null) {
240
+ return [filename];
241
+ }
242
+ return [...new Set([decoded, decoded.normalize("NFD"), decoded.normalize("NFC")])];
243
+ }
230
244
  /**
231
245
  * Encode a single value for use as one GitLab URL path segment.
232
246
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zereight/mcp-gitlab",
3
- "version": "2.3.23-next.209",
3
+ "version": "2.3.23-next.211",
4
4
  "mcpName": "io.github.zereight/gitlab-mcp",
5
5
  "description": "GitLab MCP server for projects, merge requests, issues, pipelines, wiki, releases, and more",
6
6
  "keywords": [