@vitemcp/server 1.4.0 → 1.6.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 -0
- package/dist/ViteMCP.cjs +172 -99
- package/dist/ViteMCP.cjs.map +1 -1
- package/dist/ViteMCP.d.cts +41 -2
- package/dist/ViteMCP.d.ts +41 -2
- package/dist/ViteMCP.js +155 -82
- package/dist/ViteMCP.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ A TypeScript framework for building stateless [MCP](https://glama.ai/mcp) server
|
|
|
26
26
|
- [Prompts](#prompts)
|
|
27
27
|
- [Authentication](#authentication)
|
|
28
28
|
- [Providing Instructions](#providing-instructions)
|
|
29
|
+
- [Server metadata and icons](#server-metadata-and-icons)
|
|
29
30
|
- [Multi round-trip requests](#multi-round-trip-requests)
|
|
30
31
|
- [Cacheable results](#cacheable-results)
|
|
31
32
|
- [Client ID Metadata Documents](#client-id-metadata-documents)
|
|
@@ -1261,6 +1262,36 @@ const server = new ViteMCP({
|
|
|
1261
1262
|
});
|
|
1262
1263
|
```
|
|
1263
1264
|
|
|
1265
|
+
### Server metadata and icons
|
|
1266
|
+
|
|
1267
|
+
`icons`, `title`, `description` and `websiteUrl` are returned in `serverInfo`
|
|
1268
|
+
on `initialize`, so clients can list the server with a logo and a display name
|
|
1269
|
+
instead of the bare `name`:
|
|
1270
|
+
|
|
1271
|
+
```ts
|
|
1272
|
+
const server = new ViteMCP({
|
|
1273
|
+
name: "my-server",
|
|
1274
|
+
title: "My Server",
|
|
1275
|
+
description: "Weather forecasts and alerts.",
|
|
1276
|
+
version: "1.0.0",
|
|
1277
|
+
websiteUrl: "https://example.com",
|
|
1278
|
+
icons: [
|
|
1279
|
+
{
|
|
1280
|
+
src: "https://example.com/icon.png",
|
|
1281
|
+
mimeType: "image/png",
|
|
1282
|
+
sizes: ["48x48"],
|
|
1283
|
+
},
|
|
1284
|
+
],
|
|
1285
|
+
});
|
|
1286
|
+
```
|
|
1287
|
+
|
|
1288
|
+
`src` is fetched by the client, so it has to be reachable from wherever the
|
|
1289
|
+
client runs — not just from the server. Every field is optional, and clients
|
|
1290
|
+
that do not support them ignore them.
|
|
1291
|
+
|
|
1292
|
+
`description` is for the person picking a server; `instructions` is for the
|
|
1293
|
+
model using it.
|
|
1294
|
+
|
|
1264
1295
|
### Multi round-trip requests
|
|
1265
1296
|
|
|
1266
1297
|
On the stateless protocol a server cannot pause mid-execution and ask the
|
package/dist/ViteMCP.cjs
CHANGED
|
@@ -573,7 +573,9 @@ var ViteMCP = class {
|
|
|
573
573
|
async embedded(uri) {
|
|
574
574
|
const direct = this.#resources.find((resource) => resource.uri === uri);
|
|
575
575
|
if (direct) {
|
|
576
|
-
const loaded = await direct.load(
|
|
576
|
+
const loaded = await direct.load(
|
|
577
|
+
this.#makeContext(void 0, void 0).context
|
|
578
|
+
);
|
|
577
579
|
const first = Array.isArray(loaded) ? loaded[0] : loaded;
|
|
578
580
|
if (!first) {
|
|
579
581
|
throw new UnexpectedStateError(`Resource loaded no content: ${uri}`, {
|
|
@@ -589,7 +591,7 @@ var ViteMCP = class {
|
|
|
589
591
|
}
|
|
590
592
|
const loaded = await template.load(
|
|
591
593
|
params,
|
|
592
|
-
this.#makeContext(void 0, void 0)
|
|
594
|
+
this.#makeContext(void 0, void 0).context
|
|
593
595
|
);
|
|
594
596
|
const first = Array.isArray(loaded) ? loaded[0] : loaded;
|
|
595
597
|
if (!first) {
|
|
@@ -718,7 +720,14 @@ var ViteMCP = class {
|
|
|
718
720
|
}
|
|
719
721
|
async #buildServer(auth) {
|
|
720
722
|
const server = new (0, _server.McpServer)(
|
|
721
|
-
{
|
|
723
|
+
{
|
|
724
|
+
description: this.#options.description,
|
|
725
|
+
icons: this.#options.icons,
|
|
726
|
+
name: this.#options.name,
|
|
727
|
+
title: this.#options.title,
|
|
728
|
+
version: this.#options.version,
|
|
729
|
+
websiteUrl: this.#options.websiteUrl
|
|
730
|
+
},
|
|
722
731
|
{ instructions: this.#options.instructions }
|
|
723
732
|
);
|
|
724
733
|
for (const tool of this.#tools) {
|
|
@@ -741,13 +750,14 @@ var ViteMCP = class {
|
|
|
741
750
|
)
|
|
742
751
|
},
|
|
743
752
|
(async (args, ctx) => {
|
|
744
|
-
const
|
|
753
|
+
const timeout = tool.timeoutMs ? { controller: new AbortController(), ms: tool.timeoutMs } : void 0;
|
|
754
|
+
const { context, release } = this.#makeContext(
|
|
755
|
+
auth,
|
|
756
|
+
ctx,
|
|
757
|
+
_optionalChain([timeout, 'optionalAccess', _23 => _23.controller, 'access', _24 => _24.signal])
|
|
758
|
+
);
|
|
745
759
|
try {
|
|
746
|
-
const result = await (
|
|
747
|
-
tool.execute(args, context),
|
|
748
|
-
tool.timeoutMs,
|
|
749
|
-
tool.name
|
|
750
|
-
) : tool.execute(args, context));
|
|
760
|
+
const result = await (timeout ? withTimeout(tool.execute(args, context), timeout, tool.name) : tool.execute(args, context));
|
|
751
761
|
return normalizeToolResult(result, tool.outputSchema !== void 0);
|
|
752
762
|
} catch (error) {
|
|
753
763
|
if (error instanceof UserError) {
|
|
@@ -758,6 +768,8 @@ var ViteMCP = class {
|
|
|
758
768
|
};
|
|
759
769
|
}
|
|
760
770
|
throw error;
|
|
771
|
+
} finally {
|
|
772
|
+
release();
|
|
761
773
|
}
|
|
762
774
|
})
|
|
763
775
|
);
|
|
@@ -775,16 +787,20 @@ var ViteMCP = class {
|
|
|
775
787
|
mimeType: resource.mimeType
|
|
776
788
|
},
|
|
777
789
|
(async (uri, ctx) => {
|
|
778
|
-
const context = this.#makeContext(auth, ctx);
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
790
|
+
const { context, release } = this.#makeContext(auth, ctx);
|
|
791
|
+
try {
|
|
792
|
+
const loaded = await resource.load(context);
|
|
793
|
+
const bodies = Array.isArray(loaded) ? loaded : [loaded];
|
|
794
|
+
return {
|
|
795
|
+
contents: bodies.map((body) => ({
|
|
796
|
+
...body,
|
|
797
|
+
mimeType: _nullishCoalesce(body.mimeType, () => ( resource.mimeType)),
|
|
798
|
+
uri: _nullishCoalesce(body.uri, () => ( uri.toString()))
|
|
799
|
+
}))
|
|
800
|
+
};
|
|
801
|
+
} finally {
|
|
802
|
+
release();
|
|
803
|
+
}
|
|
788
804
|
})
|
|
789
805
|
);
|
|
790
806
|
}
|
|
@@ -811,16 +827,20 @@ var ViteMCP = class {
|
|
|
811
827
|
mimeType: template.mimeType
|
|
812
828
|
},
|
|
813
829
|
(async (uri, args, ctx) => {
|
|
814
|
-
const context = this.#makeContext(auth, ctx);
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
830
|
+
const { context, release } = this.#makeContext(auth, ctx);
|
|
831
|
+
try {
|
|
832
|
+
const loaded = await template.load(_nullishCoalesce(args, () => ( {})), context);
|
|
833
|
+
const bodies = Array.isArray(loaded) ? loaded : [loaded];
|
|
834
|
+
return {
|
|
835
|
+
contents: bodies.map((body) => ({
|
|
836
|
+
...body,
|
|
837
|
+
mimeType: _nullishCoalesce(body.mimeType, () => ( template.mimeType)),
|
|
838
|
+
uri: _nullishCoalesce(body.uri, () => ( uri.toString()))
|
|
839
|
+
}))
|
|
840
|
+
};
|
|
841
|
+
} finally {
|
|
842
|
+
release();
|
|
843
|
+
}
|
|
824
844
|
})
|
|
825
845
|
);
|
|
826
846
|
}
|
|
@@ -835,19 +855,23 @@ var ViteMCP = class {
|
|
|
835
855
|
description: prompt.description
|
|
836
856
|
},
|
|
837
857
|
(async (args, ctx) => {
|
|
838
|
-
const context = this.#makeContext(auth, ctx);
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
858
|
+
const { context, release } = this.#makeContext(auth, ctx);
|
|
859
|
+
try {
|
|
860
|
+
const loaded = await prompt.load(_nullishCoalesce(args, () => ( {})), context);
|
|
861
|
+
if (typeof loaded !== "string") {
|
|
862
|
+
return loaded;
|
|
863
|
+
}
|
|
864
|
+
return {
|
|
865
|
+
messages: [
|
|
866
|
+
{
|
|
867
|
+
content: { text: loaded, type: "text" },
|
|
868
|
+
role: "user"
|
|
869
|
+
}
|
|
870
|
+
]
|
|
871
|
+
};
|
|
872
|
+
} finally {
|
|
873
|
+
release();
|
|
842
874
|
}
|
|
843
|
-
return {
|
|
844
|
-
messages: [
|
|
845
|
-
{
|
|
846
|
-
content: { text: loaded, type: "text" },
|
|
847
|
-
role: "user"
|
|
848
|
-
}
|
|
849
|
-
]
|
|
850
|
-
};
|
|
851
875
|
})
|
|
852
876
|
);
|
|
853
877
|
}
|
|
@@ -862,54 +886,70 @@ var ViteMCP = class {
|
|
|
862
886
|
);
|
|
863
887
|
return app;
|
|
864
888
|
}
|
|
865
|
-
/**
|
|
866
|
-
|
|
889
|
+
/**
|
|
890
|
+
* Bridges the v2 per-request context onto ViteMCP's `Context`.
|
|
891
|
+
*
|
|
892
|
+
* `timeoutSignal` is folded into `context.signal` for a tool that declares
|
|
893
|
+
* `timeoutMs`; everything else mirrors the SDK's request signal alone. Call
|
|
894
|
+
* `release()` once the handler has settled — see {@link requestScope}.
|
|
895
|
+
*/
|
|
896
|
+
#makeContext(auth, rawCtx, timeoutSignal) {
|
|
867
897
|
const ctx = rawCtx;
|
|
868
|
-
const mcpReq = _optionalChain([ctx, 'optionalAccess',
|
|
869
|
-
const requestedLevel = _optionalChain([mcpReq, 'optionalAccess',
|
|
898
|
+
const mcpReq = _optionalChain([ctx, 'optionalAccess', _25 => _25.mcpReq]);
|
|
899
|
+
const requestedLevel = _optionalChain([mcpReq, 'optionalAccess', _26 => _26._meta, 'optionalAccess', _27 => _27["io.modelcontextprotocol/logLevel"]]);
|
|
870
900
|
const emit = (level, message, data) => {
|
|
871
901
|
if (!requestedLevel) {
|
|
872
902
|
return;
|
|
873
903
|
}
|
|
874
|
-
void _optionalChain([mcpReq, 'optionalAccess',
|
|
904
|
+
void _optionalChain([mcpReq, 'optionalAccess', _28 => _28.notify, 'optionalCall', _29 => _29({
|
|
875
905
|
method: "notifications/message",
|
|
876
906
|
params: { data: { context: data, message }, level }
|
|
877
|
-
}), 'optionalAccess',
|
|
907
|
+
}), 'optionalAccess', _30 => _30.catch, 'call', _31 => _31(() => {
|
|
878
908
|
})]);
|
|
879
909
|
};
|
|
910
|
+
const scope = requestScope(_optionalChain([mcpReq, 'optionalAccess', _32 => _32.signal]), timeoutSignal);
|
|
880
911
|
return {
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
progress: progress.progress,
|
|
905
|
-
progressToken,
|
|
906
|
-
total: progress.total
|
|
912
|
+
context: {
|
|
913
|
+
auth,
|
|
914
|
+
elicit: (params) => _server.inputRequired.elicit({
|
|
915
|
+
message: params.message,
|
|
916
|
+
requestedSchema: params.requestedSchema
|
|
917
|
+
}),
|
|
918
|
+
input: (key, schema) => _server.acceptedContent.call(void 0,
|
|
919
|
+
_optionalChain([mcpReq, 'optionalAccess', _33 => _33.inputResponses]),
|
|
920
|
+
key,
|
|
921
|
+
schema
|
|
922
|
+
),
|
|
923
|
+
inputRequired: (inputRequests, requestState) => _server.inputRequired.call(void 0, { inputRequests, requestState }),
|
|
924
|
+
inputResponses: _optionalChain([mcpReq, 'optionalAccess', _34 => _34.inputResponses]),
|
|
925
|
+
log: {
|
|
926
|
+
debug: (m, d) => emit("debug", m, d),
|
|
927
|
+
error: (m, d) => emit("error", m, d),
|
|
928
|
+
info: (m, d) => emit("info", m, d),
|
|
929
|
+
warn: (m, d) => emit("warning", m, d)
|
|
930
|
+
},
|
|
931
|
+
reportProgress: async (progress) => {
|
|
932
|
+
const progressToken = _optionalChain([mcpReq, 'optionalAccess', _35 => _35._meta, 'optionalAccess', _36 => _36.progressToken]);
|
|
933
|
+
if (progressToken === void 0) {
|
|
934
|
+
return;
|
|
907
935
|
}
|
|
908
|
-
|
|
936
|
+
await _optionalChain([mcpReq, 'optionalAccess', _37 => _37.notify, 'optionalCall', _38 => _38({
|
|
937
|
+
method: "notifications/progress",
|
|
938
|
+
params: {
|
|
939
|
+
message: progress.message,
|
|
940
|
+
progress: progress.progress,
|
|
941
|
+
progressToken,
|
|
942
|
+
total: progress.total
|
|
943
|
+
}
|
|
944
|
+
})]);
|
|
945
|
+
},
|
|
946
|
+
requestId: _optionalChain([mcpReq, 'optionalAccess', _39 => _39.id]),
|
|
947
|
+
// The SDK exposes this as an accessor; call it so callers get the
|
|
948
|
+
// value.
|
|
949
|
+
requestState: _optionalChain([mcpReq, 'optionalAccess', _40 => _40.requestState, 'optionalCall', _41 => _41()]),
|
|
950
|
+
signal: scope.signal
|
|
909
951
|
},
|
|
910
|
-
|
|
911
|
-
// The SDK exposes this as an accessor; call it so callers get the value.
|
|
912
|
-
requestState: _optionalChain([mcpReq, 'optionalAccess', _37 => _37.requestState, 'optionalCall', _38 => _38()])
|
|
952
|
+
release: scope.release
|
|
913
953
|
};
|
|
914
954
|
}
|
|
915
955
|
/**
|
|
@@ -918,7 +958,7 @@ var ViteMCP = class {
|
|
|
918
958
|
* no addressee on a stateless transport.
|
|
919
959
|
*/
|
|
920
960
|
#notifyListChanged(kind) {
|
|
921
|
-
const notifier = _optionalChain([this, 'access',
|
|
961
|
+
const notifier = _optionalChain([this, 'access', _42 => _42.#handler, 'optionalAccess', _43 => _43.notify]);
|
|
922
962
|
if (!notifier) {
|
|
923
963
|
return;
|
|
924
964
|
}
|
|
@@ -931,7 +971,7 @@ var ViteMCP = class {
|
|
|
931
971
|
// Authentication has already run in the route below, which is the only
|
|
932
972
|
// place that can turn a refusal into an HTTP status. What reaches here
|
|
933
973
|
// is either an authenticated session or a deliberately anonymous one.
|
|
934
|
-
async () => this.#buildServer(_optionalChain([this, 'access',
|
|
974
|
+
async () => this.#buildServer(_optionalChain([this, 'access', _44 => _44.#authStore, 'access', _45 => _45.getStore, 'call', _46 => _46(), 'optionalAccess', _47 => _47.auth])),
|
|
935
975
|
{
|
|
936
976
|
// Tradeoff: `server/discover` advertises only 2026-07-28, so legacy
|
|
937
977
|
// requests are answered unadvertised and skip Mcp-* validation.
|
|
@@ -941,8 +981,8 @@ var ViteMCP = class {
|
|
|
941
981
|
}
|
|
942
982
|
);
|
|
943
983
|
this.#corsMiddleware = config.cors === false ? null : _cors.cors.call(void 0, config.cors);
|
|
944
|
-
const oauth = _nullishCoalesce(this.#options.oauth, () => ( _optionalChain([this, 'access',
|
|
945
|
-
if (_optionalChain([oauth, 'optionalAccess',
|
|
984
|
+
const oauth = _nullishCoalesce(this.#options.oauth, () => ( _optionalChain([this, 'access', _48 => _48.#options, 'access', _49 => _49.auth, 'optionalAccess', _50 => _50.getOAuthConfig, 'call', _51 => _51()])));
|
|
985
|
+
if (_optionalChain([oauth, 'optionalAccess', _52 => _52.enabled]) !== false && (_nullishCoalesce(_nullishCoalesce(_optionalChain([oauth, 'optionalAccess', _53 => _53.proxy]), () => ( _optionalChain([oauth, 'optionalAccess', _54 => _54.authorizationServer]))), () => ( _optionalChain([oauth, 'optionalAccess', _55 => _55.protectedResource]))))) {
|
|
946
986
|
this.#honoApp.route(
|
|
947
987
|
"/",
|
|
948
988
|
createOAuthRouter({
|
|
@@ -956,10 +996,10 @@ var ViteMCP = class {
|
|
|
956
996
|
this.#servesProtectedResourceMetadata = Boolean(oauth.protectedResource);
|
|
957
997
|
}
|
|
958
998
|
const health = this.#options.health;
|
|
959
|
-
if (_optionalChain([health, 'optionalAccess',
|
|
999
|
+
if (_optionalChain([health, 'optionalAccess', _56 => _56.enabled]) !== false) {
|
|
960
1000
|
this.#honoApp.get(
|
|
961
|
-
_nullishCoalesce(_optionalChain([health, 'optionalAccess',
|
|
962
|
-
(c) => c.text(_nullishCoalesce(_optionalChain([health, 'optionalAccess',
|
|
1001
|
+
_nullishCoalesce(_optionalChain([health, 'optionalAccess', _57 => _57.path]), () => ( "/health")),
|
|
1002
|
+
(c) => c.text(_nullishCoalesce(_optionalChain([health, 'optionalAccess', _58 => _58.message]), () => ( "ok")), _nullishCoalesce(_optionalChain([health, 'optionalAccess', _59 => _59.status]), () => ( 200)))
|
|
963
1003
|
);
|
|
964
1004
|
}
|
|
965
1005
|
const endpoint = `${_nullishCoalesce(config.basePath, () => ( ""))}${_nullishCoalesce(config.endpoint, () => ( "/mcp"))}`;
|
|
@@ -996,7 +1036,7 @@ var ViteMCP = class {
|
|
|
996
1036
|
"Content-Type": "application/json"
|
|
997
1037
|
});
|
|
998
1038
|
req.resume();
|
|
999
|
-
res.once("finish", () => _optionalChain([res, 'access',
|
|
1039
|
+
res.once("finish", () => _optionalChain([res, 'access', _60 => _60.socket, 'optionalAccess', _61 => _61.end, 'call', _62 => _62()]));
|
|
1000
1040
|
res.end(
|
|
1001
1041
|
JSON.stringify({
|
|
1002
1042
|
error: "invalid_request",
|
|
@@ -1006,7 +1046,7 @@ var ViteMCP = class {
|
|
|
1006
1046
|
return;
|
|
1007
1047
|
}
|
|
1008
1048
|
const response = await app.fetch(
|
|
1009
|
-
nodeToWebRequest(req, body, useTls),
|
|
1049
|
+
nodeToWebRequest(req, body, useTls, clientDisconnectSignal(res)),
|
|
1010
1050
|
{
|
|
1011
1051
|
incoming: req,
|
|
1012
1052
|
outgoing: res
|
|
@@ -1059,7 +1099,7 @@ var ViteMCP = class {
|
|
|
1059
1099
|
return void 0;
|
|
1060
1100
|
}
|
|
1061
1101
|
const standard = schema["~standard"];
|
|
1062
|
-
if (_optionalChain([standard, 'optionalAccess',
|
|
1102
|
+
if (_optionalChain([standard, 'optionalAccess', _63 => _63.jsonSchema])) {
|
|
1063
1103
|
return schema;
|
|
1064
1104
|
}
|
|
1065
1105
|
try {
|
|
@@ -1093,7 +1133,7 @@ var ViteMCP = class {
|
|
|
1093
1133
|
);
|
|
1094
1134
|
}
|
|
1095
1135
|
};
|
|
1096
|
-
var nodeToWebRequest = (req, body, secure) => {
|
|
1136
|
+
var nodeToWebRequest = (req, body, secure, signal) => {
|
|
1097
1137
|
const host = _nullishCoalesce(req.headers.host, () => ( "localhost"));
|
|
1098
1138
|
const url = `${secure ? "https" : "http"}://${host}${_nullishCoalesce(req.url, () => ( "/"))}`;
|
|
1099
1139
|
const headers = new Headers();
|
|
@@ -1114,20 +1154,53 @@ var nodeToWebRequest = (req, body, secure) => {
|
|
|
1114
1154
|
return new Request(url, {
|
|
1115
1155
|
headers,
|
|
1116
1156
|
method,
|
|
1157
|
+
signal,
|
|
1117
1158
|
...hasBody ? { body } : {}
|
|
1118
1159
|
});
|
|
1119
1160
|
};
|
|
1120
|
-
var
|
|
1161
|
+
var clientDisconnectSignal = (res) => {
|
|
1162
|
+
const controller = new AbortController();
|
|
1163
|
+
const abortIfPremature = () => {
|
|
1164
|
+
if (!res.writableEnded) {
|
|
1165
|
+
controller.abort(new Error("Client disconnected"));
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
if (res.closed) {
|
|
1169
|
+
abortIfPremature();
|
|
1170
|
+
} else {
|
|
1171
|
+
res.once("close", abortIfPremature);
|
|
1172
|
+
}
|
|
1173
|
+
return controller.signal;
|
|
1174
|
+
};
|
|
1175
|
+
var withTimeout = (work, timeout, toolName) => new Promise((resolve, reject) => {
|
|
1121
1176
|
const timer = setTimeout(() => {
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
toolName
|
|
1126
|
-
})
|
|
1177
|
+
const error = new UserError(
|
|
1178
|
+
`Tool '${toolName}' timed out after ${timeout.ms}ms`,
|
|
1179
|
+
{ timeoutMs: timeout.ms, toolName }
|
|
1127
1180
|
);
|
|
1128
|
-
|
|
1181
|
+
timeout.controller.abort(error);
|
|
1182
|
+
reject(error);
|
|
1183
|
+
}, timeout.ms);
|
|
1129
1184
|
work.then(resolve, reject).finally(() => clearTimeout(timer));
|
|
1130
1185
|
});
|
|
1186
|
+
var requestScope = (...sources) => {
|
|
1187
|
+
const controller = new AbortController();
|
|
1188
|
+
const detach = new AbortController();
|
|
1189
|
+
for (const source of sources) {
|
|
1190
|
+
if (source === void 0) {
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
if (source.aborted) {
|
|
1194
|
+
controller.abort(source.reason);
|
|
1195
|
+
break;
|
|
1196
|
+
}
|
|
1197
|
+
source.addEventListener("abort", () => controller.abort(source.reason), {
|
|
1198
|
+
once: true,
|
|
1199
|
+
signal: detach.signal
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
return { release: () => detach.abort(), signal: controller.signal };
|
|
1203
|
+
};
|
|
1131
1204
|
var formatBytes = (bytes) => {
|
|
1132
1205
|
if (bytes >= 1024 * 1024 && bytes % (1024 * 1024) === 0) {
|
|
1133
1206
|
return `${bytes / (1024 * 1024)} MiB`;
|
|
@@ -1159,8 +1232,8 @@ var assertStandardSchema = (schema, toolName, field) => {
|
|
|
1159
1232
|
if (schema === void 0) {
|
|
1160
1233
|
return;
|
|
1161
1234
|
}
|
|
1162
|
-
const standard = _optionalChain([schema, 'optionalAccess',
|
|
1163
|
-
if (typeof _optionalChain([standard, 'optionalAccess',
|
|
1235
|
+
const standard = _optionalChain([schema, 'optionalAccess', _64 => _64["~standard"]]);
|
|
1236
|
+
if (typeof _optionalChain([standard, 'optionalAccess', _65 => _65.validate]) !== "function") {
|
|
1164
1237
|
throw new UnexpectedStateError(
|
|
1165
1238
|
`Tool '${toolName}' ${field} must implement Standard Schema. If you are using Zod, upgrade to version 3.24 or later.`,
|
|
1166
1239
|
{ toolName }
|
|
@@ -1169,13 +1242,13 @@ var assertStandardSchema = (schema, toolName, field) => {
|
|
|
1169
1242
|
};
|
|
1170
1243
|
var promptArgsSchema = (prompt) => {
|
|
1171
1244
|
const args = prompt.arguments;
|
|
1172
|
-
if (!_optionalChain([args, 'optionalAccess',
|
|
1245
|
+
if (!_optionalChain([args, 'optionalAccess', _66 => _66.length])) {
|
|
1173
1246
|
return void 0;
|
|
1174
1247
|
}
|
|
1175
1248
|
const shape = {};
|
|
1176
1249
|
for (const arg of args) {
|
|
1177
1250
|
const completer = _nullishCoalesce(arg.complete, () => ( (prompt.complete ? (value) => prompt.complete(arg.name, value) : void 0)));
|
|
1178
|
-
const valueSchema = _optionalChain([arg, 'access',
|
|
1251
|
+
const valueSchema = _optionalChain([arg, 'access', _67 => _67.enum, 'optionalAccess', _68 => _68.length]) ? _zod.z.enum(arg.enum) : _zod.z.string();
|
|
1179
1252
|
const described = arg.description ? valueSchema.describe(arg.description) : valueSchema;
|
|
1180
1253
|
const base = completer ? _server.completable.call(void 0,
|
|
1181
1254
|
described,
|