@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.
Files changed (285) hide show
  1. package/README.md +6 -6
  2. package/README.md.in +1 -1
  3. package/dist/src/channel-gateway/format.js +7 -1
  4. package/dist/src/channel-gateway/format.js.map +1 -1
  5. package/dist/src/channel-gateway/forwarding.d.ts +3 -0
  6. package/dist/src/channel-gateway/forwarding.js +8 -1
  7. package/dist/src/channel-gateway/forwarding.js.map +1 -1
  8. package/dist/src/channel-gateway/gateway.d.ts +7 -0
  9. package/dist/src/channel-gateway/gateway.js +80 -16
  10. package/dist/src/channel-gateway/gateway.js.map +1 -1
  11. package/dist/src/cli/docker/container-runtime.d.ts +1 -0
  12. package/dist/src/cli/docker/container-runtime.js +37 -5
  13. package/dist/src/cli/docker/container-runtime.js.map +1 -1
  14. package/dist/src/cli/docker/docker-command.js +11 -2
  15. package/dist/src/cli/docker/docker-command.js.map +1 -1
  16. package/dist/src/cli/docker/docker-utils.d.ts +1 -0
  17. package/dist/src/cli/docker/docker-utils.js +137 -27
  18. package/dist/src/cli/docker/docker-utils.js.map +1 -1
  19. package/dist/src/cli/docker/oauth-issuer-prompt.d.ts +2 -0
  20. package/dist/src/cli/docker/oauth-issuer-prompt.js +47 -0
  21. package/dist/src/cli/docker/oauth-issuer-prompt.js.map +1 -0
  22. package/dist/src/cli/docker/types.d.ts +18 -4
  23. package/dist/src/cli/docker/types.js.map +1 -1
  24. package/dist/src/cli/list-tools.js +14 -35
  25. package/dist/src/cli/list-tools.js.map +1 -1
  26. package/dist/src/cli/setup/flows/server-setup.js +15 -0
  27. package/dist/src/cli/setup/flows/server-setup.js.map +1 -1
  28. package/dist/src/config/instances-loader.js +17 -3
  29. package/dist/src/config/instances-loader.js.map +1 -1
  30. package/dist/src/config/instances-schema.d.ts +6 -3
  31. package/dist/src/config/instances-schema.js +7 -6
  32. package/dist/src/config/instances-schema.js.map +1 -1
  33. package/dist/src/config.js.map +1 -1
  34. package/dist/src/configuration/caller.d.ts +10 -0
  35. package/dist/src/configuration/caller.js +39 -0
  36. package/dist/src/configuration/caller.js.map +1 -0
  37. package/dist/src/configuration/composed-feeds.d.ts +31 -0
  38. package/dist/src/configuration/composed-feeds.js +698 -0
  39. package/dist/src/configuration/composed-feeds.js.map +1 -0
  40. package/dist/src/configuration/composed-listings.d.ts +14 -0
  41. package/dist/src/configuration/composed-listings.js +157 -0
  42. package/dist/src/configuration/composed-listings.js.map +1 -0
  43. package/dist/src/configuration/groups.d.ts +8 -0
  44. package/dist/src/configuration/groups.js +39 -0
  45. package/dist/src/configuration/groups.js.map +1 -0
  46. package/dist/src/configuration/index.d.ts +6 -0
  47. package/dist/src/configuration/index.js +87 -0
  48. package/dist/src/configuration/index.js.map +1 -0
  49. package/dist/src/configuration/policy.d.ts +34 -0
  50. package/dist/src/configuration/policy.js +122 -0
  51. package/dist/src/configuration/policy.js.map +1 -0
  52. package/dist/src/configuration/scope-ids.d.ts +7 -0
  53. package/dist/src/configuration/scope-ids.js +78 -0
  54. package/dist/src/configuration/scope-ids.js.map +1 -0
  55. package/dist/src/configuration/scope-projects.d.ts +5 -0
  56. package/dist/src/configuration/scope-projects.js +76 -0
  57. package/dist/src/configuration/scope-projects.js.map +1 -0
  58. package/dist/src/configuration/scope-targets.d.ts +26 -0
  59. package/dist/src/configuration/scope-targets.js +307 -0
  60. package/dist/src/configuration/scope-targets.js.map +1 -0
  61. package/dist/src/configuration/scoped-execution.d.ts +6 -0
  62. package/dist/src/configuration/scoped-execution.js +577 -0
  63. package/dist/src/configuration/scoped-execution.js.map +1 -0
  64. package/dist/src/configuration/scoped-feeds.d.ts +22 -0
  65. package/dist/src/configuration/scoped-feeds.js +136 -0
  66. package/dist/src/configuration/scoped-feeds.js.map +1 -0
  67. package/dist/src/configuration/service.d.ts +53 -0
  68. package/dist/src/configuration/service.js +186 -0
  69. package/dist/src/configuration/service.js.map +1 -0
  70. package/dist/src/configuration/settings-store.d.ts +20 -0
  71. package/dist/src/configuration/settings-store.js +228 -0
  72. package/dist/src/configuration/settings-store.js.map +1 -0
  73. package/dist/src/configuration/types.d.ts +30 -0
  74. package/dist/src/configuration/types.js +20 -0
  75. package/dist/src/configuration/types.js.map +1 -0
  76. package/dist/src/contracts/storage.d.ts +2 -1
  77. package/dist/src/dashboard/html-template.js +8 -15
  78. package/dist/src/dashboard/html-template.js.map +1 -1
  79. package/dist/src/dashboard/metrics.d.ts +1 -1
  80. package/dist/src/entities/context/connection-check.d.ts +64 -0
  81. package/dist/src/entities/context/connection-check.js +117 -0
  82. package/dist/src/entities/context/connection-check.js.map +1 -0
  83. package/dist/src/entities/context/context-manager.d.ts +10 -22
  84. package/dist/src/entities/context/context-manager.js +108 -207
  85. package/dist/src/entities/context/context-manager.js.map +1 -1
  86. package/dist/src/entities/context/handlers.d.ts +3 -5
  87. package/dist/src/entities/context/handlers.js +2 -14
  88. package/dist/src/entities/context/handlers.js.map +1 -1
  89. package/dist/src/entities/context/output-schema.d.ts +272 -0
  90. package/dist/src/entities/context/output-schema.js +182 -0
  91. package/dist/src/entities/context/output-schema.js.map +1 -0
  92. package/dist/src/entities/context/profile.d.ts +29 -0
  93. package/dist/src/entities/context/profile.js +72 -0
  94. package/dist/src/entities/context/profile.js.map +1 -0
  95. package/dist/src/entities/context/registry.js +140 -3
  96. package/dist/src/entities/context/registry.js.map +1 -1
  97. package/dist/src/entities/context/schema.d.ts +6 -14
  98. package/dist/src/entities/context/schema.js +6 -13
  99. package/dist/src/entities/context/schema.js.map +1 -1
  100. package/dist/src/entities/context/scope-search.d.ts +49 -0
  101. package/dist/src/entities/context/scope-search.js +71 -0
  102. package/dist/src/entities/context/scope-search.js.map +1 -0
  103. package/dist/src/entities/context/settings-panel.d.ts +13 -0
  104. package/dist/src/entities/context/settings-panel.js +508 -0
  105. package/dist/src/entities/context/settings-panel.js.map +1 -0
  106. package/dist/src/entities/context/settings.d.ts +78 -0
  107. package/dist/src/entities/context/settings.js +239 -0
  108. package/dist/src/entities/context/settings.js.map +1 -0
  109. package/dist/src/entities/context/types.d.ts +3 -4
  110. package/dist/src/entities/context/whoami.js +39 -31
  111. package/dist/src/entities/context/whoami.js.map +1 -1
  112. package/dist/src/entities/core/registry.js +34 -33
  113. package/dist/src/entities/core/registry.js.map +1 -1
  114. package/dist/src/entities/environments/schema-readonly.d.ts +3 -3
  115. package/dist/src/entities/files/registry.js +3 -2
  116. package/dist/src/entities/files/registry.js.map +1 -1
  117. package/dist/src/entities/iterations/registry.js +3 -2
  118. package/dist/src/entities/iterations/registry.js.map +1 -1
  119. package/dist/src/entities/mrs/registry.js +11 -5
  120. package/dist/src/entities/mrs/registry.js.map +1 -1
  121. package/dist/src/entities/mrs/schema-readonly.d.ts +8 -2
  122. package/dist/src/entities/mrs/schema-readonly.js +31 -3
  123. package/dist/src/entities/mrs/schema-readonly.js.map +1 -1
  124. package/dist/src/entities/pipelines/registry.js +3 -2
  125. package/dist/src/entities/pipelines/registry.js.map +1 -1
  126. package/dist/src/entities/pipelines/schema-readonly.d.ts +3 -3
  127. package/dist/src/entities/runners/project-access.d.ts +14 -0
  128. package/dist/src/entities/runners/project-access.js +64 -0
  129. package/dist/src/entities/runners/project-access.js.map +1 -0
  130. package/dist/src/entities/runners/registry.js +54 -26
  131. package/dist/src/entities/runners/registry.js.map +1 -1
  132. package/dist/src/entities/search/schema-readonly.d.ts +28 -28
  133. package/dist/src/graphql/runners.d.ts +26 -1
  134. package/dist/src/graphql/runners.js +43 -6
  135. package/dist/src/graphql/runners.js.map +1 -1
  136. package/dist/src/graphql/vulnerabilities.d.ts +3 -0
  137. package/dist/src/graphql/vulnerabilities.js +1 -0
  138. package/dist/src/graphql/vulnerabilities.js.map +1 -1
  139. package/dist/src/handlers.js +218 -142
  140. package/dist/src/handlers.js.map +1 -1
  141. package/dist/src/logger.d.ts +3 -2
  142. package/dist/src/mcp-apps.d.ts +6 -0
  143. package/dist/src/mcp-apps.js +8 -0
  144. package/dist/src/mcp-apps.js.map +1 -0
  145. package/dist/src/middleware/mcp-auth-routes.d.ts +3 -0
  146. package/dist/src/middleware/mcp-auth-routes.js +9 -0
  147. package/dist/src/middleware/mcp-auth-routes.js.map +1 -0
  148. package/dist/src/middleware/oauth-auth.js +83 -23
  149. package/dist/src/middleware/oauth-auth.js.map +1 -1
  150. package/dist/src/middleware/rate-limiter.js +11 -10
  151. package/dist/src/middleware/rate-limiter.js.map +1 -1
  152. package/dist/src/oauth/authorization-response.d.ts +1 -0
  153. package/dist/src/oauth/authorization-response.js +14 -0
  154. package/dist/src/oauth/authorization-response.js.map +1 -0
  155. package/dist/src/oauth/client-auth.d.ts +16 -0
  156. package/dist/src/oauth/client-auth.js +73 -0
  157. package/dist/src/oauth/client-auth.js.map +1 -0
  158. package/dist/src/oauth/config.d.ts +2 -0
  159. package/dist/src/oauth/config.js +37 -0
  160. package/dist/src/oauth/config.js.map +1 -1
  161. package/dist/src/oauth/endpoints/authorize.d.ts +1 -0
  162. package/dist/src/oauth/endpoints/authorize.js +361 -102
  163. package/dist/src/oauth/endpoints/authorize.js.map +1 -1
  164. package/dist/src/oauth/endpoints/callback.js +78 -41
  165. package/dist/src/oauth/endpoints/callback.js.map +1 -1
  166. package/dist/src/oauth/endpoints/index.d.ts +1 -0
  167. package/dist/src/oauth/endpoints/index.js +3 -1
  168. package/dist/src/oauth/endpoints/index.js.map +1 -1
  169. package/dist/src/oauth/endpoints/metadata.d.ts +1 -1
  170. package/dist/src/oauth/endpoints/metadata.js +23 -8
  171. package/dist/src/oauth/endpoints/metadata.js.map +1 -1
  172. package/dist/src/oauth/endpoints/register.d.ts +3 -2
  173. package/dist/src/oauth/endpoints/register.js +70 -19
  174. package/dist/src/oauth/endpoints/register.js.map +1 -1
  175. package/dist/src/oauth/endpoints/revoke.d.ts +2 -0
  176. package/dist/src/oauth/endpoints/revoke.js +97 -0
  177. package/dist/src/oauth/endpoints/revoke.js.map +1 -0
  178. package/dist/src/oauth/endpoints/token.js +136 -62
  179. package/dist/src/oauth/endpoints/token.js.map +1 -1
  180. package/dist/src/oauth/gitlab-device-flow.d.ts +27 -8
  181. package/dist/src/oauth/gitlab-device-flow.js +119 -57
  182. package/dist/src/oauth/gitlab-device-flow.js.map +1 -1
  183. package/dist/src/oauth/gitlab-request-bound.d.ts +1 -0
  184. package/dist/src/oauth/gitlab-request-bound.js +6 -0
  185. package/dist/src/oauth/gitlab-request-bound.js.map +1 -0
  186. package/dist/src/oauth/gitlab-token-refresh.d.ts +6 -0
  187. package/dist/src/oauth/gitlab-token-refresh.js +130 -0
  188. package/dist/src/oauth/gitlab-token-refresh.js.map +1 -0
  189. package/dist/src/oauth/granted-scopes.d.ts +1 -0
  190. package/dist/src/oauth/granted-scopes.js +7 -0
  191. package/dist/src/oauth/granted-scopes.js.map +1 -0
  192. package/dist/src/oauth/index.d.ts +2 -2
  193. package/dist/src/oauth/index.js +4 -2
  194. package/dist/src/oauth/index.js.map +1 -1
  195. package/dist/src/oauth/instance-app.d.ts +4 -0
  196. package/dist/src/oauth/instance-app.js +45 -0
  197. package/dist/src/oauth/instance-app.js.map +1 -0
  198. package/dist/src/oauth/issued-tokens.d.ts +1 -0
  199. package/dist/src/oauth/issued-tokens.js +24 -0
  200. package/dist/src/oauth/issued-tokens.js.map +1 -0
  201. package/dist/src/oauth/oauth-app.d.ts +9 -0
  202. package/dist/src/oauth/oauth-app.js +14 -0
  203. package/dist/src/oauth/oauth-app.js.map +1 -0
  204. package/dist/src/oauth/request-params.d.ts +1 -0
  205. package/dist/src/oauth/request-params.js +17 -0
  206. package/dist/src/oauth/request-params.js.map +1 -0
  207. package/dist/src/oauth/resource.d.ts +12 -0
  208. package/dist/src/oauth/resource.js +66 -0
  209. package/dist/src/oauth/resource.js.map +1 -0
  210. package/dist/src/oauth/routes.d.ts +2 -0
  211. package/dist/src/oauth/routes.js +31 -0
  212. package/dist/src/oauth/routes.js.map +1 -0
  213. package/dist/src/oauth/session-store.d.ts +44 -36
  214. package/dist/src/oauth/session-store.js +125 -253
  215. package/dist/src/oauth/session-store.js.map +1 -1
  216. package/dist/src/oauth/storage/factory.js +1 -1
  217. package/dist/src/oauth/storage/factory.js.map +1 -1
  218. package/dist/src/oauth/storage/file.d.ts +23 -1
  219. package/dist/src/oauth/storage/file.js +168 -36
  220. package/dist/src/oauth/storage/file.js.map +1 -1
  221. package/dist/src/oauth/storage/memory.d.ts +23 -1
  222. package/dist/src/oauth/storage/memory.js +120 -22
  223. package/dist/src/oauth/storage/memory.js.map +1 -1
  224. package/dist/src/oauth/storage/types.d.ts +17 -1
  225. package/dist/src/oauth/storage/types.js.map +1 -1
  226. package/dist/src/oauth/tool-auth.d.ts +12 -0
  227. package/dist/src/oauth/tool-auth.js +108 -0
  228. package/dist/src/oauth/tool-auth.js.map +1 -0
  229. package/dist/src/oauth/types.d.ts +30 -0
  230. package/dist/src/profiles/scope-enforcer.d.ts +8 -0
  231. package/dist/src/profiles/scope-enforcer.js +86 -24
  232. package/dist/src/profiles/scope-enforcer.js.map +1 -1
  233. package/dist/src/profiles/types.js +4 -1
  234. package/dist/src/profiles/types.js.map +1 -1
  235. package/dist/src/registry-manager.d.ts +16 -4
  236. package/dist/src/registry-manager.js +115 -33
  237. package/dist/src/registry-manager.js.map +1 -1
  238. package/dist/src/server.js +66 -39
  239. package/dist/src/server.js.map +1 -1
  240. package/dist/src/services/ConnectionManager.d.ts +2 -1
  241. package/dist/src/services/ConnectionManager.js +26 -19
  242. package/dist/src/services/ConnectionManager.js.map +1 -1
  243. package/dist/src/services/TokenScopeDetector.d.ts +5 -1
  244. package/dist/src/services/TokenScopeDetector.js +19 -0
  245. package/dist/src/services/TokenScopeDetector.js.map +1 -1
  246. package/dist/src/session-manager.d.ts +3 -1
  247. package/dist/src/session-manager.js +35 -10
  248. package/dist/src/session-manager.js.map +1 -1
  249. package/dist/src/types.d.ts +3 -2
  250. package/dist/src/types.js.map +1 -1
  251. package/dist/src/utils/bounded-map.d.ts +1 -0
  252. package/dist/src/utils/bounded-map.js +23 -0
  253. package/dist/src/utils/bounded-map.js.map +1 -0
  254. package/dist/src/utils/fetch.d.ts +0 -1
  255. package/dist/src/utils/fetch.js +2 -12
  256. package/dist/src/utils/fetch.js.map +1 -1
  257. package/dist/src/utils/gitlab-api.js +2 -1
  258. package/dist/src/utils/gitlab-api.js.map +1 -1
  259. package/dist/src/utils/gitlab-base-url.d.ts +2 -0
  260. package/dist/src/utils/gitlab-base-url.js +30 -0
  261. package/dist/src/utils/gitlab-base-url.js.map +1 -0
  262. package/dist/src/utils/html.d.ts +1 -0
  263. package/dist/src/utils/html.js +12 -0
  264. package/dist/src/utils/html.js.map +1 -0
  265. package/dist/src/utils/namespace.d.ts +1 -0
  266. package/dist/src/utils/namespace.js +72 -24
  267. package/dist/src/utils/namespace.js.map +1 -1
  268. package/dist/src/utils/schema-utils.d.ts +5 -3
  269. package/dist/src/utils/schema-utils.js +50 -22
  270. package/dist/src/utils/schema-utils.js.map +1 -1
  271. package/dist/src/utils/smart-user-search.js +2 -1
  272. package/dist/src/utils/smart-user-search.js.map +1 -1
  273. package/dist/src/utils/sync-directory.d.ts +1 -0
  274. package/dist/src/utils/sync-directory.js +49 -0
  275. package/dist/src/utils/sync-directory.js.map +1 -0
  276. package/dist/src/utils/tool-result.d.ts +4 -0
  277. package/dist/src/utils/tool-result.js +41 -0
  278. package/dist/src/utils/tool-result.js.map +1 -0
  279. package/dist/tsconfig.build.tsbuildinfo +1 -1
  280. package/package.json +65 -18
  281. package/skills/gitlab-ci/SKILL.md +16 -0
  282. package/skills/gitlab-discovery/SKILL.md +15 -0
  283. package/skills/gitlab-review/SKILL.md +16 -0
  284. package/skills/gitlab-setup/SKILL.md +16 -0
  285. package/skills/gitlab-work-items/SKILL.md +16 -0
