@novorb/mcp-core 2.1.2 → 3.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 (240) hide show
  1. package/README.md +77 -163
  2. package/bin/mcp-core-jest.mjs +112 -0
  3. package/dist/auth.d.ts +57 -0
  4. package/dist/auth.d.ts.map +1 -0
  5. package/dist/auth.js +74 -0
  6. package/dist/auth.js.map +1 -0
  7. package/dist/bootstrap.d.ts +129 -0
  8. package/dist/bootstrap.d.ts.map +1 -0
  9. package/dist/bootstrap.js +206 -0
  10. package/dist/bootstrap.js.map +1 -0
  11. package/dist/client-input.d.ts +72 -0
  12. package/dist/client-input.d.ts.map +1 -0
  13. package/dist/client-input.js +109 -0
  14. package/dist/client-input.js.map +1 -0
  15. package/dist/credential-checks.d.ts +80 -0
  16. package/dist/credential-checks.d.ts.map +1 -0
  17. package/dist/credential-checks.js +189 -0
  18. package/dist/credential-checks.js.map +1 -0
  19. package/dist/credential-health.d.ts +12 -0
  20. package/dist/credential-health.d.ts.map +1 -0
  21. package/dist/credential-health.js +12 -0
  22. package/dist/credential-health.js.map +1 -0
  23. package/dist/credential-report.d.ts +46 -0
  24. package/dist/credential-report.d.ts.map +1 -0
  25. package/dist/credential-report.js +135 -0
  26. package/dist/credential-report.js.map +1 -0
  27. package/dist/credential-status-tool.d.ts +20 -0
  28. package/dist/credential-status-tool.d.ts.map +1 -0
  29. package/dist/credential-status-tool.js +33 -0
  30. package/dist/credential-status-tool.js.map +1 -0
  31. package/dist/credentials.d.ts +288 -0
  32. package/dist/credentials.d.ts.map +1 -0
  33. package/dist/credentials.js +652 -0
  34. package/dist/credentials.js.map +1 -0
  35. package/dist/express-peers.d.ts +29 -0
  36. package/dist/express-peers.d.ts.map +1 -0
  37. package/dist/express-peers.js +36 -0
  38. package/dist/express-peers.js.map +1 -0
  39. package/dist/express.d.ts +74 -0
  40. package/dist/express.d.ts.map +1 -0
  41. package/dist/express.js +164 -0
  42. package/dist/express.js.map +1 -0
  43. package/dist/http-client.d.ts +277 -42
  44. package/dist/http-client.d.ts.map +1 -1
  45. package/dist/http-client.js +620 -180
  46. package/dist/http-client.js.map +1 -1
  47. package/dist/index.d.ts +27 -6
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +47 -8
  50. package/dist/index.js.map +1 -1
  51. package/dist/limits.d.ts +28 -0
  52. package/dist/limits.d.ts.map +1 -0
  53. package/dist/limits.js +37 -0
  54. package/dist/limits.js.map +1 -0
  55. package/dist/list-pagination.d.ts +41 -0
  56. package/dist/list-pagination.d.ts.map +1 -0
  57. package/dist/list-pagination.js +104 -0
  58. package/dist/list-pagination.js.map +1 -0
  59. package/dist/net.d.ts +112 -0
  60. package/dist/net.d.ts.map +1 -0
  61. package/dist/net.js +490 -0
  62. package/dist/net.js.map +1 -0
  63. package/dist/notifications.d.ts +78 -0
  64. package/dist/notifications.d.ts.map +1 -0
  65. package/dist/notifications.js +173 -0
  66. package/dist/notifications.js.map +1 -0
  67. package/dist/pagination.d.ts +236 -5
  68. package/dist/pagination.d.ts.map +1 -1
  69. package/dist/pagination.js +393 -6
  70. package/dist/pagination.js.map +1 -1
  71. package/dist/prompts.d.ts +70 -0
  72. package/dist/prompts.d.ts.map +1 -0
  73. package/dist/prompts.js +109 -0
  74. package/dist/prompts.js.map +1 -0
  75. package/dist/protocol-errors.d.ts +15 -0
  76. package/dist/protocol-errors.d.ts.map +1 -0
  77. package/dist/protocol-errors.js +28 -0
  78. package/dist/protocol-errors.js.map +1 -0
  79. package/dist/protocol-logging.d.ts +37 -0
  80. package/dist/protocol-logging.d.ts.map +1 -0
  81. package/dist/protocol-logging.js +77 -0
  82. package/dist/protocol-logging.js.map +1 -0
  83. package/dist/rate-limiter.d.ts +36 -0
  84. package/dist/rate-limiter.d.ts.map +1 -0
  85. package/dist/rate-limiter.js +79 -0
  86. package/dist/rate-limiter.js.map +1 -0
  87. package/dist/request-state.d.ts +74 -0
  88. package/dist/request-state.d.ts.map +1 -0
  89. package/dist/request-state.js +190 -0
  90. package/dist/request-state.js.map +1 -0
  91. package/dist/resources.d.ts +181 -0
  92. package/dist/resources.d.ts.map +1 -0
  93. package/dist/resources.js +302 -0
  94. package/dist/resources.js.map +1 -0
  95. package/dist/result-limits.d.ts +80 -0
  96. package/dist/result-limits.d.ts.map +1 -0
  97. package/dist/result-limits.js +248 -0
  98. package/dist/result-limits.js.map +1 -0
  99. package/dist/retry.d.ts +79 -23
  100. package/dist/retry.d.ts.map +1 -1
  101. package/dist/retry.js +170 -57
  102. package/dist/retry.js.map +1 -1
  103. package/dist/sdk/client-stdio.d.ts +6 -0
  104. package/dist/sdk/client-stdio.d.ts.map +1 -0
  105. package/dist/sdk/client-stdio.js +6 -0
  106. package/dist/sdk/client-stdio.js.map +1 -0
  107. package/dist/sdk/client.d.ts +6 -0
  108. package/dist/sdk/client.d.ts.map +1 -0
  109. package/dist/sdk/client.js +6 -0
  110. package/dist/sdk/client.js.map +1 -0
  111. package/dist/sdk/express.d.ts +3 -0
  112. package/dist/sdk/express.d.ts.map +1 -0
  113. package/dist/sdk/express.js +11 -0
  114. package/dist/sdk/express.js.map +1 -0
  115. package/dist/sdk/node.d.ts +6 -0
  116. package/dist/sdk/node.d.ts.map +1 -0
  117. package/dist/sdk/node.js +6 -0
  118. package/dist/sdk/node.js.map +1 -0
  119. package/dist/sdk/server-stdio.d.ts +6 -0
  120. package/dist/sdk/server-stdio.d.ts.map +1 -0
  121. package/dist/sdk/server-stdio.js +6 -0
  122. package/dist/sdk/server-stdio.js.map +1 -0
  123. package/dist/sdk/server.d.ts +6 -0
  124. package/dist/sdk/server.d.ts.map +1 -0
  125. package/dist/sdk/server.js +6 -0
  126. package/dist/sdk/server.js.map +1 -0
  127. package/dist/server.d.ts +88 -35
  128. package/dist/server.d.ts.map +1 -1
  129. package/dist/server.js +98 -44
  130. package/dist/server.js.map +1 -1
  131. package/dist/task-request.d.ts +20 -0
  132. package/dist/task-request.d.ts.map +1 -0
  133. package/dist/task-request.js +43 -0
  134. package/dist/task-request.js.map +1 -0
  135. package/dist/task-store.d.ts +230 -0
  136. package/dist/task-store.d.ts.map +1 -0
  137. package/dist/task-store.js +459 -0
  138. package/dist/task-store.js.map +1 -0
  139. package/dist/task-tools.d.ts +115 -0
  140. package/dist/task-tools.d.ts.map +1 -0
  141. package/dist/task-tools.js +397 -0
  142. package/dist/task-tools.js.map +1 -0
  143. package/dist/testing/client.d.ts +25 -0
  144. package/dist/testing/client.d.ts.map +1 -0
  145. package/dist/testing/client.js +11 -0
  146. package/dist/testing/client.js.map +1 -0
  147. package/dist/testing/in-memory.d.ts +26 -0
  148. package/dist/testing/in-memory.d.ts.map +1 -0
  149. package/dist/testing/in-memory.js +41 -0
  150. package/dist/testing/in-memory.js.map +1 -0
  151. package/dist/testing/index.d.ts +20 -0
  152. package/dist/testing/index.d.ts.map +1 -0
  153. package/dist/testing/index.js +20 -0
  154. package/dist/testing/index.js.map +1 -0
  155. package/dist/testing/isolated-dirs.d.ts +27 -0
  156. package/dist/testing/isolated-dirs.d.ts.map +1 -0
  157. package/dist/testing/isolated-dirs.js +67 -0
  158. package/dist/testing/isolated-dirs.js.map +1 -0
  159. package/dist/testing/logs.d.ts +61 -0
  160. package/dist/testing/logs.d.ts.map +1 -0
  161. package/dist/testing/logs.js +113 -0
  162. package/dist/testing/logs.js.map +1 -0
  163. package/dist/testing/raw-http.d.ts +25 -0
  164. package/dist/testing/raw-http.d.ts.map +1 -0
  165. package/dist/testing/raw-http.js +41 -0
  166. package/dist/testing/raw-http.js.map +1 -0
  167. package/dist/testing/raw-peer.d.ts +43 -0
  168. package/dist/testing/raw-peer.d.ts.map +1 -0
  169. package/dist/testing/raw-peer.js +101 -0
  170. package/dist/testing/raw-peer.js.map +1 -0
  171. package/dist/testing/recording-server.d.ts +38 -0
  172. package/dist/testing/recording-server.d.ts.map +1 -0
  173. package/dist/testing/recording-server.js +38 -0
  174. package/dist/testing/recording-server.js.map +1 -0
  175. package/dist/testing/server-process.d.ts +76 -0
  176. package/dist/testing/server-process.d.ts.map +1 -0
  177. package/dist/testing/server-process.js +241 -0
  178. package/dist/testing/server-process.js.map +1 -0
  179. package/dist/testing/tools.d.ts +53 -0
  180. package/dist/testing/tools.d.ts.map +1 -0
  181. package/dist/testing/tools.js +98 -0
  182. package/dist/testing/tools.js.map +1 -0
  183. package/dist/testing/unit.d.ts +52 -0
  184. package/dist/testing/unit.d.ts.map +1 -0
  185. package/dist/testing/unit.js +95 -0
  186. package/dist/testing/unit.js.map +1 -0
  187. package/dist/tools.d.ts +205 -0
  188. package/dist/tools.d.ts.map +1 -0
  189. package/dist/tools.js +370 -0
  190. package/dist/tools.js.map +1 -0
  191. package/dist/transport.d.ts +143 -52
  192. package/dist/transport.d.ts.map +1 -1
  193. package/dist/transport.js +292 -123
  194. package/dist/transport.js.map +1 -1
  195. package/dist/url-path.d.ts +49 -0
  196. package/dist/url-path.d.ts.map +1 -0
  197. package/dist/url-path.js +165 -0
  198. package/dist/url-path.js.map +1 -0
  199. package/dist/utils/dataStore.d.ts +143 -0
  200. package/dist/utils/dataStore.d.ts.map +1 -0
  201. package/dist/utils/dataStore.js +429 -0
  202. package/dist/utils/dataStore.js.map +1 -0
  203. package/dist/utils/envLoader.d.ts +129 -0
  204. package/dist/utils/envLoader.d.ts.map +1 -0
  205. package/dist/utils/envLoader.js +399 -0
  206. package/dist/utils/envLoader.js.map +1 -0
  207. package/dist/utils/logger.d.ts +181 -0
  208. package/dist/utils/logger.d.ts.map +1 -0
  209. package/dist/utils/logger.js +664 -0
  210. package/dist/utils/logger.js.map +1 -0
  211. package/dist/utils/redact.d.ts +50 -0
  212. package/dist/utils/redact.d.ts.map +1 -0
  213. package/dist/utils/redact.js +318 -0
  214. package/dist/utils/redact.js.map +1 -0
  215. package/docs/api-reference.md +29 -0
  216. package/docs/building-a-server.md +63 -0
  217. package/docs/credentials.md +131 -0
  218. package/docs/data-store.md +37 -0
  219. package/docs/env.md +38 -0
  220. package/docs/features.md +28 -0
  221. package/docs/http-client.md +116 -0
  222. package/docs/logger.md +100 -0
  223. package/docs/migrating-to-v3.md +45 -0
  224. package/docs/outbound-urls.md +104 -0
  225. package/docs/pagination.md +45 -0
  226. package/docs/protocol-features.md +62 -0
  227. package/docs/resources-prompts-tasks.md +95 -0
  228. package/docs/sdk.md +33 -0
  229. package/docs/server.md +68 -0
  230. package/docs/testing-harness.md +139 -0
  231. package/docs/testing.md +151 -0
  232. package/docs/tools.md +88 -0
  233. package/docs/transport.md +85 -0
  234. package/examples/testing/tools.integration.test.example.ts +312 -0
  235. package/examples/testing/tools.unit.test.example.ts +149 -0
  236. package/package.json +130 -17
  237. package/dist/logger.d.ts +0 -80
  238. package/dist/logger.d.ts.map +0 -1
  239. package/dist/logger.js +0 -237
  240. package/dist/logger.js.map +0 -1
