@qase/mcp-server 1.1.8 → 2.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 (284) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +75 -542
  3. package/build/auth/client-context.d.ts +12 -0
  4. package/build/auth/client-context.d.ts.map +1 -0
  5. package/build/auth/client-context.js +12 -0
  6. package/build/auth/client-context.js.map +1 -0
  7. package/build/auth/jwks-verifier.d.ts +15 -0
  8. package/build/auth/jwks-verifier.d.ts.map +1 -0
  9. package/build/auth/jwks-verifier.js +31 -0
  10. package/build/auth/jwks-verifier.js.map +1 -0
  11. package/build/auth/mcp-guard.d.ts +15 -0
  12. package/build/auth/mcp-guard.d.ts.map +1 -0
  13. package/build/auth/mcp-guard.js +44 -0
  14. package/build/auth/mcp-guard.js.map +1 -0
  15. package/build/auth/oauth-config.d.ts +40 -0
  16. package/build/auth/oauth-config.d.ts.map +1 -0
  17. package/build/auth/oauth-config.js +34 -0
  18. package/build/auth/oauth-config.js.map +1 -0
  19. package/build/auth/proxy-provider.d.ts +31 -0
  20. package/build/auth/proxy-provider.d.ts.map +1 -0
  21. package/build/auth/proxy-provider.js +87 -0
  22. package/build/auth/proxy-provider.js.map +1 -0
  23. package/build/auth/token-type.d.ts +7 -0
  24. package/build/auth/token-type.d.ts.map +1 -0
  25. package/build/auth/token-type.js +10 -0
  26. package/build/auth/token-type.js.map +1 -0
  27. package/build/cache/circuit-breaker.d.ts +33 -0
  28. package/build/cache/circuit-breaker.d.ts.map +1 -0
  29. package/build/cache/circuit-breaker.js +68 -0
  30. package/build/cache/circuit-breaker.js.map +1 -0
  31. package/build/cache/index.d.ts +24 -0
  32. package/build/cache/index.d.ts.map +1 -0
  33. package/build/cache/index.js +86 -0
  34. package/build/cache/index.js.map +1 -0
  35. package/build/cache/keys.d.ts +25 -0
  36. package/build/cache/keys.d.ts.map +1 -0
  37. package/build/cache/keys.js +36 -0
  38. package/build/cache/keys.js.map +1 -0
  39. package/build/cache/layered.d.ts +31 -0
  40. package/build/cache/layered.d.ts.map +1 -0
  41. package/build/cache/layered.js +88 -0
  42. package/build/cache/layered.js.map +1 -0
  43. package/build/cache/memory.d.ts +32 -0
  44. package/build/cache/memory.d.ts.map +1 -0
  45. package/build/cache/memory.js +108 -0
  46. package/build/cache/memory.js.map +1 -0
  47. package/build/cache/metrics.d.ts +31 -0
  48. package/build/cache/metrics.d.ts.map +1 -0
  49. package/build/cache/metrics.js +95 -0
  50. package/build/cache/metrics.js.map +1 -0
  51. package/build/cache/prom-format.d.ts +7 -0
  52. package/build/cache/prom-format.d.ts.map +1 -0
  53. package/build/cache/prom-format.js +16 -0
  54. package/build/cache/prom-format.js.map +1 -0
  55. package/build/cache/redis-bus.d.ts +29 -0
  56. package/build/cache/redis-bus.d.ts.map +1 -0
  57. package/build/cache/redis-bus.js +50 -0
  58. package/build/cache/redis-bus.js.map +1 -0
  59. package/build/cache/redis.d.ts +32 -0
  60. package/build/cache/redis.d.ts.map +1 -0
  61. package/build/cache/redis.js +89 -0
  62. package/build/cache/redis.js.map +1 -0
  63. package/build/cache/types.d.ts +38 -0
  64. package/build/cache/types.d.ts.map +1 -0
  65. package/build/cache/types.js +2 -0
  66. package/build/cache/types.js.map +1 -0
  67. package/build/client/index.d.ts +10 -3
  68. package/build/client/index.d.ts.map +1 -1
  69. package/build/client/index.js +75 -50
  70. package/build/client/index.js.map +1 -1
  71. package/build/http/agent.d.ts +16 -0
  72. package/build/http/agent.d.ts.map +1 -0
  73. package/build/http/agent.js +16 -0
  74. package/build/http/agent.js.map +1 -0
  75. package/build/http/dedupe.d.ts +14 -0
  76. package/build/http/dedupe.d.ts.map +1 -0
  77. package/build/http/dedupe.js +69 -0
  78. package/build/http/dedupe.js.map +1 -0
  79. package/build/http/index.d.ts +6 -0
  80. package/build/http/index.d.ts.map +1 -0
  81. package/build/http/index.js +4 -0
  82. package/build/http/index.js.map +1 -0
  83. package/build/http/retry.d.ts +18 -0
  84. package/build/http/retry.d.ts.map +1 -0
  85. package/build/http/retry.js +52 -0
  86. package/build/http/retry.js.map +1 -0
  87. package/build/index.d.ts +1 -18
  88. package/build/index.d.ts.map +1 -1
  89. package/build/index.js +95 -63
  90. package/build/index.js.map +1 -1
  91. package/build/operations-v2/composites/ci-report.d.ts +2 -0
  92. package/build/operations-v2/composites/ci-report.d.ts.map +1 -0
  93. package/build/operations-v2/composites/ci-report.js +99 -0
  94. package/build/operations-v2/composites/ci-report.js.map +1 -0
  95. package/build/operations-v2/composites/regression-run.d.ts +2 -0
  96. package/build/operations-v2/composites/regression-run.d.ts.map +1 -0
  97. package/build/operations-v2/composites/regression-run.js +81 -0
  98. package/build/operations-v2/composites/regression-run.js.map +1 -0
  99. package/build/operations-v2/composites/triage-defect.d.ts +2 -0
  100. package/build/operations-v2/composites/triage-defect.d.ts.map +1 -0
  101. package/build/operations-v2/composites/triage-defect.js +67 -0
  102. package/build/operations-v2/composites/triage-defect.js.map +1 -0
  103. package/build/operations-v2/escape/api.d.ts +2 -0
  104. package/build/operations-v2/escape/api.d.ts.map +1 -0
  105. package/build/operations-v2/escape/api.js +34 -0
  106. package/build/operations-v2/escape/api.js.map +1 -0
  107. package/build/operations-v2/index.d.ts +19 -0
  108. package/build/operations-v2/index.d.ts.map +1 -0
  109. package/build/operations-v2/index.js +25 -0
  110. package/build/operations-v2/index.js.map +1 -0
  111. package/build/operations-v2/meta/discover.d.ts +9 -0
  112. package/build/operations-v2/meta/discover.d.ts.map +1 -0
  113. package/build/operations-v2/meta/discover.js +76 -0
  114. package/build/operations-v2/meta/discover.js.map +1 -0
  115. package/build/{operations/search.d.ts → operations-v2/qql/index.d.ts} +1 -1
  116. package/build/operations-v2/qql/index.d.ts.map +1 -0
  117. package/build/{operations/search.js → operations-v2/qql/index.js} +34 -9
  118. package/build/operations-v2/qql/index.js.map +1 -0
  119. package/build/operations-v2/read/get.d.ts +2 -0
  120. package/build/operations-v2/read/get.d.ts.map +1 -0
  121. package/build/operations-v2/read/get.js +91 -0
  122. package/build/operations-v2/read/get.js.map +1 -0
  123. package/build/operations-v2/read/project-context.d.ts +2 -0
  124. package/build/operations-v2/read/project-context.d.ts.map +1 -0
  125. package/build/operations-v2/read/project-context.js +102 -0
  126. package/build/operations-v2/read/project-context.js.map +1 -0
  127. package/build/operations-v2/write/attachments.d.ts +2 -0
  128. package/build/operations-v2/write/attachments.d.ts.map +1 -0
  129. package/build/operations-v2/write/attachments.js +58 -0
  130. package/build/operations-v2/write/attachments.js.map +1 -0
  131. package/build/operations-v2/write/cases.d.ts +2 -0
  132. package/build/operations-v2/write/cases.d.ts.map +1 -0
  133. package/build/operations-v2/write/cases.js +121 -0
  134. package/build/operations-v2/write/cases.js.map +1 -0
  135. package/build/operations-v2/write/defects.d.ts +2 -0
  136. package/build/operations-v2/write/defects.d.ts.map +1 -0
  137. package/build/operations-v2/write/defects.js +81 -0
  138. package/build/operations-v2/write/defects.js.map +1 -0
  139. package/build/operations-v2/write/environments.d.ts +2 -0
  140. package/build/operations-v2/write/environments.d.ts.map +1 -0
  141. package/build/operations-v2/write/environments.js +56 -0
  142. package/build/operations-v2/write/environments.js.map +1 -0
  143. package/build/operations-v2/write/milestones.d.ts +2 -0
  144. package/build/operations-v2/write/milestones.d.ts.map +1 -0
  145. package/build/operations-v2/write/milestones.js +56 -0
  146. package/build/operations-v2/write/milestones.js.map +1 -0
  147. package/build/operations-v2/write/plans.d.ts +2 -0
  148. package/build/operations-v2/write/plans.d.ts.map +1 -0
  149. package/build/operations-v2/write/plans.js +55 -0
  150. package/build/operations-v2/write/plans.js.map +1 -0
  151. package/build/operations-v2/write/results.d.ts +2 -0
  152. package/build/operations-v2/write/results.d.ts.map +1 -0
  153. package/build/operations-v2/write/results.js +72 -0
  154. package/build/operations-v2/write/results.js.map +1 -0
  155. package/build/operations-v2/write/runs.d.ts +2 -0
  156. package/build/operations-v2/write/runs.d.ts.map +1 -0
  157. package/build/operations-v2/write/runs.js +84 -0
  158. package/build/operations-v2/write/runs.js.map +1 -0
  159. package/build/operations-v2/write/shared-steps.d.ts +2 -0
  160. package/build/operations-v2/write/shared-steps.d.ts.map +1 -0
  161. package/build/operations-v2/write/shared-steps.js +60 -0
  162. package/build/operations-v2/write/shared-steps.js.map +1 -0
  163. package/build/operations-v2/write/suites.d.ts +2 -0
  164. package/build/operations-v2/write/suites.d.ts.map +1 -0
  165. package/build/operations-v2/write/suites.js +63 -0
  166. package/build/operations-v2/write/suites.js.map +1 -0
  167. package/build/prompts/index.d.ts +31 -0
  168. package/build/prompts/index.d.ts.map +1 -0
  169. package/build/prompts/index.js +229 -0
  170. package/build/prompts/index.js.map +1 -0
  171. package/build/transports/sse.d.ts.map +1 -1
  172. package/build/transports/sse.js +6 -0
  173. package/build/transports/sse.js.map +1 -1
  174. package/build/transports/streamableHttp.d.ts +6 -1
  175. package/build/transports/streamableHttp.d.ts.map +1 -1
  176. package/build/transports/streamableHttp.js +128 -16
  177. package/build/transports/streamableHttp.js.map +1 -1
  178. package/build/utils/auth-context.d.ts +8 -0
  179. package/build/utils/auth-context.d.ts.map +1 -1
  180. package/build/utils/auth-context.js +18 -0
  181. package/build/utils/auth-context.js.map +1 -1
  182. package/build/utils/case-enums.d.ts +5 -3
  183. package/build/utils/case-enums.d.ts.map +1 -1
  184. package/build/utils/case-enums.js +77 -59
  185. package/build/utils/case-enums.js.map +1 -1
  186. package/build/utils/output-schemas.d.ts +16 -0
  187. package/build/utils/output-schemas.d.ts.map +1 -0
  188. package/build/utils/output-schemas.js +82 -0
  189. package/build/utils/output-schemas.js.map +1 -0
  190. package/build/utils/registry.d.ts +42 -9
  191. package/build/utils/registry.d.ts.map +1 -1
  192. package/build/utils/registry.js +64 -11
  193. package/build/utils/registry.js.map +1 -1
  194. package/build/utils/response-shape.d.ts +23 -0
  195. package/build/utils/response-shape.d.ts.map +1 -0
  196. package/build/utils/response-shape.js +73 -0
  197. package/build/utils/response-shape.js.map +1 -0
  198. package/build/utils/rich-response.d.ts +58 -0
  199. package/build/utils/rich-response.d.ts.map +1 -0
  200. package/build/utils/rich-response.js +93 -0
  201. package/build/utils/rich-response.js.map +1 -0
  202. package/build/utils/server-context.d.ts +65 -0
  203. package/build/utils/server-context.d.ts.map +1 -0
  204. package/build/utils/server-context.js +67 -0
  205. package/build/utils/server-context.js.map +1 -0
  206. package/build/version.d.ts +1 -1
  207. package/build/version.js +1 -1
  208. package/docs/connect.md +81 -0
  209. package/docs/migration.md +351 -0
  210. package/docs/self-run.md +270 -0
  211. package/docs/tools.md +109 -0
  212. package/docs/troubleshooting.md +144 -0
  213. package/package.json +11 -2
  214. package/server.json +8 -2
  215. package/build/operations/attachments.d.ts +0 -8
  216. package/build/operations/attachments.d.ts.map +0 -1
  217. package/build/operations/attachments.js +0 -146
  218. package/build/operations/attachments.js.map +0 -1
  219. package/build/operations/authors.d.ts +0 -8
  220. package/build/operations/authors.d.ts.map +0 -1
  221. package/build/operations/authors.js +0 -70
  222. package/build/operations/authors.js.map +0 -1
  223. package/build/operations/cases.d.ts +0 -8
  224. package/build/operations/cases.d.ts.map +0 -1
  225. package/build/operations/cases.js +0 -370
  226. package/build/operations/cases.js.map +0 -1
  227. package/build/operations/configurations.d.ts +0 -10
  228. package/build/operations/configurations.d.ts.map +0 -1
  229. package/build/operations/configurations.js +0 -125
  230. package/build/operations/configurations.js.map +0 -1
  231. package/build/operations/custom-fields.d.ts +0 -8
  232. package/build/operations/custom-fields.d.ts.map +0 -1
  233. package/build/operations/custom-fields.js +0 -172
  234. package/build/operations/custom-fields.js.map +0 -1
  235. package/build/operations/defects.d.ts +0 -8
  236. package/build/operations/defects.d.ts.map +0 -1
  237. package/build/operations/defects.js +0 -256
  238. package/build/operations/defects.js.map +0 -1
  239. package/build/operations/environments.d.ts +0 -8
  240. package/build/operations/environments.d.ts.map +0 -1
  241. package/build/operations/environments.js +0 -154
  242. package/build/operations/environments.js.map +0 -1
  243. package/build/operations/milestones.d.ts +0 -8
  244. package/build/operations/milestones.d.ts.map +0 -1
  245. package/build/operations/milestones.js +0 -155
  246. package/build/operations/milestones.js.map +0 -1
  247. package/build/operations/plans.d.ts +0 -8
  248. package/build/operations/plans.d.ts.map +0 -1
  249. package/build/operations/plans.js +0 -158
  250. package/build/operations/plans.js.map +0 -1
  251. package/build/operations/projects.d.ts +0 -8
  252. package/build/operations/projects.d.ts.map +0 -1
  253. package/build/operations/projects.js +0 -192
  254. package/build/operations/projects.js.map +0 -1
  255. package/build/operations/results.d.ts +0 -8
  256. package/build/operations/results.d.ts.map +0 -1
  257. package/build/operations/results.js +0 -214
  258. package/build/operations/results.js.map +0 -1
  259. package/build/operations/runs.d.ts +0 -8
  260. package/build/operations/runs.d.ts.map +0 -1
  261. package/build/operations/runs.js +0 -224
  262. package/build/operations/runs.js.map +0 -1
  263. package/build/operations/search.d.ts.map +0 -1
  264. package/build/operations/search.js.map +0 -1
  265. package/build/operations/shared-parameters.d.ts +0 -10
  266. package/build/operations/shared-parameters.d.ts.map +0 -1
  267. package/build/operations/shared-parameters.js +0 -93
  268. package/build/operations/shared-parameters.js.map +0 -1
  269. package/build/operations/shared-steps.d.ts +0 -8
  270. package/build/operations/shared-steps.d.ts.map +0 -1
  271. package/build/operations/shared-steps.js +0 -160
  272. package/build/operations/shared-steps.js.map +0 -1
  273. package/build/operations/suites.d.ts +0 -8
  274. package/build/operations/suites.d.ts.map +0 -1
  275. package/build/operations/suites.js +0 -169
  276. package/build/operations/suites.js.map +0 -1
  277. package/build/operations/system-fields.d.ts +0 -10
  278. package/build/operations/system-fields.d.ts.map +0 -1
  279. package/build/operations/system-fields.js +0 -47
  280. package/build/operations/system-fields.js.map +0 -1
  281. package/build/operations/users.d.ts +0 -10
  282. package/build/operations/users.d.ts.map +0 -1
  283. package/build/operations/users.js +0 -78
  284. package/build/operations/users.js.map +0 -1
