@jangmanj/mcp 0.0.0-stage → 0.12.3

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 (184) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +337 -2
  3. package/adapters/pi/HOST-NOTES.md +65 -0
  4. package/adapters/pi/bridge.ts +721 -0
  5. package/adapters/pi/config.ts +364 -0
  6. package/adapters/pi/content-offloaded.ts +53 -0
  7. package/adapters/pi/content.ts +78 -0
  8. package/adapters/pi/diagnostics.ts +26 -0
  9. package/adapters/pi/elicitation.ts +133 -0
  10. package/adapters/pi/index.ts +210 -0
  11. package/adapters/pi/oauth.ts +219 -0
  12. package/adapters/pi/pi-api.ts +133 -0
  13. package/adapters/pi/resources.ts +177 -0
  14. package/adapters/pi/result-files.ts +32 -0
  15. package/adapters/pi/tasks.ts +49 -0
  16. package/dist/auth/client-credentials.d.ts +65 -0
  17. package/dist/auth/client-credentials.js +388 -0
  18. package/dist/auth/discovery.d.ts +28 -0
  19. package/dist/auth/discovery.js +125 -0
  20. package/dist/auth/index.d.ts +9 -0
  21. package/dist/auth/index.js +5 -0
  22. package/dist/auth/node-ports.d.ts +8 -0
  23. package/dist/auth/node-ports.js +67 -0
  24. package/dist/auth/protocol.d.ts +12 -0
  25. package/dist/auth/protocol.js +39 -0
  26. package/dist/auth/provider.d.ts +114 -0
  27. package/dist/auth/provider.js +407 -0
  28. package/dist/auth/safe-fetch.d.ts +14 -0
  29. package/dist/auth/safe-fetch.js +130 -0
  30. package/dist/client/events.d.ts +33 -0
  31. package/dist/client/events.js +84 -0
  32. package/dist/client/index.d.ts +65 -0
  33. package/dist/client/index.js +128 -0
  34. package/dist/core/auth-types.d.ts +36 -0
  35. package/dist/core/auth-types.js +11 -0
  36. package/dist/core/bearer-challenge.d.ts +3 -0
  37. package/dist/core/bearer-challenge.js +63 -0
  38. package/dist/core/cancel.d.ts +70 -0
  39. package/dist/core/cancel.js +177 -0
  40. package/dist/core/extension.d.ts +33 -0
  41. package/dist/core/extension.js +145 -0
  42. package/dist/core/index.d.ts +73 -0
  43. package/dist/core/index.js +129 -0
  44. package/dist/core/jsonrpc.d.ts +49 -0
  45. package/dist/core/jsonrpc.js +80 -0
  46. package/dist/core/lifecycle.d.ts +128 -0
  47. package/dist/core/lifecycle.js +251 -0
  48. package/dist/core/outcome.d.ts +98 -0
  49. package/dist/core/outcome.js +32 -0
  50. package/dist/core/ports.d.ts +144 -0
  51. package/dist/core/ports.js +67 -0
  52. package/dist/core/progress.d.ts +81 -0
  53. package/dist/core/progress.js +205 -0
  54. package/dist/core/request.d.ts +108 -0
  55. package/dist/core/request.js +578 -0
  56. package/dist/core/schema/index.d.ts +1 -0
  57. package/dist/core/schema/index.js +1 -0
  58. package/dist/core/schema/types.d.ts +4154 -0
  59. package/dist/core/schema/types.js +6 -0
  60. package/dist/core/telemetry.d.ts +25 -0
  61. package/dist/core/telemetry.js +37 -0
  62. package/dist/ext-events/index.d.ts +79 -0
  63. package/dist/ext-events/index.js +218 -0
  64. package/dist/ext-events/model.d.ts +10 -0
  65. package/dist/ext-events/model.js +6 -0
  66. package/dist/ext-events/push.d.ts +18 -0
  67. package/dist/ext-events/push.js +101 -0
  68. package/dist/ext-events/stream.d.ts +6 -0
  69. package/dist/ext-events/stream.js +60 -0
  70. package/dist/ext-server-cards/index.d.ts +107 -0
  71. package/dist/ext-server-cards/index.js +249 -0
  72. package/dist/ext-skills/cache.d.ts +20 -0
  73. package/dist/ext-skills/cache.js +101 -0
  74. package/dist/ext-skills/client.d.ts +82 -0
  75. package/dist/ext-skills/client.js +292 -0
  76. package/dist/ext-skills/extension.d.ts +16 -0
  77. package/dist/ext-skills/extension.js +29 -0
  78. package/dist/ext-skills/index.d.ts +4 -0
  79. package/dist/ext-skills/index.js +4 -0
  80. package/dist/ext-skills/verify.d.ts +57 -0
  81. package/dist/ext-skills/verify.js +168 -0
  82. package/dist/index.d.ts +1 -0
  83. package/dist/index.js +1 -0
  84. package/dist/mrtr-cache/cache.d.ts +51 -0
  85. package/dist/mrtr-cache/cache.js +295 -0
  86. package/dist/mrtr-cache/client.d.ts +24 -0
  87. package/dist/mrtr-cache/client.js +44 -0
  88. package/dist/mrtr-cache/common.d.ts +10 -0
  89. package/dist/mrtr-cache/common.js +9 -0
  90. package/dist/mrtr-cache/elicitation.d.ts +42 -0
  91. package/dist/mrtr-cache/elicitation.js +221 -0
  92. package/dist/mrtr-cache/index.d.ts +9 -0
  93. package/dist/mrtr-cache/index.js +8 -0
  94. package/dist/mrtr-cache/mrtr.d.ts +37 -0
  95. package/dist/mrtr-cache/mrtr.js +250 -0
  96. package/dist/mrtr-cache/refresh.d.ts +8 -0
  97. package/dist/mrtr-cache/refresh.js +30 -0
  98. package/dist/mrtr-cache/stream.d.ts +5 -0
  99. package/dist/mrtr-cache/stream.js +18 -0
  100. package/dist/mrtr-cache/subscriptions.d.ts +96 -0
  101. package/dist/mrtr-cache/subscriptions.js +288 -0
  102. package/dist/mrtr-cache/tasks.d.ts +103 -0
  103. package/dist/mrtr-cache/tasks.js +444 -0
  104. package/dist/ops/common.d.ts +18 -0
  105. package/dist/ops/common.js +39 -0
  106. package/dist/ops/completion.d.ts +44 -0
  107. package/dist/ops/completion.js +65 -0
  108. package/dist/ops/content.d.ts +40 -0
  109. package/dist/ops/content.js +117 -0
  110. package/dist/ops/icons.d.ts +29 -0
  111. package/dist/ops/icons.js +82 -0
  112. package/dist/ops/index.d.ts +30 -0
  113. package/dist/ops/index.js +28 -0
  114. package/dist/ops/pagination.d.ts +32 -0
  115. package/dist/ops/pagination.js +65 -0
  116. package/dist/ops/prompts.d.ts +32 -0
  117. package/dist/ops/prompts.js +68 -0
  118. package/dist/ops/resources.d.ts +42 -0
  119. package/dist/ops/resources.js +104 -0
  120. package/dist/ops/schema.d.ts +39 -0
  121. package/dist/ops/schema.js +163 -0
  122. package/dist/ops/tools.d.ts +88 -0
  123. package/dist/ops/tools.js +169 -0
  124. package/dist/ops/uri-template.d.ts +3 -0
  125. package/dist/ops/uri-template.js +101 -0
  126. package/dist/server/index.d.ts +5 -0
  127. package/dist/server/index.js +5 -0
  128. package/dist/server/mrtr.d.ts +38 -0
  129. package/dist/server/mrtr.js +99 -0
  130. package/dist/server/protocol.d.ts +21 -0
  131. package/dist/server/protocol.js +49 -0
  132. package/dist/server/server.d.ts +105 -0
  133. package/dist/server/server.js +383 -0
  134. package/dist/server/skills.d.ts +45 -0
  135. package/dist/server/skills.js +73 -0
  136. package/dist/server/uri.d.ts +2 -0
  137. package/dist/server/uri.js +27 -0
  138. package/dist/server-events/bus.d.ts +40 -0
  139. package/dist/server-events/bus.js +84 -0
  140. package/dist/server-events/events.d.ts +36 -0
  141. package/dist/server-events/events.js +108 -0
  142. package/dist/server-events/index.d.ts +6 -0
  143. package/dist/server-events/index.js +6 -0
  144. package/dist/server-events/notices.d.ts +24 -0
  145. package/dist/server-events/notices.js +31 -0
  146. package/dist/server-events/subscriptions.d.ts +33 -0
  147. package/dist/server-events/subscriptions.js +77 -0
  148. package/dist/server-events/tasks.d.ts +43 -0
  149. package/dist/server-events/tasks.js +101 -0
  150. package/dist/server-events/types.d.ts +25 -0
  151. package/dist/server-events/types.js +34 -0
  152. package/dist/server-transport/auth.d.ts +20 -0
  153. package/dist/server-transport/auth.js +29 -0
  154. package/dist/server-transport/channel.d.ts +17 -0
  155. package/dist/server-transport/channel.js +47 -0
  156. package/dist/server-transport/http.d.ts +19 -0
  157. package/dist/server-transport/http.js +209 -0
  158. package/dist/server-transport/index.d.ts +4 -0
  159. package/dist/server-transport/index.js +4 -0
  160. package/dist/server-transport/stdio.d.ts +16 -0
  161. package/dist/server-transport/stdio.js +83 -0
  162. package/dist/telemetry-otel/index.d.ts +64 -0
  163. package/dist/telemetry-otel/index.js +196 -0
  164. package/dist/testing/index.d.ts +36 -0
  165. package/dist/testing/index.js +140 -0
  166. package/dist/transport-http/headers.d.ts +24 -0
  167. package/dist/transport-http/headers.js +140 -0
  168. package/dist/transport-http/index.d.ts +3 -0
  169. package/dist/transport-http/index.js +3 -0
  170. package/dist/transport-http/sse.d.ts +33 -0
  171. package/dist/transport-http/sse.js +152 -0
  172. package/dist/transport-http/transport.d.ts +66 -0
  173. package/dist/transport-http/transport.js +854 -0
  174. package/dist/transport-stdio/framing.d.ts +50 -0
  175. package/dist/transport-stdio/framing.js +154 -0
  176. package/dist/transport-stdio/index.d.ts +4 -0
  177. package/dist/transport-stdio/index.js +4 -0
  178. package/dist/transport-stdio/stderr-ring.d.ts +27 -0
  179. package/dist/transport-stdio/stderr-ring.js +105 -0
  180. package/dist/transport-stdio/transport.d.ts +142 -0
  181. package/dist/transport-stdio/transport.js +743 -0
  182. package/dist/transport-stdio/write-queue.d.ts +48 -0
  183. package/dist/transport-stdio/write-queue.js +147 -0
  184. package/package.json +134 -4