package/dist/retry.js CHANGED
@@ -1,94 +1,207 @@
1
1
  /**
2
- * @novorb/mcp-core — Retry utilities
2
+ * @novorb/mcp-core - Retry utilities
3
3
  *
4
- * Exponential backoff with jitter for retrying failed HTTP requests.
4
+ * One retry policy for the whole package, shared by `retryWithBackoff` and the HTTP client:
5
+ * - retryable statuses: 408, 425, 429, 500, 502, 503, 504 (never 501, never any other 4xx)
6
+ * - retryable network errors: ECONNRESET, ETIMEDOUT, EAI_AGAIN, and ECONNREFUSED on connect only
7
+ * - `Retry-After` (seconds or HTTP date) is honoured, capped by `maxRetryAfterMs`
8
+ * - otherwise exponential backoff with full jitter, capped by `maxDelayMs`
9
+ * - bounded attempts (a loop, never recursion) and abort-signal aware
10
+ *
11
+ * Idempotency (which methods may be replayed) is decided by the caller; the HTTP client only retries
12
+ * GET/HEAD/OPTIONS/PUT/DELETE unless the request carries an idempotency key or opts in explicitly.
5
13
  */
6
14
  const DEFAULT_OPTIONS = {
7
15
  maxRetries: 3,
8
16
  initialDelayMs: 1000,
9
17
  maxDelayMs: 10000,
10
18
  backoffMultiplier: 2,
11
- jitterFactor: 0.1,
19
+ maxRetryAfterMs: 30000,
12
20
  };