@@ -6,6 +6,7 @@
6
6
  * - Convert Zod schemas to JSON Schema automatically
7
7
  * - Store and retrieve tool handlers
8
8
  * - Manage tool lifecycle
9
+ * - Support tool discovery with core/discoverable visibility
9
10
  */
10
11
  import { Tool, ToolAnnotations } from '@modelcontextprotocol/sdk/types.js';
11
12
  import { z } from 'zod';
@@ -18,24 +19,39 @@ export type ToolHandler<T = any, R = any> = (args: T) => Promise<R>;
18
19
  * Tool definition for registration
19
20
  * Contains all information needed to register a tool with the MCP server
20
21
  */
22
+ /** JSON Schema object type for outputSchema */
23
+ export interface OutputSchema {
24
+ type: 'object';
25
+ properties?: Record<string, object>;
26
+ required?: string[];
27
+ [key: string]: unknown;
28
+ }
21
29
  export interface ToolDefinition<T extends z.ZodType = z.ZodType> {
22
30
  name: string;
23
31
  description: string;
24
32
  schema: T;
25
33
  handler: ToolHandler;
26
34
  annotations?: ToolAnnotations;
35
+ /** JSON Schema describing the tool's output — enables clients to process results programmatically */
36
+ outputSchema?: OutputSchema;
37
+ /** Tool visibility: 'core' tools are always listed, 'discoverable' tools require activation via qase_discover_tools */
38
+ visibility?: 'core' | 'discoverable';
27
39
  }