@@ -0,0 +1,67 @@
1
+ export const DEFAULT_MAX_DIAGNOSTICS = 1000;
2
+ /**
3
+ * Bounded diagnostic ring buffer with AsyncIterable streaming (LIM-DIAG-1).
4
+ */
5
+ export class DiagnosticChannel {
6
+ maxEvents;
7
+ ring = [];
8
+ liveQueue = [];
9
+ waiters = [];
10
+ closed = false;
11
+ constructor(maxEvents = DEFAULT_MAX_DIAGNOSTICS) {
12
+ this.maxEvents = Math.max(0, maxEvents);
13
+ }
14
+ emit(diag) {
15
+ if (this.maxEvents > 0) {
16
+ this.ring.push(diag);
17
+ if (this.ring.length > this.maxEvents) {
18
+ this.ring.shift();
19
+ }
20
+ }
21
+ if (this.closed)
22
+ return;
23
+ const waiter = this.waiters.shift();
24
+ if (waiter) {
25
+ waiter({ value: diag, done: false });
26
+ }
27
+ else if (this.maxEvents > 0) {
28
+ this.liveQueue.push(diag);
29
+ if (this.liveQueue.length > this.maxEvents) {
30
+ this.liveQueue.shift();
31
+ }
32
+ }
33
+ }
34
+ snapshot() {
35
+ return [...this.ring];
36
+ }
37
+ close() {
38
+ if (this.closed)
39
+ return;
40
+ this.closed = true;
41
+ while (this.waiters.length > 0) {
42
+ this.waiters.shift()({ value: undefined, done: true });
43
+ }
44
+ }
45
+ [Symbol.asyncIterator]() {
46
+ return {
47
+ next: () => {
48
+ if (this.liveQueue.length > 0) {
49
+ return Promise.resolve({ value: this.liveQueue.shift(), done: false });
50
+ }
51
+ if (this.closed) {
52
+ return Promise.resolve({ value: undefined, done: true });
53
+ }
54
+ return new Promise((resolve) => {
55
+ this.waiters.push(resolve);
56
+ });
57
+ },
58
+ };
59
+ }
60
+ }
61
+ export const systemClock = {
62
+ now: () => Date.now(),
63
+ setTimeout: (fn, ms) => {
64
+ const t = globalThis.setTimeout(fn, ms);
65
+ return () => globalThis.clearTimeout(t);
66
+ },
67
+ };
@@ -0,0 +1,81 @@
1
+ import type { Clock, ProgressEvent } from "./ports.js";
2
+ /**
3
+ * Progress registry (S1.1, IMPLEMENTATION_PLAN.md §5.6; PROG-1..PROG-5).
4
+ *
5
+ * Tokens are registered when a request that carries a progressToken is started and released
6
+ * when the request settles. Notifications are accepted only for active tokens (PROG-3), only
7
+ * when the progress value strictly increases per token (PROG-2), and never after the request
8
+ * settled (PROG-4). progress/total may be any finite number (PROG-5). Every drop is counted.
9
+ */
10
+ export type ProgressToken = string | number;
11
+ export type ProgressDropReason = "inactive" | "non-monotonic" | "invalid" | "foreign";
12
+ export type ProgressDecision = {
13
+ readonly accept: true;
14
+ readonly event: ProgressEvent;
15
+ } | {
16
+ readonly accept: false;
17
+ readonly reason: ProgressDropReason;
18
+ };
19
+ export interface ProgressStats {
20
+ readonly active: number;
21
+ readonly delivered: number;
22
+ readonly inactive: number;
23
+ readonly nonMonotonic: number;
24
+ readonly invalid: number;
25
+ readonly foreign: number;
26
+ readonly collisions: number;
27
+ }
28
+ export declare function isProgressToken(v: unknown): v is ProgressToken;
29
+ export declare function progressTokenKey(token: ProgressToken): string;
30
+ /** Parses notifications/progress params; returns undefined when the shape is invalid. */
31
+ export declare function parseProgressParams(params: unknown): ProgressEvent | undefined;
32
+ export declare class ProgressRegistry {
33
+ private readonly active;
34
+ private readonly counters;
35
+ /** Registers a token for an in-flight request. Returns false when the token is already active (PROG-1). */
36
+ register(token: ProgressToken): boolean;
37
+ isActive(token: ProgressToken): boolean;
38
+ get activeCount(): number;
39
+ /**
40
+ * Decides whether a notifications/progress params object is delivered.
41
+ * When `expected` is given, a notification naming another token is dropped as foreign.
42
+ */
43
+ accept(params: unknown, expected?: ProgressToken): ProgressDecision;
44
+ /** Releases a token when its request settles (PROG-4). */
45
+ release(token: ProgressToken): void;
46
+ stats(): ProgressStats;
47
+ }
48
+ /**
49
+ * Async push queue. `close()` ends iteration after buffered items drain;
50
+ * pushes after close are ignored and reported by the return value.
51
+ */
52
+ export declare class NotificationQueue<T> implements AsyncIterable<T> {
53
+ private readonly buf;
54
+ private readonly waiters;
55
+ private closedFlag;
56
+ get closed(): boolean;
57
+ push(item: T): boolean;
58
+ close(): void;
59
+ [Symbol.asyncIterator](): AsyncIterator<T>;
60
+ }
61
+ /**
62
+ * LIM-PROG-1: rate-limits progress delivery to `limit` callbacks per `windowMs` (default 50 per
63
+ * 1000 ms) over a sliding window. Events beyond the budget are coalesced to the latest; `flush()`
64
+ * delivers the pending latest value so the final progress is always observed before settlement.
65
+ * Uses the injected Clock so fake clocks work.
66
+ */
67
+ export declare class ProgressThrottle<T> {
68
+ private readonly clock;
69
+ private readonly emit;
70
+ private readonly limit;
71
+ private readonly windowMs;
72
+ private readonly emitted;
73
+ private pending;
74
+ private cancelTimer;
75
+ constructor(clock: Clock, emit: (v: T) => void, limit?: number, windowMs?: number);
76
+ push(v: T): void;
77
+ flush(): void;
78
+ private prune;
79
+ private deliverPending;
80
+ private deliver;
81
+ }
@@ -0,0 +1,205 @@
1
+ export function isProgressToken(v) {
2
+ if (typeof v === "string")
3
+ return v.length > 0;
4
+ return typeof v === "number" && Number.isSafeInteger(v);
5
+ }
6
+ export function progressTokenKey(token) {
7
+ return `${typeof token}:${String(token)}`;
8
+ }
9
+ /** Parses notifications/progress params; returns undefined when the shape is invalid. */
10
+ export function parseProgressParams(params) {
11
+ if (typeof params !== "object" || params === null)
12
+ return undefined;
13
+ const p = params;
14
+ const token = p["progressToken"];
15
+ const progress = p["progress"];
16
+ const total = p["total"];
17
+ const message = p["message"];
18
+ if (!isProgressToken(token))
19
+ return undefined;
20
+ if (typeof progress !== "number" || !Number.isFinite(progress))
21
+ return undefined;
22
+ if (total !== undefined && (typeof total !== "number" || !Number.isFinite(total)))
23
+ return undefined;
24
+ if (message !== undefined && typeof message !== "string")
25
+ return undefined;
26
+ return {
27
+ progressToken: token,
28
+ progress,
29
+ ...(total !== undefined ? { total } : {}),
30
+ ...(message !== undefined ? { message } : {}),
31
+ };
32
+ }
33
+ export class ProgressRegistry {
34
+ active = new Map();
35
+ counters = {
36
+ delivered: 0,
37
+ inactive: 0,
38
+ nonMonotonic: 0,
39
+ invalid: 0,
40
+ foreign: 0,
41
+ collisions: 0,
42
+ };
43
+ /** Registers a token for an in-flight request. Returns false when the token is already active (PROG-1). */
44
+ register(token) {
45
+ const key = progressTokenKey(token);
46
+ if (this.active.has(key)) {
47
+ this.counters.collisions += 1;
48
+ return false;
49
+ }
50
+ this.active.set(key, { last: undefined });
51
+ return true;
52
+ }
53
+ isActive(token) {
54
+ return this.active.has(progressTokenKey(token));
55
+ }
56
+ get activeCount() {
57
+ return this.active.size;
58
+ }
59
+ /**
60
+ * Decides whether a notifications/progress params object is delivered.
61
+ * When `expected` is given, a notification naming another token is dropped as foreign.
62
+ */
63
+ accept(params, expected) {
64
+ const ev = parseProgressParams(params);
65
+ if (!ev) {
66
+ this.counters.invalid += 1;
67
+ return { accept: false, reason: "invalid" };
68
+ }
69
+ const key = progressTokenKey(ev.progressToken);
70
+ const entry = this.active.get(key);
71
+ if (!entry) {
72
+ this.counters.inactive += 1;
73
+ return { accept: false, reason: "inactive" };
74
+ }
75
+ if (expected !== undefined && progressTokenKey(expected) !== key) {
76
+ this.counters.foreign += 1;
77
+ return { accept: false, reason: "foreign" };
78
+ }
79
+ if (entry.last !== undefined && !(ev.progress > entry.last)) {
80
+ this.counters.nonMonotonic += 1;
81
+ return { accept: false, reason: "non-monotonic" };
82
+ }
83
+ entry.last = ev.progress;
84
+ this.counters.delivered += 1;
85
+ return { accept: true, event: ev };
86
+ }
87
+ /** Releases a token when its request settles (PROG-4). */
88
+ release(token) {
89
+ this.active.delete(progressTokenKey(token));
90
+ }
91
+ stats() {
92
+ return { active: this.active.size, ...this.counters };
93
+ }
94
+ }
95
+ /**
96
+ * Async push queue. `close()` ends iteration after buffered items drain;
97
+ * pushes after close are ignored and reported by the return value.
98
+ */
99
+ export class NotificationQueue {
100
+ buf = [];
101
+ waiters = [];
102
+ closedFlag = false;
103
+ get closed() {
104
+ return this.closedFlag;
105
+ }
106
+ push(item) {
107
+ if (this.closedFlag)
108
+ return false;
109
+ const w = this.waiters.shift();
110
+ if (w) {
111
+ w({ value: item, done: false });
112
+ }
113
+ else {
114
+ this.buf.push(item);
115
+ }
116
+ return true;
117
+ }
118
+ close() {
119
+ if (this.closedFlag)
120
+ return;
121
+ this.closedFlag = true;
122
+ while (this.waiters.length > 0) {
123
+ this.waiters.shift()({ value: undefined, done: true });
124
+ }
125
+ }
126
+ [Symbol.asyncIterator]() {
127
+ return {
128
+ next: () => {
129
+ if (this.buf.length > 0) {
130
+ return Promise.resolve({ value: this.buf.shift(), done: false });
131
+ }
132
+ if (this.closedFlag) {
133
+ return Promise.resolve({ value: undefined, done: true });
134
+ }
135
+ return new Promise((resolve) => {
136
+ this.waiters.push(resolve);
137
+ });
138
+ },
139
+ return: () => {
140
+ this.close();
141
+ this.buf.length = 0;
142
+ return Promise.resolve({ value: undefined, done: true });
143
+ },
144
+ };
145
+ }
146
+ }
147
+ /**
148
+ * LIM-PROG-1: rate-limits progress delivery to `limit` callbacks per `windowMs` (default 50 per
149
+ * 1000 ms) over a sliding window. Events beyond the budget are coalesced to the latest; `flush()`
150
+ * delivers the pending latest value so the final progress is always observed before settlement.
151
+ * Uses the injected Clock so fake clocks work.
152
+ */
153
+ export class ProgressThrottle {
154
+ clock;
155
+ emit;
156
+ limit;
157
+ windowMs;
158
+ emitted = [];
159
+ pending;
160
+ cancelTimer;
161
+ constructor(clock, emit, limit = 50, windowMs = 1000) {
162
+ this.clock = clock;
163
+ this.emit = emit;
164
+ this.limit = limit;
165
+ this.windowMs = windowMs;
166
+ }
167
+ push(v) {
168
+ const now = this.clock.now();
169
+ this.prune(now);
170
+ if (this.cancelTimer === undefined && this.emitted.length < this.limit) {
171
+ this.deliver(v, now);
172
+ return;
173
+ }
174
+ this.pending = { value: v };
175
+ if (this.cancelTimer === undefined) {
176
+ const wait = Math.max(0, (this.emitted[0] ?? now) + this.windowMs - now);
177
+ this.cancelTimer = this.clock.setTimeout(() => {
178
+ this.cancelTimer = undefined;
179
+ this.deliverPending();
180
+ }, wait);
181
+ }
182
+ }
183
+ flush() {
184
+ this.cancelTimer?.();
185
+ this.cancelTimer = undefined;
186
+ this.deliverPending();
187
+ }
188
+ prune(now) {
189
+ while (this.emitted.length > 0 && now - this.emitted[0] >= this.windowMs)
190
+ this.emitted.shift();
191
+ }
192
+ deliverPending() {
193
+ const p = this.pending;
194
+ if (!p)
195
+ return;
196
+ this.pending = undefined;
197
+ const now = this.clock.now();
198
+ this.prune(now);
199
+ this.deliver(p.value, now);
200
+ }
201
+ deliver(v, now) {
202
+ this.emitted.push(now);
203
+ this.emit(v);
204
+ }
205
+ }
@@ -0,0 +1,108 @@
1
+ import { ExtensionRegistry } from "./extension.js";
2
+ import { type IdGenerator, type JsonRpcNotification, type RequestId } from "./jsonrpc.js";
3
+ import { type LifecyclePolicyOptions } from "./lifecycle.js";
4
+ import { type Outcome } from "./outcome.js";
5
+ import { type PortRegistry, type ProgressEvent, type Transport } from "./ports.js";
6
+ export declare const META_PROTOCOL_VERSION: "io.modelcontextprotocol/protocolVersion";
7
+ export declare const META_CLIENT_CAPABILITIES: "io.modelcontextprotocol/clientCapabilities";
8
+ export declare const META_CLIENT_INFO: "io.modelcontextprotocol/clientInfo";
9
+ export declare const META_PROGRESS_TOKEN: "io.modelcontextprotocol/progressToken";
10
+ export interface Limits {
11
+ readonly maxInFlight: number;
12
+ readonly defaultTimeoutMs: number;
13
+ readonly hardMaxTimeoutMs: number;
14
+ }
15
+ export declare const DEFAULT_LIMITS: Limits;
16
+ export interface RequestOptions {
17
+ readonly signal?: AbortSignal;
18
+ readonly timeoutMs?: number;
19
+ readonly stream?: boolean;
20
+ readonly onProgress?: (p: ProgressEvent) => void;
21
+ readonly idempotent?: boolean;
22
+ /** HTTP-AMBIG-3: required (true) to re-issue a request after an uncertain-write. */
23
+ readonly acceptDuplicate?: boolean;
24
+ /** HTTP-AMBIG-3: original request id when re-issuing after an uncertain-write. */
25
+ readonly retryOf?: RequestId;
26
+ readonly meta?: Record<string, unknown>;
27
+ readonly mrtr?: "auto" | "manual";
28
+ readonly headersHint?: {
29
+ readonly name?: string;
30
+ readonly params?: Readonly<Record<string, string | number | boolean>>;
31
+ };
32
+ }
33
+ export interface NotifyOptions {
34
+ readonly signal?: AbortSignal;
35
+ readonly timeoutMs?: number;
36
+ readonly meta?: Record<string, unknown>;
37
+ readonly headersHint?: {
38
+ readonly name?: string;
39
+ readonly params?: Readonly<Record<string, string | number | boolean>>;
40
+ };
41
+ }
42
+ export interface ClientRequest<T = unknown> extends PromiseLike<Outcome<T>> {
43
+ readonly id: RequestId;
44
+ readonly progress: AsyncIterable<ProgressEvent>;
45
+ readonly notifications: AsyncIterable<JsonRpcNotification>;
46
+ cancel(reason?: string): void;
47
+ readonly signal: AbortSignal;
48
+ }
49
+ export interface StreamHandle extends AsyncIterable<JsonRpcNotification> {
50
+ readonly id: RequestId;
51
+ readonly done: Promise<Outcome<unknown>>;
52
+ close(): void;
53
+ }
54
+ export declare function validateMetaEntries(meta: Record<string, unknown>): void;
55
+ /**
56
+ * Validates caller-supplied _meta: reserved keys and key syntax (WIRE-META-4/5) plus the
57
+ * deprecated logLevel key (WIRE-LOG-1). Throws before anything is sent.
58
+ */
59
+ export declare function validateCallerMeta(meta: Record<string, unknown>): void;
60
+ export interface RequestManagerConfig {
61
+ readonly transport: Transport;
62
+ readonly serverLabel?: string;
63
+ readonly ports?: Partial<PortRegistry>;
64
+ readonly clientInfo?: {
65
+ readonly name: string;
66
+ readonly version: string;
67
+ readonly title?: string;
68
+ } | false;
69
+ readonly extensions?: ExtensionRegistry;
70
+ readonly idGenerator?: IdGenerator;
71
+ readonly limits?: Partial<Limits>;
72
+ readonly supportedVersions?: readonly string[];
73
+ readonly protocolVersion?: string;
74
+ readonly lifecycle?: LifecyclePolicyOptions;
75
+ }
76
+ export declare class RequestManager {
77
+ private readonly transport;
78
+ private readonly clock;
79
+ private readonly logger?;
80
+ private readonly extensions;
81
+ private readonly nextId;
82
+ private readonly limits;
83
+ private readonly ports;
84
+ private readonly serverLabel?;
85
+ private readonly clientInfo?;
86
+ private readonly supportedVersions;
87
+ private activeProtocolVersion;
88
+ private readonly hooks;
89
+ private readonly settleOnAbort;
90
+ private readonly isReadOnly;
91
+ private readonly progress;
92
+ private readonly ctx;
93
+ private readonly inFlight;
94
+ private readonly admissionQueue;
95
+ private closed;
96
+ constructor(cfg: RequestManagerConfig);
97
+ get inFlightCount(): number;
98
+ request<T = Record<string, unknown>>(method: string, params?: Record<string, unknown>, opts?: RequestOptions): ClientRequest<T>;
99
+ notify(method: string, params?: Record<string, unknown>, opts?: NotifyOptions): Promise<void>;
100
+ private buildMeta;
101
+ private execute;
102
+ private executeCore;
103
+ /** LIM-CONC-1: hand freed slots to the oldest queued requests (slot reserved before resume). */
104
+ private admitQueued;
105
+ close(opts?: {
106
+ readonly graceMs?: number;
107
+ }): Promise<void>;
108
+ }