21
+ /** HTTP statuses that are retried. 501 Not Implemented is permanent and deliberately absent. */
22
+ export const RETRYABLE_STATUS_CODES = new Set([408, 425, 429, 500, 502, 503, 504]);
23
+ /** Network error codes that are retried. ECONNREFUSED additionally requires the connect syscall. */
24
+ export const RETRYABLE_NETWORK_CODES = new Set([
25
+ 'ECONNRESET',
26
+ 'ETIMEDOUT',
27
+ 'EAI_AGAIN',
28
+ 'ECONNREFUSED',
29
+ ]);
30
+ /** Methods that are safe to replay without an idempotency key. */
31
+ export const IDEMPOTENT_METHODS = new Set(['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE']);
32
+ /** True for a status in `RETRYABLE_STATUS_CODES`. */
33
+ export function isRetryableStatus(status) {
34
+ return RETRYABLE_STATUS_CODES.has(status);
35
+ }
36
+ /** True for GET/HEAD/OPTIONS/PUT/DELETE (case-insensitive). A missing method counts as GET. */
37
+ export function isIdempotentMethod(method) {
38
+ return IDEMPOTENT_METHODS.has((method ?? 'GET').toUpperCase());
39
+ }
40
+ function asRecord(value) {
41
+ return value !== null && typeof value === 'object' ? value : undefined;
42
+ }
43
+ /** Reads an HTTP status from an axios-style error (`response.status`) or a normalized one (`status`). */
44
+ export function errorStatus(error) {
45
+ const err = asRecord(error);
46
+ if (!err)
47
+ return undefined;
48
+ const status = asRecord(err.response)?.status ?? err.status;
49
+ return typeof status === 'number' ? status : undefined;
50
+ }
51
+ function networkCode(err) {
52
+ const cause = asRecord(err.cause);
53
+ const code = typeof err.code === 'string' ? err.code : typeof cause?.code === 'string' ? cause.code : undefined;
54
+ const syscall = typeof err.syscall === 'string' ? err.syscall : typeof cause?.syscall === 'string' ? cause.syscall : undefined;
55
+ return { code, syscall };
56
+ }
13
57
  /**
14
- * Calculate retry delay with exponential backoff and jitter.
58
+ * Determine if an error is retryable under the shared policy. A response status decides when one is
59
+ * present; otherwise the network error code (own or `cause`) decides.
60
+ */
61
+ export function isRetryableError(error) {
62
+ const err = asRecord(error);
63
+ if (!err)
64
+ return false;
65
+ const status = errorStatus(error);
66
+ if (status !== undefined)
67
+ return isRetryableStatus(status);
68
+ const { code, syscall } = networkCode(err);
69
+ if (code === undefined || !RETRYABLE_NETWORK_CODES.has(code))
70
+ return false;
71
+ if (code === 'ECONNREFUSED')
72
+ return syscall === 'connect';
73
+ return true;
74
+ }
75
+ /**
76
+ * Exponential backoff with full jitter: a uniform value in [0, min(maxDelayMs, initial * mult^attempt)].
15
77
  */
