@novorb/mcp-core 2.1.1 → 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.
- package/README.md +82 -161
- package/bin/mcp-core-jest.mjs +112 -0
- package/dist/auth.d.ts +57 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +74 -0
- package/dist/auth.js.map +1 -0
- package/dist/bootstrap.d.ts +129 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +206 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/client-input.d.ts +72 -0
- package/dist/client-input.d.ts.map +1 -0
- package/dist/client-input.js +109 -0
- package/dist/client-input.js.map +1 -0
- package/dist/credential-checks.d.ts +80 -0
- package/dist/credential-checks.d.ts.map +1 -0
- package/dist/credential-checks.js +189 -0
- package/dist/credential-checks.js.map +1 -0
- package/dist/credential-health.d.ts +12 -0
- package/dist/credential-health.d.ts.map +1 -0
- package/dist/credential-health.js +12 -0
- package/dist/credential-health.js.map +1 -0
- package/dist/credential-report.d.ts +46 -0
- package/dist/credential-report.d.ts.map +1 -0
- package/dist/credential-report.js +135 -0
- package/dist/credential-report.js.map +1 -0
- package/dist/credential-status-tool.d.ts +20 -0
- package/dist/credential-status-tool.d.ts.map +1 -0
- package/dist/credential-status-tool.js +33 -0
- package/dist/credential-status-tool.js.map +1 -0
- package/dist/credentials.d.ts +288 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +652 -0
- package/dist/credentials.js.map +1 -0
- package/dist/express-peers.d.ts +29 -0
- package/dist/express-peers.d.ts.map +1 -0
- package/dist/express-peers.js +36 -0
- package/dist/express-peers.js.map +1 -0
- package/dist/express.d.ts +74 -0
- package/dist/express.d.ts.map +1 -0
- package/dist/express.js +164 -0
- package/dist/express.js.map +1 -0
- package/dist/http-client.d.ts +278 -43
- package/dist/http-client.d.ts.map +1 -1
- package/dist/http-client.js +620 -182
- package/dist/http-client.js.map +1 -1
- package/dist/index.d.ts +27 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +49 -10
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +28 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +37 -0
- package/dist/limits.js.map +1 -0
- package/dist/list-pagination.d.ts +41 -0
- package/dist/list-pagination.d.ts.map +1 -0
- package/dist/list-pagination.js +104 -0
- package/dist/list-pagination.js.map +1 -0
- package/dist/net.d.ts +112 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.js +490 -0
- package/dist/net.js.map +1 -0
- package/dist/notifications.d.ts +78 -0
- package/dist/notifications.d.ts.map +1 -0
- package/dist/notifications.js +173 -0
- package/dist/notifications.js.map +1 -0
- package/dist/pagination.d.ts +236 -5
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +393 -6
- package/dist/pagination.js.map +1 -1
- package/dist/prompts.d.ts +70 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +109 -0
- package/dist/prompts.js.map +1 -0
- package/dist/protocol-errors.d.ts +15 -0
- package/dist/protocol-errors.d.ts.map +1 -0
- package/dist/protocol-errors.js +28 -0
- package/dist/protocol-errors.js.map +1 -0
- package/dist/protocol-logging.d.ts +37 -0
- package/dist/protocol-logging.d.ts.map +1 -0
- package/dist/protocol-logging.js +77 -0
- package/dist/protocol-logging.js.map +1 -0
- package/dist/rate-limiter.d.ts +36 -0
- package/dist/rate-limiter.d.ts.map +1 -0
- package/dist/rate-limiter.js +79 -0
- package/dist/rate-limiter.js.map +1 -0
- package/dist/request-state.d.ts +74 -0
- package/dist/request-state.d.ts.map +1 -0
- package/dist/request-state.js +190 -0
- package/dist/request-state.js.map +1 -0
- package/dist/resources.d.ts +181 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +302 -0
- package/dist/resources.js.map +1 -0
- package/dist/result-limits.d.ts +80 -0
- package/dist/result-limits.d.ts.map +1 -0
- package/dist/result-limits.js +248 -0
- package/dist/result-limits.js.map +1 -0
- package/dist/retry.d.ts +79 -23
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +170 -57
- package/dist/retry.js.map +1 -1
- package/dist/sdk/client-stdio.d.ts +6 -0
- package/dist/sdk/client-stdio.d.ts.map +1 -0
- package/dist/sdk/client-stdio.js +6 -0
- package/dist/sdk/client-stdio.js.map +1 -0
- package/dist/sdk/client.d.ts +6 -0
- package/dist/sdk/client.d.ts.map +1 -0
- package/dist/sdk/client.js +6 -0
- package/dist/sdk/client.js.map +1 -0
- package/dist/sdk/express.d.ts +3 -0
- package/dist/sdk/express.d.ts.map +1 -0
- package/dist/sdk/express.js +11 -0
- package/dist/sdk/express.js.map +1 -0
- package/dist/sdk/node.d.ts +6 -0
- package/dist/sdk/node.d.ts.map +1 -0
- package/dist/sdk/node.js +6 -0
- package/dist/sdk/node.js.map +1 -0
- package/dist/sdk/server-stdio.d.ts +6 -0
- package/dist/sdk/server-stdio.d.ts.map +1 -0
- package/dist/sdk/server-stdio.js +6 -0
- package/dist/sdk/server-stdio.js.map +1 -0
- package/dist/sdk/server.d.ts +6 -0
- package/dist/sdk/server.d.ts.map +1 -0
- package/dist/sdk/server.js +6 -0
- package/dist/sdk/server.js.map +1 -0
- package/dist/server.d.ts +88 -36
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +98 -44
- package/dist/server.js.map +1 -1
- package/dist/task-request.d.ts +20 -0
- package/dist/task-request.d.ts.map +1 -0
- package/dist/task-request.js +43 -0
- package/dist/task-request.js.map +1 -0
- package/dist/task-store.d.ts +230 -0
- package/dist/task-store.d.ts.map +1 -0
- package/dist/task-store.js +459 -0
- package/dist/task-store.js.map +1 -0
- package/dist/task-tools.d.ts +115 -0
- package/dist/task-tools.d.ts.map +1 -0
- package/dist/task-tools.js +397 -0
- package/dist/task-tools.js.map +1 -0
- package/dist/testing/client.d.ts +25 -0
- package/dist/testing/client.d.ts.map +1 -0
- package/dist/testing/client.js +11 -0
- package/dist/testing/client.js.map +1 -0
- package/dist/testing/in-memory.d.ts +26 -0
- package/dist/testing/in-memory.d.ts.map +1 -0
- package/dist/testing/in-memory.js +41 -0
- package/dist/testing/in-memory.js.map +1 -0
- package/dist/testing/index.d.ts +20 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +20 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/isolated-dirs.d.ts +27 -0
- package/dist/testing/isolated-dirs.d.ts.map +1 -0
- package/dist/testing/isolated-dirs.js +67 -0
- package/dist/testing/isolated-dirs.js.map +1 -0
- package/dist/testing/logs.d.ts +61 -0
- package/dist/testing/logs.d.ts.map +1 -0
- package/dist/testing/logs.js +113 -0
- package/dist/testing/logs.js.map +1 -0
- package/dist/testing/raw-http.d.ts +25 -0
- package/dist/testing/raw-http.d.ts.map +1 -0
- package/dist/testing/raw-http.js +41 -0
- package/dist/testing/raw-http.js.map +1 -0
- package/dist/testing/raw-peer.d.ts +43 -0
- package/dist/testing/raw-peer.d.ts.map +1 -0
- package/dist/testing/raw-peer.js +101 -0
- package/dist/testing/raw-peer.js.map +1 -0
- package/dist/testing/recording-server.d.ts +38 -0
- package/dist/testing/recording-server.d.ts.map +1 -0
- package/dist/testing/recording-server.js +38 -0
- package/dist/testing/recording-server.js.map +1 -0
- package/dist/testing/server-process.d.ts +76 -0
- package/dist/testing/server-process.d.ts.map +1 -0
- package/dist/testing/server-process.js +241 -0
- package/dist/testing/server-process.js.map +1 -0
- package/dist/testing/tools.d.ts +53 -0
- package/dist/testing/tools.d.ts.map +1 -0
- package/dist/testing/tools.js +98 -0
- package/dist/testing/tools.js.map +1 -0
- package/dist/testing/unit.d.ts +52 -0
- package/dist/testing/unit.d.ts.map +1 -0
- package/dist/testing/unit.js +95 -0
- package/dist/testing/unit.js.map +1 -0
- package/dist/tools.d.ts +205 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +370 -0
- package/dist/tools.js.map +1 -0
- package/dist/transport.d.ts +144 -53
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +305 -122
- package/dist/transport.js.map +1 -1
- package/dist/url-path.d.ts +49 -0
- package/dist/url-path.d.ts.map +1 -0
- package/dist/url-path.js +165 -0
- package/dist/url-path.js.map +1 -0
- package/dist/utils/dataStore.d.ts +143 -0
- package/dist/utils/dataStore.d.ts.map +1 -0
- package/dist/utils/dataStore.js +429 -0
- package/dist/utils/dataStore.js.map +1 -0
- package/dist/utils/envLoader.d.ts +129 -0
- package/dist/utils/envLoader.d.ts.map +1 -0
- package/dist/utils/envLoader.js +399 -0
- package/dist/utils/envLoader.js.map +1 -0
- package/dist/utils/logger.d.ts +181 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +664 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/redact.d.ts +50 -0
- package/dist/utils/redact.d.ts.map +1 -0
- package/dist/utils/redact.js +318 -0
- package/dist/utils/redact.js.map +1 -0
- package/docs/api-reference.md +29 -0
- package/docs/building-a-server.md +63 -0
- package/docs/credentials.md +131 -0
- package/docs/data-store.md +37 -0
- package/docs/env.md +38 -0
- package/docs/features.md +28 -0
- package/docs/http-client.md +116 -0
- package/docs/logger.md +100 -0
- package/docs/migrating-to-v3.md +45 -0
- package/docs/outbound-urls.md +104 -0
- package/docs/pagination.md +45 -0
- package/docs/protocol-features.md +62 -0
- package/docs/resources-prompts-tasks.md +95 -0
- package/docs/sdk.md +33 -0
- package/docs/server.md +68 -0
- package/docs/testing-harness.md +139 -0
- package/docs/testing.md +151 -0
- package/docs/tools.md +88 -0
- package/docs/transport.md +85 -0
- package/examples/testing/tools.integration.test.example.ts +312 -0
- package/examples/testing/tools.unit.test.example.ts +149 -0
- package/package.json +140 -18
- package/dist/logger.d.ts +0 -80
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -236
- package/dist/logger.js.map +0 -1
package/dist/retry.js
CHANGED
|
@@ -1,94 +1,207 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @novorb/mcp-core
|
|
2
|
+
* @novorb/mcp-core - Retry utilities
|
|
3
3
|
*
|
|
4
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
return Math.max(0,
|
|
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
|
-
*
|
|
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
|
|
28
|
-
|
|
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
|
-
*
|
|
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
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
*
|
|
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
|
|
59
|
-
* @throws
|
|
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
|
|
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 <=
|
|
65
|
-
|
|
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 ===
|
|
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
|
|
75
|
-
|
|
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
|
-
|
|
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 (!isNaN(seconds))
|
|
88
|
-
return seconds * 1000;
|
|
89
|
-
const date = new Date(retryAfter);
|
|
90
|
-
if (!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
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA2CH,MAAM,eAAe,GAAG;IACtB,UAAU,EAAE,CAAC;IACb,cAAc,EAAE,IAAI;IACpB,UAAU,EAAE,KAAK;IACjB,iBAAiB,EAAE,CAAC;IACpB,eAAe,EAAE,KAAK;CACvB,CAAC;AAEF,gGAAgG;AAChG,MAAM,CAAC,MAAM,sBAAsB,GAAwB,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAExG,oGAAoG;AACpG,MAAM,CAAC,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAAC;IAClE,YAAY;IACZ,WAAW;IACX,WAAW;IACX,cAAc;CACf,CAAC,CAAC;AAEH,kEAAkE;AAClE,MAAM,CAAC,MAAM,kBAAkB,GAAwB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE5G,qDAAqD;AACrD,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,OAAO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CAAC,KAAK,CAAC,CAAC,CAAC;IACzF,IAAI,SAA4B,CAAC;IAEjC,KAAK,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"}
|
package/dist/sdk/node.js
ADDED
|
@@ -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,46 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @novorb/mcp-core
|
|
2
|
+
* @novorb/mcp-core - Server
|
|
3
3
|
*
|
|
4
|
-
* Re-exports and base patterns for building MCP servers
|
|
5
|
-
* Import from here instead of the SDK directly
|
|
6
|
-
* server-building
|
|
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
|
|
10
|
+
* import * as z from 'zod/v4';
|
|
11
11
|
*
|
|
12
|
-
*
|
|
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
|
-
*
|
|
15
|
-
*
|
|
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
|
-
|
|
36
|
-
export {
|
|
37
|
-
export
|
|
38
|
-
export type { CallToolResult as McpCallToolResult } 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';
|
|
39
31
|
/**
|
|
40
32
|
* Standard tool annotation presets.
|
|
41
33
|
*
|
|
42
34
|
* Pass one of these (or a spread of multiple) to `annotations` in `registerTool`.
|
|
43
|
-
* These are HINTS
|
|
35
|
+
* These are HINTS; clients may or may not act on them.
|
|
44
36
|
*
|
|
45
37
|
* @example
|
|
46
38
|
* annotations: TOOL_ANNOTATIONS.readOnly
|
|
@@ -68,13 +60,73 @@ export declare const TOOL_ANNOTATIONS: {
|
|
|
68
60
|
destructiveHint: true;
|
|
69
61
|
idempotentHint: false;
|
|
70
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
|
+
};
|
|
71
88
|
};
|
|
72
|
-
|
|
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;
|
|
73
113
|
/**
|
|
74
|
-
* 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`.
|
|
75
125
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
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).
|
|
78
129
|
*/
|
|
79
|
-
export declare function createMcpServer(
|
|
130
|
+
export declare function createMcpServer(info: Implementation, options?: CreateMcpServerOptions): McpServer;
|
|
131
|
+
export declare function createMcpServer(name: string, version: string, options?: CreateMcpServerOptions): McpServer;
|
|
80
132
|
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA
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