@vitemcp/server 1.2.0 → 1.3.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 +35 -2
- package/dist/{OAuthProvider-DmfNQge_.d.cts → OAuthProvider-CoIruClQ.d.cts} +35 -0
- package/dist/{OAuthProvider-DmfNQge_.d.ts → OAuthProvider-CoIruClQ.d.ts} +35 -0
- package/dist/ViteMCP.cjs +115 -19
- package/dist/ViteMCP.cjs.map +1 -1
- package/dist/ViteMCP.d.cts +46 -3
- package/dist/ViteMCP.d.ts +46 -3
- package/dist/ViteMCP.js +103 -7
- package/dist/ViteMCP.js.map +1 -1
- 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-MKS3TXYT.cjs → chunk-XC4BVJQZ.cjs} +68 -19
- package/dist/chunk-XC4BVJQZ.cjs.map +1 -0
- package/dist/{chunk-GBQHIIQM.js → chunk-XZBHP34C.js} +51 -2
- package/dist/chunk-XZBHP34C.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-GBQHIIQM.js.map +0 -1
- package/dist/chunk-MKS3TXYT.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -857,8 +857,13 @@ registration steps, redirect URIs and scopes for each.
|
|
|
857
857
|
|
|
858
858
|
#### Tool Authorization
|
|
859
859
|
|
|
860
|
-
`
|
|
861
|
-
|
|
860
|
+
Configuring `auth` (or `authenticate`) closes the endpoint on its own: a request
|
|
861
|
+
that does not authenticate is refused with `401` and an RFC 6750
|
|
862
|
+
`WWW-Authenticate` challenge before any handler runs, so nothing is reachable
|
|
863
|
+
anonymously. `canAccess` then decides what an _authenticated_ caller may use.
|
|
864
|
+
|
|
865
|
+
`canAccess` filters rejected tools out of `tools/list` entirely. Built-in helpers
|
|
866
|
+
cover the common cases:
|
|
862
867
|
|
|
863
868
|
```ts
|
|
864
869
|
import {
|
|
@@ -945,6 +950,34 @@ server.addTool({
|
|
|
945
950
|
});
|
|
946
951
|
```
|
|
947
952
|
|
|
953
|
+
The hook has two ways to refuse:
|
|
954
|
+
|
|
955
|
+
- **Return `null` or `undefined`.** ViteMCP answers `401` with a
|
|
956
|
+
`WWW-Authenticate` challenge, pointing at the protected-resource document when
|
|
957
|
+
the server publishes one. `execute` never runs.
|
|
958
|
+
- **Throw a `Response`.** It is sent to the client verbatim, for when you want an
|
|
959
|
+
exact status, body or header — as in the example above.
|
|
960
|
+
|
|
961
|
+
Anything else the hook throws is a fault in your code: it is logged and answered
|
|
962
|
+
with `500`, never served.
|
|
963
|
+
|
|
964
|
+
Because a hook that cannot identify the caller has not authenticated them,
|
|
965
|
+
returning nothing is a refusal and not an anonymous session. If your server is
|
|
966
|
+
public in part, opt in explicitly and guard the rest with `canAccess`:
|
|
967
|
+
|
|
968
|
+
```ts
|
|
969
|
+
const server = new ViteMCP({
|
|
970
|
+
name: "My Server",
|
|
971
|
+
version: "1.0.0",
|
|
972
|
+
// Callers the hook could not identify are served with `auth: undefined`.
|
|
973
|
+
allowAnonymous: true,
|
|
974
|
+
authenticate: async (request) => lookUpApiKey(request) ?? undefined,
|
|
975
|
+
});
|
|
976
|
+
|
|
977
|
+
server.addTool({ name: "public-tool" /* ... */ });
|
|
978
|
+
server.addTool({ canAccess: requireAuth, name: "private-tool" /* ... */ });
|
|
979
|
+
```
|
|
980
|
+
|
|
948
981
|
#### OAuth Proxy
|
|
949
982
|
|
|
950
983
|
The `auth` option is backed by ViteMCP's OAuth Proxy, which sits between MCP
|
|
@@ -509,6 +509,14 @@ declare class OAuthProxy {
|
|
|
509
509
|
private consentManager;
|
|
510
510
|
private issuerNs;
|
|
511
511
|
private jwtIssuer?;
|
|
512
|
+
/**
|
|
513
|
+
* The fallback storage this proxy created for itself, if any. It runs a
|
|
514
|
+
* cleanup timer that keeps the event loop alive, so `destroy()` has to stop
|
|
515
|
+
* it — and once the storage is wrapped for encryption it is reachable
|
|
516
|
+
* through nothing else. A caller-supplied storage is deliberately not
|
|
517
|
+
* recorded here: its lifetime belongs to the caller.
|
|
518
|
+
*/
|
|
519
|
+
private ownedTokenStorage;
|
|
512
520
|
/**
|
|
513
521
|
* Keyed by proxy-issued client_id for authorize/token-exchange lookups and
|
|
514
522
|
* for the defence-in-depth callback checks. A registration never changes
|
|
@@ -816,8 +824,17 @@ declare abstract class AuthProvider<TSession extends OAuthSession = OAuthSession
|
|
|
816
824
|
protected config: AuthProviderConfig;
|
|
817
825
|
/**
|
|
818
826
|
* Get the proxy, creating it lazily if needed.
|
|
827
|
+
*
|
|
828
|
+
* Refuses to rebuild after `destroy()`. Lazily replacing a torn-down proxy
|
|
829
|
+
* would be silently wrong twice over: the replacement starts the very timers
|
|
830
|
+
* `destroy()` released, and `ViteMCP` captured the original by reference when
|
|
831
|
+
* it mounted the OAuth routes, so the token endpoint would keep answering
|
|
832
|
+
* from the old instance while `authenticate()` verified against the new one —
|
|
833
|
+
* with different auto-generated signing keys, every token minted by one is
|
|
834
|
+
* invalid to the other.
|
|
819
835
|
*/
|
|
820
836
|
protected get proxy(): OAuthProxy;
|
|
837
|
+
private _destroyed;
|
|
821
838
|
private _proxy;
|
|
822
839
|
constructor(config: AuthProviderConfig);
|
|
823
840
|
/**
|
|
@@ -825,6 +842,24 @@ declare abstract class AuthProvider<TSession extends OAuthSession = OAuthSession
|
|
|
825
842
|
* Extracts Bearer token, validates it, and returns session with upstream access token.
|
|
826
843
|
*/
|
|
827
844
|
authenticate(request: Request | undefined): Promise<TSession | undefined>;
|
|
845
|
+
/**
|
|
846
|
+
* Release the resources held by the proxy this provider built for itself.
|
|
847
|
+
*
|
|
848
|
+
* That proxy runs two cleanup timers — its own sweep and its token
|
|
849
|
+
* storage's — and both keep the Node event loop alive, so a process that has
|
|
850
|
+
* stopped serving does not exit until this runs. `getProxy().destroy()`
|
|
851
|
+
* reaches the same teardown; this exists so a caller holding only the
|
|
852
|
+
* provider does not have to know that.
|
|
853
|
+
*
|
|
854
|
+
* Terminal: the provider will not serve again afterwards, and any later use
|
|
855
|
+
* throws rather than quietly building a replacement. Call it when the process
|
|
856
|
+
* is shutting down, after the HTTP server has finished draining — a request
|
|
857
|
+
* still in flight would otherwise resurrect what this just released.
|
|
858
|
+
*
|
|
859
|
+
* Safe to call more than once, and a no-op if the lazy proxy was never
|
|
860
|
+
* created.
|
|
861
|
+
*/
|
|
862
|
+
destroy(): void;
|
|
828
863
|
/**
|
|
829
864
|
* Get the OAuth configuration object for ViteMCP ServerOptions.
|
|
830
865
|
*/
|
|
@@ -509,6 +509,14 @@ declare class OAuthProxy {
|
|
|
509
509
|
private consentManager;
|
|
510
510
|
private issuerNs;
|
|
511
511
|
private jwtIssuer?;
|
|
512
|
+
/**
|
|
513
|
+
* The fallback storage this proxy created for itself, if any. It runs a
|
|
514
|
+
* cleanup timer that keeps the event loop alive, so `destroy()` has to stop
|
|
515
|
+
* it — and once the storage is wrapped for encryption it is reachable
|
|
516
|
+
* through nothing else. A caller-supplied storage is deliberately not
|
|
517
|
+
* recorded here: its lifetime belongs to the caller.
|
|
518
|
+
*/
|
|
519
|
+
private ownedTokenStorage;
|
|
512
520
|
/**
|
|
513
521
|
* Keyed by proxy-issued client_id for authorize/token-exchange lookups and
|
|
514
522
|
* for the defence-in-depth callback checks. A registration never changes
|
|
@@ -816,8 +824,17 @@ declare abstract class AuthProvider<TSession extends OAuthSession = OAuthSession
|
|
|
816
824
|
protected config: AuthProviderConfig;
|
|
817
825
|
/**
|
|
818
826
|
* Get the proxy, creating it lazily if needed.
|
|
827
|
+
*
|
|
828
|
+
* Refuses to rebuild after `destroy()`. Lazily replacing a torn-down proxy
|
|
829
|
+
* would be silently wrong twice over: the replacement starts the very timers
|
|
830
|
+
* `destroy()` released, and `ViteMCP` captured the original by reference when
|
|
831
|
+
* it mounted the OAuth routes, so the token endpoint would keep answering
|
|
832
|
+
* from the old instance while `authenticate()` verified against the new one —
|
|
833
|
+
* with different auto-generated signing keys, every token minted by one is
|
|
834
|
+
* invalid to the other.
|
|
819
835
|
*/
|
|
820
836
|
protected get proxy(): OAuthProxy;
|
|
837
|
+
private _destroyed;
|
|
821
838
|
private _proxy;
|
|
822
839
|
constructor(config: AuthProviderConfig);
|
|
823
840
|
/**
|
|
@@ -825,6 +842,24 @@ declare abstract class AuthProvider<TSession extends OAuthSession = OAuthSession
|
|
|
825
842
|
* Extracts Bearer token, validates it, and returns session with upstream access token.
|
|
826
843
|
*/
|
|
827
844
|
authenticate(request: Request | undefined): Promise<TSession | undefined>;
|
|
845
|
+
/**
|
|
846
|
+
* Release the resources held by the proxy this provider built for itself.
|
|
847
|
+
*
|
|
848
|
+
* That proxy runs two cleanup timers — its own sweep and its token
|
|
849
|
+
* storage's — and both keep the Node event loop alive, so a process that has
|
|
850
|
+
* stopped serving does not exit until this runs. `getProxy().destroy()`
|
|
851
|
+
* reaches the same teardown; this exists so a caller holding only the
|
|
852
|
+
* provider does not have to know that.
|
|
853
|
+
*
|
|
854
|
+
* Terminal: the provider will not serve again afterwards, and any later use
|
|
855
|
+
* throws rather than quietly building a replacement. Call it when the process
|
|
856
|
+
* is shutting down, after the HTTP server has finished draining — a request
|
|
857
|
+
* still in flight would otherwise resurrect what this just released.
|
|
858
|
+
*
|
|
859
|
+
* Safe to call more than once, and a no-op if the lazy proxy was never
|
|
860
|
+
* created.
|
|
861
|
+
*/
|
|
862
|
+
destroy(): void;
|
|
828
863
|
/**
|
|
829
864
|
* Get the OAuth configuration object for ViteMCP ServerOptions.
|
|
830
865
|
*/
|
package/dist/ViteMCP.cjs
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkXC4BVJQZcjs = require('./chunk-XC4BVJQZ.cjs');
|
|
16
16
|
|
|
17
17
|
// src/ViteMCP.ts
|
|
18
18
|
|
|
@@ -25,10 +25,15 @@ var _chunkMKS3TXYTcjs = require('./chunk-MKS3TXYT.cjs');
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
28
32
|
var _server = require('@modelcontextprotocol/server');
|
|
29
33
|
|
|
30
34
|
|
|
31
35
|
var _stdio = require('@modelcontextprotocol/server/stdio');
|
|
36
|
+
var _async_hooks = require('async_hooks');
|
|
32
37
|
var _promises = require('fs/promises');
|
|
33
38
|
var _hono = require('hono');
|
|
34
39
|
var _cors = require('hono/cors');
|
|
@@ -437,6 +442,27 @@ var ServerState = /* @__PURE__ */ ((ServerState2) => {
|
|
|
437
442
|
return ServerState2;
|
|
438
443
|
})(ServerState || {});
|
|
439
444
|
var ViteMCP = class {
|
|
445
|
+
/**
|
|
446
|
+
* The `auth` provider this server was constructed with, or `undefined` when
|
|
447
|
+
* OAuth was configured through the `oauth` option instead (or not at all).
|
|
448
|
+
*
|
|
449
|
+
* Exposed so a caller who inlined the provider into the options — the way
|
|
450
|
+
* every example does — can still reach it at shutdown. The provider holds an
|
|
451
|
+
* `OAuthProxy` with two cleanup timers, and `stop()` deliberately leaves them
|
|
452
|
+
* running: the server does not own the provider, and a stopped server can be
|
|
453
|
+
* started again. Terminal teardown is therefore the caller's call:
|
|
454
|
+
*
|
|
455
|
+
* ```ts
|
|
456
|
+
* await server.stop();
|
|
457
|
+
* server.authProvider?.destroy();
|
|
458
|
+
* ```
|
|
459
|
+
*
|
|
460
|
+
* In that order — `destroy()` is terminal, and a request still draining would
|
|
461
|
+
* throw against a destroyed provider.
|
|
462
|
+
*/
|
|
463
|
+
get authProvider() {
|
|
464
|
+
return this.#options.auth;
|
|
465
|
+
}
|
|
440
466
|
/**
|
|
441
467
|
* The port the HTTP server is actually listening on, or `null` when it is
|
|
442
468
|
* not running over HTTP. Pass `httpStream.port: 0` to let the OS assign a
|
|
@@ -451,6 +477,13 @@ var ViteMCP = class {
|
|
|
451
477
|
return this.#serverState;
|
|
452
478
|
}
|
|
453
479
|
#authenticate;
|
|
480
|
+
/**
|
|
481
|
+
* Carries the `authenticate` result from the HTTP route into the per-request
|
|
482
|
+
* server factory. The SDK invokes that factory from within `handler.fetch`,
|
|
483
|
+
* so the running store is always the one this request established — whereas
|
|
484
|
+
* a field on `this` would be shared by every concurrent request.
|
|
485
|
+
*/
|
|
486
|
+
#authStore = new (0, _async_hooks.AsyncLocalStorage)();
|
|
454
487
|
#connectedServers = [];
|
|
455
488
|
#corsMiddleware = null;
|
|
456
489
|
#handler = null;
|
|
@@ -462,6 +495,13 @@ var ViteMCP = class {
|
|
|
462
495
|
#resources = [];
|
|
463
496
|
#resourceTemplates = [];
|
|
464
497
|
#serverState = "stopped" /* Stopped */;
|
|
498
|
+
/**
|
|
499
|
+
* Whether this server publishes an RFC 9728 protected-resource document, and
|
|
500
|
+
* so whether a 401 can point a client at it. Latched when the routes are
|
|
501
|
+
* mounted rather than read back from `auth` per rejection: the provider's
|
|
502
|
+
* config getter builds its proxy on demand and refuses once destroyed.
|
|
503
|
+
*/
|
|
504
|
+
#servesProtectedResourceMetadata = false;
|
|
465
505
|
#stdioHandle = null;
|
|
466
506
|
#tools = [];
|
|
467
507
|
constructor(options) {
|
|
@@ -644,6 +684,38 @@ var ViteMCP = class {
|
|
|
644
684
|
}
|
|
645
685
|
this.#serverState = "stopped" /* Stopped */;
|
|
646
686
|
}
|
|
687
|
+
/**
|
|
688
|
+
* Runs the `authenticate` hook and decides whether the exchange may proceed,
|
|
689
|
+
* returning either the store to run it under or the `Response` refusing it.
|
|
690
|
+
*
|
|
691
|
+
* Deliberately *not* done inside the per-request server factory: that
|
|
692
|
+
* factory's only return channel is an `McpServer`, so a refusal raised there
|
|
693
|
+
* is indistinguishable from a crash and reaches the client as a 500 with no
|
|
694
|
+
* `WWW-Authenticate` — the one header that tells an MCP client where to log
|
|
695
|
+
* in. Doing it here also covers the legacy fallback, which shares the same
|
|
696
|
+
* route, so no transport can be reached without passing this.
|
|
697
|
+
*/
|
|
698
|
+
async #authenticateRequest(request) {
|
|
699
|
+
if (!this.#authenticate) {
|
|
700
|
+
return { auth: void 0 };
|
|
701
|
+
}
|
|
702
|
+
let auth;
|
|
703
|
+
try {
|
|
704
|
+
auth = await this.#authenticate(request);
|
|
705
|
+
} catch (error) {
|
|
706
|
+
if (error instanceof Response) {
|
|
707
|
+
return error;
|
|
708
|
+
}
|
|
709
|
+
this.#logger.error("[ViteMCP error]", error);
|
|
710
|
+
return _server.bearerAuthChallengeResponse.call(void 0,
|
|
711
|
+
new (0, _server.OAuthError)(_server.OAuthErrorCode.ServerError, "Internal Server Error")
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
if (!auth) {
|
|
715
|
+
return this.#options.allowAnonymous ? { auth: void 0 } : this.#unauthorized(request);
|
|
716
|
+
}
|
|
717
|
+
return { auth };
|
|
718
|
+
}
|
|
647
719
|
async #buildServer(auth) {
|
|
648
720
|
const server = new (0, _server.McpServer)(
|
|
649
721
|
{ name: this.#options.name, version: this.#options.version },
|
|
@@ -856,11 +928,10 @@ var ViteMCP = class {
|
|
|
856
928
|
}
|
|
857
929
|
async #startHttp(config) {
|
|
858
930
|
this.#handler = _server.createMcpHandler.call(void 0,
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
},
|
|
931
|
+
// Authentication has already run in the route below, which is the only
|
|
932
|
+
// place that can turn a refusal into an HTTP status. What reaches here
|
|
933
|
+
// is either an authenticated session or a deliberately anonymous one.
|
|
934
|
+
async () => this.#buildServer(_optionalChain([this, 'access', _41 => _41.#authStore, 'access', _42 => _42.getStore, 'call', _43 => _43(), 'optionalAccess', _44 => _44.auth])),
|
|
864
935
|
{
|
|
865
936
|
// Tradeoff: `server/discover` advertises only 2026-07-28, so legacy
|
|
866
937
|
// requests are answered unadvertised and skip Mcp-* validation.
|
|
@@ -870,8 +941,8 @@ var ViteMCP = class {
|
|
|
870
941
|
}
|
|
871
942
|
);
|
|
872
943
|
this.#corsMiddleware = config.cors === false ? null : _cors.cors.call(void 0, config.cors);
|
|
873
|
-
const oauth = _nullishCoalesce(this.#options.oauth, () => ( _optionalChain([this, 'access',
|
|
874
|
-
if (_optionalChain([oauth, 'optionalAccess',
|
|
944
|
+
const oauth = _nullishCoalesce(this.#options.oauth, () => ( _optionalChain([this, 'access', _45 => _45.#options, 'access', _46 => _46.auth, 'optionalAccess', _47 => _47.getOAuthConfig, 'call', _48 => _48()])));
|
|
945
|
+
if (_optionalChain([oauth, 'optionalAccess', _49 => _49.enabled]) !== false && (_nullishCoalesce(_nullishCoalesce(_optionalChain([oauth, 'optionalAccess', _50 => _50.proxy]), () => ( _optionalChain([oauth, 'optionalAccess', _51 => _51.authorizationServer]))), () => ( _optionalChain([oauth, 'optionalAccess', _52 => _52.protectedResource]))))) {
|
|
875
946
|
this.#honoApp.route(
|
|
876
947
|
"/",
|
|
877
948
|
createOAuthRouter({
|
|
@@ -882,12 +953,13 @@ var ViteMCP = class {
|
|
|
882
953
|
proxy: oauth.proxy
|
|
883
954
|
})
|
|
884
955
|
);
|
|
956
|
+
this.#servesProtectedResourceMetadata = Boolean(oauth.protectedResource);
|
|
885
957
|
}
|
|
886
958
|
const health = this.#options.health;
|
|
887
|
-
if (_optionalChain([health, 'optionalAccess',
|
|
959
|
+
if (_optionalChain([health, 'optionalAccess', _53 => _53.enabled]) !== false) {
|
|
888
960
|
this.#honoApp.get(
|
|
889
|
-
_nullishCoalesce(_optionalChain([health, 'optionalAccess',
|
|
890
|
-
(c) => c.text(_nullishCoalesce(_optionalChain([health, 'optionalAccess',
|
|
961
|
+
_nullishCoalesce(_optionalChain([health, 'optionalAccess', _54 => _54.path]), () => ( "/health")),
|
|
962
|
+
(c) => c.text(_nullishCoalesce(_optionalChain([health, 'optionalAccess', _55 => _55.message]), () => ( "ok")), _nullishCoalesce(_optionalChain([health, 'optionalAccess', _56 => _56.status]), () => ( 200)))
|
|
891
963
|
);
|
|
892
964
|
}
|
|
893
965
|
const endpoint = `${_nullishCoalesce(config.basePath, () => ( ""))}${_nullishCoalesce(config.endpoint, () => ( "/mcp"))}`;
|
|
@@ -905,7 +977,11 @@ var ViteMCP = class {
|
|
|
905
977
|
if (rejected) {
|
|
906
978
|
return rejected;
|
|
907
979
|
}
|
|
908
|
-
|
|
980
|
+
const authenticated = await this.#authenticateRequest(c.req.raw);
|
|
981
|
+
if (authenticated instanceof Response) {
|
|
982
|
+
return authenticated;
|
|
983
|
+
}
|
|
984
|
+
return this.#authStore.run(authenticated, () => handler.fetch(c.req.raw));
|
|
909
985
|
});
|
|
910
986
|
const app = this.#honoApp;
|
|
911
987
|
const maxBodySize = _nullishCoalesce(config.maxBodySize, () => ( OAUTH_PROXY_MAX_BODY_SIZE));
|
|
@@ -920,7 +996,7 @@ var ViteMCP = class {
|
|
|
920
996
|
"Content-Type": "application/json"
|
|
921
997
|
});
|
|
922
998
|
req.resume();
|
|
923
|
-
res.once("finish", () => _optionalChain([res, 'access',
|
|
999
|
+
res.once("finish", () => _optionalChain([res, 'access', _57 => _57.socket, 'optionalAccess', _58 => _58.end, 'call', _59 => _59()]));
|
|
924
1000
|
res.end(
|
|
925
1001
|
JSON.stringify({
|
|
926
1002
|
error: "invalid_request",
|
|
@@ -983,7 +1059,7 @@ var ViteMCP = class {
|
|
|
983
1059
|
return void 0;
|
|
984
1060
|
}
|
|
985
1061
|
const standard = schema["~standard"];
|
|
986
|
-
if (_optionalChain([standard, 'optionalAccess',
|
|
1062
|
+
if (_optionalChain([standard, 'optionalAccess', _60 => _60.jsonSchema])) {
|
|
987
1063
|
return schema;
|
|
988
1064
|
}
|
|
989
1065
|
try {
|
|
@@ -996,6 +1072,26 @@ var ViteMCP = class {
|
|
|
996
1072
|
);
|
|
997
1073
|
}
|
|
998
1074
|
}
|
|
1075
|
+
/**
|
|
1076
|
+
* The RFC 6750 §3 challenge sent when `authenticate` refuses a request.
|
|
1077
|
+
*
|
|
1078
|
+
* `resource_metadata` (RFC 9728 §5.1) is the parameter that turns a bare
|
|
1079
|
+
* rejection into a login: it points the client at this server's
|
|
1080
|
+
* protected-resource document, from which it discovers the authorization
|
|
1081
|
+
* server and starts the flow. It is derived from the URL the request
|
|
1082
|
+
* arrived on, which is exactly where `createOAuthRouter` mounts that
|
|
1083
|
+
* document, and is omitted when this server publishes no such document.
|
|
1084
|
+
*/
|
|
1085
|
+
#unauthorized(request) {
|
|
1086
|
+
return _server.bearerAuthChallengeResponse.call(void 0,
|
|
1087
|
+
new (0, _server.OAuthError)(_server.OAuthErrorCode.InvalidToken, "Authentication required"),
|
|
1088
|
+
this.#servesProtectedResourceMetadata ? {
|
|
1089
|
+
resourceMetadataUrl: _server.getOAuthProtectedResourceMetadataUrl.call(void 0,
|
|
1090
|
+
new URL(request.url)
|
|
1091
|
+
)
|
|
1092
|
+
} : {}
|
|
1093
|
+
);
|
|
1094
|
+
}
|
|
999
1095
|
};
|
|
1000
1096
|
var nodeToWebRequest = (req, body, secure) => {
|
|
1001
1097
|
const host = _nullishCoalesce(req.headers.host, () => ( "localhost"));
|
|
@@ -1063,8 +1159,8 @@ var assertStandardSchema = (schema, toolName, field) => {
|
|
|
1063
1159
|
if (schema === void 0) {
|
|
1064
1160
|
return;
|
|
1065
1161
|
}
|
|
1066
|
-
const standard = _optionalChain([schema, 'optionalAccess',
|
|
1067
|
-
if (typeof _optionalChain([standard, 'optionalAccess',
|
|
1162
|
+
const standard = _optionalChain([schema, 'optionalAccess', _61 => _61["~standard"]]);
|
|
1163
|
+
if (typeof _optionalChain([standard, 'optionalAccess', _62 => _62.validate]) !== "function") {
|
|
1068
1164
|
throw new UnexpectedStateError(
|
|
1069
1165
|
`Tool '${toolName}' ${field} must implement Standard Schema. If you are using Zod, upgrade to version 3.24 or later.`,
|
|
1070
1166
|
{ toolName }
|
|
@@ -1073,13 +1169,13 @@ var assertStandardSchema = (schema, toolName, field) => {
|
|
|
1073
1169
|
};
|
|
1074
1170
|
var promptArgsSchema = (prompt) => {
|
|
1075
1171
|
const args = prompt.arguments;
|
|
1076
|
-
if (!_optionalChain([args, 'optionalAccess',
|
|
1172
|
+
if (!_optionalChain([args, 'optionalAccess', _63 => _63.length])) {
|
|
1077
1173
|
return void 0;
|
|
1078
1174
|
}
|
|
1079
1175
|
const shape = {};
|
|
1080
1176
|
for (const arg of args) {
|
|
1081
1177
|
const completer = _nullishCoalesce(arg.complete, () => ( (prompt.complete ? (value) => prompt.complete(arg.name, value) : void 0)));
|
|
1082
|
-
const valueSchema = _optionalChain([arg, 'access',
|
|
1178
|
+
const valueSchema = _optionalChain([arg, 'access', _64 => _64.enum, 'optionalAccess', _65 => _65.length]) ? _zod.z.enum(arg.enum) : _zod.z.string();
|
|
1083
1179
|
const described = arg.description ? valueSchema.describe(arg.description) : valueSchema;
|
|
1084
1180
|
const base = completer ? _server.completable.call(void 0,
|
|
1085
1181
|
described,
|
|
@@ -1136,5 +1232,5 @@ var normalizeToolResult = (result) => {
|
|
|
1136
1232
|
|
|
1137
1233
|
|
|
1138
1234
|
|
|
1139
|
-
exports.AuthProvider =
|
|
1235
|
+
exports.AuthProvider = _chunkXC4BVJQZcjs.AuthProvider; exports.AzureProvider = _chunkXC4BVJQZcjs.AzureProvider; exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.GitHubProvider = _chunkXC4BVJQZcjs.GitHubProvider; exports.GoogleProvider = _chunkXC4BVJQZcjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkXC4BVJQZcjs.OAuthProvider; exports.OAuthProxy = _chunkXC4BVJQZcjs.OAuthProxy; exports.OAuthProxyError = _chunkXC4BVJQZcjs.OAuthProxyError; exports.ServerState = ServerState; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.ViteMCP = ViteMCP; exports.ViteMCPError = ViteMCPError; exports.audioContent = audioContent; exports.delay = _promises3.setTimeout; exports.getAuthSession = _chunkXC4BVJQZcjs.getAuthSession; exports.imageContent = imageContent; exports.jsonSchemaAdapter = jsonSchemaAdapter; exports.requireAll = _chunkXC4BVJQZcjs.requireAll; exports.requireAny = _chunkXC4BVJQZcjs.requireAny; exports.requireAuth = _chunkXC4BVJQZcjs.requireAuth; exports.requireRole = _chunkXC4BVJQZcjs.requireRole; exports.requireScopes = _chunkXC4BVJQZcjs.requireScopes;
|
|
1140
1236
|
//# sourceMappingURL=ViteMCP.cjs.map
|