@@ -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) || toolName === 'manage_context') {
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 { content: [{ type: 'text', text: JSON.stringify(connError, null, 2) }], isError: true };
148
+ return (0, tool_result_1.errorToolResult)(connError);
138
149
  }
139
- async function resyncSessionAfterSwitchProfile(toolName, toolArguments, sessionId) {
140
- if (toolName !== 'manage_context' || !sessionId)
141
- return;
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
- await resyncSessionAfterSwitchProfile(toolName, toolArguments, sessionId);
181
- return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
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 { toolName, toolArguments, effectiveInstanceUrl, oauthMode, connectionManager, healthMonitor, isTimedOut, bootstrapState, } = ctx;
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
- const errorCategory = initError instanceof Error ? (0, error_handler_1.classifyError)(initError) : 'permanent';
225
- if (initError instanceof Error) {
226
- if (!isTimedOut() || errorCategory === 'auth' || errorCategory === 'permanent') {
227
- healthMonitor.reportError(effectiveInstanceUrl, initError);
228
- }
229
- }
230
- (0, logger_1.logError)(`Connection initialization failed: ${initError instanceof Error ? initError.message : String(initError)}`, {
231
- instanceUrl: effectiveInstanceUrl,
232
- err: initError instanceof Error ? initError : new Error(String(initError)),
233
- });
234
- const action = toolArguments && typeof toolArguments.action === 'string' ? toolArguments.action : 'unknown';
235
- const monitorState = healthMonitor.getState(effectiveInstanceUrl);
236
- let derivedState;
237
- if (monitorState === 'connecting' || monitorState === 'failed') {
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
- else {
244
- derivedState = 'disconnected';
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
- const connError = (0, error_handler_1.createConnectionFailedError)(toolName, action, effectiveInstanceUrl, derivedState);
247
- if (!isTimedOut()) {
248
- recordEarlyReturnError(toolName, action, connError.message);
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 tools = registryManager.getAllToolDefinitions(sessionInstanceUrl);
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
- return { ...tool, inputSchema };
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 rawInstanceUrl = oauthEnabled
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
- const toolArguments = request.params.arguments;
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
- const { getContextManager } = await Promise.resolve().then(() => __importStar(require('./entities/context/context-manager')));
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.executeTool(toolName, request.params.arguments, effectiveInstanceUrl);
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
- if (!timedOut && error instanceof Error) {
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([handlerWork(), timeoutPromise]);
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);