@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.
- package/LICENSE +21 -0
- package/README.md +337 -2
- package/adapters/pi/HOST-NOTES.md +65 -0
- package/adapters/pi/bridge.ts +721 -0
- package/adapters/pi/config.ts +364 -0
- package/adapters/pi/content-offloaded.ts +53 -0
- package/adapters/pi/content.ts +78 -0
- package/adapters/pi/diagnostics.ts +26 -0
- package/adapters/pi/elicitation.ts +133 -0
- package/adapters/pi/index.ts +210 -0
- package/adapters/pi/oauth.ts +219 -0
- package/adapters/pi/pi-api.ts +133 -0
- package/adapters/pi/resources.ts +177 -0
- package/adapters/pi/result-files.ts +32 -0
- package/adapters/pi/tasks.ts +49 -0
- package/dist/auth/client-credentials.d.ts +65 -0
- package/dist/auth/client-credentials.js +388 -0
- package/dist/auth/discovery.d.ts +28 -0
- package/dist/auth/discovery.js +125 -0
- package/dist/auth/index.d.ts +9 -0
- package/dist/auth/index.js +5 -0
- package/dist/auth/node-ports.d.ts +8 -0
- package/dist/auth/node-ports.js +67 -0
- package/dist/auth/protocol.d.ts +12 -0
- package/dist/auth/protocol.js +39 -0
- package/dist/auth/provider.d.ts +114 -0
- package/dist/auth/provider.js +407 -0
- package/dist/auth/safe-fetch.d.ts +14 -0
- package/dist/auth/safe-fetch.js +130 -0
- package/dist/client/events.d.ts +33 -0
- package/dist/client/events.js +84 -0
- package/dist/client/index.d.ts +65 -0
- package/dist/client/index.js +128 -0
- package/dist/core/auth-types.d.ts +36 -0
- package/dist/core/auth-types.js +11 -0
- package/dist/core/bearer-challenge.d.ts +3 -0
- package/dist/core/bearer-challenge.js +63 -0
- package/dist/core/cancel.d.ts +70 -0
- package/dist/core/cancel.js +177 -0
- package/dist/core/extension.d.ts +33 -0
- package/dist/core/extension.js +145 -0
- package/dist/core/index.d.ts +73 -0
- package/dist/core/index.js +129 -0
- package/dist/core/jsonrpc.d.ts +49 -0
- package/dist/core/jsonrpc.js +80 -0
- package/dist/core/lifecycle.d.ts +128 -0
- package/dist/core/lifecycle.js +251 -0
- package/dist/core/outcome.d.ts +98 -0
- package/dist/core/outcome.js +32 -0
- package/dist/core/ports.d.ts +144 -0
- package/dist/core/ports.js +67 -0
- package/dist/core/progress.d.ts +81 -0
- package/dist/core/progress.js +205 -0
- package/dist/core/request.d.ts +108 -0
- package/dist/core/request.js +578 -0
- package/dist/core/schema/index.d.ts +1 -0
- package/dist/core/schema/index.js +1 -0
- package/dist/core/schema/types.d.ts +4154 -0
- package/dist/core/schema/types.js +6 -0
- package/dist/core/telemetry.d.ts +25 -0
- package/dist/core/telemetry.js +37 -0
- package/dist/ext-events/index.d.ts +79 -0
- package/dist/ext-events/index.js +218 -0
- package/dist/ext-events/model.d.ts +10 -0
- package/dist/ext-events/model.js +6 -0
- package/dist/ext-events/push.d.ts +18 -0
- package/dist/ext-events/push.js +101 -0
- package/dist/ext-events/stream.d.ts +6 -0
- package/dist/ext-events/stream.js +60 -0
- package/dist/ext-server-cards/index.d.ts +107 -0
- package/dist/ext-server-cards/index.js +249 -0
- package/dist/ext-skills/cache.d.ts +20 -0
- package/dist/ext-skills/cache.js +101 -0
- package/dist/ext-skills/client.d.ts +82 -0
- package/dist/ext-skills/client.js +292 -0
- package/dist/ext-skills/extension.d.ts +16 -0
- package/dist/ext-skills/extension.js +29 -0
- package/dist/ext-skills/index.d.ts +4 -0
- package/dist/ext-skills/index.js +4 -0
- package/dist/ext-skills/verify.d.ts +57 -0
- package/dist/ext-skills/verify.js +168 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mrtr-cache/cache.d.ts +51 -0
- package/dist/mrtr-cache/cache.js +295 -0
- package/dist/mrtr-cache/client.d.ts +24 -0
- package/dist/mrtr-cache/client.js +44 -0
- package/dist/mrtr-cache/common.d.ts +10 -0
- package/dist/mrtr-cache/common.js +9 -0
- package/dist/mrtr-cache/elicitation.d.ts +42 -0
- package/dist/mrtr-cache/elicitation.js +221 -0
- package/dist/mrtr-cache/index.d.ts +9 -0
- package/dist/mrtr-cache/index.js +8 -0
- package/dist/mrtr-cache/mrtr.d.ts +37 -0
- package/dist/mrtr-cache/mrtr.js +250 -0
- package/dist/mrtr-cache/refresh.d.ts +8 -0
- package/dist/mrtr-cache/refresh.js +30 -0
- package/dist/mrtr-cache/stream.d.ts +5 -0
- package/dist/mrtr-cache/stream.js +18 -0
- package/dist/mrtr-cache/subscriptions.d.ts +96 -0
- package/dist/mrtr-cache/subscriptions.js +288 -0
- package/dist/mrtr-cache/tasks.d.ts +103 -0
- package/dist/mrtr-cache/tasks.js +444 -0
- package/dist/ops/common.d.ts +18 -0
- package/dist/ops/common.js +39 -0
- package/dist/ops/completion.d.ts +44 -0
- package/dist/ops/completion.js +65 -0
- package/dist/ops/content.d.ts +40 -0
- package/dist/ops/content.js +117 -0
- package/dist/ops/icons.d.ts +29 -0
- package/dist/ops/icons.js +82 -0
- package/dist/ops/index.d.ts +30 -0
- package/dist/ops/index.js +28 -0
- package/dist/ops/pagination.d.ts +32 -0
- package/dist/ops/pagination.js +65 -0
- package/dist/ops/prompts.d.ts +32 -0
- package/dist/ops/prompts.js +68 -0
- package/dist/ops/resources.d.ts +42 -0
- package/dist/ops/resources.js +104 -0
- package/dist/ops/schema.d.ts +39 -0
- package/dist/ops/schema.js +163 -0
- package/dist/ops/tools.d.ts +88 -0
- package/dist/ops/tools.js +169 -0
- package/dist/ops/uri-template.d.ts +3 -0
- package/dist/ops/uri-template.js +101 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +5 -0
- package/dist/server/mrtr.d.ts +38 -0
- package/dist/server/mrtr.js +99 -0
- package/dist/server/protocol.d.ts +21 -0
- package/dist/server/protocol.js +49 -0
- package/dist/server/server.d.ts +105 -0
- package/dist/server/server.js +383 -0
- package/dist/server/skills.d.ts +45 -0
- package/dist/server/skills.js +73 -0
- package/dist/server/uri.d.ts +2 -0
- package/dist/server/uri.js +27 -0
- package/dist/server-events/bus.d.ts +40 -0
- package/dist/server-events/bus.js +84 -0
- package/dist/server-events/events.d.ts +36 -0
- package/dist/server-events/events.js +108 -0
- package/dist/server-events/index.d.ts +6 -0
- package/dist/server-events/index.js +6 -0
- package/dist/server-events/notices.d.ts +24 -0
- package/dist/server-events/notices.js +31 -0
- package/dist/server-events/subscriptions.d.ts +33 -0
- package/dist/server-events/subscriptions.js +77 -0
- package/dist/server-events/tasks.d.ts +43 -0
- package/dist/server-events/tasks.js +101 -0
- package/dist/server-events/types.d.ts +25 -0
- package/dist/server-events/types.js +34 -0
- package/dist/server-transport/auth.d.ts +20 -0
- package/dist/server-transport/auth.js +29 -0
- package/dist/server-transport/channel.d.ts +17 -0
- package/dist/server-transport/channel.js +47 -0
- package/dist/server-transport/http.d.ts +19 -0
- package/dist/server-transport/http.js +209 -0
- package/dist/server-transport/index.d.ts +4 -0
- package/dist/server-transport/index.js +4 -0
- package/dist/server-transport/stdio.d.ts +16 -0
- package/dist/server-transport/stdio.js +83 -0
- package/dist/telemetry-otel/index.d.ts +64 -0
- package/dist/telemetry-otel/index.js +196 -0
- package/dist/testing/index.d.ts +36 -0
- package/dist/testing/index.js +140 -0
- package/dist/transport-http/headers.d.ts +24 -0
- package/dist/transport-http/headers.js +140 -0
- package/dist/transport-http/index.d.ts +3 -0
- package/dist/transport-http/index.js +3 -0
- package/dist/transport-http/sse.d.ts +33 -0
- package/dist/transport-http/sse.js +152 -0
- package/dist/transport-http/transport.d.ts +66 -0
- package/dist/transport-http/transport.js +854 -0
- package/dist/transport-stdio/framing.d.ts +50 -0
- package/dist/transport-stdio/framing.js +154 -0
- package/dist/transport-stdio/index.d.ts +4 -0
- package/dist/transport-stdio/index.js +4 -0
- package/dist/transport-stdio/stderr-ring.d.ts +27 -0
- package/dist/transport-stdio/stderr-ring.js +105 -0
- package/dist/transport-stdio/transport.d.ts +142 -0
- package/dist/transport-stdio/transport.js +743 -0
- package/dist/transport-stdio/write-queue.d.ts +48 -0
- package/dist/transport-stdio/write-queue.js +147 -0
- package/package.json +134 -4
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { NotificationQueue, systemClock, } from "../core/index.js";
|
|
2
|
+
import { object } from "./common.js";
|
|
3
|
+
export const SUBSCRIPTION_ID = "io.modelcontextprotocol/subscriptionId";
|
|
4
|
+
const kinds = ["tools", "prompts", "resources"];
|
|
5
|
+
const key = (k) => `${k}ListChanged`;
|
|
6
|
+
function subset(requested, offered, accepted) {
|
|
7
|
+
const f = {};
|
|
8
|
+
for (const k of kinds) {
|
|
9
|
+
const n = key(k);
|
|
10
|
+
if (requested[n] && (offered[n] === true) === accepted)
|
|
11
|
+
f[n] = true;
|
|
12
|
+
}
|
|
13
|
+
const uris = requested.resourceSubscriptions?.filter((u) => (Array.isArray(offered.resourceSubscriptions) &&
|
|
14
|
+
offered.resourceSubscriptions.includes(u)) === accepted);
|
|
15
|
+
if (uris?.length)
|
|
16
|
+
f.resourceSubscriptions = uris;
|
|
17
|
+
return f;
|
|
18
|
+
}
|
|
19
|
+
function grantedMethod(n, params, f) {
|
|
20
|
+
return (kinds.some((k) => n === `notifications/${k}/list_changed` && f[key(k)]) ||
|
|
21
|
+
(n === "notifications/resources/updated" &&
|
|
22
|
+
typeof params.uri === "string" &&
|
|
23
|
+
f.resourceSubscriptions?.includes(params.uri)));
|
|
24
|
+
}
|
|
25
|
+
class Listener {
|
|
26
|
+
owner;
|
|
27
|
+
opt;
|
|
28
|
+
filter;
|
|
29
|
+
state = "opening";
|
|
30
|
+
reason;
|
|
31
|
+
events = new NotificationQueue();
|
|
32
|
+
stream;
|
|
33
|
+
resolve;
|
|
34
|
+
reject;
|
|
35
|
+
acknowledged = new Promise((r, j) => {
|
|
36
|
+
this.resolve = r;
|
|
37
|
+
this.reject = j;
|
|
38
|
+
});
|
|
39
|
+
cancelTimer = () => { };
|
|
40
|
+
grant;
|
|
41
|
+
previous;
|
|
42
|
+
retries = 0;
|
|
43
|
+
attempts = [];
|
|
44
|
+
clock;
|
|
45
|
+
constructor(owner, opt, filter) {
|
|
46
|
+
this.owner = owner;
|
|
47
|
+
this.opt = opt;
|
|
48
|
+
this.filter = filter;
|
|
49
|
+
this.clock = opt.clock ?? systemClock;
|
|
50
|
+
this.acknowledged.catch(() => { });
|
|
51
|
+
this.start();
|
|
52
|
+
}
|
|
53
|
+
get id() {
|
|
54
|
+
return this.stream.id;
|
|
55
|
+
}
|
|
56
|
+
timer(ms, fn) {
|
|
57
|
+
this.cancelTimer();
|
|
58
|
+
this.cancelTimer = this.clock.setTimeout(fn, ms);
|
|
59
|
+
}
|
|
60
|
+
watchdog() {
|
|
61
|
+
this.cancelTimer();
|
|
62
|
+
if (this.opt.listenIdleMs)
|
|
63
|
+
this.timer(this.opt.listenIdleMs, () => {
|
|
64
|
+
const stream = this.stream;
|
|
65
|
+
this.abrupt();
|
|
66
|
+
stream.close();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
start() {
|
|
70
|
+
if (this.state === "ended")
|
|
71
|
+
return;
|
|
72
|
+
this.cancelTimer();
|
|
73
|
+
this.state = "opening";
|
|
74
|
+
this.grant = undefined;
|
|
75
|
+
const stream = this.opt.open("subscriptions/listen", {
|
|
76
|
+
notifications: structuredClone(this.filter),
|
|
77
|
+
});
|
|
78
|
+
this.stream = stream;
|
|
79
|
+
this.owner.register(this);
|
|
80
|
+
this.timer(this.opt.ackTimeoutMs ?? 10_000, () => {
|
|
81
|
+
this.end("transport-failure/no-ack");
|
|
82
|
+
stream.close();
|
|
83
|
+
});
|
|
84
|
+
const pump = (async () => {
|
|
85
|
+
for await (const n of stream) {
|
|
86
|
+
if (stream !== this.stream || this.state === "ended")
|
|
87
|
+
break;
|
|
88
|
+
this.owner.route(n, this.opt.binding === "stdio" ? undefined : stream.id);
|
|
89
|
+
}
|
|
90
|
+
})();
|
|
91
|
+
void pump.catch(() => {
|
|
92
|
+
if (this.stream === stream)
|
|
93
|
+
this.abrupt();
|
|
94
|
+
});
|
|
95
|
+
void stream.done
|
|
96
|
+
.then(async (out) => {
|
|
97
|
+
if (out.kind === "ok")
|
|
98
|
+
await pump;
|
|
99
|
+
if (stream !== this.stream ||
|
|
100
|
+
this.state === "ended" ||
|
|
101
|
+
this.state === "reconnecting")
|
|
102
|
+
return;
|
|
103
|
+
if (out.kind === "ok") {
|
|
104
|
+
if (this.grant &&
|
|
105
|
+
object(out.value) &&
|
|
106
|
+
out.value.resultType === "complete" &&
|
|
107
|
+
object(out.value._meta) &&
|
|
108
|
+
out.value._meta[SUBSCRIPTION_ID] === this.id)
|
|
109
|
+
this.end("server-graceful");
|
|
110
|
+
else
|
|
111
|
+
this.end("protocol-violation");
|
|
112
|
+
}
|
|
113
|
+
else if (out.kind === "transport-failure" &&
|
|
114
|
+
[401, 403].includes(out.failure.status ?? 0))
|
|
115
|
+
this.end("authorization");
|
|
116
|
+
else
|
|
117
|
+
this.abrupt();
|
|
118
|
+
})
|
|
119
|
+
.catch(() => {
|
|
120
|
+
if (stream === this.stream)
|
|
121
|
+
this.abrupt();
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
resync(f) {
|
|
125
|
+
const c = this.opt.cache, s = this.opt.serverRef;
|
|
126
|
+
c?.invalidate(s, "server/discover");
|
|
127
|
+
for (const k of kinds)
|
|
128
|
+
if (f[key(k)])
|
|
129
|
+
c?.invalidate(s, `${k}/list`);
|
|
130
|
+
for (const u of f.resourceSubscriptions ?? [])
|
|
131
|
+
c?.invalidate(s, "resources/read", u);
|
|
132
|
+
}
|
|
133
|
+
receive(n) {
|
|
134
|
+
const p = object(n.params) ? n.params : {};
|
|
135
|
+
if (n.method === "notifications/cancelled") {
|
|
136
|
+
this.end("server-cancelled");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (!this.grant &&
|
|
140
|
+
n.method === "notifications/subscriptions/acknowledged" &&
|
|
141
|
+
object(p.notifications)) {
|
|
142
|
+
this.grant = subset(this.filter, p.notifications, true);
|
|
143
|
+
this.state = "active";
|
|
144
|
+
this.watchdog();
|
|
145
|
+
this.resolve({
|
|
146
|
+
granted: structuredClone(this.grant),
|
|
147
|
+
unsupported: subset(this.filter, p.notifications, false),
|
|
148
|
+
});
|
|
149
|
+
if (this.retries) {
|
|
150
|
+
this.resync(this.previous ?? this.filter);
|
|
151
|
+
this.resync(this.grant);
|
|
152
|
+
this.events.push({ method: "resync-needed", params: {} });
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (!this.grant || !grantedMethod(n.method, p, this.grant)) {
|
|
157
|
+
this.opt.diagnostic?.(this.grant ? "ungranted-notification" : "before-ack");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
this.watchdog();
|
|
161
|
+
this.opt.cache?.notification(this.opt.serverRef, n.method, p);
|
|
162
|
+
this.events.push({ method: n.method, params: p });
|
|
163
|
+
}
|
|
164
|
+
abrupt() {
|
|
165
|
+
if (this.state === "ended" || this.state === "reconnecting")
|
|
166
|
+
return;
|
|
167
|
+
this.cancelTimer();
|
|
168
|
+
this.owner.unregister(this);
|
|
169
|
+
if (this.grant)
|
|
170
|
+
this.previous = this.grant;
|
|
171
|
+
if (this.opt.binding !== "stdio" && this.opt.reconnect === "never") {
|
|
172
|
+
this.end("transport");
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
this.state = "reconnecting";
|
|
176
|
+
this.reason = "transport";
|
|
177
|
+
this.retries++;
|
|
178
|
+
if (this.opt.binding !== "stdio") {
|
|
179
|
+
const now = this.clock.now();
|
|
180
|
+
this.attempts = this.attempts.filter((t) => t > now - 60_000);
|
|
181
|
+
const cap = Math.max(1, this.opt.maxAttemptsPerMinute ?? 12);
|
|
182
|
+
const wait = this.attempts.length >= cap
|
|
183
|
+
? Math.max(0, this.attempts[0] + 60_000 - now)
|
|
184
|
+
: 0;
|
|
185
|
+
this.timer(Math.max(wait, (this.opt.random ?? Math.random)() *
|
|
186
|
+
Math.min(60_000, 1000 * 2 ** (this.retries - 1))), () => {
|
|
187
|
+
this.attempts.push(this.clock.now());
|
|
188
|
+
this.restart();
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
restart() {
|
|
193
|
+
if (this.state !== "reconnecting")
|
|
194
|
+
return;
|
|
195
|
+
this.reason = undefined;
|
|
196
|
+
try {
|
|
197
|
+
this.start();
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
this.abrupt();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
end(reason) {
|
|
204
|
+
if (this.state === "ended")
|
|
205
|
+
return;
|
|
206
|
+
this.cancelTimer();
|
|
207
|
+
this.owner.remove(this);
|
|
208
|
+
this.state = "ended";
|
|
209
|
+
this.reason = reason;
|
|
210
|
+
this.reject(new Error(reason));
|
|
211
|
+
this.events.close();
|
|
212
|
+
}
|
|
213
|
+
close() {
|
|
214
|
+
if (this.state === "ended")
|
|
215
|
+
return;
|
|
216
|
+
const live = this.state !== "reconnecting";
|
|
217
|
+
this.end("client");
|
|
218
|
+
if (live)
|
|
219
|
+
this.stream.close();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
export class SubscriptionManager {
|
|
223
|
+
options;
|
|
224
|
+
listeners = new Set();
|
|
225
|
+
active = new Map();
|
|
226
|
+
constructor(options) {
|
|
227
|
+
this.options = options;
|
|
228
|
+
}
|
|
229
|
+
register(l) {
|
|
230
|
+
this.listeners.add(l);
|
|
231
|
+
this.active.set(l.id, l);
|
|
232
|
+
}
|
|
233
|
+
unregister(l) {
|
|
234
|
+
this.active.delete(l.id);
|
|
235
|
+
}
|
|
236
|
+
remove(l) {
|
|
237
|
+
this.unregister(l);
|
|
238
|
+
this.listeners.delete(l);
|
|
239
|
+
}
|
|
240
|
+
listen(f) {
|
|
241
|
+
const caps = this.options.capabilities, filter = {};
|
|
242
|
+
for (const k of kinds) {
|
|
243
|
+
const c = caps?.[k];
|
|
244
|
+
if (f[k] && (!caps || (object(c) && c.listChanged === true)))
|
|
245
|
+
filter[key(k)] = true;
|
|
246
|
+
}
|
|
247
|
+
const c = caps?.resources;
|
|
248
|
+
if (f.resourceUris?.length &&
|
|
249
|
+
(!caps || (object(c) && c.subscribe === true))) {
|
|
250
|
+
if (f.resourceUris.length > (this.options.maxResourceUris ?? 1000))
|
|
251
|
+
throw RangeError("too many subscription URIs");
|
|
252
|
+
filter.resourceSubscriptions = [...new Set(f.resourceUris)];
|
|
253
|
+
}
|
|
254
|
+
if (this.listeners.size >= (this.options.maxListenStreams ?? 8))
|
|
255
|
+
throw RangeError("too many concurrent listen streams");
|
|
256
|
+
return new Listener(this, this.options, filter);
|
|
257
|
+
}
|
|
258
|
+
route(n, streamId) {
|
|
259
|
+
const p = n.params;
|
|
260
|
+
const id = object(p)
|
|
261
|
+
? n.method === "notifications/cancelled"
|
|
262
|
+
? p.requestId
|
|
263
|
+
: object(p._meta)
|
|
264
|
+
? p._meta[SUBSCRIPTION_ID]
|
|
265
|
+
: undefined
|
|
266
|
+
: undefined;
|
|
267
|
+
const l = typeof id === "number" || typeof id === "string"
|
|
268
|
+
? this.active.get(id)
|
|
269
|
+
: undefined;
|
|
270
|
+
if (!l || (streamId !== undefined && id !== streamId)) {
|
|
271
|
+
this.options.diagnostic?.("subscription-id-mismatch");
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
l.receive(n);
|
|
275
|
+
}
|
|
276
|
+
async change(old, f) {
|
|
277
|
+
const next = this.listen(f);
|
|
278
|
+
await next.acknowledged;
|
|
279
|
+
old.close();
|
|
280
|
+
return next;
|
|
281
|
+
}
|
|
282
|
+
reconnected() {
|
|
283
|
+
this.options.cache?.invalidate(this.options.serverRef, "server/discover");
|
|
284
|
+
if (this.options.binding === "stdio")
|
|
285
|
+
for (const l of this.listeners)
|
|
286
|
+
l.restart();
|
|
287
|
+
}
|
|
288
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type Clock, type Disposable, type Extension, type ExtensionCapabilities, type ExtensionHost, type JsonRpcNotification, type Outcome, type StreamHandle } from "../core/index.js";
|
|
2
|
+
import { type Obj, type RequestFn } from "./common.js";
|
|
3
|
+
import { type ElicitationOptions } from "./elicitation.js";
|
|
4
|
+
export declare const TASKS_ID = "io.modelcontextprotocol/tasks";
|
|
5
|
+
export type TaskStatus = "working" | "input_required" | "completed" | "failed" | "cancelled";
|
|
6
|
+
export interface TaskRecord {
|
|
7
|
+
readonly serverKey: string;
|
|
8
|
+
readonly taskId: string;
|
|
9
|
+
readonly createdAt: number;
|
|
10
|
+
readonly lastStatus: TaskStatus;
|
|
11
|
+
readonly ttlMs?: number;
|
|
12
|
+
readonly pollIntervalMs?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface TaskStore {
|
|
15
|
+
put(record: TaskRecord): void;
|
|
16
|
+
get(serverKey: string, taskId: string): TaskRecord | undefined;
|
|
17
|
+
list(serverKey: string): readonly TaskRecord[];
|
|
18
|
+
delete(serverKey: string, taskId: string): void;
|
|
19
|
+
}
|
|
20
|
+
export declare class MemoryTaskStore implements TaskStore {
|
|
21
|
+
private readonly records;
|
|
22
|
+
put(r: TaskRecord): void;
|
|
23
|
+
get(s: string, t: string): TaskRecord | undefined;
|
|
24
|
+
list(s: string): TaskRecord[];
|
|
25
|
+
delete(s: string, t: string): void;
|
|
26
|
+
}
|
|
27
|
+
export interface TaskState extends Obj {
|
|
28
|
+
taskId: string;
|
|
29
|
+
status: TaskStatus;
|
|
30
|
+
ttl?: number | null;
|
|
31
|
+
ttlMs?: number;
|
|
32
|
+
pollIntervalMs?: number;
|
|
33
|
+
inputRequests?: Record<string, {
|
|
34
|
+
method: string;
|
|
35
|
+
params: Obj;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
export interface TasksOptions {
|
|
39
|
+
serverKey?: string;
|
|
40
|
+
store?: TaskStore;
|
|
41
|
+
clock?: Clock;
|
|
42
|
+
healthy?: boolean;
|
|
43
|
+
force?: boolean;
|
|
44
|
+
peerCapabilities?: Obj | (() => Obj);
|
|
45
|
+
elicitation?: ElicitationOptions;
|
|
46
|
+
request?: RequestFn;
|
|
47
|
+
}
|
|
48
|
+
export declare class TasksRuntime {
|
|
49
|
+
readonly opts: TasksOptions;
|
|
50
|
+
readonly store: TaskStore;
|
|
51
|
+
readonly serverKey: string;
|
|
52
|
+
readonly clock: Clock;
|
|
53
|
+
private readonly listeners;
|
|
54
|
+
private readonly watchers;
|
|
55
|
+
private readonly states;
|
|
56
|
+
constructor(opts?: TasksOptions);
|
|
57
|
+
refusal(method: string): Outcome<unknown> | undefined;
|
|
58
|
+
remember(s: TaskState): void;
|
|
59
|
+
latestState(id: string): TaskState | undefined;
|
|
60
|
+
emitUpdate(state: TaskState): void;
|
|
61
|
+
subscribe(id: string, fn: (update: TaskState | undefined) => void): () => void;
|
|
62
|
+
accept(s: Obj): Outcome<unknown>;
|
|
63
|
+
resume(id: string): TaskHandle;
|
|
64
|
+
resumeAll(): TaskHandle[];
|
|
65
|
+
wait(id: string, opts?: {
|
|
66
|
+
signal?: AbortSignal;
|
|
67
|
+
}): Promise<void>;
|
|
68
|
+
notify(n: JsonRpcNotification): void;
|
|
69
|
+
listen(stream: StreamHandle): Promise<void>;
|
|
70
|
+
}
|
|
71
|
+
export declare class TaskHandle {
|
|
72
|
+
readonly runtime: TasksRuntime;
|
|
73
|
+
readonly id: string;
|
|
74
|
+
private state?;
|
|
75
|
+
constructor(runtime: TasksRuntime, id: string, state?: TaskState | undefined);
|
|
76
|
+
private currentState;
|
|
77
|
+
status(): TaskStatus | undefined;
|
|
78
|
+
private send;
|
|
79
|
+
/** Fetches the current task state immediately on demand without pre-sleeping. */
|
|
80
|
+
get(opts?: {
|
|
81
|
+
signal?: AbortSignal;
|
|
82
|
+
} | AbortSignal): Promise<Outcome<unknown>>;
|
|
83
|
+
cancel(opts?: {
|
|
84
|
+
signal?: AbortSignal;
|
|
85
|
+
} | AbortSignal): Promise<Outcome<unknown>>;
|
|
86
|
+
update(inputResponses?: Obj, opts?: {
|
|
87
|
+
signal?: AbortSignal;
|
|
88
|
+
} | AbortSignal): Promise<Outcome<unknown>>;
|
|
89
|
+
/**
|
|
90
|
+
* Push-first watcher yielding task state updates. Uses `tasks/get` only initially
|
|
91
|
+
* (when state is unknown), on wake-only notifications without state, or when `fallbackPoll` is enabled.
|
|
92
|
+
*/
|
|
93
|
+
watch(opts?: {
|
|
94
|
+
signal?: AbortSignal;
|
|
95
|
+
fallbackPoll?: boolean;
|
|
96
|
+
}): AsyncIterable<TaskState>;
|
|
97
|
+
}
|
|
98
|
+
export declare class TasksExtension extends TasksRuntime implements Extension {
|
|
99
|
+
readonly id = "io.modelcontextprotocol/tasks";
|
|
100
|
+
capabilities(isWorking: boolean): ExtensionCapabilities;
|
|
101
|
+
attach(host: ExtensionHost): Disposable;
|
|
102
|
+
}
|
|
103
|
+
export declare function createTasksExtension(opts?: TasksOptions): TasksExtension;
|