@vitemcp/server 1.8.8 → 1.9.1
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 +9 -3
- package/dist/{OAuthProvider-COBBSCMI.d.cts → OAuthProvider-BaPwgWny.d.cts} +23 -2
- package/dist/{OAuthProvider-COBBSCMI.d.ts → OAuthProvider-BaPwgWny.d.ts} +23 -2
- package/dist/ViteMCP.cjs +4 -3
- package/dist/ViteMCP.cjs.map +1 -1
- package/dist/ViteMCP.d.cts +5 -4
- package/dist/ViteMCP.d.ts +5 -4
- package/dist/ViteMCP.js +3 -2
- package/dist/auth/index.cjs +2 -2
- package/dist/auth/index.d.cts +2 -2
- package/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +1 -1
- package/dist/chunk-4FH73ERY.js +64 -0
- package/dist/chunk-4FH73ERY.js.map +1 -0
- package/dist/chunk-FEM6LNS4.cjs +64 -0
- package/dist/chunk-FEM6LNS4.cjs.map +1 -0
- package/dist/{chunk-M22UTH2Z.js → chunk-IHX3AXKW.js} +204 -137
- package/dist/chunk-IHX3AXKW.js.map +1 -0
- package/dist/{chunk-5KNSU2F3.js → chunk-KKSDTVEW.js} +87 -18
- package/dist/chunk-KKSDTVEW.js.map +1 -0
- package/dist/{chunk-Y3GRHB77.cjs → chunk-SHPKRGNY.cjs} +101 -32
- package/dist/chunk-SHPKRGNY.cjs.map +1 -0
- package/dist/{chunk-7UCE3YTY.cjs → chunk-Y52P2PCS.cjs} +216 -149
- package/dist/chunk-Y52P2PCS.cjs.map +1 -0
- package/dist/edge/index.cjs +128 -21
- package/dist/edge/index.cjs.map +1 -1
- package/dist/edge/index.d.cts +6 -0
- package/dist/edge/index.d.ts +6 -0
- package/dist/edge/index.js +127 -20
- package/dist/edge/index.js.map +1 -1
- package/dist/openapi/index.cjs +36 -18
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.js +28 -10
- package/dist/openapi/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-5KNSU2F3.js.map +0 -1
- package/dist/chunk-7UCE3YTY.cjs.map +0 -1
- package/dist/chunk-M22UTH2Z.js.map +0 -1
- package/dist/chunk-Y3GRHB77.cjs.map +0 -1
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withoutTrailingSlash
|
|
3
|
+
} from "./chunk-KKSDTVEW.js";
|
|
4
|
+
import {
|
|
5
|
+
formatBytes,
|
|
6
|
+
toSdkSchema,
|
|
7
|
+
valibotToJsonSchema
|
|
8
|
+
} from "./chunk-4FH73ERY.js";
|
|
9
|
+
|
|
1
10
|
// src/ViteMCP.ts
|
|
2
11
|
import {
|
|
3
12
|
acceptedContent,
|
|
@@ -5,13 +14,16 @@ import {
|
|
|
5
14
|
completable,
|
|
6
15
|
createMcpHandler,
|
|
7
16
|
getOAuthProtectedResourceMetadataUrl,
|
|
17
|
+
InMemoryServerEventBus,
|
|
8
18
|
inputRequired,
|
|
9
19
|
localhostAllowedOrigins,
|
|
20
|
+
LOG_LEVEL_META_KEY,
|
|
10
21
|
McpServer,
|
|
11
22
|
OAuthError,
|
|
12
23
|
OAuthErrorCode,
|
|
13
24
|
originValidationResponse,
|
|
14
|
-
ResourceTemplate as SDKResourceTemplate
|
|
25
|
+
ResourceTemplate as SDKResourceTemplate,
|
|
26
|
+
UriTemplate
|
|
15
27
|
} from "@modelcontextprotocol/server";
|
|
16
28
|
import {
|
|
17
29
|
serveStdio
|
|
@@ -460,6 +472,16 @@ var ServerState = /* @__PURE__ */ ((ServerState2) => {
|
|
|
460
472
|
})(ServerState || {});
|
|
461
473
|
var LATCH_NAME = "vitemcp.internal.capability-latch";
|
|
462
474
|
var LATCH_URI = "vitemcp-internal:capability-latch";
|
|
475
|
+
var LOG_LEVELS = [
|
|
476
|
+
"debug",
|
|
477
|
+
"info",
|
|
478
|
+
"notice",
|
|
479
|
+
"warning",
|
|
480
|
+
"error",
|
|
481
|
+
"critical",
|
|
482
|
+
"alert",
|
|
483
|
+
"emergency"
|
|
484
|
+
];
|
|
463
485
|
var stderrLogger = {
|
|
464
486
|
debug: (...args) => console.error(...args),
|
|
465
487
|
error: (...args) => console.error(...args),
|
|
@@ -518,16 +540,16 @@ var ViteMCP = class {
|
|
|
518
540
|
#logger;
|
|
519
541
|
#options;
|
|
520
542
|
#prompts = [];
|
|
521
|
-
#resources = [];
|
|
522
|
-
#resourceTemplates = [];
|
|
523
|
-
#serverState = "stopped" /* Stopped */;
|
|
524
543
|
/**
|
|
525
|
-
*
|
|
526
|
-
*
|
|
544
|
+
* The RFC 9728 protected-resource document this server publishes, if it
|
|
545
|
+
* publishes one — what a 401 points a client at. Latched when the routes are
|
|
527
546
|
* mounted rather than read back from `auth` per rejection: the provider's
|
|
528
547
|
* config getter builds its proxy on demand and refuses once destroyed.
|
|
529
548
|
*/
|
|
530
|
-
#
|
|
549
|
+
#protectedResource;
|
|
550
|
+
#resources = [];
|
|
551
|
+
#resourceTemplates = [];
|
|
552
|
+
#serverState = "stopped" /* Stopped */;
|
|
531
553
|
#stdioHandle = null;
|
|
532
554
|
#tools = [];
|
|
533
555
|
/** Each tool's schemas, as `#sdkSchemasFor` converted them. */
|
|
@@ -610,7 +632,11 @@ var ViteMCP = class {
|
|
|
610
632
|
uri
|
|
611
633
|
});
|
|
612
634
|
}
|
|
613
|
-
return {
|
|
635
|
+
return {
|
|
636
|
+
...first,
|
|
637
|
+
mimeType: first.mimeType ?? direct.mimeType,
|
|
638
|
+
uri: first.uri ?? uri
|
|
639
|
+
};
|
|
614
640
|
}
|
|
615
641
|
for (const template of this.#resourceTemplates) {
|
|
616
642
|
const params = parseURITemplate(template.uriTemplate).fromUri(uri);
|
|
@@ -628,7 +654,11 @@ var ViteMCP = class {
|
|
|
628
654
|
{ uri }
|
|
629
655
|
);
|
|
630
656
|
}
|
|
631
|
-
return {
|
|
657
|
+
return {
|
|
658
|
+
...first,
|
|
659
|
+
mimeType: first.mimeType ?? template.mimeType,
|
|
660
|
+
uri: first.uri ?? uri
|
|
661
|
+
};
|
|
632
662
|
}
|
|
633
663
|
throw new UnexpectedStateError(`Resource not found: ${uri}`, { uri });
|
|
634
664
|
}
|
|
@@ -638,7 +668,8 @@ var ViteMCP = class {
|
|
|
638
668
|
}
|
|
639
669
|
/**
|
|
640
670
|
* Publishes `notifications/resources/updated` for a URI to any subscription
|
|
641
|
-
* that opted in to it.
|
|
671
|
+
* that opted in to it and whose caller may read it. HTTP only: a stdio
|
|
672
|
+
* client is never reached.
|
|
642
673
|
*/
|
|
643
674
|
notifyResourceUpdated(uri) {
|
|
644
675
|
this.#handler?.notify.resourceUpdated(uri);
|
|
@@ -684,7 +715,9 @@ var ViteMCP = class {
|
|
|
684
715
|
try {
|
|
685
716
|
if (options.transportType === "stdio") {
|
|
686
717
|
this.#logger = this.#options.logger ?? stderrLogger;
|
|
687
|
-
this.#stdioHandle = serveStdio(
|
|
718
|
+
this.#stdioHandle = serveStdio(
|
|
719
|
+
({ era }) => this.#buildServer(void 0, { era })
|
|
720
|
+
);
|
|
688
721
|
this.#logger.info(`[ViteMCP info] server is running on stdio`);
|
|
689
722
|
} else {
|
|
690
723
|
await this.#startHttp(options.httpStream);
|
|
@@ -747,7 +780,16 @@ var ViteMCP = class {
|
|
|
747
780
|
}
|
|
748
781
|
return { auth };
|
|
749
782
|
}
|
|
750
|
-
|
|
783
|
+
/**
|
|
784
|
+
* `era` is the protocol era the server will speak, where it is known: one
|
|
785
|
+
* built for `connect()` speaks whichever the client picks.
|
|
786
|
+
* `resourceSubscriptions` declares `resources.subscribe`. Set it only where
|
|
787
|
+
* `notifyResourceUpdated` delivers: to 2026-07-28 HTTP clients.
|
|
788
|
+
*/
|
|
789
|
+
async #buildServer(auth, {
|
|
790
|
+
era,
|
|
791
|
+
resourceSubscriptions = false
|
|
792
|
+
} = {}) {
|
|
751
793
|
const server = new McpServer(
|
|
752
794
|
{
|
|
753
795
|
description: this.#options.description,
|
|
@@ -757,7 +799,15 @@ var ViteMCP = class {
|
|
|
757
799
|
version: this.#options.version,
|
|
758
800
|
websiteUrl: this.#options.websiteUrl
|
|
759
801
|
},
|
|
760
|
-
{
|
|
802
|
+
{
|
|
803
|
+
// Without it the SDK refuses to send `notifications/message`, and
|
|
804
|
+
// `log.*` swallows the refusal, so every log line vanished silently.
|
|
805
|
+
// Left out for a 2025-era client: `log.*` answers only the 2026-07-28
|
|
806
|
+
// per-request opt-in, so the `logging/setLevel` it would promise that
|
|
807
|
+
// client could never take effect.
|
|
808
|
+
capabilities: era === "legacy" ? {} : { logging: {} },
|
|
809
|
+
instructions: this.#options.instructions
|
|
810
|
+
}
|
|
761
811
|
);
|
|
762
812
|
const visible = (all) => all.filter((entry) => !entry.canAccess || entry.canAccess(auth));
|
|
763
813
|
const tools = (await Promise.all(
|
|
@@ -770,6 +820,29 @@ var ViteMCP = class {
|
|
|
770
820
|
const resourceTemplates = visible(this.#resourceTemplates);
|
|
771
821
|
const prompts = visible(this.#prompts);
|
|
772
822
|
for (const { schemas, tool } of tools) {
|
|
823
|
+
const call = async (args, ctx) => {
|
|
824
|
+
const timeout = tool.timeoutMs ? { controller: new AbortController(), ms: tool.timeoutMs } : void 0;
|
|
825
|
+
const { context, release } = this.#makeContext(
|
|
826
|
+
auth,
|
|
827
|
+
ctx,
|
|
828
|
+
timeout?.controller.signal
|
|
829
|
+
);
|
|
830
|
+
try {
|
|
831
|
+
const result = await (timeout ? withTimeout(tool.execute(args, context), timeout, tool.name) : tool.execute(args, context));
|
|
832
|
+
return normalizeToolResult(result, tool.outputSchema !== void 0);
|
|
833
|
+
} catch (error) {
|
|
834
|
+
if (error instanceof UserError) {
|
|
835
|
+
return {
|
|
836
|
+
content: [{ text: error.message, type: "text" }],
|
|
837
|
+
isError: true,
|
|
838
|
+
...error.extras ? { structuredContent: error.extras } : {}
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
throw error;
|
|
842
|
+
} finally {
|
|
843
|
+
release();
|
|
844
|
+
}
|
|
845
|
+
};
|
|
773
846
|
server.registerTool(
|
|
774
847
|
tool.name,
|
|
775
848
|
{
|
|
@@ -779,29 +852,12 @@ var ViteMCP = class {
|
|
|
779
852
|
inputSchema: schemas.inputSchema,
|
|
780
853
|
outputSchema: schemas.outputSchema
|
|
781
854
|
},
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
);
|
|
789
|
-
try {
|
|
790
|
-
const result = await (timeout ? withTimeout(tool.execute(args, context), timeout, tool.name) : tool.execute(args, context));
|
|
791
|
-
return normalizeToolResult(result, tool.outputSchema !== void 0);
|
|
792
|
-
} catch (error) {
|
|
793
|
-
if (error instanceof UserError) {
|
|
794
|
-
return {
|
|
795
|
-
content: [{ text: error.message, type: "text" }],
|
|
796
|
-
isError: true,
|
|
797
|
-
...error.extras ? { structuredContent: error.extras } : {}
|
|
798
|
-
};
|
|
799
|
-
}
|
|
800
|
-
throw error;
|
|
801
|
-
} finally {
|
|
802
|
-
release();
|
|
803
|
-
}
|
|
804
|
-
})
|
|
855
|
+
// The SDK passes arguments only to a tool that declares an input
|
|
856
|
+
// schema; one that does not is called with the request context alone.
|
|
857
|
+
// Registering `call` as it stands would take that context for `args`
|
|
858
|
+
// and leave the tool without one: no progress, no logs, no request id
|
|
859
|
+
// and a `signal` that never fires.
|
|
860
|
+
schemas.inputSchema ? call : (ctx) => call(void 0, ctx)
|
|
805
861
|
);
|
|
806
862
|
}
|
|
807
863
|
for (const resource of resources) {
|
|
@@ -869,31 +925,32 @@ var ViteMCP = class {
|
|
|
869
925
|
);
|
|
870
926
|
}
|
|
871
927
|
for (const prompt of prompts) {
|
|
928
|
+
const argsSchema = promptArgsSchema(prompt);
|
|
929
|
+
const load = async (args, ctx) => {
|
|
930
|
+
const { context, release } = this.#makeContext(auth, ctx);
|
|
931
|
+
try {
|
|
932
|
+
const loaded = await prompt.load(args ?? {}, context);
|
|
933
|
+
if (typeof loaded !== "string") {
|
|
934
|
+
return loaded;
|
|
935
|
+
}
|
|
936
|
+
return {
|
|
937
|
+
messages: [
|
|
938
|
+
{
|
|
939
|
+
content: { text: loaded, type: "text" },
|
|
940
|
+
role: "user"
|
|
941
|
+
}
|
|
942
|
+
]
|
|
943
|
+
};
|
|
944
|
+
} finally {
|
|
945
|
+
release();
|
|
946
|
+
}
|
|
947
|
+
};
|
|
872
948
|
server.registerPrompt(
|
|
873
949
|
prompt.name,
|
|
874
|
-
{
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
(async (args, ctx) => {
|
|
879
|
-
const { context, release } = this.#makeContext(auth, ctx);
|
|
880
|
-
try {
|
|
881
|
-
const loaded = await prompt.load(args ?? {}, context);
|
|
882
|
-
if (typeof loaded !== "string") {
|
|
883
|
-
return loaded;
|
|
884
|
-
}
|
|
885
|
-
return {
|
|
886
|
-
messages: [
|
|
887
|
-
{
|
|
888
|
-
content: { text: loaded, type: "text" },
|
|
889
|
-
role: "user"
|
|
890
|
-
}
|
|
891
|
-
]
|
|
892
|
-
};
|
|
893
|
-
} finally {
|
|
894
|
-
release();
|
|
895
|
-
}
|
|
896
|
-
})
|
|
950
|
+
{ argsSchema, description: prompt.description },
|
|
951
|
+
// As for tools: without `argsSchema` the SDK passes the request
|
|
952
|
+
// context alone.
|
|
953
|
+
argsSchema ? load : (ctx) => load(void 0, ctx)
|
|
897
954
|
);
|
|
898
955
|
}
|
|
899
956
|
if (this.#tools.length > 0 && tools.length === 0) {
|
|
@@ -907,8 +964,48 @@ var ViteMCP = class {
|
|
|
907
964
|
if (this.#prompts.length > 0 && prompts.length === 0) {
|
|
908
965
|
server.registerPrompt(LATCH_NAME, {}, (() => ({ messages: [] }))).remove();
|
|
909
966
|
}
|
|
967
|
+
if (resourceSubscriptions && server.server.getCapabilities().resources) {
|
|
968
|
+
server.server.registerCapabilities({ resources: { subscribe: true } });
|
|
969
|
+
}
|
|
910
970
|
return server;
|
|
911
971
|
}
|
|
972
|
+
/**
|
|
973
|
+
* Whether `resources/read` would serve `uri` to this caller: a resource of
|
|
974
|
+
* that URI, or a template matching it, that `canAccess` leaves visible.
|
|
975
|
+
*/
|
|
976
|
+
#canRead(uri, auth) {
|
|
977
|
+
const visible = (entry) => !entry.canAccess || entry.canAccess(auth);
|
|
978
|
+
return this.#resources.some(
|
|
979
|
+
(resource) => resource.uri === uri && visible(resource)
|
|
980
|
+
) || this.#resourceTemplates.some(
|
|
981
|
+
(template) => visible(template) && new UriTemplate(template.uriTemplate).match(uri) !== null
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* The bus `notifyResourceUpdated` publishes to and `subscriptions/listen`
|
|
986
|
+
* streams read from, narrowed per stream to updates its caller could read.
|
|
987
|
+
*
|
|
988
|
+
* `canAccess` keeps a resource out of `resources/read`, so its updates must
|
|
989
|
+
* not reach that caller either, or subscribing to the URI would reveal what
|
|
990
|
+
* reading it cannot. The SDK subscribes a stream while serving its listen
|
|
991
|
+
* request, so that caller's auth is still in scope here.
|
|
992
|
+
*/
|
|
993
|
+
#eventBus() {
|
|
994
|
+
const events = new InMemoryServerEventBus(
|
|
995
|
+
(error) => this.#logger.error("[ViteMCP error]", error)
|
|
996
|
+
);
|
|
997
|
+
return {
|
|
998
|
+
publish: (event) => events.publish(event),
|
|
999
|
+
subscribe: (listener) => {
|
|
1000
|
+
const auth = this.#authStore.getStore()?.auth;
|
|
1001
|
+
return events.subscribe((event) => {
|
|
1002
|
+
if (event.kind !== "resource_updated" || this.#canRead(event.uri, auth)) {
|
|
1003
|
+
listener(event);
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
912
1009
|
/** Builds the Hono app with the CORS shim installed ahead of user routes. */
|
|
913
1010
|
#freshApp() {
|
|
914
1011
|
const app = new Hono2();
|
|
@@ -928,9 +1025,9 @@ var ViteMCP = class {
|
|
|
928
1025
|
#makeContext(auth, rawCtx, timeoutSignal) {
|
|
929
1026
|
const ctx = rawCtx;
|
|
930
1027
|
const mcpReq = ctx?.mcpReq;
|
|
931
|
-
const requestedLevel = mcpReq?.
|
|
1028
|
+
const requestedLevel = mcpReq?.envelope?.[LOG_LEVEL_META_KEY];
|
|
932
1029
|
const emit = (level, message, data) => {
|
|
933
|
-
if (!requestedLevel) {
|
|
1030
|
+
if (!requestedLevel || LOG_LEVELS.indexOf(level) < LOG_LEVELS.indexOf(requestedLevel)) {
|
|
934
1031
|
return;
|
|
935
1032
|
}
|
|
936
1033
|
void mcpReq?.notify?.({
|
|
@@ -1038,8 +1135,14 @@ var ViteMCP = class {
|
|
|
1038
1135
|
// Authentication has already run in the route below, which is the only
|
|
1039
1136
|
// place that can turn a refusal into an HTTP status. What reaches here
|
|
1040
1137
|
// is either an authenticated session or a deliberately anonymous one.
|
|
1041
|
-
async () => this.#buildServer(this.#authStore.getStore()?.auth
|
|
1138
|
+
async ({ era }) => this.#buildServer(this.#authStore.getStore()?.auth, {
|
|
1139
|
+
era,
|
|
1140
|
+
// A 2025-era client reads `resources.subscribe` as a promise of
|
|
1141
|
+
// `resources/subscribe`, which is not served.
|
|
1142
|
+
resourceSubscriptions: era === "modern"
|
|
1143
|
+
}),
|
|
1042
1144
|
{
|
|
1145
|
+
bus: this.#eventBus(),
|
|
1043
1146
|
// Tradeoff: `server/discover` advertises only 2026-07-28, so legacy
|
|
1044
1147
|
// requests are answered unadvertised and skip Mcp-* validation.
|
|
1045
1148
|
legacy: config.legacy ?? "stateless",
|
|
@@ -1048,7 +1151,11 @@ var ViteMCP = class {
|
|
|
1048
1151
|
}
|
|
1049
1152
|
);
|
|
1050
1153
|
this.#corsMiddleware = config.cors === false ? null : cors(config.cors);
|
|
1051
|
-
const
|
|
1154
|
+
const provider = this.#options.auth;
|
|
1155
|
+
const oauth = this.#options.oauth ?? (provider && withEndpointAsResource(
|
|
1156
|
+
provider.getOAuthConfig(),
|
|
1157
|
+
config.endpoint ?? "/mcp"
|
|
1158
|
+
));
|
|
1052
1159
|
if (oauth?.enabled !== false && (oauth?.proxy ?? oauth?.authorizationServer ?? oauth?.protectedResource)) {
|
|
1053
1160
|
this.#honoApp.route(
|
|
1054
1161
|
"/",
|
|
@@ -1060,7 +1167,7 @@ var ViteMCP = class {
|
|
|
1060
1167
|
proxy: oauth.proxy
|
|
1061
1168
|
})
|
|
1062
1169
|
);
|
|
1063
|
-
this.#
|
|
1170
|
+
this.#protectedResource = oauth.protectedResource;
|
|
1064
1171
|
}
|
|
1065
1172
|
const health = this.#options.health;
|
|
1066
1173
|
if (health?.enabled !== false) {
|
|
@@ -1119,7 +1226,7 @@ var ViteMCP = class {
|
|
|
1119
1226
|
outgoing: res
|
|
1120
1227
|
}
|
|
1121
1228
|
);
|
|
1122
|
-
res.writeHead(response.status,
|
|
1229
|
+
res.writeHead(response.status, toNodeHeaders(response.headers));
|
|
1123
1230
|
if (!response.body) {
|
|
1124
1231
|
res.end();
|
|
1125
1232
|
return;
|
|
@@ -1177,43 +1284,18 @@ var ViteMCP = class {
|
|
|
1177
1284
|
);
|
|
1178
1285
|
}
|
|
1179
1286
|
/**
|
|
1180
|
-
*
|
|
1181
|
-
*
|
|
1182
|
-
* (Valibot, say) is converted, and the conversion is only what `tools/list`
|
|
1183
|
-
* advertises. Validation stays with the library the schema was written in:
|
|
1184
|
-
* the conversion drops what JSON Schema cannot say — a transform, a
|
|
1185
|
-
* `check()` — so validating against it instead would pass `execute`
|
|
1186
|
-
* arguments the schema never produced.
|
|
1187
|
-
*
|
|
1188
|
-
* Advertised inputs are closed with `strictInputSchema`. Outputs are left as
|
|
1189
|
-
* converted, since closing them would misdescribe results the schema allows.
|
|
1287
|
+
* A tool schema in the form the SDK registers it — see `toSdkSchema` — with
|
|
1288
|
+
* a failed conversion reported under the tool's own name.
|
|
1190
1289
|
*/
|
|
1191
1290
|
async #toSdkSchema(schema, label, io) {
|
|
1192
|
-
if (!schema) {
|
|
1193
|
-
return void 0;
|
|
1194
|
-
}
|
|
1195
|
-
const standard = schema["~standard"];
|
|
1196
|
-
if (standard.jsonSchema) {
|
|
1197
|
-
return schema;
|
|
1198
|
-
}
|
|
1199
|
-
let json;
|
|
1200
1291
|
try {
|
|
1201
|
-
|
|
1292
|
+
return await toSdkSchema(schema, io, convertToJsonSchema);
|
|
1202
1293
|
} catch (error) {
|
|
1203
1294
|
throw new UnexpectedStateError(
|
|
1204
1295
|
`${label} is not a supported Standard Schema: ${error instanceof Error ? error.message : String(error)}`,
|
|
1205
1296
|
{ label }
|
|
1206
1297
|
);
|
|
1207
1298
|
}
|
|
1208
|
-
const advertised = io === "input" ? strictInputSchema(json) : json;
|
|
1209
|
-
return {
|
|
1210
|
-
"~standard": {
|
|
1211
|
-
jsonSchema: { input: () => advertised, output: () => advertised },
|
|
1212
|
-
validate: (value) => standard.validate(value),
|
|
1213
|
-
vendor: standard.vendor,
|
|
1214
|
-
version: standard.version
|
|
1215
|
-
}
|
|
1216
|
-
};
|
|
1217
1299
|
}
|
|
1218
1300
|
/**
|
|
1219
1301
|
* The RFC 6750 §3 challenge sent when `authenticate` refuses a request.
|
|
@@ -1221,21 +1303,36 @@ var ViteMCP = class {
|
|
|
1221
1303
|
* `resource_metadata` (RFC 9728 §5.1) is the parameter that turns a bare
|
|
1222
1304
|
* rejection into a login: it points the client at this server's
|
|
1223
1305
|
* protected-resource document, from which it discovers the authorization
|
|
1224
|
-
* server and starts the flow. It is
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1306
|
+
* server and starts the flow. It is omitted when this server publishes no
|
|
1307
|
+
* such document.
|
|
1308
|
+
*
|
|
1309
|
+
* The URL is formed from the resource that document names: the address the
|
|
1310
|
+
* server was configured as, which is the one a client can reach. The
|
|
1311
|
+
* request's own URL is not that address behind a proxy that terminates TLS —
|
|
1312
|
+
* it carries the listener's scheme and whatever Host was forwarded, so a
|
|
1313
|
+
* challenge built from it sent clients to `http://`, or to an internal host.
|
|
1314
|
+
* It is the fallback only, for a document that names no resource.
|
|
1227
1315
|
*/
|
|
1228
1316
|
#unauthorized(request) {
|
|
1317
|
+
const published = this.#protectedResource;
|
|
1229
1318
|
return bearerAuthChallengeResponse(
|
|
1230
1319
|
new OAuthError(OAuthErrorCode.InvalidToken, "Authentication required"),
|
|
1231
|
-
|
|
1320
|
+
published ? {
|
|
1232
1321
|
resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(
|
|
1233
|
-
new URL(request.url)
|
|
1322
|
+
toUrl(published.resource) ?? new URL(request.url)
|
|
1234
1323
|
)
|
|
1235
1324
|
} : {}
|
|
1236
1325
|
);
|
|
1237
1326
|
}
|
|
1238
1327
|
};
|
|
1328
|
+
var toUrl = (value) => typeof value === "string" && URL.canParse(value) ? new URL(value) : void 0;
|
|
1329
|
+
var withEndpointAsResource = (config, endpoint) => ({
|
|
1330
|
+
...config,
|
|
1331
|
+
protectedResource: {
|
|
1332
|
+
...config.protectedResource,
|
|
1333
|
+
resource: `${withoutTrailingSlash(config.protectedResource.resource)}${endpoint}`
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1239
1336
|
var nodeToWebRequest = (req, body, secure, signal) => {
|
|
1240
1337
|
const host = req.headers.host ?? "localhost";
|
|
1241
1338
|
const url = `${secure ? "https" : "http"}://${host}${req.url ?? "/"}`;
|
|
@@ -1261,6 +1358,13 @@ var nodeToWebRequest = (req, body, secure, signal) => {
|
|
|
1261
1358
|
...hasBody ? { body } : {}
|
|
1262
1359
|
});
|
|
1263
1360
|
};
|
|
1361
|
+
var toNodeHeaders = (headers) => {
|
|
1362
|
+
const cookies = headers.getSetCookie();
|
|
1363
|
+
return {
|
|
1364
|
+
...Object.fromEntries(headers),
|
|
1365
|
+
...cookies.length > 0 ? { "set-cookie": cookies } : {}
|
|
1366
|
+
};
|
|
1367
|
+
};
|
|
1264
1368
|
var clientDisconnectSignal = (res) => {
|
|
1265
1369
|
const controller = new AbortController();
|
|
1266
1370
|
const abortIfPremature = () => {
|
|
@@ -1304,15 +1408,6 @@ var requestScope = (...sources) => {
|
|
|
1304
1408
|
}
|
|
1305
1409
|
return { release: () => detach.abort(), signal: controller.signal };
|
|
1306
1410
|
};
|
|
1307
|
-
var formatBytes = (bytes) => {
|
|
1308
|
-
if (bytes >= 1024 * 1024 && bytes % (1024 * 1024) === 0) {
|
|
1309
|
-
return `${bytes / (1024 * 1024)} MiB`;
|
|
1310
|
-
}
|
|
1311
|
-
if (bytes >= 1024 && bytes % 1024 === 0) {
|
|
1312
|
-
return `${bytes / 1024} KiB`;
|
|
1313
|
-
}
|
|
1314
|
-
return `${bytes} bytes`;
|
|
1315
|
-
};
|
|
1316
1411
|
var OVERSIZE = /* @__PURE__ */ Symbol("oversize");
|
|
1317
1412
|
var readCappedNodeBody = async (req, maxBytes) => {
|
|
1318
1413
|
const declared = Number(req.headers["content-length"] ?? 0);
|
|
@@ -1331,35 +1426,7 @@ var readCappedNodeBody = async (req, maxBytes) => {
|
|
|
1331
1426
|
}
|
|
1332
1427
|
return Buffer.concat(chunks);
|
|
1333
1428
|
};
|
|
1334
|
-
var convertToJsonSchema = async (schema, io) =>
|
|
1335
|
-
if (schema["~standard"].vendor !== "valibot") {
|
|
1336
|
-
return toJsonSchema(schema);
|
|
1337
|
-
}
|
|
1338
|
-
let converter;
|
|
1339
|
-
try {
|
|
1340
|
-
converter = await import("@valibot/to-json-schema");
|
|
1341
|
-
} catch {
|
|
1342
|
-
throw new Error(
|
|
1343
|
-
'The "@valibot/to-json-schema" package is required to describe Valibot schemas. Install it with: npm install @valibot/to-json-schema'
|
|
1344
|
-
);
|
|
1345
|
-
}
|
|
1346
|
-
return converter.toJsonSchema(schema, {
|
|
1347
|
-
errorMode: "ignore",
|
|
1348
|
-
typeMode: io
|
|
1349
|
-
});
|
|
1350
|
-
};
|
|
1351
|
-
var strictInputSchema = (schema) => ({
|
|
1352
|
-
...schema,
|
|
1353
|
-
additionalProperties: typeof schema.additionalProperties === "object" ? schema.additionalProperties : false,
|
|
1354
|
-
...schema.properties && {
|
|
1355
|
-
properties: Object.fromEntries(
|
|
1356
|
-
Object.entries(schema.properties).map(([key, value]) => [
|
|
1357
|
-
key,
|
|
1358
|
-
typeof value === "object" && value.type === "object" ? strictInputSchema(value) : value
|
|
1359
|
-
])
|
|
1360
|
-
)
|
|
1361
|
-
}
|
|
1362
|
-
});
|
|
1429
|
+
var convertToJsonSchema = async (schema, io) => schema["~standard"].vendor === "valibot" ? valibotToJsonSchema(schema, io) : toJsonSchema(schema);
|
|
1363
1430
|
var assertStandardSchema = (schema, toolName, field) => {
|
|
1364
1431
|
if (schema === void 0) {
|
|
1365
1432
|
return;
|
|
@@ -1465,4 +1532,4 @@ export {
|
|
|
1465
1532
|
ServerState,
|
|
1466
1533
|
ViteMCP
|
|
1467
1534
|
};
|
|
1468
|
-
//# sourceMappingURL=chunk-
|
|
1535
|
+
//# sourceMappingURL=chunk-IHX3AXKW.js.map
|