16
78
  export function calculateRetryDelay(attempt, options = {}) {
17
- const opts = { ...DEFAULT_OPTIONS, ...options };
18
- const exponentialDelay = opts.initialDelayMs * opts.backoffMultiplier ** attempt;
19
- const cappedDelay = Math.min(exponentialDelay, opts.maxDelayMs);
20
- const jitterRange = cappedDelay * opts.jitterFactor;
21
- const jitter = (Math.random() * 2 - 1) * jitterRange;
22
- return Math.max(0, cappedDelay + jitter);
79
+ const initial = options.initialDelayMs ?? DEFAULT_OPTIONS.initialDelayMs;
80
+ const multiplier = options.backoffMultiplier ?? DEFAULT_OPTIONS.backoffMultiplier;
81
+ const maxDelay = options.maxDelayMs ?? DEFAULT_OPTIONS.maxDelayMs;
82
+ const random = options.random ?? Math.random;
83
+ const ceiling = Math.min(maxDelay, initial * multiplier ** Math.max(0, attempt));
84
+ return Math.max(0, Math.floor(random() * ceiling));
85
+ }
86
+ /**
87
+ * Parse a Retry-After header value (delta seconds or an HTTP date) to milliseconds. Returns undefined
88
+ * for a missing or unparseable value; a date in the past gives 0.
89
+ */
90
+ export function parseRetryAfter(retryAfter, now = Date.now()) {
91
+ if (!retryAfter)
92
+ return undefined;
93
+ const trimmed = retryAfter.trim();
94
+ if (/^\d+$/.test(trimmed))
95
+ return Number(trimmed) * 1000;
96
+ // An HTTP date always names a day/month; this keeps `-5` or `1.5` from parsing as a year.
97
+ const date = /[a-z]/i.test(trimmed) ? Date.parse(trimmed) : Number.NaN;
98
+ if (!Number.isNaN(date))
99
+ return Math.max(0, date - now);
100
+ return undefined;
101
+ }
102
+ function headerFrom(headers, name) {
103
+ const record = asRecord(headers);
104
+ if (!record)
105
+ return undefined;
106
+ const getter = record.get;
107
+ if (typeof getter === 'function') {
108
+ const value = getter.call(headers, name);
109
+ if (typeof value === 'string')
110
+ return value;
111
+ }
112
+ for (const [key, value] of Object.entries(record)) {
113
+ if (key.toLowerCase() === name && typeof value === 'string')
114
+ return value;
115
+ }
116
+ return undefined;
23
117
  }
24
118
  /**
25
- * Sleep for specified milliseconds.
119
+ * The Retry-After delay carried by an error, in milliseconds: a normalized error's `retryAfterMs`, or
120
+ * the `retry-after` header of an axios-style `response`.
26
121
  */
