@casys/mcp-server 0.27.0 → 0.27.2

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 (253) hide show
  1. package/CHANGELOG.md +18 -1764
  2. package/README.md +21 -631
  3. package/esm/mod.d.ts +1 -102
  4. package/esm/mod.js +1 -103
  5. package/package.json +17 -25
  6. package/esm/_dnt.polyfills.d.ts +0 -12
  7. package/esm/_dnt.polyfills.d.ts.map +0 -1
  8. package/esm/_dnt.polyfills.js +0 -15
  9. package/esm/_dnt.shims.d.ts +0 -2
  10. package/esm/_dnt.shims.d.ts.map +0 -1
  11. package/esm/_dnt.shims.js +0 -57
  12. package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts +0 -33
  13. package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts.map +0 -1
  14. package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.js +0 -48
  15. package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts +0 -106
  16. package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts.map +0 -1
  17. package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.js +0 -636
  18. package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts +0 -67
  19. package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts.map +0 -1
  20. package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.js +0 -1393
  21. package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts +0 -44
  22. package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts.map +0 -1
  23. package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.js +0 -117
  24. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts +0 -3
  25. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts.map +0 -1
  26. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.js +0 -103
  27. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts +0 -3
  28. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts.map +0 -1
  29. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.js +0 -32
  30. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts +0 -3
  31. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts.map +0 -1
  32. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.js +0 -96
  33. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts +0 -3
  34. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts.map +0 -1
  35. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.js +0 -159
  36. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts +0 -3
  37. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts.map +0 -1
  38. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.js +0 -14
  39. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts +0 -3
  40. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts.map +0 -1
  41. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.js +0 -10
  42. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts +0 -3
  43. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts.map +0 -1
  44. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.js +0 -22
  45. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts +0 -3
  46. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts.map +0 -1
  47. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.js +0 -29
  48. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts +0 -3
  49. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts.map +0 -1
  50. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.js +0 -19
  51. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts +0 -3
  52. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts.map +0 -1
  53. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.js +0 -30
  54. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts +0 -3
  55. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts.map +0 -1
  56. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.js +0 -10
  57. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts +0 -3
  58. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts.map +0 -1
  59. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.js +0 -14
  60. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts +0 -3
  61. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts.map +0 -1
  62. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.js +0 -9
  63. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts +0 -3
  64. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts.map +0 -1
  65. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.js +0 -81
  66. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts +0 -3
  67. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts.map +0 -1
  68. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.js +0 -20
  69. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts +0 -32
  70. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts.map +0 -1
  71. package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.js +0 -6
  72. package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts +0 -4
  73. package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts.map +0 -1
  74. package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.js +0 -13
  75. package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts +0 -51
  76. package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts.map +0 -1
  77. package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.js +0 -53
  78. package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts +0 -79
  79. package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts.map +0 -1
  80. package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.js +0 -91
  81. package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts +0 -100
  82. package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts.map +0 -1
  83. package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.js +0 -33
  84. package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts +0 -111
  85. package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts.map +0 -1
  86. package/esm/deps/jsr.io/@std/yaml/1.2.0/types.js +0 -104
  87. package/esm/mod.d.ts.map +0 -1
  88. package/esm/package.json +0 -3
  89. package/esm/src/auth/as-metadata-proxy.d.ts +0 -112
  90. package/esm/src/auth/as-metadata-proxy.d.ts.map +0 -1
  91. package/esm/src/auth/as-metadata-proxy.js +0 -171
  92. package/esm/src/auth/config.d.ts +0 -117
  93. package/esm/src/auth/config.d.ts.map +0 -1
  94. package/esm/src/auth/config.js +0 -219
  95. package/esm/src/auth/jwt-provider.d.ts +0 -157
  96. package/esm/src/auth/jwt-provider.d.ts.map +0 -1
  97. package/esm/src/auth/jwt-provider.js +0 -187
  98. package/esm/src/auth/middleware.d.ts +0 -61
  99. package/esm/src/auth/middleware.d.ts.map +0 -1
  100. package/esm/src/auth/middleware.js +0 -209
  101. package/esm/src/auth/mod.d.ts +0 -23
  102. package/esm/src/auth/mod.d.ts.map +0 -1
  103. package/esm/src/auth/mod.js +0 -27
  104. package/esm/src/auth/multi-tenant-middleware.d.ts +0 -131
  105. package/esm/src/auth/multi-tenant-middleware.d.ts.map +0 -1
  106. package/esm/src/auth/multi-tenant-middleware.js +0 -128
  107. package/esm/src/auth/presets.d.ts +0 -231
  108. package/esm/src/auth/presets.d.ts.map +0 -1
  109. package/esm/src/auth/presets.js +0 -223
  110. package/esm/src/auth/provider.d.ts +0 -47
  111. package/esm/src/auth/provider.d.ts.map +0 -1
  112. package/esm/src/auth/provider.js +0 -34
  113. package/esm/src/auth/scope-middleware.d.ts +0 -30
  114. package/esm/src/auth/scope-middleware.d.ts.map +0 -1
  115. package/esm/src/auth/scope-middleware.js +0 -48
  116. package/esm/src/auth/static-token-provider.d.ts +0 -155
  117. package/esm/src/auth/static-token-provider.d.ts.map +0 -1
  118. package/esm/src/auth/static-token-provider.js +0 -256
  119. package/esm/src/auth/types.d.ts +0 -151
  120. package/esm/src/auth/types.d.ts.map +0 -1
  121. package/esm/src/auth/types.js +0 -64
  122. package/esm/src/client-auth/callback-server.d.ts +0 -34
  123. package/esm/src/client-auth/callback-server.d.ts.map +0 -1
  124. package/esm/src/client-auth/callback-server.js +0 -141
  125. package/esm/src/client-auth/client-id-metadata.d.ts +0 -29
  126. package/esm/src/client-auth/client-id-metadata.d.ts.map +0 -1
  127. package/esm/src/client-auth/client-id-metadata.js +0 -149
  128. package/esm/src/client-auth/connect.d.ts +0 -32
  129. package/esm/src/client-auth/connect.d.ts.map +0 -1
  130. package/esm/src/client-auth/connect.js +0 -47
  131. package/esm/src/client-auth/mod.d.ts +0 -19
  132. package/esm/src/client-auth/mod.d.ts.map +0 -1
  133. package/esm/src/client-auth/mod.js +0 -19
  134. package/esm/src/client-auth/provider.d.ts +0 -78
  135. package/esm/src/client-auth/provider.d.ts.map +0 -1
  136. package/esm/src/client-auth/provider.js +0 -246
  137. package/esm/src/client-auth/token-store/file-store.d.ts +0 -20
  138. package/esm/src/client-auth/token-store/file-store.d.ts.map +0 -1
  139. package/esm/src/client-auth/token-store/file-store.js +0 -62
  140. package/esm/src/client-auth/token-store/memory-store.d.ts +0 -14
  141. package/esm/src/client-auth/token-store/memory-store.d.ts.map +0 -1
  142. package/esm/src/client-auth/token-store/memory-store.js +0 -25
  143. package/esm/src/client-auth/types.d.ts +0 -89
  144. package/esm/src/client-auth/types.d.ts.map +0 -1
  145. package/esm/src/client-auth/types.js +0 -10
  146. package/esm/src/concurrency/rate-limiter.d.ts +0 -87
  147. package/esm/src/concurrency/rate-limiter.d.ts.map +0 -1
  148. package/esm/src/concurrency/rate-limiter.js +0 -165
  149. package/esm/src/concurrency/request-queue.d.ts +0 -71
  150. package/esm/src/concurrency/request-queue.d.ts.map +0 -1
  151. package/esm/src/concurrency/request-queue.js +0 -128
  152. package/esm/src/http/body.d.ts +0 -20
  153. package/esm/src/http/body.d.ts.map +0 -1
  154. package/esm/src/http/body.js +0 -63
  155. package/esm/src/http/request-guards.d.ts +0 -54
  156. package/esm/src/http/request-guards.d.ts.map +0 -1
  157. package/esm/src/http/request-guards.js +0 -114
  158. package/esm/src/http/wire.d.ts +0 -26
  159. package/esm/src/http/wire.d.ts.map +0 -1
  160. package/esm/src/http/wire.js +0 -35
  161. package/esm/src/inspector/launcher.d.ts +0 -48
  162. package/esm/src/inspector/launcher.d.ts.map +0 -1
  163. package/esm/src/inspector/launcher.js +0 -100
  164. package/esm/src/mcp-app.d.ts +0 -728
  165. package/esm/src/mcp-app.d.ts.map +0 -1
  166. package/esm/src/mcp-app.js +0 -3530
  167. package/esm/src/middleware/backpressure.d.ts +0 -24
  168. package/esm/src/middleware/backpressure.d.ts.map +0 -1
  169. package/esm/src/middleware/backpressure.js +0 -31
  170. package/esm/src/middleware/mod.d.ts +0 -11
  171. package/esm/src/middleware/mod.d.ts.map +0 -1
  172. package/esm/src/middleware/mod.js +0 -11
  173. package/esm/src/middleware/rate-limit.d.ts +0 -22
  174. package/esm/src/middleware/rate-limit.d.ts.map +0 -1
  175. package/esm/src/middleware/rate-limit.js +0 -33
  176. package/esm/src/middleware/runner.d.ts +0 -32
  177. package/esm/src/middleware/runner.d.ts.map +0 -1
  178. package/esm/src/middleware/runner.js +0 -49
  179. package/esm/src/middleware/types.d.ts +0 -76
  180. package/esm/src/middleware/types.d.ts.map +0 -1
  181. package/esm/src/middleware/types.js +0 -9
  182. package/esm/src/middleware/validation.d.ts +0 -24
  183. package/esm/src/middleware/validation.d.ts.map +0 -1
  184. package/esm/src/middleware/validation.js +0 -30
  185. package/esm/src/mrtr/capability-check.d.ts +0 -75
  186. package/esm/src/mrtr/capability-check.d.ts.map +0 -1
  187. package/esm/src/mrtr/capability-check.js +0 -233
  188. package/esm/src/mrtr/mod.d.ts +0 -18
  189. package/esm/src/mrtr/mod.d.ts.map +0 -1
  190. package/esm/src/mrtr/mod.js +0 -12
  191. package/esm/src/mrtr/replay-store.d.ts +0 -50
  192. package/esm/src/mrtr/replay-store.d.ts.map +0 -1
  193. package/esm/src/mrtr/replay-store.js +0 -61
  194. package/esm/src/mrtr/request-state.d.ts +0 -181
  195. package/esm/src/mrtr/request-state.d.ts.map +0 -1
  196. package/esm/src/mrtr/request-state.js +0 -313
  197. package/esm/src/mrtr/retry-guard.d.ts +0 -61
  198. package/esm/src/mrtr/retry-guard.d.ts.map +0 -1
  199. package/esm/src/mrtr/retry-guard.js +0 -53
  200. package/esm/src/mrtr/types.d.ts +0 -99
  201. package/esm/src/mrtr/types.d.ts.map +0 -1
  202. package/esm/src/mrtr/types.js +0 -14
  203. package/esm/src/observability/metrics.d.ts +0 -104
  204. package/esm/src/observability/metrics.d.ts.map +0 -1
  205. package/esm/src/observability/metrics.js +0 -207
  206. package/esm/src/observability/mod.d.ts +0 -12
  207. package/esm/src/observability/mod.d.ts.map +0 -1
  208. package/esm/src/observability/mod.js +0 -11
  209. package/esm/src/observability/otel.d.ts +0 -73
  210. package/esm/src/observability/otel.d.ts.map +0 -1
  211. package/esm/src/observability/otel.js +0 -260
  212. package/esm/src/runtime/runtime.d.ts +0 -10
  213. package/esm/src/runtime/runtime.d.ts.map +0 -1
  214. package/esm/src/runtime/runtime.deno.d.ts +0 -50
  215. package/esm/src/runtime/runtime.deno.d.ts.map +0 -1
  216. package/esm/src/runtime/runtime.deno.js +0 -120
  217. package/esm/src/runtime/runtime.js +0 -41
  218. package/esm/src/runtime/runtime.node.d.ts +0 -51
  219. package/esm/src/runtime/runtime.node.d.ts.map +0 -1
  220. package/esm/src/runtime/runtime.node.js +0 -268
  221. package/esm/src/runtime/types.d.ts +0 -107
  222. package/esm/src/runtime/types.d.ts.map +0 -1
  223. package/esm/src/runtime/types.js +0 -12
  224. package/esm/src/security/channel-hmac.d.ts +0 -43
  225. package/esm/src/security/channel-hmac.d.ts.map +0 -1
  226. package/esm/src/security/channel-hmac.js +0 -135
  227. package/esm/src/security/csp.d.ts +0 -50
  228. package/esm/src/security/csp.d.ts.map +0 -1
  229. package/esm/src/security/csp.js +0 -63
  230. package/esm/src/security/message-signer.d.ts +0 -88
  231. package/esm/src/security/message-signer.d.ts.map +0 -1
  232. package/esm/src/security/message-signer.js +0 -166
  233. package/esm/src/subscriptions/subscription-registry.d.ts +0 -256
  234. package/esm/src/subscriptions/subscription-registry.d.ts.map +0 -1
  235. package/esm/src/subscriptions/subscription-registry.js +0 -406
  236. package/esm/src/tasks/mod.d.ts +0 -13
  237. package/esm/src/tasks/mod.d.ts.map +0 -1
  238. package/esm/src/tasks/mod.js +0 -11
  239. package/esm/src/tasks/task-store.d.ts +0 -342
  240. package/esm/src/tasks/task-store.d.ts.map +0 -1
  241. package/esm/src/tasks/task-store.js +0 -649
  242. package/esm/src/transport/request-headers.d.ts +0 -145
  243. package/esm/src/transport/request-headers.d.ts.map +0 -1
  244. package/esm/src/transport/request-headers.js +0 -525
  245. package/esm/src/types.d.ts +0 -776
  246. package/esm/src/types.d.ts.map +0 -1
  247. package/esm/src/types.js +0 -92
  248. package/esm/src/ui/viewer-utils.d.ts +0 -45
  249. package/esm/src/ui/viewer-utils.d.ts.map +0 -1
  250. package/esm/src/ui/viewer-utils.js +0 -97
  251. package/esm/src/validation/schema-validator.d.ts +0 -115
  252. package/esm/src/validation/schema-validator.d.ts.map +0 -1
  253. package/esm/src/validation/schema-validator.js +0 -249
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/tasks/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,YAAY,EACV,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,IAAI,EACJ,cAAc,EACd,gBAAgB,EAChB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,SAAS,GACV,MAAM,iBAAiB,CAAC"}
@@ -1,11 +0,0 @@
1
- /**
2
- * Public API for the Tasks extension (io.modelcontextprotocol/tasks, SEP-2663).
3
- *
4
- * Tool handlers use `createTask()` to opt into async-task mode.
5
- * The transport layer uses `TaskStore` to manage task lifecycle.
6
- * `isAsyncTaskDescriptor()` is the discriminant the framework uses at the
7
- * tools/call boundary to decide whether to spawn a task or return a result.
8
- *
9
- * @module lib/server/tasks
10
- */
11
- export { createTask, generateTaskId, isAsyncTaskDescriptor, TaskStore, } from "./task-store.js";
@@ -1,342 +0,0 @@
1
- /**
2
- * Produce a cryptographically-random task ID.
3
- *
4
- * 128 bits of entropy (32 lowercase hex chars). Spec §Security Considerations:
5
- * "Task IDs MUST be generated with sufficient entropy that a third party cannot
6
- * enumerate or guess them." 128 bits satisfies that at the same level as a
7
- * UUID v4 but without the version/variant bits that reduce its effective
8
- * entropy to 122 bits.
9
- */
10
- export declare function generateTaskId(): string;
11
- /**
12
- * Options a tool handler provides when opting into async-task mode.
13
- *
14
- * All fields are optional; `TaskStore` fills defaults from its own options.
15
- */
16
- export interface CreateTaskOptions {
17
- /**
18
- * TTL in ms from creation. `null` = no expiry (held until maxTasks eviction).
19
- * Spec is silent on a default — callers omit this to get the store default.
20
- */
21
- ttlMs?: number | null;
22
- /**
23
- * Hint to the client: how often to call tasks/get (ms).
24
- * Spec §Task Polling: clients SHOULD respect this.
25
- * Default chosen as 5 000 ms — practical minimum that avoids hammering the
26
- * server without causing noticeable delays on human-facing workflows.
27
- */
28
- pollIntervalMs?: number;
29
- /** Human-readable description of the initial working state. */
30
- statusMessage?: string;
31
- }
32
- /**
33
- * One outstanding server-to-client request, registered in `inputRequests`.
34
- *
35
- * Shape is intentionally minimal: it mirrors the spec's `InputRequest` type
36
- * (method + params). The protocol is open-ended — concrete method names are
37
- * defined per-extension (e.g. `sampling/createMessage`).
38
- */
39
- export interface InputRequest {
40
- readonly method: string;
41
- readonly params: Record<string, unknown>;
42
- }
43
- /**
44
- * Interface the running task's work function uses to interact with the store.
45
- *
46
- * Design rule: `TaskController` is never stored by the framework after the
47
- * `run()` promise settles. Tool handlers MUST NOT hold it past the promise.
48
- */
49
- export interface TaskController {
50
- /**
51
- * Block the running work until the client delivers a response for `key`.
52
- *
53
- * Registers the request under `key` in `inputRequests` (moves task to
54
- * `input_required`) and resolves with the client-provided response when
55
- * `tasks/update` carries that key.
56
- *
57
- * Rejects with `DOMException("Task was cancelled", "AbortError")` if the
58
- * task is cancelled while waiting.
59
- *
60
- * Spec §Task Update Requests: "Each inputRequests key MUST be unique over
61
- * the entire lifetime of a single task. Server MUST NOT reuse a key after
62
- * a response for that key has been delivered."
63
- */
64
- requireInput(key: string, request: InputRequest): Promise<Record<string, unknown>>;
65
- /** Update the status message visible on the next tasks/get. */
66
- setStatusMessage(msg: string): void;
67
- /**
68
- * AbortSignal that fires when tasks/cancel is received.
69
- * Long-running work SHOULD check this to short-circuit early.
70
- * Spec: cancellation is cooperative — the task may still finish normally.
71
- */
72
- readonly signal: AbortSignal;
73
- }
74
- /**
75
- * Discriminated return value: a tool handler returns this to ask the framework
76
- * to materialise an async task instead of a synchronous result.
77
- *
78
- * Use `createTask()` to construct; do not build this object manually — the
79
- * `_type` discriminant is what `isAsyncTaskDescriptor()` keys on.
80
- */
81
- export interface AsyncTaskDescriptor {
82
- readonly _type: "async-task";
83
- readonly options: CreateTaskOptions;
84
- /**
85
- * Background work. Return value becomes `CompletedTask.result`.
86
- *
87
- * To signal a protocol-level failure (→ `FailedTask`), throw an object with
88
- * `{ code: number; message: string }`. This mirrors JSON-RPC error shape and
89
- * is the spec's definition of the `failed` status.
90
- *
91
- * A tool-level business error (the ERPNext equivalent of "order not found")
92
- * MUST NOT throw — it should be returned as part of the normal result, which
93
- * reaches `completed`. Spec: "The 'failed' status MUST NOT be used for
94
- * non-JSON-RPC errors. A tool result with isError: true reaches 'completed',
95
- * not 'failed'."
96
- */
97
- readonly run: (ctrl: TaskController) => Promise<unknown>;
98
- }
99
- /** Base fields shared by every task shape. */
100
- export interface Task {
101
- taskId: string;
102
- status: "working" | "input_required" | "completed" | "cancelled" | "failed";
103
- statusMessage?: string;
104
- createdAt: string;
105
- lastUpdatedAt: string;
106
- ttlMs: number | null;
107
- pollIntervalMs?: number;
108
- }
109
- export interface WorkingTask extends Task {
110
- status: "working";
111
- }
112
- export interface InputRequiredTask extends Task {
113
- status: "input_required";
114
- /** All outstanding server-to-client requests, keyed by a unique caller-chosen identifier. */
115
- inputRequests: Record<string, InputRequest>;
116
- }
117
- export interface CompletedTask extends Task {
118
- status: "completed";
119
- result: Record<string, unknown>;
120
- }
121
- export interface FailedTask extends Task {
122
- status: "failed";
123
- error: Record<string, unknown>;
124
- }
125
- export interface CancelledTask extends Task {
126
- status: "cancelled";
127
- }
128
- /** Discriminated union of all possible task states. */
129
- export type DetailedTask = WorkingTask | InputRequiredTask | CompletedTask | FailedTask | CancelledTask;
130
- /**
131
- * Fields returned as the initial result when tools/call spawns a task.
132
- *
133
- * `resultType: "task"` is added by the transport layer (NOT by stampResult —
134
- * stampResult always sets `"complete"`, and CreateTaskResult requires `"task"`.
135
- * The caller builds the response manually; see integration instructions.)
136
- */
137
- export type CreateTaskResultFields = Task;
138
- export interface TaskStoreOptions {
139
- /**
140
- * Default TTL for tasks whose handler did not provide one.
141
- *
142
- * Spec is silent. 3 600 000 ms (1 h) chosen because it's long enough for
143
- * realistic ERPNext whole-table scans (stock treemap, revenue aggregations)
144
- * but short enough to bound memory in a long-running server.
145
- */
146
- defaultTtlMs: number;
147
- /**
148
- * Hard cap on stored tasks (terminal + non-terminal combined).
149
- *
150
- * Spec is silent. 5 000 chosen as half the session cap (10 000) since each
151
- * task can carry an arbitrarily large `result` payload, so the per-entry
152
- * cost is higher than a session entry.
153
- *
154
- * Eviction order when the cap is reached: terminal tasks first (by
155
- * `terminalAt`, oldest first), then oldest non-terminal by `createdAt`.
156
- * Terminal tasks have already served their purpose; evicting them first is
157
- * the least-harmful policy.
158
- */
159
- maxTasks: number;
160
- /**
161
- * How often to sweep tasks for TTL expiry.
162
- *
163
- * Piggybacking on the same 5-minute rhythm as the session cleanup in
164
- * McpApp keeps operational patterns consistent. Not exposed to callers
165
- * as a tunable because the appropriate value tracks the session timer.
166
- */
167
- cleanupIntervalMs: number;
168
- /**
169
- * Optional callback invoked on every status transition.
170
- *
171
- * Intended as the wiring point for Track G (subscriptions/listen): once
172
- * that lands, the subscription layer registers here and the TaskStore
173
- * drives notifications without knowing about SSE or HTTP. No-op until
174
- * Track G ships.
175
- */
176
- onNotification?: (task: DetailedTask) => void;
177
- /**
178
- * Runtime hook to unref the sweep timer, so it cannot hold the process open.
179
- *
180
- * Injected rather than imported: the store is runtime-agnostic, and Deno and
181
- * Node expose different mechanisms for this.
182
- */
183
- unrefTimer?: (id: ReturnType<typeof setInterval>) => void;
184
- }
185
- /**
186
- * Factory for tool handlers that want to run asynchronously.
187
- *
188
- * Returns an `AsyncTaskDescriptor` the framework detects and routes through
189
- * the `TaskStore`. The handler never sees the store directly — it only receives
190
- * the `TaskController` when `run()` is invoked.
191
- *
192
- * @example
193
- * ```typescript
194
- * // Inside a tool handler:
195
- * return createTask({ ttlMs: 60_000, pollIntervalMs: 3_000 }, async (ctrl) => {
196
- * const rows = await scanWholeTable(args, ctrl.signal);
197
- * return { rows };
198
- * });
199
- * ```
200
- */
201
- export declare function createTask(options: CreateTaskOptions, run: (ctrl: TaskController) => Promise<unknown>): AsyncTaskDescriptor;
202
- /**
203
- * Type guard used by the transport to distinguish an `AsyncTaskDescriptor`
204
- * from an ordinary tool result.
205
- *
206
- * Checks the private `_type` discriminant rather than shape-matching public
207
- * fields, so a tool result that happens to carry similar fields is never
208
- * misidentified.
209
- */
210
- export declare function isAsyncTaskDescriptor(v: unknown): v is AsyncTaskDescriptor;
211
- /**
212
- * Server-side store for background tasks spawned by the Tasks extension.
213
- *
214
- * Responsibilities:
215
- * - Issue unique, unguessable task IDs.
216
- * - Store task state and transition it as work progresses.
217
- * - Route client input (tasks/update) to waiting requireInput() calls.
218
- * - Enforce TTL expiry and a hard memory cap via eviction.
219
- * - Surface a notification callback for Track G (subscriptions/listen).
220
- *
221
- * All public methods are synchronous (except the background work itself)
222
- * to ensure the tasks/get → tasks/update → tasks/cancel request flow
223
- * never blocks on I/O inside the store.
224
- */
225
- export declare class TaskStore {
226
- private readonly _options;
227
- private readonly _tasks;
228
- private _cleanupTimer;
229
- constructor(options?: Partial<TaskStoreOptions>);
230
- /**
231
- * Spawn a background task from an `AsyncTaskDescriptor`.
232
- *
233
- * MUST be called after verifying the client declared the tasks capability.
234
- *
235
- * Returns the `CreateTaskResultFields` the transport should send as the
236
- * result of the triggering tools/call, with `resultType: "task"` added by
237
- * the caller. (stampResult() sets `"complete"` and must NOT be called here.)
238
- *
239
- * Spec §Task Creation: "Server MUST NOT return CreateTaskResult until the
240
- * task is durably created — a subsequent tasks/get for the returned taskId
241
- * must resolve immediately." Fulfilled: we insert into `_tasks` before
242
- * returning.
243
- */
244
- spawn(descriptor: AsyncTaskDescriptor, owner: string, formatResult?: (raw: unknown) => Record<string, unknown>): CreateTaskResultFields;
245
- /**
246
- * Service a tasks/get request.
247
- *
248
- * Returns `null` when the taskId is unknown or has been purged
249
- * (caller returns -32602).
250
- *
251
- * Spec §Task Polling: "If status is 'working', return Task with status
252
- * 'working'; if 'input_required', return Task with inputRequests containing
253
- * all outstanding server-to-client requests; if 'completed', return Task
254
- * with result; if 'cancelled', return Task with status 'cancelled'; if
255
- * 'failed', return Task with error."
256
- */
257
- get(taskId: string, caller: string): DetailedTask | null;
258
- /**
259
- * Service a tasks/update request.
260
- *
261
- * Delivers client responses to outstanding requireInput() calls.
262
- *
263
- * Returns `true` on success, `false` if the taskId is unknown
264
- * (caller SHOULD return -32602 per spec §Task Update Requests).
265
- *
266
- * Spec §Task Update Requests:
267
- * - "Server SHOULD ignore inputResponses mapped to unknown, already-answered,
268
- * or superseded keys."
269
- * - "Server MAY accept a partial set of responses."
270
- *
271
- * Silently ignores responses for unknown keys instead of erroring, because
272
- * a stale retry from an impatient client must not break an otherwise healthy
273
- * task.
274
- */
275
- update(taskId: string, inputResponses: Record<string, unknown>, caller: string): boolean;
276
- /**
277
- * Service a tasks/cancel request.
278
- *
279
- * Returns `true` if the task was found (regardless of whether the work
280
- * actually stops). Returns `false` if unknown (caller SHOULD return -32602).
281
- *
282
- * Spec §Task Cancellation: "Cancellation is cooperative: the server is not
283
- * obligated to actually stop the work; it only acknowledges intent. Eventual
284
- * transition to 'cancelled' is not guaranteed."
285
- *
286
- * `notifications/cancelled` MUST NOT be used for task cancellation — the spec
287
- * reserves a dedicated `notifications/tasks/statusChanged` notification for
288
- * Track G instead.
289
- */
290
- cancel(taskId: string, caller: string): boolean;
291
- /**
292
- * Signal all in-flight AbortControllers.
293
- *
294
- * Called by McpApp.stop() before awaiting httpServer.shutdown(), giving
295
- * background Promises a chance to observe the signal and exit early.
296
- * Does NOT await completion — best-effort on graceful shutdown.
297
- */
298
- drain(): void;
299
- /**
300
- * Clear the cleanup interval.
301
- *
302
- * Must be called after drain() in McpApp.stop() to release the timer
303
- * and let the process exit cleanly.
304
- */
305
- /** True once dispose() ran; suppresses any late notification. */
306
- private _disposed;
307
- /** Whether this store has been torn down and must not accept new work. */
308
- get isDisposed(): boolean;
309
- /**
310
- * Emit a status change, unless the store was disposed.
311
- *
312
- * A drained task's `run()` promise can still settle after dispose() — abort is
313
- * cooperative, so work that ignores the signal keeps going. Pushing that
314
- * transition to a subscriber whose transport is already torn down is at best
315
- * useless and at worst a write to a closed stream.
316
- */
317
- private _notify;
318
- dispose(): void;
319
- /** Current number of tracked tasks (terminal + non-terminal). */
320
- get size(): number;
321
- /**
322
- * Sweep for TTL-expired tasks and mark them failed.
323
- *
324
- * Spec §Task Polling: "Server MAY mark a task as 'failed' at any point
325
- * after the TTL elapses, and subsequently delete it at any time. Returning
326
- * -32602 for an expired deleted task is compliant."
327
- *
328
- * We mark `failed` immediately on expiry and let maxTasks eviction handle
329
- * physical deletion — this avoids a second timestamp-based deletion pass.
330
- */
331
- private _sweep;
332
- /**
333
- * Enforce the maxTasks cap before inserting a new task.
334
- *
335
- * Eviction order (spec is silent; justified in TaskStoreOptions.maxTasks):
336
- * 1. Terminal tasks, oldest-terminalAt first (already served their purpose).
337
- * 2. Non-terminal tasks, oldest-createdAt first (least likely to be polled
338
- * soon), with abort signal sent to allow cooperative cleanup.
339
- */
340
- private _maybeEvict;
341
- }
342
- //# sourceMappingURL=task-store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"task-store.d.ts","sourceRoot":"","sources":["../../../src/src/tasks/task-store.ts"],"names":[],"mappings":"AAkBA;;;;;;;;GAQG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAIvC;AAID;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+DAA+D;IAC/D,aAAa,CA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