@zereight/mcp-gitlab 2.3.15-next.174 → 2.3.15-next.176
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.
- package/build/index.js +3 -0
- package/build/oauth-proxy.js +15 -10
- package/build/server/http-error-handler.js +89 -0
- package/build/utils/logger.js +3 -3
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -95,6 +95,7 @@ import { getForwardedPublicBaseUrl, getForwardedRequestHost, } from "./utils/for
|
|
|
95
95
|
import { registerDownloadProxy } from "./downloads/proxy.js";
|
|
96
96
|
import { createDownloadToken } from "./utils/download-token.js";
|
|
97
97
|
import { loadRemoteHttpStack } from "./server/remote-http-stack.js";
|
|
98
|
+
import { createHttpErrorHandler } from "./server/http-error-handler.js";
|
|
98
99
|
import { determineTransportMode, TransportMode } from "./server/transport-mode.js";
|
|
99
100
|
import { formatPrometheusMetrics } from "./server/metrics.js";
|
|
100
101
|
import { SERVER_VERSION } from "./server/version.js";
|
|
@@ -11568,6 +11569,7 @@ async function startSSEServer() {
|
|
|
11568
11569
|
uptime: process.uptime(),
|
|
11569
11570
|
});
|
|
11570
11571
|
});
|
|
11572
|
+
app.use(createHttpErrorHandler(logger));
|
|
11571
11573
|
const httpServer = app.listen(Number(PORT), HOST, () => {
|
|
11572
11574
|
logger.info("GitLab MCP Server running with SSE transport");
|
|
11573
11575
|
logger.info(`${colorGreen}Endpoint: http://${HOST}:${PORT}/sse${colorReset}`);
|
|
@@ -12891,6 +12893,7 @@ async function startStreamableHTTPServer() {
|
|
|
12891
12893
|
message: "Method Not Allowed. Use GET, POST, or DELETE to communicate with the MCP server.",
|
|
12892
12894
|
});
|
|
12893
12895
|
});
|
|
12896
|
+
app.use(createHttpErrorHandler(logger));
|
|
12894
12897
|
// Start server
|
|
12895
12898
|
const httpServer = app.listen(Number(PORT), HOST, () => {
|
|
12896
12899
|
logger.info(`GitLab MCP Server running with Streamable HTTP transport`);
|
package/build/oauth-proxy.js
CHANGED
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
*
|
|
45
45
|
* Activated when GITLAB_MCP_OAUTH=true. All other auth modes are unaffected.
|
|
46
46
|
*/
|
|
47
|
-
import { CustomOAuthError, InsufficientScopeError, InvalidGrantError, InvalidTokenError, ServerError, } from "@modelcontextprotocol/sdk/server/auth/errors.js";
|
|
47
|
+
import { CustomOAuthError, InsufficientScopeError, InvalidGrantError, InvalidRequestError, InvalidTokenError, ServerError, } from "@modelcontextprotocol/sdk/server/auth/errors.js";
|
|
48
48
|
import { OAuthTokensSchema } from "@modelcontextprotocol/sdk/shared/auth.js";
|
|
49
49
|
import { randomUUID, randomBytes, createHash } from "node:crypto";
|
|
50
50
|
import { looksLikeStatelessClientId, mintClientId, openClientId, } from "./stateless/client-id.js";
|
|
@@ -433,6 +433,11 @@ class GitLabOAuthServerProvider {
|
|
|
433
433
|
// The authorizationCode is a proxy code we generated in handleCallback().
|
|
434
434
|
// It is either a sealed token (stateless mode) or a random UUID that
|
|
435
435
|
// keys into the _storedTokens LRU (legacy mode).
|
|
436
|
+
// A code that is unknown, expired, already used, or fails the client,
|
|
437
|
+
// redirect_uri or PKCE binding is invalid_grant, and a missing
|
|
438
|
+
// code_verifier is invalid_request (RFC 6749 §5.2, RFC 7636 §4.6), so
|
|
439
|
+
// the client restarts authorization. Only transient conditions
|
|
440
|
+
// (exchange in progress, replay cache full) are ServerError.
|
|
436
441
|
const stateless = this._stateless;
|
|
437
442
|
let entry = null;
|
|
438
443
|
if (stateless && looksLikeStatelessStoredTokensCode(authorizationCode)) {
|
|
@@ -444,7 +449,7 @@ class GitLabOAuthServerProvider {
|
|
|
444
449
|
if (reserved.reason === "pending") {
|
|
445
450
|
throw new ServerError("Authorization code exchange in progress — please retry");
|
|
446
451
|
}
|
|
447
|
-
throw new
|
|
452
|
+
throw new InvalidGrantError("Authorization code already used");
|
|
448
453
|
}
|
|
449
454
|
}
|
|
450
455
|
catch (err) {
|
|
@@ -460,7 +465,7 @@ class GitLabOAuthServerProvider {
|
|
|
460
465
|
reservedProxyCode = { hash: codeHash, id: reserved.reservationId };
|
|
461
466
|
const payload = openStoredTokensCode(stateless.material, authorizationCode, stateless.storedTtlSeconds);
|
|
462
467
|
if (!payload) {
|
|
463
|
-
throw new
|
|
468
|
+
throw new InvalidGrantError("Invalid or expired authorization code");
|
|
464
469
|
}
|
|
465
470
|
entry = {
|
|
466
471
|
tokens: payload.t,
|
|
@@ -477,10 +482,10 @@ class GitLabOAuthServerProvider {
|
|
|
477
482
|
// client/redirect/PKCE binding checks fail (DoS prevention).
|
|
478
483
|
const lru = this._storedTokens.getAndDelete(authorizationCode);
|
|
479
484
|
if (!lru) {
|
|
480
|
-
throw new
|
|
485
|
+
throw new InvalidGrantError("Invalid or expired authorization code");
|
|
481
486
|
}
|
|
482
487
|
if (Date.now() - lru.createdAt > PENDING_AUTH_TTL_MS) {
|
|
483
|
-
throw new
|
|
488
|
+
throw new InvalidGrantError("Authorization code expired — please restart the OAuth flow");
|
|
484
489
|
}
|
|
485
490
|
legacyRestorable = { code: authorizationCode, entry: lru };
|
|
486
491
|
entry = {
|
|
@@ -495,20 +500,20 @@ class GitLabOAuthServerProvider {
|
|
|
495
500
|
// Binding + PKCE run while consumption is only *reserved* (pending /
|
|
496
501
|
// restorable); failed checks release so the legitimate client can retry.
|
|
497
502
|
if (client.client_id !== entry.clientId) {
|
|
498
|
-
throw new
|
|
503
|
+
throw new InvalidGrantError("Invalid client for authorization code");
|
|
499
504
|
}
|
|
500
505
|
if (redirectUri !== entry.clientRedirectUri) {
|
|
501
|
-
throw new
|
|
506
|
+
throw new InvalidGrantError("Invalid redirect_uri for authorization code");
|
|
502
507
|
}
|
|
503
508
|
// Verify client PKCE: the client's code_verifier must match the
|
|
504
509
|
// code_challenge stored during /authorize.
|
|
505
510
|
if (entry.clientCodeChallenge) {
|
|
506
511
|
if (!codeVerifier) {
|
|
507
|
-
throw new
|
|
512
|
+
throw new InvalidRequestError("PKCE code_verifier is required");
|
|
508
513
|
}
|
|
509
514
|
const computed = createHash("sha256").update(codeVerifier).digest("base64url");
|
|
510
515
|
if (computed !== entry.clientCodeChallenge) {
|
|
511
|
-
throw new
|
|
516
|
+
throw new InvalidGrantError("PKCE verification failed");
|
|
512
517
|
}
|
|
513
518
|
}
|
|
514
519
|
tokens = entry.tokens;
|
|
@@ -541,7 +546,7 @@ class GitLabOAuthServerProvider {
|
|
|
541
546
|
}
|
|
542
547
|
if (!(await this.isAllowedGroupMember(tokens.access_token))) {
|
|
543
548
|
logger.warn({ allowedGroups: this._allowedGroups }, "Token issuance denied: user is not a member of any allowed group");
|
|
544
|
-
throw new
|
|
549
|
+
throw new InvalidGrantError(GROUP_ACCESS_DENIED_MESSAGE);
|
|
545
550
|
}
|
|
546
551
|
// All checks passed — permanently consume the proxy code.
|
|
547
552
|
legacyRestorable = null;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { STATUS_CODES } from "node:http";
|
|
2
|
+
const JSON_RPC_PARSE_ERROR_CODE = -32700;
|
|
3
|
+
const JSON_RPC_PARSE_ERROR_BODY = {
|
|
4
|
+
jsonrpc: "2.0",
|
|
5
|
+
error: {
|
|
6
|
+
code: JSON_RPC_PARSE_ERROR_CODE,
|
|
7
|
+
message: "Parse error",
|
|
8
|
+
},
|
|
9
|
+
id: null,
|
|
10
|
+
};
|
|
11
|
+
const BODY_PARSER_JSON_PARSE_TYPE = "entity.parse.failed";
|
|
12
|
+
const CLIENT_ERROR_MIN_STATUS = 400;
|
|
13
|
+
const SERVER_ERROR_MIN_STATUS = 500;
|
|
14
|
+
const MAX_HTTP_STATUS = 599;
|
|
15
|
+
function isObject(value) {
|
|
16
|
+
return typeof value === "object" && value !== null;
|
|
17
|
+
}
|
|
18
|
+
function readErrorType(error) {
|
|
19
|
+
if (isObject(error) && typeof error.type === "string" && error.type.length > 0) {
|
|
20
|
+
return error.type;
|
|
21
|
+
}
|
|
22
|
+
if (error instanceof Error && error.name.length > 0) {
|
|
23
|
+
return error.name;
|
|
24
|
+
}
|
|
25
|
+
return "Error";
|
|
26
|
+
}
|
|
27
|
+
function readHttpStatus(error) {
|
|
28
|
+
if (!isObject(error)) {
|
|
29
|
+
return SERVER_ERROR_MIN_STATUS;
|
|
30
|
+
}
|
|
31
|
+
for (const key of ["status", "statusCode"]) {
|
|
32
|
+
const value = error[key];
|
|
33
|
+
if (typeof value === "number" &&
|
|
34
|
+
Number.isInteger(value) &&
|
|
35
|
+
value >= CLIENT_ERROR_MIN_STATUS &&
|
|
36
|
+
value <= MAX_HTTP_STATUS) {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return SERVER_ERROR_MIN_STATUS;
|
|
41
|
+
}
|
|
42
|
+
function isJsonParseError(error) {
|
|
43
|
+
return isObject(error) && error.type === BODY_PARSER_JSON_PARSE_TYPE;
|
|
44
|
+
}
|
|
45
|
+
function clientErrorPhrase(status) {
|
|
46
|
+
const phrase = STATUS_CODES[status];
|
|
47
|
+
return typeof phrase === "string" ? phrase : "Request Error";
|
|
48
|
+
}
|
|
49
|
+
function responseBodyForError(error, status) {
|
|
50
|
+
if (isJsonParseError(error)) {
|
|
51
|
+
return JSON_RPC_PARSE_ERROR_BODY;
|
|
52
|
+
}
|
|
53
|
+
if (status >= SERVER_ERROR_MIN_STATUS) {
|
|
54
|
+
return { error: "Internal server error" };
|
|
55
|
+
}
|
|
56
|
+
return { error: clientErrorPhrase(status) };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Express 5.3's default handler logs `console.error(err)`. body-parser's JSON
|
|
60
|
+
* SyntaxError carries the raw request on `err.body`, so that path prints
|
|
61
|
+
* credentials that pino redaction never sees. `stdSerializers.err` would copy
|
|
62
|
+
* the same field. Log type/status only, and never `next(err)`.
|
|
63
|
+
*/
|
|
64
|
+
export function createHttpErrorHandler(logger) {
|
|
65
|
+
return function httpErrorHandler(err, req, res, _next) {
|
|
66
|
+
const type = readErrorType(err);
|
|
67
|
+
const status = readHttpStatus(err);
|
|
68
|
+
const fields = { type, status };
|
|
69
|
+
if (typeof req.method === "string") {
|
|
70
|
+
fields.method = req.method;
|
|
71
|
+
}
|
|
72
|
+
if (typeof req.path === "string") {
|
|
73
|
+
fields.path = req.path;
|
|
74
|
+
}
|
|
75
|
+
if (status >= SERVER_ERROR_MIN_STATUS) {
|
|
76
|
+
logger.error(fields, "HTTP request error");
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
logger.warn(fields, "HTTP request error");
|
|
80
|
+
}
|
|
81
|
+
if (res.headersSent) {
|
|
82
|
+
if (!res.writableEnded) {
|
|
83
|
+
res.end();
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
res.status(isJsonParseError(err) ? 400 : status).json(responseBodyForError(err, status));
|
|
88
|
+
};
|
|
89
|
+
}
|
package/build/utils/logger.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { pino } from "pino";
|
|
2
|
+
import { pino, destination, stdSerializers, } from "pino";
|
|
3
3
|
import { redactUrlSecretsInError, redactUrlSecretsInLogLine } from "./redact-url.js";
|
|
4
4
|
const require = createRequire(import.meta.url);
|
|
5
5
|
const REDACT_PATHS = [
|
|
@@ -60,7 +60,7 @@ function loadPrettifier() {
|
|
|
60
60
|
return prettyModule.prettyFactory({ colorize: true, levelFirst: true });
|
|
61
61
|
}
|
|
62
62
|
function createAsyncStderr() {
|
|
63
|
-
return
|
|
63
|
+
return destination({
|
|
64
64
|
dest: STDERR_FD,
|
|
65
65
|
sync: false,
|
|
66
66
|
minLength: ASYNC_LOG_MIN_LENGTH,
|
|
@@ -123,7 +123,7 @@ export function flushBufferedLogs(logger) {
|
|
|
123
123
|
* that the line redaction cannot recognize.
|
|
124
124
|
*/
|
|
125
125
|
export function serializeLoggedError(error) {
|
|
126
|
-
return
|
|
126
|
+
return stdSerializers.err(redactUrlSecretsInError(error));
|
|
127
127
|
}
|
|
128
128
|
// Keys whose error pino or pino-pretty prints even though no serializer runs on it.
|
|
129
129
|
const LOGGED_ERROR_KEYS = ["err", "error"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zereight/mcp-gitlab",
|
|
3
|
-
"version": "2.3.15-next.
|
|
3
|
+
"version": "2.3.15-next.176",
|
|
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": [
|