27
- export function sleep(ms) {
28
- return new Promise((resolve) => setTimeout(resolve, ms));
122
+ export function retryAfterFromError(error, now = Date.now()) {
123
+ const err = asRecord(error);
124
+ if (!err)
125
+ return undefined;
126
+ if (typeof err.retryAfterMs === 'number')
127
+ return err.retryAfterMs;
128
+ return parseRetryAfter(headerFrom(asRecord(err.response)?.headers, 'retry-after'), now);
29
129
  }
30
- /** HTTP status codes that should be retried */
31
- const RETRYABLE_STATUS_CODES = [408, 429, 502, 503, 504];
32
- /** Network error codes that should be retried */
33
- const RETRYABLE_NETWORK_CODES = ['ECONNRESET', 'ETIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED'];
34
130
  /**
35
- * Determine if an error is retryable.
131
+ * The delay before the next attempt: the error's Retry-After capped by `maxRetryAfterMs`, else the
132
+ * full-jitter backoff for `attempt`.
36
133
  */
37
- export function isRetryableError(error) {
38
- if (error && typeof error === 'object') {
39
- const err = error;
40
- // Network errors
41
- if (typeof err.code === 'string' && RETRYABLE_NETWORK_CODES.includes(err.code)) {
42
- return true;
43
- }
44
- // HTTP status codes
45
- const response = err.response;
46
- const status = response?.status;
47
- if (typeof status === 'number') {
48
- return RETRYABLE_STATUS_CODES.includes(status);
49
- }
134
+ export function retryDelayFor(error, attempt, options = {}) {
135
+ const retryAfter = retryAfterFromError(error);
136
+ if (retryAfter !== undefined) {
137
+ const cap = options.maxRetryAfterMs ?? DEFAULT_OPTIONS.maxRetryAfterMs;
138
+ return { delayMs: Math.min(retryAfter, cap), fromRetryAfter: true };
50
139
  }
51
- return false;
140
+ return { delayMs: calculateRetryDelay(attempt, options), fromRetryAfter: false };
141
+ }
142
+ function abortReason(signal) {
143
+ const reason = signal.reason;
144
+ if (reason instanceof Error)
145
+ return reason;
146
+ const err = new Error('The operation was aborted');
147
+ err.name = 'AbortError';
148
+ return err;
149
+ }
150
+ /** Throws the signal's abort reason when it has aborted. */
151
+ export function throwIfAborted(signal) {
152
+ if (signal?.aborted)
153
+ throw abortReason(signal);
52
154
  }
53
155
  /**
54
- * Retry a function with exponential backoff.
156
+ * Sleep for `ms` milliseconds. With a signal, rejects with its abort reason as soon as it aborts.
157
+ */
158
+ export function sleep(ms, signal) {
159
+ return new Promise((resolve, reject) => {
160
+ if (signal?.aborted) {
161
+ reject(abortReason(signal));
162
+ return;
163
+ }
164
+ const onAbort = () => {
165
+ clearTimeout(timer);
166
+ reject(abortReason(signal));
167
+ };
168
+ const timer = setTimeout(() => {
169
+ signal?.removeEventListener('abort', onAbort);
170
+ resolve();
171
+ }, ms);
172
+ signal?.addEventListener('abort', onAbort, { once: true });
173
+ });
174
+ }
175
+ /**
176
+ * Retry a function under the shared policy.
55
177
  *
56
178
  * @param fn - Async function to retry (receives RetryContext)
57
179
  * @param options - Retry options
58
- * @returns Result of successful function call
59
- * @throws Last error if all retries exhausted or error is not retryable
180
+ * @returns Result of the first successful call
181
+ * @throws The last error when retries are exhausted or the error is not retryable; the abort reason
182
+ * when the signal aborts
60
183
  */
61
184
  export async function retryWithBackoff(fn, options = {}) {
62
- const opts = { ...DEFAULT_OPTIONS, ...options };
185
+ const maxRetries = Math.max(0, options.maxRetries ?? DEFAULT_OPTIONS.maxRetries);
186
+ const shouldRetry = options.shouldRetry ?? ((error) => isRetryableError(error));
63
187
  let lastError;
64
- for (let attempt = 0; attempt <= opts.maxRetries; attempt++) {
65
- const context = { attempt, maxRetries: opts.maxRetries, lastError };
188
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
189
+ throwIfAborted(options.signal);
190
+ const context = { attempt, maxRetries, lastError };
66
191
  try {
67
192
  return await fn(context);
68
193
  }
69
194
  catch (error) {
70
- lastError = error;
71
- if (attempt === opts.maxRetries || !isRetryableError(error)) {
195
+ lastError = error instanceof Error ? error : new Error(String(error));
196
+ if (attempt === maxRetries || options.signal?.aborted || !shouldRetry(error, context)) {
72
197
  throw error;
73
198
  }
74
- const delay = calculateRetryDelay(attempt, options);
75
- await sleep(delay);
199
+ const { delayMs, fromRetryAfter } = retryDelayFor(error, attempt, options);
200
+ options.onRetry?.({ attempt, delayMs, fromRetryAfter, error });
201
+ await sleep(delayMs, options.signal);
76
202
  }
77
203
  }
78
- throw lastError || new Error('Retry exhausted');
79
- }
80
- /**
81
- * Parse Retry-After header value to milliseconds.
82
- */
83
- export function parseRetryAfter(retryAfter) {
84
- if (!retryAfter)
85
- return undefined;
86
- const seconds = parseInt(retryAfter, 10);
87
- if (!Number.isNaN(seconds))
88
- return seconds * 1000;
89
- const date = new Date(retryAfter);
90
- if (!Number.isNaN(date.getTime()))
91
- return Math.max(0, date.getTime() - Date.now());
92
- return undefined;
204
+ /* istanbul ignore next -- unreachable: the last attempt always returns or throws inside the loop */
205
+ throw lastError ?? new Error('Retry exhausted');
93
206
  }
94
207
  //# sourceMappingURL=retry.js.map
package/dist/retry.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAwBH,MAAM,eAAe,GAA2B;IAC9C,UAAU,EAAE,CAAC;IACb,cAAc,EAAE,IAAI;IACpB,UAAU,EAAE,KAAK;IACjB,iBAAiB,EAAE,CAAC;IACpB,YAAY,EAAE,GAAG;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe,EAAE,UAAwB,EAAE;IAC7E,MAAM,IAAI,GAAG,EAAE,GAAG,eAAe,E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,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC/B,MAAM,OAAO,GAAiB,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;QACjE,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACtE,IAAI,OAAO,KAAK,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;gBACtF,MAAM,KAAK,CAAC;YACd,CAAC;YACD,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YAC3E,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC;YAC/D,MAAM,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IACD,oGAAoG;IACpG,MAAM,SAAS,IAAI,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @novorb/mcp-core SDK re-export of `@modelcontextprotocol/client/stdio` (every runtime export and type).
3
+ * Consumers import the SDK only through mcp-core; see README "The SDK through mcp-core".
4
+ */
5
+ export * from '@modelcontextprotocol/client/stdio';
6
+ //# sourceMappingURL=client-stdio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-stdio.d.ts","sourceRoot":"","sources":["../../src/sdk/client-stdio.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,oCAAoC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @novorb/mcp-core SDK re-export of `@modelcontextprotocol/client/stdio` (every runtime export and type).
3
+ * Consumers import the SDK only through mcp-core; see README "The SDK through mcp-core".
4
+ */
5
+ export * from '@modelcontextprotocol/client/stdio';
6
+ //# sourceMappingURL=client-stdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-stdio.js","sourceRoot":"","sources":["../../src/sdk/client-stdio.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,oCAAoC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @novorb/mcp-core SDK re-export of `@modelcontextprotocol/client` (every runtime export and type).
3
+ * Consumers import the SDK only through mcp-core; see README "The SDK through mcp-core".
4
+ */
5
+ export * from '@modelcontextprotocol/client';
6
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/sdk/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @novorb/mcp-core SDK re-export of `@modelcontextprotocol/client` (every runtime export and type).
3
+ * Consumers import the SDK only through mcp-core; see README "The SDK through mcp-core".
4
+ */
5
+ export * from '@modelcontextprotocol/client';
6
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/sdk/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { AuthMetadataOptions, BearerAuthMiddlewareOptions, CreateMcpExpressAppOptions, OAuthTokenVerifier, } from '@modelcontextprotocol/express';
2
+ export declare const createMcpExpressApp: typeof import("@modelcontextprotocol/express").createMcpExpressApp, getOAuthProtectedResourceMetadataUrl: typeof import("@modelcontextprotocol/server").getOAuthProtectedResourceMetadataUrl, hostHeaderValidation: typeof import("@modelcontextprotocol/express").hostHeaderValidation, localhostHostValidation: typeof import("@modelcontextprotocol/express").localhostHostValidation, localhostOriginValidation: typeof import("@modelcontextprotocol/express").localhostOriginValidation, mcpAuthMetadataRouter: typeof import("@modelcontextprotocol/express").mcpAuthMetadataRouter, originValidation: typeof import("@modelcontextprotocol/express").originValidation, requireBearerAuth: typeof import("@modelcontextprotocol/express").requireBearerAuth;
3
+ //# sourceMappingURL=express.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/sdk/express.ts"],"names":[],"mappings":"AAWA,YAAY,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AACvC,eAAO,MACL,mBAAmB,sEACnB,oCAAoC,sFACpC,oBAAoB,uEACpB,uBAAuB,0EACvB,yBAAyB,4EACzB,qBAAqB,wEACrB,gBAAgB,mEAChB,iBAAiB,kEACR,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @novorb/mcp-core SDK re-export of `@modelcontextprotocol/express` (every runtime export and type).
3
+ * Consumers import the SDK only through mcp-core; see README "The SDK through mcp-core".
4
+ *
5
+ * `@modelcontextprotocol/express` and `express` are optional peers: this subpath loads them lazily and
6
+ * fails at import with `ExpressAdapterUnavailableError` when either is not installed.
7
+ */
8
+ import { loadExpressPeers } from '../express-peers.js';
9
+ const { adapter } = await loadExpressPeers();
10
+ export const { createMcpExpressApp, getOAuthProtectedResourceMetadataUrl, hostHeaderValidation, localhostHostValidation, localhostOriginValidation, mcpAuthMetadataRouter, originValidation, requireBearerAuth, } = adapter;
11
+ //# sourceMappingURL=express.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/sdk/express.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,gBAAgB,EAAE,CAAC;AAQ7C,MAAM,CAAC,MAAM,EACX,mBAAmB,EACnB,oCAAoC,EACpC,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,GAClB,GAAG,OAAO,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @novorb/mcp-core SDK re-export of `@modelcontextprotocol/node` (every runtime export and type).
3
+ * Consumers import the SDK only through mcp-core; see README "The SDK through mcp-core".
4
+ */
5
+ export * from '@modelcontextprotocol/node';
6
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/sdk/node.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @novorb/mcp-core SDK re-export of `@modelcontextprotocol/node` (every runtime export and type).
3
+ * Consumers import the SDK only through mcp-core; see README "The SDK through mcp-core".
4
+ */
5
+ export * from '@modelcontextprotocol/node';
6
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/sdk/node.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @novorb/mcp-core SDK re-export of `@modelcontextprotocol/server/stdio` (every runtime export and type).
3
+ * Consumers import the SDK only through mcp-core; see README "The SDK through mcp-core".
4
+ */
5
+ export * from '@modelcontextprotocol/server/stdio';
6
+ //# sourceMappingURL=server-stdio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-stdio.d.ts","sourceRoot":"","sources":["../../src/sdk/server-stdio.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,oCAAoC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @novorb/mcp-core SDK re-export of `@modelcontextprotocol/server/stdio` (every runtime export and type).
3
+ * Consumers import the SDK only through mcp-core; see README "The SDK through mcp-core".
4
+ */
5
+ export * from '@modelcontextprotocol/server/stdio';
6
+ //# sourceMappingURL=server-stdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-stdio.js","sourceRoot":"","sources":["../../src/sdk/server-stdio.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,oCAAoC,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @novorb/mcp-core SDK re-export of `@modelcontextprotocol/server` (every runtime export and type).
3
+ * Consumers import the SDK only through mcp-core; see README "The SDK through mcp-core".
4
+ */
5
+ export * from '@modelcontextprotocol/server';
6
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/sdk/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @novorb/mcp-core SDK re-export of `@modelcontextprotocol/server` (every runtime export and type).
3
+ * Consumers import the SDK only through mcp-core; see README "The SDK through mcp-core".
4
+ */
5
+ export * from '@modelcontextprotocol/server';
6
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/sdk/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,8BAA8B,CAAC"}
package/dist/server.d.ts CHANGED
@@ -1,45 +1,38 @@
1
1
  /**
2
- * @novorb/mcp-core — Server
2
+ * @novorb/mcp-core - Server
3
3
  *
4
- * Re-exports and base patterns for building MCP servers with the high-level McpServer API.
5
- * Import from here instead of the SDK directly — one centralised import point for all
6
- * server-building primitives.
4
+ * Re-exports and base patterns for building MCP servers on `@modelcontextprotocol/server` (SDK v2).
5
+ * Import from here instead of the SDK directly: one centralised import point for every
6
+ * server-building primitive, high-level (`McpServer`) and low-level (`Server`) alike.
7
7
  *
8
8
  * Usage:
9
9
  * import { createMcpServer, TOOL_ANNOTATIONS, completable } from '@novorb/mcp-core/server';
10
- * import type { McpToolAnnotations, McpCallToolResult } from '@novorb/mcp-core/server';
10
+ * import * as z from 'zod/v4';
11
11
  *
12
- * const server = createMcpServer('my-mcp', '1.0.0');
12
+ * export function buildServer(): McpServer {
13
+ * const server = createMcpServer('my-mcp', '1.0.0');
14
+ * server.registerTool('lookup', {
15
+ * description: 'Look up data by key',
16
+ * inputSchema: z.object({ key: z.string() }),
17
+ * annotations: TOOL_ANNOTATIONS.readOnly,
18
+ * }, async ({ key }) => ({ content: [{ type: 'text', text: await lookup(key) }] }));
19
+ * server.registerPrompt('find', {
20
+ * argsSchema: z.object({ key: completable(z.string(), (v) => ['foo', 'bar'].filter((k) => k.startsWith(v))) }),
21
+ * }, ({ key }) => ({ messages: [{ role: 'user', content: { type: 'text', text: `Find ${key}` } }] }));
22
+ * return server;
23
+ * }
13
24
  *
14
- * server.registerTool('lookup', {
15
- * description: 'Look up data by key',
16
- * inputSchema: { key: z.string() },
17
- * outputSchema: { value: z.string(), found: z.boolean() },
18
- * annotations: TOOL_ANNOTATIONS.readOnly,
19
- * }, async ({ key }) => {
20
- * const value = await lookup(key);
21
- * return {
22
- * content: [{ type: 'text', text: value ?? 'not found' }],
23
- * structuredContent: { value: value ?? '', found: value !== null },
24
- * };
25
- * });
26
- *
27
- * server.registerPrompt('find-and-summarise', {
28
- * title: 'Find and summarise',
29
- * description: 'Look up a key and summarise the value',
30
- * argsSchema: { key: completable(z.string(), val => ['foo', 'bar'].filter(k => k.startsWith(val))) },
31
- * }, ({ key }) => ({
32
- * messages: [{ role: 'user', content: { type: 'text', text: `Look up "${key}" and summarise the result.` } }],
33
- * }));
25
+ * An optional completable argument is written `completable(z.string(), cb).optional()`; the inverse
26
+ * nesting `completable(z.string().optional(), cb)` silently yields no completions in SDK v2.
34
27
  */
35
- export { completable } from '@modelcontextprotocol/sdk/server/completable.js';
36
- export { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
37
- export type { CallToolResult as McpCallToolResult, ToolAnnotations as McpToolAnnotations, } from '@modelcontextprotocol/sdk/types.js';
28
+ import { type Implementation, McpServer, type McpServerOptions, type RequestStateCodec } from '@modelcontextprotocol/server';
29
+ export type { AuthInfo, CallToolResult as McpCallToolResult, EmbeddedResource, GetPromptResult, Implementation, InputRequests, InputRequiredResult, InputResponses, McpServerOptions, OAuthTokenVerifier, ReadResourceResult, RegisteredPrompt, RegisteredResource, RegisteredResourceTemplate, RegisteredTool, RequestStateCodec, Resource, ResourceLink, ScopeChallengeHandler, ServerContext, ToolAnnotations as McpToolAnnotations, } from '@modelcontextprotocol/server';
30
+ export { acceptedContent, completable, createRequestStateCodec, fromJsonSchema, inputRequired, inputResponse, McpServer, OAuthError, OAuthErrorCode, ProtocolError, ProtocolErrorCode, ResourceNotFoundError, ResourceTemplate, requireScopes, Server, UrlElicitationRequiredError, } from '@modelcontextprotocol/server';
38
31
  /**
39
32
  * Standard tool annotation presets.
40
33
  *
41
34
  * Pass one of these (or a spread of multiple) to `annotations` in `registerTool`.
42
- * These are HINTS — clients may or may not act on them.
35
+ * These are HINTS; clients may or may not act on them.
43
36
  *
44
37
  * @example
45
38
  * annotations: TOOL_ANNOTATIONS.readOnly
@@ -67,13 +60,73 @@ export declare const TOOL_ANNOTATIONS: {
67
60
  destructiveHint: true;
68
61
  idempotentHint: false;
69
62
  };
63
+ /** `readOnly` + `openWorldHint` (lookups against an external API). */
64
+ readonly readOnlyOpenWorld: {
65
+ readOnlyHint: true;
66
+ idempotentHint: true;
67
+ openWorldHint: true;
68
+ };
69
+ /** `idempotentWrite` + `openWorldHint`. */
70
+ readonly idempotentWriteOpenWorld: {
71
+ readOnlyHint: false;
72
+ idempotentHint: true;
73
+ openWorldHint: true;
74
+ };
75
+ /** `mutableWrite` + `openWorldHint`. */
76
+ readonly mutableWriteOpenWorld: {
77
+ readOnlyHint: false;
78
+ idempotentHint: false;
79
+ openWorldHint: true;
80
+ };
81
+ /** `destructive` + `openWorldHint`. */
82
+ readonly destructiveOpenWorld: {
83
+ readOnlyHint: false;
84
+ destructiveHint: true;
85
+ idempotentHint: false;
86
+ openWorldHint: true;
87
+ };
70
88
  };
71
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
89
+ /** mcp-core's default cache hints: tool lists are static per process, private while they may vary by caller. */
90
+ export declare const DEFAULT_CACHE_HINTS: NonNullable<McpServerOptions['cacheHints']>;
91
+ /** `McpServerOptions` (the SDK's, passed through) plus mcp-core's own switches. */
92
+ export interface CreateMcpServerOptions extends McpServerOptions {
93
+ /**
94
+ * Page size for `tools/list` (and `prompts/list`, `resources/list`, `resources/templates/list`).
95
+ * Default `MCP_LIST_PAGE_SIZE`, else 100; 0 disables list pagination.
96
+ */
97
+ listPageSize?: number;
98
+ /**
99
+ * Advertise the `logging` capability and forward logger entries to the client as MCP logging
100
+ * notifications (deprecated by 2026-07-28, functional for at least twelve months). Default
101
+ * `LOG_PROTOCOL`, else false.
102
+ */
103
+ protocolLogging?: boolean;
104
+ /**
105
+ * The requestState codec for multi-step flows (`requestStateCodecFromEnv()`, or the SDK's HMAC
106
+ * `createRequestStateCodec`): installed as `requestState.verify`, and used by `ToolContext.continueWith`
107
+ * to mint and by `ToolContext.requestState()` to read the verified payload.
108
+ */
109
+ requestStateCodec?: RequestStateCodec;
110
+ }
111
+ /** The requestState codec `createMcpServer` installed on `server`, if any. */
112
+ export declare function requestStateCodecOf(server: McpServer): RequestStateCodec | undefined;
72
113
  /**
73
- * Create a pre-configured McpServer instance.
114
+ * Create a pre-configured McpServer instance (call it inside the factory handed to `startMcpServer`:
115
+ * in SDK v2 one instance serves one connection).
116
+ *
117
+ * Accepts the full `Implementation` (`name`, `version`, `title`, `description`, `websiteUrl`, `icons`)
118
+ * or the `(name, version)` shorthand, and the SDK's `McpServerOptions` (`instructions`, `capabilities`,
119
+ * `cacheHints`, `maxToolInputElements`, `inputRequired`, `requestState`, ...), with mcp-core defaults:
120
+ *
121
+ * - `cacheHints`: `tools/list` private for 5 minutes (`DEFAULT_CACHE_HINTS`), merged under yours;
122
+ * - `maxToolInputElements`: `MCP_MAX_TOOL_INPUT_ELEMENTS`, else 10000;
123
+ * - list pagination on (`listPageSize`);
124
+ * - protocol logging off unless `protocolLogging` / `LOG_PROTOCOL`.
74
125
  *
75
- * Thin wrapper kept so individual servers import only from @novorb/mcp-core and
76
- * don't carry a direct @modelcontextprotocol/sdk import.
126
+ * List capabilities (`tools`, `prompts`, `resources`) passed in `capabilities` are registered after the
127
+ * list pagination hook is in place; the SDK then installs the list handler on the first registration
128
+ * (a capability declared with nothing registered is answered by no list handler).
77
129
  */
78
- export declare function createMcpServer(name: string, version: string): McpServer;
130
+ export declare function createMcpServer(info: Implementation, options?: CreateMcpServerOptions): McpServer;
131
+ export declare function createMcpServer(name: string, version: string, options?: CreateMcpServerOptions): McpServer;
79
132
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAMH,OAAO,EAAE,WAAW,EAAE,MAAM,iDAAiD,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,YAAY,EACV,cAAc,IAAI,iBAAiB,EACnC,eAAe,IAAI,kBAAkB,GACtC,MAAM,oCAAoC,CAAC;AAQ5C;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB;IAC3B,4EAA4E;;;;;IAE5E,iEAAiE;;;;;IAEjE,kEAAkE;;;;;IAElE,sDAAsD;;;;;;CAE9C,CAAC;AAMX,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE;;;;;GAKG;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