@structured-world/gitlab-mcp 10.0.1 → 11.0.0
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/README.md +6 -6
- package/README.md.in +1 -1
- package/dist/src/channel-gateway/format.js +7 -1
- package/dist/src/channel-gateway/format.js.map +1 -1
- package/dist/src/channel-gateway/forwarding.d.ts +3 -0
- package/dist/src/channel-gateway/forwarding.js +8 -1
- package/dist/src/channel-gateway/forwarding.js.map +1 -1
- package/dist/src/channel-gateway/gateway.d.ts +7 -0
- package/dist/src/channel-gateway/gateway.js +80 -16
- package/dist/src/channel-gateway/gateway.js.map +1 -1
- package/dist/src/cli/docker/container-runtime.d.ts +1 -0
- package/dist/src/cli/docker/container-runtime.js +37 -5
- package/dist/src/cli/docker/container-runtime.js.map +1 -1
- package/dist/src/cli/docker/docker-command.js +11 -2
- package/dist/src/cli/docker/docker-command.js.map +1 -1
- package/dist/src/cli/docker/docker-utils.d.ts +1 -0
- package/dist/src/cli/docker/docker-utils.js +137 -27
- package/dist/src/cli/docker/docker-utils.js.map +1 -1
- package/dist/src/cli/docker/oauth-issuer-prompt.d.ts +2 -0
- package/dist/src/cli/docker/oauth-issuer-prompt.js +47 -0
- package/dist/src/cli/docker/oauth-issuer-prompt.js.map +1 -0
- package/dist/src/cli/docker/types.d.ts +18 -4
- package/dist/src/cli/docker/types.js.map +1 -1
- package/dist/src/cli/list-tools.js +14 -35
- package/dist/src/cli/list-tools.js.map +1 -1
- package/dist/src/cli/setup/flows/server-setup.js +15 -0
- package/dist/src/cli/setup/flows/server-setup.js.map +1 -1
- package/dist/src/config/instances-loader.js +17 -3
- package/dist/src/config/instances-loader.js.map +1 -1
- package/dist/src/config/instances-schema.d.ts +6 -3
- package/dist/src/config/instances-schema.js +7 -6
- package/dist/src/config/instances-schema.js.map +1 -1
- package/dist/src/config.js.map +1 -1
- package/dist/src/configuration/caller.d.ts +10 -0
- package/dist/src/configuration/caller.js +39 -0
- package/dist/src/configuration/caller.js.map +1 -0
- package/dist/src/configuration/composed-feeds.d.ts +31 -0
- package/dist/src/configuration/composed-feeds.js +698 -0
- package/dist/src/configuration/composed-feeds.js.map +1 -0
- package/dist/src/configuration/composed-listings.d.ts +14 -0
- package/dist/src/configuration/composed-listings.js +157 -0
- package/dist/src/configuration/composed-listings.js.map +1 -0
- package/dist/src/configuration/groups.d.ts +8 -0
- package/dist/src/configuration/groups.js +39 -0
- package/dist/src/configuration/groups.js.map +1 -0
- package/dist/src/configuration/index.d.ts +6 -0
- package/dist/src/configuration/index.js +87 -0
- package/dist/src/configuration/index.js.map +1 -0
- package/dist/src/configuration/policy.d.ts +34 -0
- package/dist/src/configuration/policy.js +122 -0
- package/dist/src/configuration/policy.js.map +1 -0
- package/dist/src/configuration/scope-ids.d.ts +7 -0
- package/dist/src/configuration/scope-ids.js +78 -0
- package/dist/src/configuration/scope-ids.js.map +1 -0
- package/dist/src/configuration/scope-projects.d.ts +5 -0
- package/dist/src/configuration/scope-projects.js +76 -0
- package/dist/src/configuration/scope-projects.js.map +1 -0
- package/dist/src/configuration/scope-targets.d.ts +26 -0
- package/dist/src/configuration/scope-targets.js +307 -0
- package/dist/src/configuration/scope-targets.js.map +1 -0
- package/dist/src/configuration/scoped-execution.d.ts +6 -0
- package/dist/src/configuration/scoped-execution.js +577 -0
- package/dist/src/configuration/scoped-execution.js.map +1 -0
- package/dist/src/configuration/scoped-feeds.d.ts +22 -0
- package/dist/src/configuration/scoped-feeds.js +136 -0
- package/dist/src/configuration/scoped-feeds.js.map +1 -0
- package/dist/src/configuration/service.d.ts +53 -0
- package/dist/src/configuration/service.js +186 -0
- package/dist/src/configuration/service.js.map +1 -0
- package/dist/src/configuration/settings-store.d.ts +20 -0
- package/dist/src/configuration/settings-store.js +228 -0
- package/dist/src/configuration/settings-store.js.map +1 -0
- package/dist/src/configuration/types.d.ts +30 -0
- package/dist/src/configuration/types.js +20 -0
- package/dist/src/configuration/types.js.map +1 -0
- package/dist/src/contracts/storage.d.ts +2 -1
- package/dist/src/dashboard/html-template.js +8 -15
- package/dist/src/dashboard/html-template.js.map +1 -1
- package/dist/src/dashboard/metrics.d.ts +1 -1
- package/dist/src/entities/context/connection-check.d.ts +64 -0
- package/dist/src/entities/context/connection-check.js +117 -0
- package/dist/src/entities/context/connection-check.js.map +1 -0
- package/dist/src/entities/context/context-manager.d.ts +10 -22
- package/dist/src/entities/context/context-manager.js +108 -207
- package/dist/src/entities/context/context-manager.js.map +1 -1
- package/dist/src/entities/context/handlers.d.ts +3 -5
- package/dist/src/entities/context/handlers.js +2 -14
- package/dist/src/entities/context/handlers.js.map +1 -1
- package/dist/src/entities/context/output-schema.d.ts +272 -0
- package/dist/src/entities/context/output-schema.js +182 -0
- package/dist/src/entities/context/output-schema.js.map +1 -0
- package/dist/src/entities/context/profile.d.ts +29 -0
- package/dist/src/entities/context/profile.js +72 -0
- package/dist/src/entities/context/profile.js.map +1 -0
- package/dist/src/entities/context/registry.js +140 -3
- package/dist/src/entities/context/registry.js.map +1 -1
- package/dist/src/entities/context/schema.d.ts +6 -14
- package/dist/src/entities/context/schema.js +6 -13
- package/dist/src/entities/context/schema.js.map +1 -1
- package/dist/src/entities/context/scope-search.d.ts +49 -0
- package/dist/src/entities/context/scope-search.js +71 -0
- package/dist/src/entities/context/scope-search.js.map +1 -0
- package/dist/src/entities/context/settings-panel.d.ts +13 -0
- package/dist/src/entities/context/settings-panel.js +508 -0
- package/dist/src/entities/context/settings-panel.js.map +1 -0
- package/dist/src/entities/context/settings.d.ts +78 -0
- package/dist/src/entities/context/settings.js +239 -0
- package/dist/src/entities/context/settings.js.map +1 -0
- package/dist/src/entities/context/types.d.ts +3 -4
- package/dist/src/entities/context/whoami.js +39 -31
- package/dist/src/entities/context/whoami.js.map +1 -1
- package/dist/src/entities/core/registry.js +34 -33
- package/dist/src/entities/core/registry.js.map +1 -1
- package/dist/src/entities/environments/schema-readonly.d.ts +3 -3
- package/dist/src/entities/files/registry.js +3 -2
- package/dist/src/entities/files/registry.js.map +1 -1
- package/dist/src/entities/iterations/registry.js +3 -2
- package/dist/src/entities/iterations/registry.js.map +1 -1
- package/dist/src/entities/mrs/registry.js +11 -5
- package/dist/src/entities/mrs/registry.js.map +1 -1
- package/dist/src/entities/mrs/schema-readonly.d.ts +8 -2
- package/dist/src/entities/mrs/schema-readonly.js +31 -3
- package/dist/src/entities/mrs/schema-readonly.js.map +1 -1
- package/dist/src/entities/pipelines/registry.js +3 -2
- package/dist/src/entities/pipelines/registry.js.map +1 -1
- package/dist/src/entities/pipelines/schema-readonly.d.ts +3 -3
- package/dist/src/entities/runners/project-access.d.ts +14 -0
- package/dist/src/entities/runners/project-access.js +64 -0
- package/dist/src/entities/runners/project-access.js.map +1 -0
- package/dist/src/entities/runners/registry.js +54 -26
- package/dist/src/entities/runners/registry.js.map +1 -1
- package/dist/src/entities/search/schema-readonly.d.ts +28 -28
- package/dist/src/graphql/runners.d.ts +26 -1
- package/dist/src/graphql/runners.js +43 -6
- package/dist/src/graphql/runners.js.map +1 -1
- package/dist/src/graphql/vulnerabilities.d.ts +3 -0
- package/dist/src/graphql/vulnerabilities.js +1 -0
- package/dist/src/graphql/vulnerabilities.js.map +1 -1
- package/dist/src/handlers.js +218 -142
- package/dist/src/handlers.js.map +1 -1
- package/dist/src/logger.d.ts +3 -2
- package/dist/src/mcp-apps.d.ts +6 -0
- package/dist/src/mcp-apps.js +8 -0
- package/dist/src/mcp-apps.js.map +1 -0
- package/dist/src/middleware/mcp-auth-routes.d.ts +3 -0
- package/dist/src/middleware/mcp-auth-routes.js +9 -0
- package/dist/src/middleware/mcp-auth-routes.js.map +1 -0
- package/dist/src/middleware/oauth-auth.js +83 -23
- package/dist/src/middleware/oauth-auth.js.map +1 -1
- package/dist/src/middleware/rate-limiter.js +11 -10
- package/dist/src/middleware/rate-limiter.js.map +1 -1
- package/dist/src/oauth/authorization-response.d.ts +1 -0
- package/dist/src/oauth/authorization-response.js +14 -0
- package/dist/src/oauth/authorization-response.js.map +1 -0
- package/dist/src/oauth/client-auth.d.ts +16 -0
- package/dist/src/oauth/client-auth.js +73 -0
- package/dist/src/oauth/client-auth.js.map +1 -0
- package/dist/src/oauth/config.d.ts +2 -0
- package/dist/src/oauth/config.js +37 -0
- package/dist/src/oauth/config.js.map +1 -1
- package/dist/src/oauth/endpoints/authorize.d.ts +1 -0
- package/dist/src/oauth/endpoints/authorize.js +361 -102
- package/dist/src/oauth/endpoints/authorize.js.map +1 -1
- package/dist/src/oauth/endpoints/callback.js +78 -41
- package/dist/src/oauth/endpoints/callback.js.map +1 -1
- package/dist/src/oauth/endpoints/index.d.ts +1 -0
- package/dist/src/oauth/endpoints/index.js +3 -1
- package/dist/src/oauth/endpoints/index.js.map +1 -1
- package/dist/src/oauth/endpoints/metadata.d.ts +1 -1
- package/dist/src/oauth/endpoints/metadata.js +23 -8
- package/dist/src/oauth/endpoints/metadata.js.map +1 -1
- package/dist/src/oauth/endpoints/register.d.ts +3 -2
- package/dist/src/oauth/endpoints/register.js +70 -19
- package/dist/src/oauth/endpoints/register.js.map +1 -1
- package/dist/src/oauth/endpoints/revoke.d.ts +2 -0
- package/dist/src/oauth/endpoints/revoke.js +97 -0
- package/dist/src/oauth/endpoints/revoke.js.map +1 -0
- package/dist/src/oauth/endpoints/token.js +136 -62
- package/dist/src/oauth/endpoints/token.js.map +1 -1
- package/dist/src/oauth/gitlab-device-flow.d.ts +27 -8
- package/dist/src/oauth/gitlab-device-flow.js +119 -57
- package/dist/src/oauth/gitlab-device-flow.js.map +1 -1
- package/dist/src/oauth/gitlab-request-bound.d.ts +1 -0
- package/dist/src/oauth/gitlab-request-bound.js +6 -0
- package/dist/src/oauth/gitlab-request-bound.js.map +1 -0
- package/dist/src/oauth/gitlab-token-refresh.d.ts +6 -0
- package/dist/src/oauth/gitlab-token-refresh.js +130 -0
- package/dist/src/oauth/gitlab-token-refresh.js.map +1 -0
- package/dist/src/oauth/granted-scopes.d.ts +1 -0
- package/dist/src/oauth/granted-scopes.js +7 -0
- package/dist/src/oauth/granted-scopes.js.map +1 -0
- package/dist/src/oauth/index.d.ts +2 -2
- package/dist/src/oauth/index.js +4 -2
- package/dist/src/oauth/index.js.map +1 -1
- package/dist/src/oauth/instance-app.d.ts +4 -0
- package/dist/src/oauth/instance-app.js +45 -0
- package/dist/src/oauth/instance-app.js.map +1 -0
- package/dist/src/oauth/issued-tokens.d.ts +1 -0
- package/dist/src/oauth/issued-tokens.js +24 -0
- package/dist/src/oauth/issued-tokens.js.map +1 -0
- package/dist/src/oauth/oauth-app.d.ts +9 -0
- package/dist/src/oauth/oauth-app.js +14 -0
- package/dist/src/oauth/oauth-app.js.map +1 -0
- package/dist/src/oauth/request-params.d.ts +1 -0
- package/dist/src/oauth/request-params.js +17 -0
- package/dist/src/oauth/request-params.js.map +1 -0
- package/dist/src/oauth/resource.d.ts +12 -0
- package/dist/src/oauth/resource.js +66 -0
- package/dist/src/oauth/resource.js.map +1 -0
- package/dist/src/oauth/routes.d.ts +2 -0
- package/dist/src/oauth/routes.js +31 -0
- package/dist/src/oauth/routes.js.map +1 -0
- package/dist/src/oauth/session-store.d.ts +44 -36
- package/dist/src/oauth/session-store.js +125 -253
- package/dist/src/oauth/session-store.js.map +1 -1
- package/dist/src/oauth/storage/factory.js +1 -1
- package/dist/src/oauth/storage/factory.js.map +1 -1
- package/dist/src/oauth/storage/file.d.ts +23 -1
- package/dist/src/oauth/storage/file.js +168 -36
- package/dist/src/oauth/storage/file.js.map +1 -1
- package/dist/src/oauth/storage/memory.d.ts +23 -1
- package/dist/src/oauth/storage/memory.js +120 -22
- package/dist/src/oauth/storage/memory.js.map +1 -1
- package/dist/src/oauth/storage/types.d.ts +17 -1
- package/dist/src/oauth/storage/types.js.map +1 -1
- package/dist/src/oauth/tool-auth.d.ts +12 -0
- package/dist/src/oauth/tool-auth.js +108 -0
- package/dist/src/oauth/tool-auth.js.map +1 -0
- package/dist/src/oauth/types.d.ts +30 -0
- package/dist/src/profiles/scope-enforcer.d.ts +8 -0
- package/dist/src/profiles/scope-enforcer.js +86 -24
- package/dist/src/profiles/scope-enforcer.js.map +1 -1
- package/dist/src/profiles/types.js +4 -1
- package/dist/src/profiles/types.js.map +1 -1
- package/dist/src/registry-manager.d.ts +16 -4
- package/dist/src/registry-manager.js +115 -33
- package/dist/src/registry-manager.js.map +1 -1
- package/dist/src/server.js +66 -39
- package/dist/src/server.js.map +1 -1
- package/dist/src/services/ConnectionManager.d.ts +2 -1
- package/dist/src/services/ConnectionManager.js +26 -19
- package/dist/src/services/ConnectionManager.js.map +1 -1
- package/dist/src/services/TokenScopeDetector.d.ts +5 -1
- package/dist/src/services/TokenScopeDetector.js +19 -0
- package/dist/src/services/TokenScopeDetector.js.map +1 -1
- package/dist/src/session-manager.d.ts +3 -1
- package/dist/src/session-manager.js +35 -10
- package/dist/src/session-manager.js.map +1 -1
- package/dist/src/types.d.ts +3 -2
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/bounded-map.d.ts +1 -0
- package/dist/src/utils/bounded-map.js +23 -0
- package/dist/src/utils/bounded-map.js.map +1 -0
- package/dist/src/utils/fetch.d.ts +0 -1
- package/dist/src/utils/fetch.js +2 -12
- package/dist/src/utils/fetch.js.map +1 -1
- package/dist/src/utils/gitlab-api.js +2 -1
- package/dist/src/utils/gitlab-api.js.map +1 -1
- package/dist/src/utils/gitlab-base-url.d.ts +2 -0
- package/dist/src/utils/gitlab-base-url.js +30 -0
- package/dist/src/utils/gitlab-base-url.js.map +1 -0
- package/dist/src/utils/html.d.ts +1 -0
- package/dist/src/utils/html.js +12 -0
- package/dist/src/utils/html.js.map +1 -0
- package/dist/src/utils/namespace.d.ts +1 -0
- package/dist/src/utils/namespace.js +72 -24
- package/dist/src/utils/namespace.js.map +1 -1
- package/dist/src/utils/schema-utils.d.ts +5 -3
- package/dist/src/utils/schema-utils.js +50 -22
- package/dist/src/utils/schema-utils.js.map +1 -1
- package/dist/src/utils/smart-user-search.js +2 -1
- package/dist/src/utils/smart-user-search.js.map +1 -1
- package/dist/src/utils/sync-directory.d.ts +1 -0
- package/dist/src/utils/sync-directory.js +49 -0
- package/dist/src/utils/sync-directory.js.map +1 -0
- package/dist/src/utils/tool-result.d.ts +4 -0
- package/dist/src/utils/tool-result.js +41 -0
- package/dist/src/utils/tool-result.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +65 -18
- package/skills/gitlab-ci/SKILL.md +16 -0
- package/skills/gitlab-discovery/SKILL.md +15 -0
- package/skills/gitlab-review/SKILL.md +16 -0
- package/skills/gitlab-setup/SKILL.md +16 -0
- package/skills/gitlab-work-items/SKILL.md +16 -0
package/dist/src/handlers.js
CHANGED
|
@@ -36,6 +36,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.resetHandlersState = resetHandlersState;
|
|
37
37
|
exports.setupHandlers = setupHandlers;
|
|
38
38
|
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
39
|
+
const settings_panel_1 = require("./entities/context/settings-panel");
|
|
40
|
+
const mcp_apps_1 = require("./mcp-apps");
|
|
39
41
|
const ConnectionManager_1 = require("./services/ConnectionManager");
|
|
40
42
|
const HealthMonitor_1 = require("./services/HealthMonitor");
|
|
41
43
|
const url_1 = require("./utils/url");
|
|
@@ -44,6 +46,13 @@ const error_handler_1 = require("./utils/error-handler");
|
|
|
44
46
|
const fetch_1 = require("./utils/fetch");
|
|
45
47
|
const index_1 = require("./logging/index");
|
|
46
48
|
const config_1 = require("./config");
|
|
49
|
+
const schema_utils_1 = require("./utils/schema-utils");
|
|
50
|
+
const tool_result_1 = require("./utils/tool-result");
|
|
51
|
+
const tool_auth_1 = require("./oauth/tool-auth");
|
|
52
|
+
const configuration_1 = require("./configuration");
|
|
53
|
+
const policy_1 = require("./configuration/policy");
|
|
54
|
+
const scoped_execution_1 = require("./configuration/scoped-execution");
|
|
55
|
+
const scope_ids_1 = require("./configuration/scope-ids");
|
|
47
56
|
function hasAction(value) {
|
|
48
57
|
return (typeof value === 'object' &&
|
|
49
58
|
value !== null &&
|
|
@@ -74,14 +83,15 @@ function recordEarlyReturnError(toolName, action, errorMessage) {
|
|
|
74
83
|
}
|
|
75
84
|
}
|
|
76
85
|
}
|
|
77
|
-
function isIdempotentOperation(toolName) {
|
|
86
|
+
function isIdempotentOperation(toolName, declared) {
|
|
87
|
+
if (declared !== undefined)
|
|
88
|
+
return declared;
|
|
78
89
|
return (toolName.startsWith('browse_') ||
|
|
79
90
|
toolName.startsWith('list_') ||
|
|
80
91
|
toolName.startsWith('get_') ||
|
|
81
|
-
toolName.startsWith('download_')
|
|
82
|
-
toolName === 'manage_context');
|
|
92
|
+
toolName.startsWith('download_'));
|
|
83
93
|
}
|
|
84
|
-
function toStructuredError(error, toolName, toolArgs) {
|
|
94
|
+
function toStructuredError(error, toolName, toolArgs, declaredIdempotent) {
|
|
85
95
|
if ((0, error_handler_1.isStructuredToolError)(error)) {
|
|
86
96
|
return error.structuredError;
|
|
87
97
|
}
|
|
@@ -101,13 +111,13 @@ function toStructuredError(error, toolName, toolArgs) {
|
|
|
101
111
|
error.name === 'GitLabTimeoutError' &&
|
|
102
112
|
'timeoutMs' in error &&
|
|
103
113
|
typeof error.timeoutMs === 'number')) {
|
|
104
|
-
const retryable = isIdempotentOperation(toolName);
|
|
114
|
+
const retryable = isIdempotentOperation(toolName, declaredIdempotent);
|
|
105
115
|
return (0, error_handler_1.createTimeoutError)(toolName, action, error.timeoutMs, retryable);
|
|
106
116
|
}
|
|
107
117
|
if (error instanceof Error) {
|
|
108
118
|
const timeoutMs = (0, error_handler_1.parseTimeoutError)(error.message);
|
|
109
119
|
if (timeoutMs !== null) {
|
|
110
|
-
const retryable = isIdempotentOperation(toolName);
|
|
120
|
+
const retryable = isIdempotentOperation(toolName, declaredIdempotent);
|
|
111
121
|
return (0, error_handler_1.createTimeoutError)(toolName, action, timeoutMs, retryable);
|
|
112
122
|
}
|
|
113
123
|
}
|
|
@@ -117,7 +127,8 @@ function toStructuredError(error, toolName, toolArgs) {
|
|
|
117
127
|
return (0, error_handler_1.handleGitLabError)({ status: parsed.status, message: parsed.message }, toolName, action, toolArgs);
|
|
118
128
|
}
|
|
119
129
|
function checkUnreachableInstance(toolName, toolArguments, effectiveInstanceUrl, healthMonitor) {
|
|
120
|
-
if (healthMonitor.isInstanceReachable(effectiveInstanceUrl) ||
|
|
130
|
+
if (healthMonitor.isInstanceReachable(effectiveInstanceUrl) ||
|
|
131
|
+
policy_1.CONFIGURATION_TOOLS.has(toolName)) {
|
|
121
132
|
return null;
|
|
122
133
|
}
|
|
123
134
|
const action = toolArguments && typeof toolArguments.action === 'string' ? toolArguments.action : 'unknown';
|
|
@@ -134,35 +145,11 @@ function checkUnreachableInstance(toolName, toolArguments, effectiveInstanceUrl,
|
|
|
134
145
|
}
|
|
135
146
|
const connError = (0, error_handler_1.createConnectionFailedError)(toolName, action, effectiveInstanceUrl, connectionState);
|
|
136
147
|
recordEarlyReturnError(toolName, action, connError.message);
|
|
137
|
-
return
|
|
148
|
+
return (0, tool_result_1.errorToolResult)(connError);
|
|
138
149
|
}
|
|
139
|
-
async function
|
|
140
|
-
if (toolName
|
|
141
|
-
|
|
142
|
-
const action = toolArguments && typeof toolArguments.action === 'string' ? toolArguments.action : undefined;
|
|
143
|
-
if (action !== 'switch_profile')
|
|
144
|
-
return;
|
|
145
|
-
try {
|
|
146
|
-
const { getContextManager } = await Promise.resolve().then(() => __importStar(require('./entities/context/context-manager')));
|
|
147
|
-
const newProfileUrl = await getContextManager().getCurrentProfileUrl();
|
|
148
|
-
if (!newProfileUrl)
|
|
149
|
-
return;
|
|
150
|
-
const normalized = (0, url_1.normalizeInstanceUrl)(newProfileUrl);
|
|
151
|
-
const { getSessionManager } = await Promise.resolve().then(() => __importStar(require('./session-manager')));
|
|
152
|
-
const sessionManager = getSessionManager();
|
|
153
|
-
const pinnedUrl = sessionManager.getSessionInstanceUrl(sessionId);
|
|
154
|
-
if (pinnedUrl && (0, url_1.normalizeInstanceUrl)(pinnedUrl) === normalized)
|
|
155
|
-
return;
|
|
156
|
-
sessionManager.setSessionInstanceUrl(sessionId, normalized);
|
|
157
|
-
}
|
|
158
|
-
catch (err) {
|
|
159
|
-
(0, logger_1.logWarn)('Failed to re-pin session after switch_profile', {
|
|
160
|
-
error: err instanceof Error ? err.message : String(err),
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
async function tryManageContextFastPath(toolName, toolArguments, effectiveInstanceUrl, healthMonitor, sessionId) {
|
|
165
|
-
if (toolName !== 'manage_context' || healthMonitor.isInstanceReachable(effectiveInstanceUrl)) {
|
|
150
|
+
async function tryManageContextFastPath(toolName, toolArguments, effectiveInstanceUrl, healthMonitor, sessionId, requestScopes) {
|
|
151
|
+
if (!policy_1.CONFIGURATION_TOOLS.has(toolName) ||
|
|
152
|
+
healthMonitor.isInstanceReachable(effectiveInstanceUrl)) {
|
|
166
153
|
return null;
|
|
167
154
|
}
|
|
168
155
|
if (config_1.LOG_FORMAT === 'condensed') {
|
|
@@ -173,17 +160,17 @@ async function tryManageContextFastPath(toolName, toolArguments, effectiveInstan
|
|
|
173
160
|
const { RegistryManager } = await Promise.resolve().then(() => __importStar(require('./registry-manager')));
|
|
174
161
|
const registryManager = RegistryManager.getInstance();
|
|
175
162
|
if (registryManager.hasToolHandler(toolName, effectiveInstanceUrl)) {
|
|
176
|
-
const result = await registryManager.executeTool(toolName, toolArguments, effectiveInstanceUrl);
|
|
163
|
+
const result = await registryManager.executeTool(toolName, toolArguments, effectiveInstanceUrl, requestScopes);
|
|
177
164
|
if (result === undefined) {
|
|
178
165
|
return null;
|
|
179
166
|
}
|
|
180
|
-
|
|
181
|
-
return
|
|
167
|
+
healthMonitor.forceReconnect(effectiveInstanceUrl);
|
|
168
|
+
return (0, tool_result_1.formatToolResult)(result, registryManager.getTool(toolName, effectiveInstanceUrl, requestScopes));
|
|
182
169
|
}
|
|
183
170
|
return null;
|
|
184
171
|
}
|
|
185
172
|
async function ensureBootstrapped(ctx) {
|
|
186
|
-
const {
|
|
173
|
+
const { effectiveInstanceUrl, oauthMode, requestScopes, connectionManager, bootstrapState } = ctx;
|
|
187
174
|
bootstrapState.started = true;
|
|
188
175
|
try {
|
|
189
176
|
if (!connectionManager.isConnected(effectiveInstanceUrl)) {
|
|
@@ -194,7 +181,7 @@ async function ensureBootstrapped(ctx) {
|
|
|
194
181
|
}
|
|
195
182
|
connectionManager.getClient(effectiveInstanceUrl);
|
|
196
183
|
if (oauthMode) {
|
|
197
|
-
await connectionManager.ensureIntrospected(effectiveInstanceUrl);
|
|
184
|
+
await connectionManager.ensureIntrospected(effectiveInstanceUrl, requestScopes);
|
|
198
185
|
}
|
|
199
186
|
bootstrapState.complete = true;
|
|
200
187
|
try {
|
|
@@ -221,37 +208,117 @@ async function ensureBootstrapped(ctx) {
|
|
|
221
208
|
return undefined;
|
|
222
209
|
}
|
|
223
210
|
catch (initError) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
derivedState = monitorState;
|
|
239
|
-
}
|
|
240
|
-
else if (errorCategory === 'auth' || errorCategory === 'permanent') {
|
|
241
|
-
derivedState = 'failed';
|
|
211
|
+
return formatBootstrapFailure(ctx, initError);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function bootstrapFailureState(monitorState, category) {
|
|
215
|
+
if (monitorState === 'connecting' || monitorState === 'failed')
|
|
216
|
+
return monitorState;
|
|
217
|
+
return category === 'auth' || category === 'permanent' ? 'failed' : 'disconnected';
|
|
218
|
+
}
|
|
219
|
+
function formatBootstrapFailure(ctx, initError) {
|
|
220
|
+
const { toolName, toolArguments, effectiveInstanceUrl, healthMonitor, isTimedOut } = ctx;
|
|
221
|
+
const errorCategory = initError instanceof Error ? (0, error_handler_1.classifyError)(initError) : 'permanent';
|
|
222
|
+
if (initError instanceof Error) {
|
|
223
|
+
if (!isTimedOut() || errorCategory === 'auth' || errorCategory === 'permanent') {
|
|
224
|
+
healthMonitor.reportError(effectiveInstanceUrl, initError);
|
|
242
225
|
}
|
|
243
|
-
|
|
244
|
-
|
|
226
|
+
}
|
|
227
|
+
(0, logger_1.logError)(`Connection initialization failed: ${initError instanceof Error ? initError.message : String(initError)}`, {
|
|
228
|
+
instanceUrl: effectiveInstanceUrl,
|
|
229
|
+
err: initError instanceof Error ? initError : new Error(String(initError)),
|
|
230
|
+
});
|
|
231
|
+
const action = toolArguments && typeof toolArguments.action === 'string' ? toolArguments.action : 'unknown';
|
|
232
|
+
const monitorState = healthMonitor.getState(effectiveInstanceUrl);
|
|
233
|
+
const derivedState = bootstrapFailureState(monitorState, errorCategory);
|
|
234
|
+
const connError = (0, error_handler_1.createConnectionFailedError)(toolName, action, effectiveInstanceUrl, derivedState);
|
|
235
|
+
if (!isTimedOut()) {
|
|
236
|
+
recordEarlyReturnError(toolName, action, connError.message);
|
|
237
|
+
}
|
|
238
|
+
return (0, tool_auth_1.withReauthChallenge)((0, tool_result_1.errorToolResult)(connError), initError);
|
|
239
|
+
}
|
|
240
|
+
function activeInstanceUrl(oauthEnabled, oauthContextUrl) {
|
|
241
|
+
const raw = oauthEnabled
|
|
242
|
+
? (oauthContextUrl ?? config_1.GITLAB_BASE_URL)
|
|
243
|
+
: (ConnectionManager_1.ConnectionManager.getInstance().getCurrentInstanceUrl() ?? config_1.GITLAB_BASE_URL);
|
|
244
|
+
return (0, url_1.normalizeInstanceUrl)(raw);
|
|
245
|
+
}
|
|
246
|
+
async function withoutRestrictedTools(tools, caller, registryManager) {
|
|
247
|
+
let policy;
|
|
248
|
+
try {
|
|
249
|
+
policy = (await (0, configuration_1.getConfigurationService)().resolve(caller)).policy;
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
(0, logger_1.logWarn)('Could not read the caller settings for the tool list', { err: error });
|
|
253
|
+
return tools;
|
|
254
|
+
}
|
|
255
|
+
const listed = [];
|
|
256
|
+
for (const tool of tools) {
|
|
257
|
+
const inputSchema = (0, policy_1.listedToolSchema)(policy, registryManager.getToolFacts(tool.name), tool.inputSchema);
|
|
258
|
+
if (inputSchema)
|
|
259
|
+
listed.push(inputSchema === tool.inputSchema ? tool : { ...tool, inputSchema });
|
|
260
|
+
}
|
|
261
|
+
return listed;
|
|
262
|
+
}
|
|
263
|
+
async function prepareScopedCall(toolName, args, configured, registryManager) {
|
|
264
|
+
const unscoped = settingsRejection(toolName, args, (0, policy_1.withoutScope)(configured), registryManager);
|
|
265
|
+
if (unscoped || !configured.scopeEnforcer || (0, policy_1.isExemptFromSettings)(toolName))
|
|
266
|
+
return { rejection: unscoped, args, policy: configured };
|
|
267
|
+
const policy = await (0, scope_ids_1.withScopePaths)(configured);
|
|
268
|
+
const selected = (0, scoped_execution_1.parseScopedArguments)(toolName, args);
|
|
269
|
+
const action = typeof args.action === 'string' ? args.action : undefined;
|
|
270
|
+
const declared = selected === args ? registryManager.getDeclaredArguments(toolName, action) : undefined;
|
|
271
|
+
const own = declared
|
|
272
|
+
? Object.fromEntries(Object.entries(selected).filter(([name]) => declared.has(name)))
|
|
273
|
+
: selected;
|
|
274
|
+
return {
|
|
275
|
+
rejection: settingsRejection(toolName, await (0, scope_ids_1.withTargetPaths)(own, undefined, policy.scopeEnforcer), policy, registryManager),
|
|
276
|
+
args: selected,
|
|
277
|
+
policy,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function settingsRejection(toolName, args, policy, registryManager) {
|
|
281
|
+
const reason = (0, policy_1.callRestriction)(policy, registryManager.getToolFacts(toolName), args);
|
|
282
|
+
if (reason === null)
|
|
283
|
+
return null;
|
|
284
|
+
const action = typeof args.action === 'string' ? args.action : undefined;
|
|
285
|
+
const call = action ? `${toolName} ${action}` : toolName;
|
|
286
|
+
const message = `'${call}' is not allowed by the current settings: ` +
|
|
287
|
+
`${reason}. The account settings are changed with update_settings, this session's ` +
|
|
288
|
+
'with manage_context.';
|
|
289
|
+
recordEarlyReturnError(toolName, action, message);
|
|
290
|
+
return (0, tool_result_1.errorToolResult)({ error: message });
|
|
291
|
+
}
|
|
292
|
+
async function executeInScope(registryManager, toolName, requested, policy, instanceUrl, requestScopes) {
|
|
293
|
+
const run = (tool, toolArgs) => requestScopes === undefined
|
|
294
|
+
? registryManager.executeTool(tool, toolArgs, instanceUrl)
|
|
295
|
+
: registryManager.executeTool(tool, toolArgs, instanceUrl, requestScopes);
|
|
296
|
+
return (0, scoped_execution_1.executeScoped)(run, toolName, requested, policy, true);
|
|
297
|
+
}
|
|
298
|
+
function recordCallContext(scopePath, readOnly) {
|
|
299
|
+
const requestTracker = (0, index_1.getRequestTracker)();
|
|
300
|
+
if (scopePath) {
|
|
301
|
+
requestTracker.setContextForCurrentRequest(scopePath);
|
|
302
|
+
}
|
|
303
|
+
requestTracker.setReadOnlyForCurrentRequest(readOnly);
|
|
304
|
+
const currentRequestId = (0, index_1.getCurrentRequestId)();
|
|
305
|
+
if (currentRequestId) {
|
|
306
|
+
const stack = requestTracker.getStack(currentRequestId);
|
|
307
|
+
if (stack?.sessionId) {
|
|
308
|
+
const connectionTracker = (0, index_1.getConnectionTracker)();
|
|
309
|
+
connectionTracker.incrementTools(stack.sessionId);
|
|
245
310
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function throwDispatchError(error, toolName, instanceUrl, healthMonitor, timedOut) {
|
|
314
|
+
if (!timedOut && error instanceof Error) {
|
|
315
|
+
const category = (0, error_handler_1.classifyError)(error);
|
|
316
|
+
if (category === 'transient' || category === 'auth') {
|
|
317
|
+
healthMonitor.reportError(instanceUrl, error);
|
|
249
318
|
}
|
|
250
|
-
return {
|
|
251
|
-
content: [{ type: 'text', text: JSON.stringify(connError, null, 2) }],
|
|
252
|
-
isError: true,
|
|
253
|
-
};
|
|
254
319
|
}
|
|
320
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
321
|
+
throw new Error(`Failed to execute tool '${toolName}': ${errorMessage}`, { cause: error });
|
|
255
322
|
}
|
|
256
323
|
let healthMonitorStartup = null;
|
|
257
324
|
let stateChangeRegistered = false;
|
|
@@ -312,6 +379,39 @@ async function setupHandlers(server) {
|
|
|
312
379
|
else {
|
|
313
380
|
(0, logger_1.logInfo)('Skipping connection initialization - no authentication configured');
|
|
314
381
|
}
|
|
382
|
+
server.setRequestHandler(types_js_1.ListResourcesRequestSchema, () => {
|
|
383
|
+
const rejection = (0, tool_auth_1.resourceScopeRejection)();
|
|
384
|
+
if (rejection)
|
|
385
|
+
throw rejection;
|
|
386
|
+
return {
|
|
387
|
+
resources: [
|
|
388
|
+
{
|
|
389
|
+
uri: settings_panel_1.SETTINGS_PANEL_URI,
|
|
390
|
+
name: 'GitLab connection panel',
|
|
391
|
+
mimeType: mcp_apps_1.MCP_APP_MIME_TYPE,
|
|
392
|
+
_meta: settings_panel_1.SETTINGS_PANEL_RESOURCE_META,
|
|
393
|
+
},
|
|
394
|
+
],
|
|
395
|
+
};
|
|
396
|
+
});
|
|
397
|
+
server.setRequestHandler(types_js_1.ReadResourceRequestSchema, (request) => {
|
|
398
|
+
const rejection = (0, tool_auth_1.resourceScopeRejection)();
|
|
399
|
+
if (rejection)
|
|
400
|
+
throw rejection;
|
|
401
|
+
if (request.params.uri !== settings_panel_1.SETTINGS_PANEL_URI) {
|
|
402
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Unknown resource: ${request.params.uri}`);
|
|
403
|
+
}
|
|
404
|
+
return {
|
|
405
|
+
contents: [
|
|
406
|
+
{
|
|
407
|
+
uri: settings_panel_1.SETTINGS_PANEL_URI,
|
|
408
|
+
mimeType: mcp_apps_1.MCP_APP_MIME_TYPE,
|
|
409
|
+
text: (0, settings_panel_1.settingsPanelHtml)(),
|
|
410
|
+
_meta: settings_panel_1.SETTINGS_PANEL_RESOURCE_META,
|
|
411
|
+
},
|
|
412
|
+
],
|
|
413
|
+
};
|
|
414
|
+
});
|
|
315
415
|
server.setRequestHandler(types_js_1.ListToolsRequestSchema, async (_request, extra) => {
|
|
316
416
|
(0, logger_1.logInfo)('ListToolsRequest received');
|
|
317
417
|
const { getSessionManager: getSessionMgr } = await Promise.resolve().then(() => __importStar(require('./session-manager')));
|
|
@@ -322,7 +422,16 @@ async function setupHandlers(server) {
|
|
|
322
422
|
: undefined;
|
|
323
423
|
const { RegistryManager } = await Promise.resolve().then(() => __importStar(require('./registry-manager')));
|
|
324
424
|
const registryManager = RegistryManager.getInstance();
|
|
325
|
-
const
|
|
425
|
+
const mode = (0, schema_utils_1.getSchemaMode)(server.getClientVersion()?.name);
|
|
426
|
+
const { getTokenContext: getCatalogContext, isOAuthEnabled: isCatalogOAuth, getGitLabApiUrlFromContext: getCatalogUrl, } = await Promise.resolve().then(() => __importStar(require('./oauth/index')));
|
|
427
|
+
const scopes = getCatalogContext()?.gitlabScopes;
|
|
428
|
+
const securitySchemes = isCatalogOAuth() ? tool_auth_1.OAUTH_SECURITY_SCHEMES : undefined;
|
|
429
|
+
const catalog = scopes === undefined
|
|
430
|
+
? registryManager.getAllToolDefinitions(sessionInstanceUrl, mode)
|
|
431
|
+
: registryManager.getAllToolDefinitions(sessionInstanceUrl, mode, scopes);
|
|
432
|
+
const callerInstanceUrl = sessionInstanceUrl ??
|
|
433
|
+
activeInstanceUrl(isCatalogOAuth(), isCatalogOAuth() ? getCatalogUrl() : undefined);
|
|
434
|
+
const tools = await withoutRestrictedTools(catalog, (0, configuration_1.resolveCaller)(listToolsSessionId, callerInstanceUrl), registryManager);
|
|
326
435
|
(0, logger_1.logInfo)('Returning tools list', { toolCount: tools.length });
|
|
327
436
|
function resolveRefs(schema, rootSchema) {
|
|
328
437
|
if (!schema || typeof schema !== 'object')
|
|
@@ -378,25 +487,39 @@ async function setupHandlers(server) {
|
|
|
378
487
|
delete cleanedSchema.$schema;
|
|
379
488
|
inputSchema = cleanedSchema;
|
|
380
489
|
}
|
|
381
|
-
|
|
490
|
+
if (!securitySchemes || tool._meta?.securitySchemes !== undefined) {
|
|
491
|
+
return { ...tool, inputSchema };
|
|
492
|
+
}
|
|
493
|
+
const schemes = tool._meta?.ui ? tool_auth_1.APP_PANEL_SECURITY_SCHEMES : securitySchemes;
|
|
494
|
+
return {
|
|
495
|
+
...tool,
|
|
496
|
+
inputSchema,
|
|
497
|
+
securitySchemes: schemes,
|
|
498
|
+
_meta: { ...tool._meta, securitySchemes: schemes },
|
|
499
|
+
};
|
|
382
500
|
});
|
|
383
501
|
return {
|
|
384
502
|
tools: modifiedTools,
|
|
385
503
|
};
|
|
386
504
|
});
|
|
387
505
|
server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request, extra) => {
|
|
388
|
-
const { getGitLabApiUrlFromContext: getUrlFromCtx, isOAuthEnabled } = await Promise.resolve().then(() => __importStar(require('./oauth/index')));
|
|
506
|
+
const { getGitLabApiUrlFromContext: getUrlFromCtx, isOAuthEnabled, getTokenContext: getCallContext, } = await Promise.resolve().then(() => __importStar(require('./oauth/index')));
|
|
389
507
|
const oauthEnabled = isOAuthEnabled();
|
|
508
|
+
if (oauthEnabled) {
|
|
509
|
+
const rejection = (0, tool_auth_1.toolScopeRejection)();
|
|
510
|
+
if (rejection)
|
|
511
|
+
return rejection;
|
|
512
|
+
}
|
|
513
|
+
const requestScopes = oauthEnabled ? getCallContext()?.gitlabScopes : undefined;
|
|
514
|
+
let declaredIdempotent;
|
|
390
515
|
const oauthContextUrl = oauthEnabled ? getUrlFromCtx() : undefined;
|
|
391
|
-
const
|
|
392
|
-
? (oauthContextUrl ?? config_1.GITLAB_BASE_URL)
|
|
393
|
-
: (ConnectionManager_1.ConnectionManager.getInstance().getCurrentInstanceUrl() ?? config_1.GITLAB_BASE_URL);
|
|
394
|
-
const requestInstanceUrl = (0, url_1.normalizeInstanceUrl)(rawInstanceUrl);
|
|
516
|
+
const requestInstanceUrl = activeInstanceUrl(oauthEnabled, oauthContextUrl);
|
|
395
517
|
const callSessionId = extra?.sessionId;
|
|
396
518
|
if (callSessionId && (!oauthEnabled || oauthContextUrl !== undefined)) {
|
|
397
519
|
const { getSessionManager: getSessionMgrForCall } = await Promise.resolve().then(() => __importStar(require('./session-manager')));
|
|
398
520
|
getSessionMgrForCall().setSessionInstanceUrl(callSessionId, requestInstanceUrl);
|
|
399
521
|
}
|
|
522
|
+
const caller = (0, configuration_1.resolveCaller)(callSessionId, requestInstanceUrl);
|
|
400
523
|
let timedOut = false;
|
|
401
524
|
const bootstrapState = { started: false, complete: false };
|
|
402
525
|
const HANDLER_TIMEOUT_SYMBOL = Symbol('handler_timeout');
|
|
@@ -408,9 +531,6 @@ async function setupHandlers(server) {
|
|
|
408
531
|
}, config_1.HANDLER_TIMEOUT_MS);
|
|
409
532
|
});
|
|
410
533
|
const handlerWork = async () => {
|
|
411
|
-
if (!request.params.arguments) {
|
|
412
|
-
throw new Error('Arguments are required');
|
|
413
|
-
}
|
|
414
534
|
if (config_1.LOG_FORMAT === 'verbose') {
|
|
415
535
|
(0, logger_1.logInfo)(`Tool called: ${request.params.name}`);
|
|
416
536
|
}
|
|
@@ -425,11 +545,17 @@ async function setupHandlers(server) {
|
|
|
425
545
|
const connectionManager = ConnectionManager_1.ConnectionManager.getInstance();
|
|
426
546
|
const healthMonitor = HealthMonitor_1.HealthMonitor.getInstance();
|
|
427
547
|
const toolName = request.params.name;
|
|
428
|
-
|
|
548
|
+
let toolArguments = request.params.arguments;
|
|
549
|
+
const { RegistryManager: CallRegistry } = await Promise.resolve().then(() => __importStar(require('./registry-manager')));
|
|
550
|
+
const configuration = await (0, configuration_1.getConfigurationService)().resolve(caller);
|
|
551
|
+
const prepared = await prepareScopedCall(toolName, toolArguments ?? {}, configuration.policy, CallRegistry.getInstance());
|
|
552
|
+
if (prepared.rejection)
|
|
553
|
+
return prepared.rejection;
|
|
554
|
+
toolArguments = prepared.args;
|
|
429
555
|
const unreachableResult = checkUnreachableInstance(toolName, toolArguments, effectiveInstanceUrl, healthMonitor);
|
|
430
556
|
if (unreachableResult)
|
|
431
557
|
return unreachableResult;
|
|
432
|
-
const fastPathResult = await tryManageContextFastPath(toolName, toolArguments, effectiveInstanceUrl, healthMonitor, callSessionId);
|
|
558
|
+
const fastPathResult = await tryManageContextFastPath(toolName, toolArguments, effectiveInstanceUrl, healthMonitor, callSessionId, requestScopes);
|
|
433
559
|
if (fastPathResult)
|
|
434
560
|
return fastPathResult;
|
|
435
561
|
const oauthMode = isOAuthEnabled();
|
|
@@ -438,6 +564,7 @@ async function setupHandlers(server) {
|
|
|
438
564
|
toolArguments,
|
|
439
565
|
effectiveInstanceUrl,
|
|
440
566
|
oauthMode,
|
|
567
|
+
requestScopes,
|
|
441
568
|
connectionManager,
|
|
442
569
|
healthMonitor,
|
|
443
570
|
isTimedOut: () => timedOut,
|
|
@@ -450,25 +577,13 @@ async function setupHandlers(server) {
|
|
|
450
577
|
if (config_1.LOG_FORMAT === 'condensed') {
|
|
451
578
|
const requestTracker = (0, index_1.getRequestTracker)();
|
|
452
579
|
requestTracker.setToolForCurrentRequest(toolName, action);
|
|
453
|
-
|
|
454
|
-
const contextManager = getContextManager();
|
|
455
|
-
const sessionContext = contextManager.getContext();
|
|
456
|
-
if (sessionContext.scope?.path) {
|
|
457
|
-
requestTracker.setContextForCurrentRequest(sessionContext.scope.path);
|
|
458
|
-
}
|
|
459
|
-
requestTracker.setReadOnlyForCurrentRequest(sessionContext.readOnly);
|
|
460
|
-
const currentRequestId = (0, index_1.getCurrentRequestId)();
|
|
461
|
-
if (currentRequestId) {
|
|
462
|
-
const stack = requestTracker.getStack(currentRequestId);
|
|
463
|
-
if (stack?.sessionId) {
|
|
464
|
-
const connectionTracker = (0, index_1.getConnectionTracker)();
|
|
465
|
-
connectionTracker.incrementTools(stack.sessionId);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
580
|
+
recordCallContext((0, policy_1.scopeLabel)(configuration.policy.scope), config_1.GITLAB_READ_ONLY_MODE || configuration.policy.readOnly);
|
|
468
581
|
}
|
|
469
582
|
try {
|
|
470
583
|
const { RegistryManager } = await Promise.resolve().then(() => __importStar(require('./registry-manager')));
|
|
471
584
|
const registryManager = RegistryManager.getInstance();
|
|
585
|
+
const definition = registryManager.getTool(toolName, effectiveInstanceUrl, requestScopes);
|
|
586
|
+
declaredIdempotent = definition?.idempotent ?? definition?.annotations?.idempotentHint;
|
|
472
587
|
if (!registryManager.hasToolHandler(toolName, effectiveInstanceUrl)) {
|
|
473
588
|
throw new Error(`Tool '${toolName}' is not available or has been filtered out`);
|
|
474
589
|
}
|
|
@@ -484,42 +599,27 @@ async function setupHandlers(server) {
|
|
|
484
599
|
tool: toolName,
|
|
485
600
|
});
|
|
486
601
|
}
|
|
487
|
-
const result = await registryManager
|
|
602
|
+
const result = await executeInScope(registryManager, toolName, toolArguments, prepared.policy, effectiveInstanceUrl, requestScopes);
|
|
488
603
|
if (result === undefined) {
|
|
489
604
|
throw new Error(`Tool '${toolName}' is not available or has been filtered out`);
|
|
490
605
|
}
|
|
491
|
-
await resyncSessionAfterSwitchProfile(toolName, request.params.arguments, callSessionId);
|
|
492
606
|
if (!timedOut) {
|
|
493
607
|
healthMonitor.reportSuccess(effectiveInstanceUrl);
|
|
494
608
|
}
|
|
495
|
-
return
|
|
496
|
-
content: [
|
|
497
|
-
{
|
|
498
|
-
type: 'text',
|
|
499
|
-
text: JSON.stringify(result, null, 2),
|
|
500
|
-
},
|
|
501
|
-
],
|
|
502
|
-
};
|
|
609
|
+
return (0, tool_result_1.formatToolResult)(result, definition);
|
|
503
610
|
}
|
|
504
611
|
catch (error) {
|
|
505
|
-
|
|
506
|
-
const category = (0, error_handler_1.classifyError)(error);
|
|
507
|
-
if (category === 'transient' || category === 'auth') {
|
|
508
|
-
healthMonitor.reportError(effectiveInstanceUrl, error);
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
512
|
-
throw new Error(`Failed to execute tool '${toolName}': ${errorMessage}`, { cause: error });
|
|
612
|
+
throwDispatchError(error, toolName, effectiveInstanceUrl, healthMonitor, timedOut);
|
|
513
613
|
}
|
|
514
614
|
};
|
|
515
615
|
try {
|
|
516
|
-
const result = await Promise.race([
|
|
616
|
+
const result = await Promise.race([(0, configuration_1.runWithCaller)(caller, handlerWork), timeoutPromise]);
|
|
517
617
|
if (result === HANDLER_TIMEOUT_SYMBOL) {
|
|
518
618
|
const toolName = request.params.name;
|
|
519
619
|
const action = request.params.arguments && typeof request.params.arguments.action === 'string'
|
|
520
620
|
? request.params.arguments.action
|
|
521
621
|
: 'unknown';
|
|
522
|
-
const retryable = isIdempotentOperation(toolName);
|
|
622
|
+
const retryable = isIdempotentOperation(toolName, declaredIdempotent);
|
|
523
623
|
const timeoutError = (0, error_handler_1.createTimeoutError)(toolName, action, config_1.HANDLER_TIMEOUT_MS, retryable);
|
|
524
624
|
(0, logger_1.logError)(`Handler timeout: tool '${toolName}' timed out after ${config_1.HANDLER_TIMEOUT_MS}ms`);
|
|
525
625
|
if (bootstrapState.started && !bootstrapState.complete) {
|
|
@@ -527,15 +627,7 @@ async function setupHandlers(server) {
|
|
|
527
627
|
ConnectionManager_1.ConnectionManager.getInstance().clearInflight(requestInstanceUrl);
|
|
528
628
|
}
|
|
529
629
|
recordEarlyReturnError(toolName, action, timeoutError.message);
|
|
530
|
-
return
|
|
531
|
-
content: [
|
|
532
|
-
{
|
|
533
|
-
type: 'text',
|
|
534
|
-
text: JSON.stringify(timeoutError, null, 2),
|
|
535
|
-
},
|
|
536
|
-
],
|
|
537
|
-
isError: true,
|
|
538
|
-
};
|
|
630
|
+
return (0, tool_result_1.errorToolResult)(timeoutError);
|
|
539
631
|
}
|
|
540
632
|
return result;
|
|
541
633
|
}
|
|
@@ -554,29 +646,13 @@ async function setupHandlers(server) {
|
|
|
554
646
|
}
|
|
555
647
|
const toolName = request.params.name;
|
|
556
648
|
const toolArgs = request.params.arguments;
|
|
557
|
-
const structuredError = toStructuredError(error, toolName, toolArgs);
|
|
649
|
+
const structuredError = toStructuredError(error, toolName, toolArgs, declaredIdempotent);
|
|
558
650
|
if (structuredError) {
|
|
559
651
|
(0, logger_1.logDebug)('Returning structured error response', { structuredError });
|
|
560
|
-
return
|
|
561
|
-
content: [
|
|
562
|
-
{
|
|
563
|
-
type: 'text',
|
|
564
|
-
text: JSON.stringify(structuredError, null, 2),
|
|
565
|
-
},
|
|
566
|
-
],
|
|
567
|
-
isError: true,
|
|
568
|
-
};
|
|
652
|
+
return (0, tool_auth_1.withReauthChallenge)((0, tool_result_1.errorToolResult)(structuredError), error);
|
|
569
653
|
}
|
|
570
654
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
571
|
-
return {
|
|
572
|
-
content: [
|
|
573
|
-
{
|
|
574
|
-
type: 'text',
|
|
575
|
-
text: JSON.stringify({ error: errorMessage }, null, 2),
|
|
576
|
-
},
|
|
577
|
-
],
|
|
578
|
-
isError: true,
|
|
579
|
-
};
|
|
655
|
+
return (0, tool_auth_1.withReauthChallenge)((0, tool_result_1.errorToolResult)({ error: errorMessage }), error);
|
|
580
656
|
}
|
|
581
657
|
finally {
|
|
582
658
|
clearTimeout(handlerTimeoutId);
|