28
40
  /**
29
41
  * Tool Registry Class
30
- * Manages the lifecycle of MCP tools
42
+ * Manages the lifecycle of MCP tools with support for dynamic discovery
31
43
  */
32
44
  export declare class ToolRegistry {
33
45
  private tools;
34
46
  private handlers;
47
+ private activeTools;
48
+ private toolVisibility;
49
+ /** Callback invoked when the active tool set changes (wired to server.sendToolListChanged) */
50
+ onToolsChanged?: () => void;
35
51
  /**
36
52
  * Register a new tool with the registry
37
53
  *
38
- * @param definition - Tool definition including name, description, schema, and handler
54
+ * @param definition - Tool definition including name, description, schema, handler, and visibility
39
55
  *
40
56
  * @example
41
57
  * ```typescript
@@ -43,18 +59,33 @@ export declare class ToolRegistry {
43
59
  * name: 'list_projects',
44
60
  * description: 'Get all projects',
45
61
  * schema: z.object({ limit: z.number().optional() }),
46
- * handler: async (args) => { ... }
62
+ * handler: async (args) => { ... },
63
+ * visibility: 'discoverable', // hidden until discovered
47
64
  * });
48
65
  * ```
49
66
  */
50
67
  register<T extends z.ZodType>(definition: ToolDefinition<T>): void;
51
68
  /**
52
- * Get all registered tools
69
+ * Get active tools only (core + activated discoverable)
53
70
  * Used by the ListToolsRequestSchema handler
54
- *
55
- * @returns Array of all registered tools
56
71
  */
57
72
  getTools(): Tool[];
73
+ /**
74
+ * Get ALL registered tools regardless of activation status.
75
+ * Used for discovery search and testing.
76
+ */
77
+ getAllTools(): Tool[];
78
+ /**
79
+ * Search tools by name or description (case-insensitive substring match).
80
+ * Searches the full catalog including inactive tools.
81
+ */
82
+ searchTools(query: string): Tool[];
83
+ /**
84
+ * Activate tools by name, making them visible in getTools().
85
+ * Returns the list of newly activated tool names.
86
+ * Triggers onToolsChanged callback if any tools were activated.
87
+ */
88
+ activateTools(names: string[]): string[];
58
89
  /**
59
90
  * Get handler function for a specific tool
60
91
  *
@@ -62,6 +93,10 @@ export declare class ToolRegistry {
62
93
  * @returns Handler function or undefined if not found
63
94
  */
64
95
  getHandler(name: string): ToolHandler | undefined;
96
+ /**
97
+ * Get a specific tool definition by name
98
+ */
99
+ getTool(name: string): Tool | undefined;
65
100
  /**
66
101
  * Check if a tool exists in the registry
67
102
  *
@@ -70,9 +105,7 @@ export declare class ToolRegistry {
70
105
  */
71
106
  hasTool(name: string): boolean;
72
107
  /**
73
- * Get the count of registered tools
74
- *
75
- * @returns Number of registered tools
108
+ * Get the count of registered tools (all, including inactive)
76
109
  */
77
110
  getToolCount(): number;
78
111
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;GAGG;AAEH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAEpE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AI,IAAI,EAAE;IAIrB;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE;IASlC;;;;OAIG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAcxC;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAIjD;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAIvC;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;;;;;OAMG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAQjC;;;;OAIG;IACH,KAAK,IAAI,IAAI;CAMd;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,cAAqB,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,eAK5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,eAK9B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,eAK9B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,eAK9B,CAAC"}
@@ -6,19 +6,24 @@
6
6
  * - Convert Zod schemas to JSON Schema automatically
7
7
  * - Store and retrieve tool handlers
8
8
  * - Manage tool lifecycle
9
+ * - Support tool discovery with core/discoverable visibility
9
10
  */
10
11
  import { zodToJsonSchema } from 'zod-to-json-schema';
11
12
  /**
12
13
  * Tool Registry Class
13
- * Manages the lifecycle of MCP tools
14
+ * Manages the lifecycle of MCP tools with support for dynamic discovery
14
15
  */
15
16
  export class ToolRegistry {
16
17
  tools = new Map();
17
18
  handlers = new Map();
19
+ activeTools = new Set();
20
+ toolVisibility = new Map();
21
+ /** Callback invoked when the active tool set changes (wired to server.sendToolListChanged) */
22
+ onToolsChanged;
18
23
  /**
19
24
  * Register a new tool with the registry
20
25
  *
21
- * @param definition - Tool definition including name, description, schema, and handler
26
+ * @param definition - Tool definition including name, description, schema, handler, and visibility
22
27
  *
23
28
  * @example
24
29
  * ```typescript
@@ -26,12 +31,14 @@ export class ToolRegistry {
26
31
  * name: 'list_projects',
27
32
  * description: 'Get all projects',
28
33
  * schema: z.object({ limit: z.number().optional() }),
29
- * handler: async (args) => { ... }
34
+ * handler: async (args) => { ... },
35
+ * visibility: 'discoverable', // hidden until discovered
30
36
  * });
31
37
  * ```
32
38
  */
33
39
  register(definition) {
34
- const { name, description, schema, handler, annotations } = definition;
40
+ const { name, description, schema, handler, annotations, outputSchema } = definition;
41
+ const visibility = definition.visibility ?? 'core';
35
42
  // Convert Zod schema to JSON Schema for MCP protocol
36
43
  // Using explicit type assertion to avoid TypeScript's deep type inference issues
37
44
  // The zodToJsonSchema function can cause "excessively deep" type errors with complex schemas
@@ -66,21 +73,59 @@ export class ToolRegistry {
66
73
  description,
67
74
  inputSchema,
68
75
  ...(annotations && { annotations }),
76
+ ...(outputSchema && { outputSchema }),
69
77
  });
70
78
  // Store handler function
71
79
  this.handlers.set(name, handler);
80
+ // Track visibility and activation
81
+ this.toolVisibility.set(name, visibility);
82
+ if (visibility === 'core') {
83
+ this.activeTools.add(name);
84
+ }
72
85
  // Log registration for debugging (to stderr)
73
- console.error(`[Registry] Registered tool: ${name}`);
86
+ console.error(`[Registry] Registered tool: ${name} (${visibility})`);
74
87
  }
75
88
  /**
76
- * Get all registered tools
89
+ * Get active tools only (core + activated discoverable)
77
90
  * Used by the ListToolsRequestSchema handler
78
- *
79
- * @returns Array of all registered tools
80
91
  */
81
92
  getTools() {
93
+ return Array.from(this.tools.values()).filter((t) => this.activeTools.has(t.name));
94
+ }
95
+ /**
96
+ * Get ALL registered tools regardless of activation status.
97
+ * Used for discovery search and testing.
98
+ */
99
+ getAllTools() {
82
100
  return Array.from(this.tools.values());
83
101
  }
102
+ /**
103
+ * Search tools by name or description (case-insensitive substring match).
104
+ * Searches the full catalog including inactive tools.
105
+ */
106
+ searchTools(query) {
107
+ const lower = query.toLowerCase();
108
+ return this.getAllTools().filter((t) => t.name.toLowerCase().includes(lower) ||
109
+ (t.description?.toLowerCase().includes(lower) ?? false));
110
+ }
111
+ /**
112
+ * Activate tools by name, making them visible in getTools().
113
+ * Returns the list of newly activated tool names.
114
+ * Triggers onToolsChanged callback if any tools were activated.
115
+ */
116
+ activateTools(names) {
117
+ const newlyActivated = [];
118
+ for (const name of names) {
119
+ if (this.tools.has(name) && !this.activeTools.has(name)) {
120
+ this.activeTools.add(name);
121
+ newlyActivated.push(name);
122
+ }
123
+ }
124
+ if (newlyActivated.length > 0 && this.onToolsChanged) {
125
+ this.onToolsChanged();
126
+ }
127
+ return newlyActivated;
128
+ }
84
129
  /**
85
130
  * Get handler function for a specific tool
86
131
  *
@@ -90,6 +135,12 @@ export class ToolRegistry {
90
135
  getHandler(name) {
91
136
  return this.handlers.get(name);
92
137
  }
138
+ /**
139
+ * Get a specific tool definition by name
140
+ */
141
+ getTool(name) {
142
+ return this.tools.get(name);
143
+ }
93
144
  /**
94
145
  * Check if a tool exists in the registry
95
146
  *
@@ -100,9 +151,7 @@ export class ToolRegistry {
100
151
  return this.tools.has(name);
101
152
  }
102
153
  /**
103
- * Get the count of registered tools
104
- *
105
- * @returns Number of registered tools
154
+ * Get the count of registered tools (all, including inactive)
106
155
  */
107
156
  getToolCount() {
108
157
  return this.tools.size;
@@ -117,6 +166,8 @@ export class ToolRegistry {
117
166
  unregister(name) {
118
167
  const hadTool = this.tools.delete(name);
119
168
  this.handlers.delete(name);
169
+ this.activeTools.delete(name);
170
+ this.toolVisibility.delete(name);
120
171
  return hadTool;
121
172
  }
122
173
  /**
@@ -127,6 +178,8 @@ export class ToolRegistry {
127
178
  clear() {
128
179
  this.tools.clear();
129
180
  this.handlers.clear();
181
+ this.activeTools.clear();
182
+ this.toolVisibility.clear();
130
183
  }
131
184
  }
132
185
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":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Ae,EAAE,KAAK;IACtB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAoB;IAC/C,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,KAAK;IACrB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAoB;IAC/C,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAoB;IAC/C,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,IAAI;IACrB,cAAc,EAAE,IAAI;IACpB,aAAa,EAAE,IAAI;CACpB,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Recursively strip `null`, `undefined`, empty arrays, and empty objects
3
+ * from API responses before sending them to the LLM.
4
+ *
5
+ * Zero, false, and empty strings are preserved — they carry signal (e.g.
6
+ * `"description": ""` is different from missing description when the user
7
+ * asked about it).
8
+ *
9
+ * Returns `undefined` only when the input itself is `null` or `undefined`.
10
+ * For objects that collapse to zero kept fields, returns `{}` (an empty
11
+ * object) — callers should test with `Object.keys(result).length === 0` if
12
+ * they want to detect collapse, not `result === undefined`. Arrays that
13
+ * become empty are returned as `[]`.
14
+ */
15
+ export declare function compactResponse(value: unknown): unknown;
16
+ /**
17
+ * Keep only the listed top-level fields on an object, or apply the same
18
+ * projection to each element of an array.
19
+ *
20
+ * Special case: `['*']` returns the input unchanged.
21
+ */
22
+ export declare function projectFields<T>(value: T, fields: string[]): T;
23
+ //# sourceMappingURL=response-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-shape.d.ts","sourceRoot":"","sources":["../../src/utils/response-shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAyBvD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAM9D"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Recursively strip `null`, `undefined`, empty arrays, and empty objects
3
+ * from API responses before sending them to the LLM.
4
+ *
5
+ * Zero, false, and empty strings are preserved — they carry signal (e.g.
6
+ * `"description": ""` is different from missing description when the user
7
+ * asked about it).
8
+ *
9
+ * Returns `undefined` only when the input itself is `null` or `undefined`.
10
+ * For objects that collapse to zero kept fields, returns `{}` (an empty
11
+ * object) — callers should test with `Object.keys(result).length === 0` if
12
+ * they want to detect collapse, not `result === undefined`. Arrays that
13
+ * become empty are returned as `[]`.
14
+ */
15
+ export function compactResponse(value) {
16
+ if (value === null || value === undefined)
17
+ return undefined;
18
+ if (typeof value !== 'object')
19
+ return value;
20
+ if (Array.isArray(value)) {
21
+ const compactedItems = [];
22
+ for (const item of value) {
23
+ const c = compactResponse(item);
24
+ if (c !== undefined)
25
+ compactedItems.push(c);
26
+ }
27
+ return compactedItems;
28
+ }
29
+ const record = value;
30
+ const out = {};
31
+ let kept = 0;
32
+ for (const key of Object.keys(record)) {
33
+ const c = compactResponse(record[key]);
34
+ if (c === undefined)
35
+ continue;
36
+ if (Array.isArray(c) && c.length === 0)
37
+ continue;
38
+ if (isPlainObject(c) && Object.keys(c).length === 0)
39
+ continue;
40
+ out[key] = c;
41
+ kept += 1;
42
+ }
43
+ return kept === 0 ? {} : out;
44
+ }
45
+ /**
46
+ * Keep only the listed top-level fields on an object, or apply the same
47
+ * projection to each element of an array.
48
+ *
49
+ * Special case: `['*']` returns the input unchanged.
50
+ */
51
+ export function projectFields(value, fields) {
52
+ if (fields.length === 1 && fields[0] === '*')
53
+ return value;
54
+ if (Array.isArray(value)) {
55
+ return value.map((item) => projectSingle(item, fields));
56
+ }
57
+ return projectSingle(value, fields);
58
+ }
59
+ function projectSingle(obj, fields) {
60
+ if (!isPlainObject(obj))
61
+ return obj;
62
+ const src = obj;
63
+ const out = {};
64
+ for (const f of fields) {
65
+ if (f in src)
66
+ out[f] = src[f];
67
+ }
68
+ return out;
69
+ }
70
+ function isPlainObject(v) {
71
+ return typeof v === 'object' && v !== null && !Array.isArray(v);
72
+ }
73
+ //# sourceMappingURL=response-shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-shape.js","sourceRoot":"","sources":["../../src/utils/response-shape.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC5D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE5C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,cAAc,GAAc,EAAE,CAAC;QACrC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;YAChC,IAAI,CAAC,KAAK,SAAS;gBAAE,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,MAAM,MAAM,GAAG,KAAgC,CAAC;IAChD,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,MAAM,CAAC,GAAG,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACvC,IAAI,CAAC,KAAK,SAAS;YAAE,SAAS;QAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI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,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Rich Response Utilities
3
+ *
4
+ * Helpers for building multi-block MCP tool responses with audience annotations.
5
+ * Tools that return RichToolResult bypass the default JSON.stringify wrapping
6
+ * and deliver content blocks directly to the client.
7
+ *
8
+ * - summaryBlock: human-readable markdown for the user (audience: ['user'])
9
+ * - dataBlock: structured JSON for the assistant (audience: ['assistant'])
10
+ */
11
+ /** Symbol marker to distinguish rich results from plain handler returns */
12
+ declare const RICH_MARKER: unique symbol;
13
+ /** A single content block in a rich tool result */
14
+ export interface ContentBlock {
15
+ type: 'text';
16
+ text: string;
17
+ annotations?: {
18
+ audience?: Array<'user' | 'assistant'>;
19
+ priority?: number;
20
+ };
21
+ }
22
+ /** Pre-formatted tool result with multiple content blocks */
23
+ export interface RichToolResult {
24
+ [RICH_MARKER]: true;
25
+ content: ContentBlock[];
26
+ /** Machine-readable data for programmatic processing by MCP clients */
27
+ structuredContent?: Record<string, unknown>;
28
+ }
29
+ /**
30
+ * Type guard: returns true if the value is a RichToolResult.
31
+ */
32
+ export declare function isRichResult(value: unknown): value is RichToolResult;
33
+ /**
34
+ * Build a rich tool result from content blocks.
35
+ * @param content - Content blocks for display
36
+ * @param structuredContent - Machine-readable data for programmatic client processing
37
+ */
38
+ export declare function richResult(content: ContentBlock[], structuredContent?: Record<string, unknown>): RichToolResult;
39
+ /**
40
+ * Create a user-facing summary block (markdown).
41
+ * Shown to the user with highest priority.
42
+ */
43
+ export declare function summaryBlock(text: string): ContentBlock;
44
+ /**
45
+ * Create an assistant-facing data block (JSON).
46
+ * Consumed by the LLM for further reasoning.
47
+ */
48
+ export declare function dataBlock(data: unknown): ContentBlock;
49
+ /**
50
+ * Build a markdown table with properly padded columns.
51
+ *
52
+ * @param headers - Column header labels
53
+ * @param rows - Array of row data (same length as headers)
54
+ * @param align - Per-column alignment: 'l' (left, default), 'r' (right), 'c' (center)
55
+ */
56
+ export declare function markdownTable(headers: string[], rows: string[][], align?: string[]): string;
57
+ export {};
58
+ //# sourceMappingURL=rich-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rich-response.d.ts","sourceRoot":"","sources":["../../src/utils/rich-response.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,2EAA2E;AAC3E,QAAA,MAAM,WAAW,eAAiC,CAAC;AAEnD,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE;QACZ,QAAQ,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC;QACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,6DAA6D;AAC7D,MAAM,WAAW,cAAc;IAC7B,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC;IACpB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,uEAAuE;IACvE,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAMpE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,YAAY,EAAE,EACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC1C,cAAc,CAMhB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAMvD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,CAMrD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAgC3F"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Rich Response Utilities
3
+ *
4
+ * Helpers for building multi-block MCP tool responses with audience annotations.
5
+ * Tools that return RichToolResult bypass the default JSON.stringify wrapping
6
+ * and deliver content blocks directly to the client.
7
+ *
8
+ * - summaryBlock: human-readable markdown for the user (audience: ['user'])
9
+ * - dataBlock: structured JSON for the assistant (audience: ['assistant'])
10
+ */
11
+ /** Symbol marker to distinguish rich results from plain handler returns */
12
+ const RICH_MARKER = Symbol.for('qase.rich_result');
13
+ /**
14
+ * Type guard: returns true if the value is a RichToolResult.
15
+ */
16
+ export function isRichResult(value) {
17
+ return (typeof value === 'object' &&
18
+ value !== null &&
19
+ value[RICH_MARKER] === true);
20
+ }
21
+ /**
22
+ * Build a rich tool result from content blocks.
23
+ * @param content - Content blocks for display
24
+ * @param structuredContent - Machine-readable data for programmatic client processing
25
+ */
26
+ export function richResult(content, structuredContent) {
27
+ return {
28
+ [RICH_MARKER]: true,
29
+ content,
30
+ ...(structuredContent && { structuredContent }),
31
+ };
32
+ }
33
+ /**
34
+ * Create a user-facing summary block (markdown).
35
+ * Shown to the user with highest priority.
36
+ */
37
+ export function summaryBlock(text) {
38
+ return {
39
+ type: 'text',
40
+ text,
41
+ annotations: { audience: ['user'], priority: 1 },
42
+ };
43
+ }
44
+ /**
45
+ * Create an assistant-facing data block (JSON).
46
+ * Consumed by the LLM for further reasoning.
47
+ */
48
+ export function dataBlock(data) {
49
+ return {
50
+ type: 'text',
51
+ text: JSON.stringify(data),
52
+ annotations: { audience: ['assistant'], priority: 0 },
53
+ };
54
+ }
55
+ /**
56
+ * Build a markdown table with properly padded columns.
57
+ *
58
+ * @param headers - Column header labels
59
+ * @param rows - Array of row data (same length as headers)
60
+ * @param align - Per-column alignment: 'l' (left, default), 'r' (right), 'c' (center)
61
+ */
62
+ export function markdownTable(headers, rows, align) {
63
+ // Compute max width per column
64
+ const widths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? '').length)));
65
+ const pad = (s, w, a) => {
66
+ const gap = w - s.length;
67
+ if (gap <= 0)
68
+ return s;
69
+ if (a === 'r')
70
+ return ' '.repeat(gap) + s;
71
+ if (a === 'c')
72
+ return ' '.repeat(Math.floor(gap / 2)) + s + ' '.repeat(Math.ceil(gap / 2));
73
+ return s + ' '.repeat(gap);
74
+ };
75
+ const aligns = align ?? headers.map(() => 'l');
76
+ const headerRow = '| ' + headers.map((h, i) => pad(h, widths[i], aligns[i])).join(' | ') + ' |';
77
+ const sepRow = '| ' +
78
+ widths
79
+ .map((w, i) => {
80
+ const a = aligns[i];
81
+ const bar = '-'.repeat(w);
82
+ if (a === 'r')
83
+ return bar.slice(0, -1) + ':';
84
+ if (a === 'c')
85
+ return ':' + bar.slice(1, -1) + ':';
86
+ return bar;
87
+ })
88
+ .join(' | ') +
89
+ ' |';
90
+ const dataRows = rows.map((r) => '| ' + r.map((c, i) => pad(c ?? '', widths[i], aligns[i])).join(' | ') + ' |');
91
+ return [headerRow, sepRow, ...dataRows].join('\n');
92
+ }
93
+ //# sourceMappingURL=rich-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rich-response.js","sourceRoot":"","sources":["../../src/utils/rich-response.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,2EAA2E;AAC3E,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAoBnD;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACb,KAAiC,CAAC,WAAW,CAAC,KAAK,IAAI,CACzD,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,OAAuB,EACvB,iBAA2C;IAE3C,OAAO;QACL,CAAC,WAAW,CAAC,EAAE,IAAI;QACnB,OAAO;QACP,GAAG,CAAC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AG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CACrF,CAAC;IAEF,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Server Context
3
+ *
4
+ * Provides access to the MCP Server instance within tool handlers
5
+ * via AsyncLocalStorage, following the same pattern as auth-context.ts.
6
+ *
7
+ * This enables features that require server-level access (elicitation,
8
+ * tool list notifications) without passing the server through handler signatures.
9
+ */
10
+ import { AsyncLocalStorage } from 'async_hooks';
11
+ import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
12
+ /**
13
+ * Per-request server storage.
14
+ * Holds the Server instance for the current request context.
15
+ */
16
+ export declare const serverStorage: AsyncLocalStorage<Server<{
17
+ method: string;
18
+ params?: {
19
+ [x: string]: unknown;
20
+ _meta?: {
21
+ [x: string]: unknown;
22
+ progressToken?: string | number | undefined;
23
+ "io.modelcontextprotocol/related-task"?: {
24
+ taskId: string;
25
+ } | undefined;
26
+ } | undefined;
27
+ } | undefined;
28
+ }, {
29
+ method: string;
30
+ params?: {
31
+ [x: string]: unknown;
32
+ _meta?: {
33
+ [x: string]: unknown;
34
+ progressToken?: string | number | undefined;
35
+ "io.modelcontextprotocol/related-task"?: {
36
+ taskId: string;
37
+ } | undefined;
38
+ } | undefined;
39
+ } | undefined;
40
+ }, {
41
+ [x: string]: unknown;
42
+ _meta?: {
43
+ [x: string]: unknown;
44
+ progressToken?: string | number | undefined;
45
+ "io.modelcontextprotocol/related-task"?: {
46
+ taskId: string;
47
+ } | undefined;
48
+ } | undefined;
49
+ }>>;
50
+ /**
51
+ * Get the Server instance from the current async context.
52
+ * Returns undefined if called outside of a serverStorage.run() scope.
53
+ */
54
+ export declare function getServer(): Server | undefined;
55
+ /**
56
+ * Ask the user to confirm a destructive action via MCP elicitation.
57
+ *
58
+ * Graceful degradation:
59
+ * - No server in context → proceed (return true)
60
+ * - Client doesn't support elicitation → proceed
61
+ * - elicitInput() throws → proceed (log error)
62
+ * - User declines or cancels → return false
63
+ */
64
+ export declare function confirmDestructiveAction(toolName: string, args: Record<string, unknown>): Promise<boolean>;
65
+ //# sourceMappingURL=server-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-context.d.ts","sourceRoot":"","sources":["../../src/utils/server-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAAkC,CAAC;AAE7D;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,GAAG,SAAS,CAE9C;AAED;;;;;;;;GAQG;AACH,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,OAAO,CAAC,CAmClB"}