@todoist/mcp-core 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -23
- package/dist/host/challenge.d.ts +6 -3
- package/dist/host/challenge.d.ts.map +1 -1
- package/dist/host/challenge.js.map +1 -1
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.d.ts.map +1 -1
- package/dist/host/index.js +1 -0
- package/dist/host/index.js.map +1 -1
- package/dist/host/rate-limit.d.ts +16 -0
- package/dist/host/rate-limit.d.ts.map +1 -0
- package/dist/host/rate-limit.js +21 -0
- package/dist/host/rate-limit.js.map +1 -0
- package/dist/host/server-contract.d.ts +2 -2
- package/dist/host/transient.d.ts +6 -1
- package/dist/host/transient.d.ts.map +1 -1
- package/dist/host/transient.js +10 -8
- package/dist/host/transient.js.map +1 -1
- package/dist/host/validate-bearer-token.d.ts +8 -4
- package/dist/host/validate-bearer-token.d.ts.map +1 -1
- package/dist/host/validate-bearer-token.js +29 -5
- package/dist/host/validate-bearer-token.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -23,17 +23,17 @@ The MCP SDK and Zod are peer dependencies, so the server and the core share one
|
|
|
23
23
|
|
|
24
24
|
## What's in it
|
|
25
25
|
|
|
26
|
-
| Module | Key exports
|
|
27
|
-
| ------------------- |
|
|
28
|
-
| `tool` | `McpTool`, `AnyMcpTool`, `ToolResult`, `ExecuteResult`, `RequiredToolAnnotations`, `ToolSchemaSource` (types)
|
|
29
|
-
| `register-tool` | `createToolRegistrar`, `ToolRegistrarOptions`, `RegisterTool`, `ToolFailure`
|
|
30
|
-
| `tool-output` | `getToolOutput`, `getErrorOutput`, `ToolOutputOptions`
|
|
31
|
-
| `sanitize` | `removeNullFields`, `RemoveNullFieldsOptions`
|
|
32
|
-
| `tool-schemas` | `getToolSchemas`, `ToolSchemas`
|
|
33
|
-
| `annotations` | `getMcpAnnotations`, `formatToolTitle`
|
|
34
|
-
| `app-meta` | `normalizeToolMeta`
|
|
35
|
-
| `host` (subpath) | `validateBearerToken`, `ValidateBearerTokenOptions`, `TokenValidationError`, `TokenValidationResult`, `ValidateToken`, `McpServerOptions`, `isTransientValidationError`, `buildBearerChallenge`, `createTokenVerdictCache` |
|
|
36
|
-
| `testing` (subpath) | `describeOutputSchemaNullability`, `describeAdvertisedToolSchemas`, `describeToolAnnotations`, `describeTokenFootprint`, `measureTokenFootprint`, `findNullablePaths`, `listAdvertisedTools`
|
|
26
|
+
| Module | Key exports |
|
|
27
|
+
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
28
|
+
| `tool` | `McpTool`, `AnyMcpTool`, `ToolResult`, `ExecuteResult`, `RequiredToolAnnotations`, `ToolSchemaSource` (types) |
|
|
29
|
+
| `register-tool` | `createToolRegistrar`, `ToolRegistrarOptions`, `RegisterTool`, `ToolFailure` |
|
|
30
|
+
| `tool-output` | `getToolOutput`, `getErrorOutput`, `ToolOutputOptions` |
|
|
31
|
+
| `sanitize` | `removeNullFields`, `RemoveNullFieldsOptions` |
|
|
32
|
+
| `tool-schemas` | `getToolSchemas`, `ToolSchemas` |
|
|
33
|
+
| `annotations` | `getMcpAnnotations`, `formatToolTitle` |
|
|
34
|
+
| `app-meta` | `normalizeToolMeta` |
|
|
35
|
+
| `host` (subpath) | `validateBearerToken`, `ValidateBearerTokenOptions`, `TokenValidationError`, `TokenValidationResult`, `ValidateToken`, `McpServerOptions`, `isTransientValidationError`, `getValidationRateLimit`, `ValidationRateLimit`, `buildBearerChallenge`, `createTokenVerdictCache` |
|
|
36
|
+
| `testing` (subpath) | `describeOutputSchemaNullability`, `describeAdvertisedToolSchemas`, `describeToolAnnotations`, `describeTokenFootprint`, `measureTokenFootprint`, `findNullablePaths`, `listAdvertisedTools` |
|
|
37
37
|
|
|
38
38
|
## Usage
|
|
39
39
|
|
|
@@ -129,23 +129,24 @@ export const validateNotesToken: ValidateToken = (token, baseUrl = 'https://note
|
|
|
129
129
|
validateBearerToken({ url: `${baseUrl}/api/v1/me`, token })
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
-
| The API answers | `validateBearerToken`
|
|
133
|
-
| ------------------------------------- |
|
|
134
|
-
| 2xx | `valid`
|
|
135
|
-
| 401 | `invalid`: the host sends a 401 challenge, and the client refreshes its token
|
|
136
|
-
| 403 | `forbidden`, or whatever `classifyForbidden(response)` returns
|
|
137
|
-
| any other status, a redirect included | throws `TokenValidationError`, whose `httpStatusCode` lets the host treat a 5xx as transient |
|
|
138
|
-
| nothing within `timeoutMs` (5s) | rejects with the `TimeoutError`
|
|
139
|
-
| a network failure | rejects with the error unchanged
|
|
132
|
+
| The API answers | `validateBearerToken` |
|
|
133
|
+
| ------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
134
|
+
| 2xx | `valid` |
|
|
135
|
+
| 401 | `invalid`: the host sends a 401 `invalid_token` challenge, and the client refreshes its token |
|
|
136
|
+
| 403 | `forbidden`, or whatever `classifyForbidden(response)` returns |
|
|
137
|
+
| any other status, a redirect included | throws `TokenValidationError`, whose `httpStatusCode` lets the host treat a 5xx as transient and a 429 as rate-limited, with the `Retry-After` as `retryAfterSeconds` |
|
|
138
|
+
| nothing within `timeoutMs` (5s) | rejects with the `TimeoutError` |
|
|
139
|
+
| a network failure | rejects with the error unchanged |
|
|
140
140
|
|
|
141
141
|
The body is drained unread, so a change to the response's shape can't misclassify a token and the connection goes back to the pool. Redirects aren't followed: a sign-in page that answers 200 would otherwise pass for an accepted token. Pass `classifyForbidden` when a 403 can also mean a refusal that consent can't lift, `headers` to tag the request, and `fetch` when the server's API client has its own transport (a proxy from `HTTPS_PROXY`, say), so validation goes the same way as every other call.
|
|
142
142
|
|
|
143
|
-
On the host's side,
|
|
143
|
+
On the host's side, four helpers turn a validator's answer into a response, whatever the HTTP framework:
|
|
144
144
|
|
|
145
145
|
```ts
|
|
146
146
|
import {
|
|
147
147
|
buildBearerChallenge,
|
|
148
148
|
createTokenVerdictCache,
|
|
149
|
+
getValidationRateLimit,
|
|
149
150
|
isTransientValidationError,
|
|
150
151
|
} from '@todoist/mcp-core/host'
|
|
151
152
|
|
|
@@ -157,6 +158,12 @@ async function checkToken(token: string, baseUrl: string): Promise<Response | 'p
|
|
|
157
158
|
try {
|
|
158
159
|
result = await validateNotesToken(token, baseUrl)
|
|
159
160
|
} catch (error) {
|
|
161
|
+
const rateLimit = getValidationRateLimit(error)
|
|
162
|
+
if (rateLimit) {
|
|
163
|
+
// Never cached, and not let through: the same limit would refuse the request.
|
|
164
|
+
const retryAfter = String(rateLimit.retryAfterSeconds ?? 60)
|
|
165
|
+
return new Response(null, { status: 429, headers: { 'Retry-After': retryAfter } })
|
|
166
|
+
}
|
|
160
167
|
if (isTransientValidationError(error)) return 'proceed' // or a 503; never cached
|
|
161
168
|
throw error
|
|
162
169
|
}
|
|
@@ -168,7 +175,7 @@ async function checkToken(token: string, baseUrl: string): Promise<Response | 'p
|
|
|
168
175
|
status: forbidden ? 403 : 401,
|
|
169
176
|
headers: {
|
|
170
177
|
'WWW-Authenticate': buildBearerChallenge({
|
|
171
|
-
error: forbidden ? 'insufficient_scope' :
|
|
178
|
+
error: forbidden ? 'insufficient_scope' : 'invalid_token',
|
|
172
179
|
resourceMetadataUrl:
|
|
173
180
|
'https://notes.example.com/.well-known/oauth-protected-resource/mcp',
|
|
174
181
|
scopes: ['notes:read', 'notes:write'],
|
|
@@ -178,8 +185,9 @@ async function checkToken(token: string, baseUrl: string): Promise<Response | 'p
|
|
|
178
185
|
}
|
|
179
186
|
```
|
|
180
187
|
|
|
181
|
-
- `isTransientValidationError`: a timeout, a dropped or refused connection, or a 5xx, the rejections worth retrying. A redirect or a
|
|
182
|
-
- `
|
|
188
|
+
- `isTransientValidationError`: a timeout, a dropped or refused connection, or a 5xx, the rejections worth retrying. A redirect, a 404 or a 429 is not.
|
|
189
|
+
- `getValidationRateLimit`: for a 429, the API rate-limiting the token's user, `{ retryAfterSeconds }` from its `Retry-After` (undefined when it sent none, so the host picks a wait); undefined for anything else. Answer 429 with `Retry-After` rather than letting the request through, where the same limit would refuse it again.
|
|
190
|
+
- `buildBearerChallenge`: `Bearer`, with `error="…"`, `resource_metadata="…"` and `scope="…"` (from `scopes`, space-separated) when given. Pass `error: 'invalid_token'` on a 401 for a token that was sent and refused, `'insufficient_scope'` on a 403, and no `error` when the request carried no token (RFC 6750 §3.1). MCP clients request the challenge's `scope` ahead of the metadata's `scopes_supported`, so pass the resource's scopes to help a client that never reads the metadata.
|
|
183
191
|
- `createTokenVerdictCache`: verdicts keyed by token and base URL, kept for `ttlMs`, the oldest dropped when full.
|
|
184
192
|
|
|
185
193
|
### Contract tests
|
package/dist/host/challenge.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export type BearerChallengeOptions = {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* The RFC 6750 error code. `invalid_token` for a 401 on a token that was sent but is revoked,
|
|
4
|
+
* expired or otherwise refused, so the client knows to refresh it or authorise again.
|
|
5
|
+
* `insufficient_scope` for a 403 on a token that lacks a scope, so the client asks for consent
|
|
6
|
+
* again. Left out when the request carried no token at all (RFC 6750 §3.1): there is nothing
|
|
7
|
+
* wrong with a token that was never sent.
|
|
5
8
|
*/
|
|
6
|
-
error?: 'insufficient_scope';
|
|
9
|
+
error?: 'invalid_token' | 'insufficient_scope';
|
|
7
10
|
/** The resource's protected-resource metadata (RFC 9728), where the client finds how to authorise. */
|
|
8
11
|
resourceMetadataUrl?: string;
|
|
9
12
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"challenge.d.ts","sourceRoot":"","sources":["../../src/host/challenge.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG;IACjC
|
|
1
|
+
{"version":3,"file":"challenge.d.ts","sourceRoot":"","sources":["../../src/host/challenge.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG;IACjC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,eAAe,GAAG,oBAAoB,CAAA;IAC9C,sGAAsG;IACtG,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAC7B,CAAA;AAED,+DAA+D;AAC/D,wBAAgB,oBAAoB,CAAC,EACjC,KAAK,EACL,mBAAmB,EACnB,MAAM,GACT,GAAE,sBAA2B,GAAG,MAAM,CAOtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"challenge.js","sourceRoot":"","sources":["../../src/host/challenge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"challenge.js","sourceRoot":"","sources":["../../src/host/challenge.ts"],"names":[],"mappings":"AAmBA,+DAA+D;AAC/D,MAAM,UAAU,oBAAoB,CAAC,EACjC,KAAK,EACL,mBAAmB,EACnB,MAAM,GACT,GAA2B,EAAE;IAC1B,MAAM,MAAM,GAAG;QACX,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,sBAAsB,mBAAmB,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9E,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1E,CAAA;IACD,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAA;AACvE,CAAC"}
|
package/dist/host/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { buildBearerChallenge, type BearerChallengeOptions } from './challenge.js';
|
|
2
2
|
export type { McpServerOptions, TokenValidationResult, ValidateToken } from './server-contract.js';
|
|
3
|
+
export { getValidationRateLimit, type ValidationRateLimit } from './rate-limit.js';
|
|
3
4
|
export { isTransientValidationError } from './transient.js';
|
|
4
5
|
export { TokenValidationError, validateBearerToken, type ValidateBearerTokenOptions, } from './validate-bearer-token.js';
|
|
5
6
|
export { createTokenVerdictCache, type TokenVerdictCache, type TokenVerdictCacheOptions, } from './verdict-cache.js';
|
package/dist/host/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,KAAK,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAClF,YAAY,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAClG,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EACH,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,0BAA0B,GAClC,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACH,uBAAuB,EACvB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,GAChC,MAAM,oBAAoB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,KAAK,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAClF,YAAY,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAClG,OAAO,EAAE,sBAAsB,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAClF,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EACH,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,0BAA0B,GAClC,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACH,uBAAuB,EACvB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,GAChC,MAAM,oBAAoB,CAAA"}
|
package/dist/host/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { buildBearerChallenge } from './challenge.js';
|
|
2
|
+
export { getValidationRateLimit } from './rate-limit.js';
|
|
2
3
|
export { isTransientValidationError } from './transient.js';
|
|
3
4
|
export { TokenValidationError, validateBearerToken, } from './validate-bearer-token.js';
|
|
4
5
|
export { createTokenVerdictCache, } from './verdict-cache.js';
|
package/dist/host/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAA+B,MAAM,gBAAgB,CAAA;AAElF,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EACH,oBAAoB,EACpB,mBAAmB,GAEtB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACH,uBAAuB,GAG1B,MAAM,oBAAoB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/host/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAA+B,MAAM,gBAAgB,CAAA;AAElF,OAAO,EAAE,sBAAsB,EAA4B,MAAM,iBAAiB,CAAA;AAClF,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EACH,oBAAoB,EACpB,mBAAmB,GAEtB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACH,uBAAuB,GAG1B,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** How a host answers a validation the API refused with a 429. */
|
|
2
|
+
export type ValidationRateLimit = {
|
|
3
|
+
/** The API's `Retry-After`, in seconds. Undefined when it sent none, so the host picks one. */
|
|
4
|
+
retryAfterSeconds: number | undefined;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Whether a `ValidateToken` rejection is the API rate-limiting the token's user (a 429), and if
|
|
8
|
+
* so how long the API asked the client to wait. Undefined for any other rejection.
|
|
9
|
+
*
|
|
10
|
+
* A 429 is no verdict on the token, and retrying it at once only spends more of the user's
|
|
11
|
+
* limit, so it is not transient either. A host answers 429 with `Retry-After` rather than
|
|
12
|
+
* letting the request through, where the same limit would refuse it again, and never caches it
|
|
13
|
+
* as a verdict.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getValidationRateLimit(error: unknown): ValidationRateLimit | undefined;
|
|
16
|
+
//# sourceMappingURL=rate-limit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/host/rate-limit.ts"],"names":[],"mappings":"AAEA,kEAAkE;AAClE,MAAM,MAAM,mBAAmB,GAAG;IAC9B,+FAA+F;IAC/F,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAA;CACxC,CAAA;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,GAAG,SAAS,CAStF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { statusOf } from './transient.js';
|
|
2
|
+
/**
|
|
3
|
+
* Whether a `ValidateToken` rejection is the API rate-limiting the token's user (a 429), and if
|
|
4
|
+
* so how long the API asked the client to wait. Undefined for any other rejection.
|
|
5
|
+
*
|
|
6
|
+
* A 429 is no verdict on the token, and retrying it at once only spends more of the user's
|
|
7
|
+
* limit, so it is not transient either. A host answers 429 with `Retry-After` rather than
|
|
8
|
+
* letting the request through, where the same limit would refuse it again, and never caches it
|
|
9
|
+
* as a verdict.
|
|
10
|
+
*/
|
|
11
|
+
export function getValidationRateLimit(error) {
|
|
12
|
+
if (statusOf(error) !== 429)
|
|
13
|
+
return undefined;
|
|
14
|
+
const retryAfter = error.retryAfterSeconds;
|
|
15
|
+
return {
|
|
16
|
+
retryAfterSeconds: typeof retryAfter === 'number' && Number.isFinite(retryAfter) && retryAfter >= 0
|
|
17
|
+
? retryAfter
|
|
18
|
+
: undefined,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=rate-limit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../src/host/rate-limit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAQzC;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACjD,IAAI,QAAQ,CAAC,KAAK,CAAC,KAAK,GAAG;QAAE,OAAO,SAAS,CAAA;IAC7C,MAAM,UAAU,GAAI,KAAyC,CAAC,iBAAiB,CAAA;IAC/E,OAAO;QACH,iBAAiB,EACb,OAAO,UAAU,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,IAAI,CAAC;YAC5E,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,SAAS;KACtB,CAAA;AACL,CAAC"}
|
|
@@ -14,8 +14,8 @@ export type TokenValidationResult = 'valid' | 'invalid' | 'forbidden';
|
|
|
14
14
|
*
|
|
15
15
|
* Resolves only with a verdict on the token. Anything else rejects: a `TokenValidationError`
|
|
16
16
|
* for an unexpected status, or the network or timeout error unchanged. A host can then tell a
|
|
17
|
-
* failure worth retrying (a 5xx, a timeout, a dropped connection)
|
|
18
|
-
* caches
|
|
17
|
+
* failure worth retrying (a 5xx, a timeout, a dropped connection) and a rate-limited user (a
|
|
18
|
+
* 429) from a verdict, and never caches either as one.
|
|
19
19
|
*/
|
|
20
20
|
export type ValidateToken = (token: string, baseUrl?: string) => Promise<TokenValidationResult>;
|
|
21
21
|
/**
|
package/dist/host/transient.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP status a rejection carries, read off any object: `TokenValidationError`'s
|
|
3
|
+
* `httpStatusCode`, or a `statusCode`. Undefined for anything that is not an object.
|
|
4
|
+
*/
|
|
5
|
+
export declare function statusOf(error: unknown): number | undefined;
|
|
1
6
|
/**
|
|
2
7
|
* Whether a `ValidateToken` rejection is worth retrying rather than a fault to report: a timeout,
|
|
3
8
|
* a dropped or refused connection (by its `code`, on the error or on its `cause`), or a 5xx
|
|
4
9
|
* (`TokenValidationError` carries it as `httpStatusCode`). A host can then let the request through or answer 503, and never caches
|
|
5
10
|
* the failure as a verdict. Anything else, such as a redirect or a 404 from a misconfigured base
|
|
6
|
-
* URL, is not transient.
|
|
11
|
+
* URL, is not transient. Nor is a 429, which `getValidationRateLimit` reads instead.
|
|
7
12
|
*/
|
|
8
13
|
export declare function isTransientValidationError(error: unknown): boolean;
|
|
9
14
|
//# sourceMappingURL=transient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transient.d.ts","sourceRoot":"","sources":["../../src/host/transient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transient.d.ts","sourceRoot":"","sources":["../../src/host/transient.ts"],"names":[],"mappings":"AAeA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAM3D;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAgBlE"}
|
package/dist/host/transient.js
CHANGED
|
@@ -11,7 +11,13 @@ const TRANSIENT_CODES = new Set([
|
|
|
11
11
|
function codeOf(value) {
|
|
12
12
|
return value?.code;
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The HTTP status a rejection carries, read off any object: `TokenValidationError`'s
|
|
16
|
+
* `httpStatusCode`, or a `statusCode`. Undefined for anything that is not an object.
|
|
17
|
+
*/
|
|
18
|
+
export function statusOf(error) {
|
|
19
|
+
if (error === null || typeof error !== 'object')
|
|
20
|
+
return undefined;
|
|
15
21
|
const record = error;
|
|
16
22
|
if (typeof record.httpStatusCode === 'number')
|
|
17
23
|
return record.httpStatusCode;
|
|
@@ -24,7 +30,7 @@ function statusOf(error) {
|
|
|
24
30
|
* a dropped or refused connection (by its `code`, on the error or on its `cause`), or a 5xx
|
|
25
31
|
* (`TokenValidationError` carries it as `httpStatusCode`). A host can then let the request through or answer 503, and never caches
|
|
26
32
|
* the failure as a verdict. Anything else, such as a redirect or a 404 from a misconfigured base
|
|
27
|
-
* URL, is not transient.
|
|
33
|
+
* URL, is not transient. Nor is a 429, which `getValidationRateLimit` reads instead.
|
|
28
34
|
*/
|
|
29
35
|
export function isTransientValidationError(error) {
|
|
30
36
|
if (error instanceof Error) {
|
|
@@ -40,11 +46,7 @@ export function isTransientValidationError(error) {
|
|
|
40
46
|
if (error.message.includes('fetch failed'))
|
|
41
47
|
return true;
|
|
42
48
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (status !== undefined && status >= 500 && status <= 599)
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
return false;
|
|
49
|
+
const status = statusOf(error);
|
|
50
|
+
return status !== undefined && status >= 500 && status <= 599;
|
|
49
51
|
}
|
|
50
52
|
//# sourceMappingURL=transient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transient.js","sourceRoot":"","sources":["../../src/host/transient.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC5B,cAAc;IACd,YAAY;IACZ,WAAW;IACX,WAAW;IACX,WAAW;IACX,OAAO;IACP,yBAAyB;IACzB,gBAAgB;CACnB,CAAC,CAAA;AAEF,SAAS,MAAM,CAAC,KAAc;IAC1B,OAAQ,KAAwC,EAAE,IAAI,CAAA;AAC1D,CAAC;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cAAc,CAAC;YAAE,OAAO,IAAI,CAAA;IAC3D,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC9B,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG,CAAA;AACjE,CAAC"}
|
|
@@ -2,11 +2,15 @@ import type { TokenValidationResult } from './server-contract.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* The validation call got an answer that is no verdict on the token: a 5xx, a 429, a redirect,
|
|
4
4
|
* or a 404 from a misconfigured base URL. `httpStatusCode` is what a host reads to treat a 5xx
|
|
5
|
-
* as transient.
|
|
5
|
+
* as transient and a 429 as the token's user being rate-limited. `retryAfterSeconds` is the
|
|
6
|
+
* response's `Retry-After`, when it sent one that can be read.
|
|
6
7
|
*/
|
|
7
8
|
export declare class TokenValidationError extends Error {
|
|
8
9
|
readonly httpStatusCode: number;
|
|
9
|
-
|
|
10
|
+
readonly retryAfterSeconds: number | undefined;
|
|
11
|
+
constructor(httpStatusCode: number, { retryAfterSeconds }?: {
|
|
12
|
+
retryAfterSeconds?: number;
|
|
13
|
+
});
|
|
10
14
|
}
|
|
11
15
|
export type ValidateBearerTokenOptions = {
|
|
12
16
|
/** An endpoint every usable token can read, ideally the cheapest one. */
|
|
@@ -36,8 +40,8 @@ export type ValidateBearerTokenOptions = {
|
|
|
36
40
|
* Redirects are not followed: a 302 to a sign-in page that anyone can load would otherwise
|
|
37
41
|
* come back 200 and pass for an accepted token.
|
|
38
42
|
*
|
|
39
|
-
* @throws {TokenValidationError} for any other status, a redirect included
|
|
40
|
-
* errors propagate unchanged.
|
|
43
|
+
* @throws {TokenValidationError} for any other status, a redirect included, carrying the
|
|
44
|
+
* response's `Retry-After`. Network and timeout errors propagate unchanged.
|
|
41
45
|
*/
|
|
42
46
|
export declare function validateBearerToken({ url, token, headers, timeoutMs, classifyForbidden, fetch: send, }: ValidateBearerTokenOptions): Promise<TokenValidationResult>;
|
|
43
47
|
//# sourceMappingURL=validate-bearer-token.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-bearer-token.d.ts","sourceRoot":"","sources":["../../src/host/validate-bearer-token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAIjE
|
|
1
|
+
{"version":3,"file":"validate-bearer-token.d.ts","sourceRoot":"","sources":["../../src/host/validate-bearer-token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAIjE;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAA;IAE9C,YACI,cAAc,EAAE,MAAM,EACtB,EAAE,iBAAiB,EAAE,GAAE;QAAE,iBAAiB,CAAC,EAAE,MAAM,CAAA;KAAO,EAM7D;CACJ;AAkBD,MAAM,MAAM,0BAA0B,GAAG;IACrC,yEAAyE;IACzE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,sFAAsF;IACtF,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,qBAAqB,CAAA;IACjE;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CACtE,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CAAC,EACtC,GAAG,EACH,KAAK,EACL,OAAO,EACP,SAA8B,EAC9B,iBAAqC,EACrC,KAAK,EAAE,IAAY,GACtB,EAAE,0BAA0B,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAoB7D"}
|
|
@@ -2,16 +2,38 @@ const DEFAULT_TIMEOUT_MS = 5_000;
|
|
|
2
2
|
/**
|
|
3
3
|
* The validation call got an answer that is no verdict on the token: a 5xx, a 429, a redirect,
|
|
4
4
|
* or a 404 from a misconfigured base URL. `httpStatusCode` is what a host reads to treat a 5xx
|
|
5
|
-
* as transient.
|
|
5
|
+
* as transient and a 429 as the token's user being rate-limited. `retryAfterSeconds` is the
|
|
6
|
+
* response's `Retry-After`, when it sent one that can be read.
|
|
6
7
|
*/
|
|
7
8
|
export class TokenValidationError extends Error {
|
|
8
9
|
httpStatusCode;
|
|
9
|
-
|
|
10
|
+
retryAfterSeconds;
|
|
11
|
+
constructor(httpStatusCode, { retryAfterSeconds } = {}) {
|
|
10
12
|
super(`Token validation failed with status ${httpStatusCode}`);
|
|
11
13
|
this.name = 'TokenValidationError';
|
|
12
14
|
this.httpStatusCode = httpStatusCode;
|
|
15
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
13
16
|
}
|
|
14
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* The seconds a `Retry-After` header asks for (RFC 9110 section 10.2.3): its delay-seconds, or the
|
|
20
|
+
* time until its HTTP date, never below 0. Undefined when the header is missing or unreadable.
|
|
21
|
+
*/
|
|
22
|
+
function parseRetryAfter(value) {
|
|
23
|
+
if (value === null)
|
|
24
|
+
return undefined;
|
|
25
|
+
const trimmed = value.trim();
|
|
26
|
+
if (/^\d+$/.test(trimmed))
|
|
27
|
+
return Number(trimmed);
|
|
28
|
+
// An HTTP date always names its day and month. Without a letter, Date.parse would read a
|
|
29
|
+
// stray number such as "-5" as a year.
|
|
30
|
+
if (!/[a-z]/i.test(trimmed))
|
|
31
|
+
return undefined;
|
|
32
|
+
const date = Date.parse(trimmed);
|
|
33
|
+
if (Number.isNaN(date))
|
|
34
|
+
return undefined;
|
|
35
|
+
return Math.max(0, Math.ceil((date - Date.now()) / 1000));
|
|
36
|
+
}
|
|
15
37
|
/**
|
|
16
38
|
* Validates a bearer token with one status-only `GET`: 2xx is `valid`, 401 `invalid`, 403
|
|
17
39
|
* `forbidden` (or whatever `classifyForbidden` says). The body is drained unread, so a change
|
|
@@ -20,8 +42,8 @@ export class TokenValidationError extends Error {
|
|
|
20
42
|
* Redirects are not followed: a 302 to a sign-in page that anyone can load would otherwise
|
|
21
43
|
* come back 200 and pass for an accepted token.
|
|
22
44
|
*
|
|
23
|
-
* @throws {TokenValidationError} for any other status, a redirect included
|
|
24
|
-
* errors propagate unchanged.
|
|
45
|
+
* @throws {TokenValidationError} for any other status, a redirect included, carrying the
|
|
46
|
+
* response's `Retry-After`. Network and timeout errors propagate unchanged.
|
|
25
47
|
*/
|
|
26
48
|
export async function validateBearerToken({ url, token, headers, timeoutMs = DEFAULT_TIMEOUT_MS, classifyForbidden = () => 'forbidden', fetch: send = fetch, }) {
|
|
27
49
|
const requestHeaders = new Headers(headers);
|
|
@@ -41,6 +63,8 @@ export async function validateBearerToken({ url, token, headers, timeoutMs = DEF
|
|
|
41
63
|
return 'invalid';
|
|
42
64
|
if (response.status === 403)
|
|
43
65
|
return classifyForbidden(response);
|
|
44
|
-
throw new TokenValidationError(response.status
|
|
66
|
+
throw new TokenValidationError(response.status, {
|
|
67
|
+
retryAfterSeconds: parseRetryAfter(response.headers.get('retry-after')),
|
|
68
|
+
});
|
|
45
69
|
}
|
|
46
70
|
//# sourceMappingURL=validate-bearer-token.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-bearer-token.js","sourceRoot":"","sources":["../../src/host/validate-bearer-token.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GAAG,KAAK,CAAA;AAEhC
|
|
1
|
+
{"version":3,"file":"validate-bearer-token.js","sourceRoot":"","sources":["../../src/host/validate-bearer-token.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB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GAAG,KAAK,GACM;IACzB,MAAM,cAAc,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;IAC3C,cAAc,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,KAAK,EAAE,CAAC,CAAA;IAEtD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE;QAC7B,OAAO,EAAE,cAAc;QACvB,QAAQ,EAAE,QAAQ;QAClB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC;KACzC,CAAC,CAAA;IACF,4FAA4F;IAC5F,8FAA8F;IAC9F,sEAAsE;IACtE,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,cAAc,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IAExE,IAAI,QAAQ,CAAC,EAAE;QAAE,OAAO,OAAO,CAAA;IAC/B,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;QAAE,OAAO,SAAS,CAAA;IAC7C,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG;QAAE,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IAC/D,MAAM,IAAI,oBAAoB,CAAC,QAAQ,CAAC,MAAM,EAAE;QAC5C,iBAAiB,EAAE,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;KAC1E,CAAC,CAAA;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@todoist/mcp-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Shared core for the Doist MCP servers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
"@types/node": "25.9.9",
|
|
65
65
|
"conventional-changelog-conventionalcommits": "9.3.1",
|
|
66
66
|
"lefthook": "2.2.2",
|
|
67
|
-
"oxfmt": "0.
|
|
68
|
-
"oxlint": "1.
|
|
67
|
+
"oxfmt": "0.79.0",
|
|
68
|
+
"oxlint": "1.94.0",
|
|
69
69
|
"semantic-release": "25.0.9",
|
|
70
70
|
"typescript": "7.0.2",
|
|
71
|
-
"vitest": "5.
|
|
71
|
+
"vitest": "5.1.1",
|
|
72
72
|
"zod": "4.6.7"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|