@vitemcp/server 1.9.15 → 1.9.17
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/dist/{OAuthProvider-AjmrLphi.d.cts → OAuthProvider-STkC4R2N.d.cts} +55 -1
- package/dist/{OAuthProvider-AjmrLphi.d.ts → OAuthProvider-STkC4R2N.d.ts} +55 -1
- package/dist/ViteMCP.cjs +3 -3
- package/dist/ViteMCP.d.cts +2 -2
- package/dist/ViteMCP.d.ts +2 -2
- package/dist/ViteMCP.js +2 -2
- package/dist/auth/index.cjs +2 -2
- package/dist/auth/index.d.cts +17 -3
- package/dist/auth/index.d.ts +17 -3
- package/dist/auth/index.js +1 -1
- package/dist/bin/vitemcp.cjs +0 -1
- package/dist/bin/vitemcp.cjs.map +1 -1
- package/dist/bin/vitemcp.js +0 -1
- package/dist/bin/vitemcp.js.map +1 -1
- package/dist/{chunk-WOQXAQIG.js → chunk-4BX2CT5Z.js} +180 -24
- package/dist/chunk-4BX2CT5Z.js.map +1 -0
- package/dist/{chunk-2JOXLIMJ.js → chunk-B3LLXB6O.js} +3 -3
- package/dist/{chunk-2JOXLIMJ.js.map → chunk-B3LLXB6O.js.map} +1 -1
- package/dist/{chunk-AOEXFXTH.cjs → chunk-TNT3APOK.cjs} +4 -4
- package/dist/{chunk-AOEXFXTH.cjs.map → chunk-TNT3APOK.cjs.map} +1 -1
- package/dist/{chunk-7XWK66ZT.cjs → chunk-ZEYQBA72.cjs} +196 -40
- package/dist/chunk-ZEYQBA72.cjs.map +1 -0
- package/dist/openapi/index.cjs +12 -12
- package/dist/openapi/index.d.cts +1 -1
- package/dist/openapi/index.d.ts +1 -1
- package/dist/openapi/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-7XWK66ZT.cjs.map +0 -1
- package/dist/chunk-WOQXAQIG.js.map +0 -1
|
@@ -77,6 +77,8 @@ interface ClientCode {
|
|
|
77
77
|
interface ConsentData {
|
|
78
78
|
clientName: string;
|
|
79
79
|
provider: string;
|
|
80
|
+
/** Where the client is sent once the user approves. */
|
|
81
|
+
redirectUri?: string;
|
|
80
82
|
scope: string[];
|
|
81
83
|
timestamp: number;
|
|
82
84
|
transactionId: string;
|
|
@@ -346,6 +348,11 @@ interface OAuthTransaction {
|
|
|
346
348
|
clientCodeChallengeMethod: string;
|
|
347
349
|
/** Client ID from registration */
|
|
348
350
|
clientId: string;
|
|
351
|
+
/**
|
|
352
|
+
* Digest of the cookie held by the browser the consent screen was shown to.
|
|
353
|
+
* Approving the request and finishing it both take that cookie.
|
|
354
|
+
*/
|
|
355
|
+
consentBinding?: string;
|
|
349
356
|
/** Whether user consent was given */
|
|
350
357
|
consentGiven?: boolean;
|
|
351
358
|
/** Transaction creation timestamp */
|
|
@@ -578,8 +585,13 @@ declare class OAuthProxy {
|
|
|
578
585
|
constructor(config: OAuthProxyConfig);
|
|
579
586
|
/**
|
|
580
587
|
* OAuth authorization endpoint
|
|
588
|
+
*
|
|
589
|
+
* With consent required the response is the consent screen, and it sets the
|
|
590
|
+
* cookie that the request is approved and finished with: return its headers
|
|
591
|
+
* to the browser. Pass that browser's `request` as well, so that one with
|
|
592
|
+
* several authorization requests open keeps a single cookie for all of them.
|
|
581
593
|
*/
|
|
582
|
-
authorize(params: AuthorizationParams): Promise<Response>;
|
|
594
|
+
authorize(params: AuthorizationParams, request?: Request): Promise<Response>;
|
|
583
595
|
/**
|
|
584
596
|
* Stop cleanup interval and destroy resources
|
|
585
597
|
*/
|
|
@@ -663,6 +675,24 @@ declare class OAuthProxy {
|
|
|
663
675
|
* Periodic maintenance hook. Expiry is enforced by the token storage.
|
|
664
676
|
*/
|
|
665
677
|
private cleanup;
|
|
678
|
+
/**
|
|
679
|
+
* The cookie that ties consent requests to the browser they were shown to.
|
|
680
|
+
* A browser holds one, shared by every request it has open, and it lasts as
|
|
681
|
+
* long as a request does. `Lax` lets it travel with the provider's redirect
|
|
682
|
+
* back to the callback, which is a cross-site navigation. Over HTTPS the
|
|
683
|
+
* `__Host-` prefix keeps another host on the same site from setting it.
|
|
684
|
+
*/
|
|
685
|
+
private consentCookie;
|
|
686
|
+
private consentCookieName;
|
|
687
|
+
/**
|
|
688
|
+
* The consent cookie `request` carries, if it carries a well-formed one.
|
|
689
|
+
*
|
|
690
|
+
* Only the spaces and tabs that may surround a cookie are dropped. Trimming
|
|
691
|
+
* all white space would take a cookie whose name begins with, say, a
|
|
692
|
+
* no-break space for this one, and a browser does not hold such a name to
|
|
693
|
+
* the `__Host-` rules.
|
|
694
|
+
*/
|
|
695
|
+
private consentCookieValue;
|
|
666
696
|
/**
|
|
667
697
|
* Create a new OAuth transaction
|
|
668
698
|
*/
|
|
@@ -725,6 +755,14 @@ declare class OAuthProxy {
|
|
|
725
755
|
* Handle swap mode refresh - verify ViteMCP JWT and issue new tokens
|
|
726
756
|
*/
|
|
727
757
|
private handleSwapModeRefresh;
|
|
758
|
+
/**
|
|
759
|
+
* Whether `request` comes from the browser the transaction's consent screen
|
|
760
|
+
* was shown to: it carries the cookie that screen set. A transaction that
|
|
761
|
+
* never had a consent screen is bound to no browser.
|
|
762
|
+
*/
|
|
763
|
+
private isConsentBoundTo;
|
|
764
|
+
/** Whether browsers reach this proxy over HTTPS, going by its `baseUrl`. */
|
|
765
|
+
private isServedOverHttps;
|
|
728
766
|
/**
|
|
729
767
|
* Issue swapped tokens (JWT pattern)
|
|
730
768
|
* Issues short-lived ViteMCP JWTs and stores upstream tokens securely
|
|
@@ -782,6 +820,22 @@ declare class OAuthProxy {
|
|
|
782
820
|
* itself is a live upstream credential.
|
|
783
821
|
*/
|
|
784
822
|
private passthroughRefreshKey;
|
|
823
|
+
/**
|
|
824
|
+
* What a refusal from the token endpoint says: the `error` and
|
|
825
|
+
* `error_description` RFC 6749 §5.2 gives it.
|
|
826
|
+
*
|
|
827
|
+
* §5.2 sends them as JSON, but a provider that answers a successful request
|
|
828
|
+
* with a form — GitHub, by default — may refuse with one too, and read as
|
|
829
|
+
* JSON that lost the provider's own code and description to a bare HTTP
|
|
830
|
+
* status.
|
|
831
|
+
*
|
|
832
|
+
* What parses as JSON is read as JSON, whatever the response declares, as
|
|
833
|
+
* every refusal was before. A form is read only when the response declares
|
|
834
|
+
* one, by its media type alone: a 502 page can name that type in a parameter
|
|
835
|
+
* and carry `error=` in a link, and is no provider's refusal. Rejects when
|
|
836
|
+
* the body is neither, and the caller falls back to the HTTP status.
|
|
837
|
+
*/
|
|
838
|
+
private readUpstreamError;
|
|
785
839
|
/**
|
|
786
840
|
* Send the user's browser back to the client's registered callback with how
|
|
787
841
|
* its request came out: a code, or an error (RFC 6749 §4.1.2). The `state`
|
|
@@ -77,6 +77,8 @@ interface ClientCode {
|
|
|
77
77
|
interface ConsentData {
|
|
78
78
|
clientName: string;
|
|
79
79
|
provider: string;
|
|
80
|
+
/** Where the client is sent once the user approves. */
|
|
81
|
+
redirectUri?: string;
|
|
80
82
|
scope: string[];
|
|
81
83
|
timestamp: number;
|
|
82
84
|
transactionId: string;
|
|
@@ -346,6 +348,11 @@ interface OAuthTransaction {
|
|
|
346
348
|
clientCodeChallengeMethod: string;
|
|
347
349
|
/** Client ID from registration */
|
|
348
350
|
clientId: string;
|
|
351
|
+
/**
|
|
352
|
+
* Digest of the cookie held by the browser the consent screen was shown to.
|
|
353
|
+
* Approving the request and finishing it both take that cookie.
|
|
354
|
+
*/
|
|
355
|
+
consentBinding?: string;
|
|
349
356
|
/** Whether user consent was given */
|
|
350
357
|
consentGiven?: boolean;
|
|
351
358
|
/** Transaction creation timestamp */
|
|
@@ -578,8 +585,13 @@ declare class OAuthProxy {
|
|
|
578
585
|
constructor(config: OAuthProxyConfig);
|
|
579
586
|
/**
|
|
580
587
|
* OAuth authorization endpoint
|
|
588
|
+
*
|
|
589
|
+
* With consent required the response is the consent screen, and it sets the
|
|
590
|
+
* cookie that the request is approved and finished with: return its headers
|
|
591
|
+
* to the browser. Pass that browser's `request` as well, so that one with
|
|
592
|
+
* several authorization requests open keeps a single cookie for all of them.
|
|
581
593
|
*/
|
|
582
|
-
authorize(params: AuthorizationParams): Promise<Response>;
|
|
594
|
+
authorize(params: AuthorizationParams, request?: Request): Promise<Response>;
|
|
583
595
|
/**
|
|
584
596
|
* Stop cleanup interval and destroy resources
|
|
585
597
|
*/
|
|
@@ -663,6 +675,24 @@ declare class OAuthProxy {
|
|
|
663
675
|
* Periodic maintenance hook. Expiry is enforced by the token storage.
|
|
664
676
|
*/
|
|
665
677
|
private cleanup;
|
|
678
|
+
/**
|
|
679
|
+
* The cookie that ties consent requests to the browser they were shown to.
|
|
680
|
+
* A browser holds one, shared by every request it has open, and it lasts as
|
|
681
|
+
* long as a request does. `Lax` lets it travel with the provider's redirect
|
|
682
|
+
* back to the callback, which is a cross-site navigation. Over HTTPS the
|
|
683
|
+
* `__Host-` prefix keeps another host on the same site from setting it.
|
|
684
|
+
*/
|
|
685
|
+
private consentCookie;
|
|
686
|
+
private consentCookieName;
|
|
687
|
+
/**
|
|
688
|
+
* The consent cookie `request` carries, if it carries a well-formed one.
|
|
689
|
+
*
|
|
690
|
+
* Only the spaces and tabs that may surround a cookie are dropped. Trimming
|
|
691
|
+
* all white space would take a cookie whose name begins with, say, a
|
|
692
|
+
* no-break space for this one, and a browser does not hold such a name to
|
|
693
|
+
* the `__Host-` rules.
|
|
694
|
+
*/
|
|
695
|
+
private consentCookieValue;
|
|
666
696
|
/**
|
|
667
697
|
* Create a new OAuth transaction
|
|
668
698
|
*/
|
|
@@ -725,6 +755,14 @@ declare class OAuthProxy {
|
|
|
725
755
|
* Handle swap mode refresh - verify ViteMCP JWT and issue new tokens
|
|
726
756
|
*/
|
|
727
757
|
private handleSwapModeRefresh;
|
|
758
|
+
/**
|
|
759
|
+
* Whether `request` comes from the browser the transaction's consent screen
|
|
760
|
+
* was shown to: it carries the cookie that screen set. A transaction that
|
|
761
|
+
* never had a consent screen is bound to no browser.
|
|
762
|
+
*/
|
|
763
|
+
private isConsentBoundTo;
|
|
764
|
+
/** Whether browsers reach this proxy over HTTPS, going by its `baseUrl`. */
|
|
765
|
+
private isServedOverHttps;
|
|
728
766
|
/**
|
|
729
767
|
* Issue swapped tokens (JWT pattern)
|
|
730
768
|
* Issues short-lived ViteMCP JWTs and stores upstream tokens securely
|
|
@@ -782,6 +820,22 @@ declare class OAuthProxy {
|
|
|
782
820
|
* itself is a live upstream credential.
|
|
783
821
|
*/
|
|
784
822
|
private passthroughRefreshKey;
|
|
823
|
+
/**
|
|
824
|
+
* What a refusal from the token endpoint says: the `error` and
|
|
825
|
+
* `error_description` RFC 6749 §5.2 gives it.
|
|
826
|
+
*
|
|
827
|
+
* §5.2 sends them as JSON, but a provider that answers a successful request
|
|
828
|
+
* with a form — GitHub, by default — may refuse with one too, and read as
|
|
829
|
+
* JSON that lost the provider's own code and description to a bare HTTP
|
|
830
|
+
* status.
|
|
831
|
+
*
|
|
832
|
+
* What parses as JSON is read as JSON, whatever the response declares, as
|
|
833
|
+
* every refusal was before. A form is read only when the response declares
|
|
834
|
+
* one, by its media type alone: a 502 page can name that type in a parameter
|
|
835
|
+
* and carry `error=` in a link, and is no provider's refusal. Rejects when
|
|
836
|
+
* the body is neither, and the caller falls back to the HTTP status.
|
|
837
|
+
*/
|
|
838
|
+
private readUpstreamError;
|
|
785
839
|
/**
|
|
786
840
|
* Send the user's browser back to the client's registered callback with how
|
|
787
841
|
* its request came out: a code, or an error (RFC 6749 §4.1.2). The `state`
|
package/dist/ViteMCP.cjs
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkTNT3APOKcjs = require('./chunk-TNT3APOK.cjs');
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
@@ -25,7 +25,7 @@ var _chunkAOEXFXTHcjs = require('./chunk-AOEXFXTH.cjs');
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
var
|
|
28
|
+
var _chunkZEYQBA72cjs = require('./chunk-ZEYQBA72.cjs');
|
|
29
29
|
require('./chunk-QPVEGWOL.cjs');
|
|
30
30
|
|
|
31
31
|
|
|
@@ -52,5 +52,5 @@ require('./chunk-QPVEGWOL.cjs');
|
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
|
|
55
|
-
exports.AuthProvider =
|
|
55
|
+
exports.AuthProvider = _chunkZEYQBA72cjs.AuthProvider; exports.AzureProvider = _chunkZEYQBA72cjs.AzureProvider; exports.DiscoveryDocumentCache = _chunkTNT3APOKcjs.DiscoveryDocumentCache; exports.GitHubProvider = _chunkZEYQBA72cjs.GitHubProvider; exports.GoogleProvider = _chunkZEYQBA72cjs.GoogleProvider; exports.MEDIA_FETCH_TIMEOUT_MS = _chunkTNT3APOKcjs.MEDIA_FETCH_TIMEOUT_MS; exports.OAuthProvider = _chunkZEYQBA72cjs.OAuthProvider; exports.OAuthProxy = _chunkZEYQBA72cjs.OAuthProxy; exports.OAuthProxyError = _chunkZEYQBA72cjs.OAuthProxyError; exports.ServerState = _chunkTNT3APOKcjs.ServerState; exports.UnexpectedStateError = _chunkTNT3APOKcjs.UnexpectedStateError; exports.UserError = _chunkTNT3APOKcjs.UserError; exports.ViteMCP = _chunkTNT3APOKcjs.ViteMCP; exports.ViteMCPError = _chunkTNT3APOKcjs.ViteMCPError; exports.audioContent = _chunkTNT3APOKcjs.audioContent; exports.delay = _chunkTNT3APOKcjs.delay; exports.getAuthSession = _chunkZEYQBA72cjs.getAuthSession; exports.imageContent = _chunkTNT3APOKcjs.imageContent; exports.jsonSchemaAdapter = _chunkTNT3APOKcjs.jsonSchemaAdapter; exports.requireAll = _chunkZEYQBA72cjs.requireAll; exports.requireAny = _chunkZEYQBA72cjs.requireAny; exports.requireAuth = _chunkZEYQBA72cjs.requireAuth; exports.requireRole = _chunkZEYQBA72cjs.requireRole; exports.requireScopes = _chunkZEYQBA72cjs.requireScopes;
|
|
56
56
|
//# sourceMappingURL=ViteMCP.cjs.map
|
package/dist/ViteMCP.d.cts
CHANGED
|
@@ -4,8 +4,8 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
|
4
4
|
import { Hono } from 'hono';
|
|
5
5
|
import { cors } from 'hono/cors';
|
|
6
6
|
export { setTimeout as delay } from 'timers/promises';
|
|
7
|
-
import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-
|
|
8
|
-
export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, p as OAuthProxyError, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-
|
|
7
|
+
import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-STkC4R2N.cjs';
|
|
8
|
+
export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, p as OAuthProxyError, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-STkC4R2N.cjs';
|
|
9
9
|
|
|
10
10
|
declare class DiscoveryDocumentCache {
|
|
11
11
|
#private;
|
package/dist/ViteMCP.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
|
4
4
|
import { Hono } from 'hono';
|
|
5
5
|
import { cors } from 'hono/cors';
|
|
6
6
|
export { setTimeout as delay } from 'timers/promises';
|
|
7
|
-
import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-
|
|
8
|
-
export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, p as OAuthProxyError, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-
|
|
7
|
+
import { A as AuthProvider, O as OAuthSession, a as OAuthProxy } from './OAuthProvider-STkC4R2N.js';
|
|
8
|
+
export { j as AuthProviderConfig, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, d as OAuthProvider, p as OAuthProxyError, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from './OAuthProvider-STkC4R2N.js';
|
|
9
9
|
|
|
10
10
|
declare class DiscoveryDocumentCache {
|
|
11
11
|
#private;
|
package/dist/ViteMCP.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
delay,
|
|
11
11
|
imageContent,
|
|
12
12
|
jsonSchemaAdapter
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-B3LLXB6O.js";
|
|
14
14
|
import {
|
|
15
15
|
AuthProvider,
|
|
16
16
|
AzureProvider,
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
requireAuth,
|
|
26
26
|
requireRole,
|
|
27
27
|
requireScopes
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-4BX2CT5Z.js";
|
|
29
29
|
import "./chunk-JMDI672G.js";
|
|
30
30
|
export {
|
|
31
31
|
AuthProvider,
|
package/dist/auth/index.cjs
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
|
|
27
|
-
var
|
|
27
|
+
var _chunkZEYQBA72cjs = require('../chunk-ZEYQBA72.cjs');
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
|
|
@@ -51,5 +51,5 @@ var _chunk7XWK66ZTcjs = require('../chunk-7XWK66ZT.cjs');
|
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
|
|
54
|
-
exports.AuthProvider =
|
|
54
|
+
exports.AuthProvider = _chunkZEYQBA72cjs.AuthProvider; exports.AzureProvider = _chunkZEYQBA72cjs.AzureProvider; exports.ConsentManager = _chunkZEYQBA72cjs.ConsentManager; exports.DEFAULT_ACCESS_TOKEN_TTL = _chunkZEYQBA72cjs.DEFAULT_ACCESS_TOKEN_TTL; exports.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH = _chunkZEYQBA72cjs.DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH; exports.DEFAULT_AUTHORIZATION_CODE_TTL = _chunkZEYQBA72cjs.DEFAULT_AUTHORIZATION_CODE_TTL; exports.DEFAULT_REFRESH_TOKEN_TTL = _chunkZEYQBA72cjs.DEFAULT_REFRESH_TOKEN_TTL; exports.DEFAULT_TRANSACTION_TTL = _chunkZEYQBA72cjs.DEFAULT_TRANSACTION_TTL; exports.DiskStore = _chunkZEYQBA72cjs.DiskStore; exports.EncryptedTokenStorage = _chunkZEYQBA72cjs.EncryptedTokenStorage; exports.GitHubProvider = _chunkZEYQBA72cjs.GitHubProvider; exports.GoogleProvider = _chunkZEYQBA72cjs.GoogleProvider; exports.JWKSVerifier = _chunkZEYQBA72cjs.JWKSVerifier; exports.JWTIssuer = _chunkZEYQBA72cjs.JWTIssuer; exports.MemoryTokenStorage = _chunkZEYQBA72cjs.MemoryTokenStorage; exports.OAuthProvider = _chunkZEYQBA72cjs.OAuthProvider; exports.OAuthProxy = _chunkZEYQBA72cjs.OAuthProxy; exports.OAuthProxyError = _chunkZEYQBA72cjs.OAuthProxyError; exports.PKCEUtils = _chunkZEYQBA72cjs.PKCEUtils; exports.getAuthSession = _chunkZEYQBA72cjs.getAuthSession; exports.requireAll = _chunkZEYQBA72cjs.requireAll; exports.requireAny = _chunkZEYQBA72cjs.requireAny; exports.requireAuth = _chunkZEYQBA72cjs.requireAuth; exports.requireRole = _chunkZEYQBA72cjs.requireRole; exports.requireScopes = _chunkZEYQBA72cjs.requireScopes;
|
|
55
55
|
//# sourceMappingURL=index.cjs.map
|
package/dist/auth/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { q as OAuthTransaction, C as ConsentData, T as TokenStorage, s as TokenVerifier, t as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-
|
|
2
|
-
export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, u as ClientIdMetadataOptions, E as CustomClaimsPassthroughConfig, F as DCRClientMetadata, H as DCRRequest, I as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, v as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, w as DEFAULT_AUTHORIZATION_CODE_TTL, x as DEFAULT_REFRESH_TOKEN_TTL, y as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, J as OAuthError, d as OAuthProvider, K as OAuthProviderConfig, a as OAuthProxy, L as OAuthProxyConfig, p as OAuthProxyError, O as OAuthSession, M as ProxyDCRClient, R as RefreshRequest, S as SessionAuth, N as TokenMapping, Q as TokenRequest, U as TokenResponse, V as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-
|
|
1
|
+
import { q as OAuthTransaction, C as ConsentData, T as TokenStorage, s as TokenVerifier, t as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-STkC4R2N.cjs';
|
|
2
|
+
export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, u as ClientIdMetadataOptions, E as CustomClaimsPassthroughConfig, F as DCRClientMetadata, H as DCRRequest, I as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, v as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, w as DEFAULT_AUTHORIZATION_CODE_TTL, x as DEFAULT_REFRESH_TOKEN_TTL, y as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, J as OAuthError, d as OAuthProvider, K as OAuthProviderConfig, a as OAuthProxy, L as OAuthProxyConfig, p as OAuthProxyError, O as OAuthSession, M as ProxyDCRClient, R as RefreshRequest, S as SessionAuth, N as TokenMapping, Q as TokenRequest, U as TokenResponse, V as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-STkC4R2N.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Consent Management
|
|
@@ -14,8 +14,15 @@ declare class ConsentManager {
|
|
|
14
14
|
constructor(signingKey: string);
|
|
15
15
|
/**
|
|
16
16
|
* Create HTTP response with consent screen
|
|
17
|
+
*
|
|
18
|
+
* `cookie` is a `Set-Cookie` value that ties the request to the browser the
|
|
19
|
+
* screen is shown to. The screen may not be framed: a page that embeds it
|
|
20
|
+
* could have the user approve without seeing what they are approving.
|
|
17
21
|
*/
|
|
18
|
-
createConsentResponse(transaction: OAuthTransaction, provider: string
|
|
22
|
+
createConsentResponse(transaction: OAuthTransaction, provider: string, options?: {
|
|
23
|
+
clientName?: string;
|
|
24
|
+
cookie?: string;
|
|
25
|
+
}): Response;
|
|
19
26
|
/**
|
|
20
27
|
* Generate HTML for consent screen
|
|
21
28
|
*
|
|
@@ -33,6 +40,13 @@ declare class ConsentManager {
|
|
|
33
40
|
* Validate and parse consent cookie
|
|
34
41
|
*/
|
|
35
42
|
validateConsentCookie(cookie: string): ConsentData | null;
|
|
43
|
+
/**
|
|
44
|
+
* Where a redirect URI leads, as the browser will read it rather than as it
|
|
45
|
+
* was typed: the parsed host, so that a look-alike character, a tab or a
|
|
46
|
+
* backslash shows for what it does. A long host keeps its end, which is the
|
|
47
|
+
* part that says whose it is.
|
|
48
|
+
*/
|
|
49
|
+
private describeDestination;
|
|
36
50
|
/**
|
|
37
51
|
* Escape HTML to prevent XSS
|
|
38
52
|
*/
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { q as OAuthTransaction, C as ConsentData, T as TokenStorage, s as TokenVerifier, t as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-
|
|
2
|
-
export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, u as ClientIdMetadataOptions, E as CustomClaimsPassthroughConfig, F as DCRClientMetadata, H as DCRRequest, I as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, v as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, w as DEFAULT_AUTHORIZATION_CODE_TTL, x as DEFAULT_REFRESH_TOKEN_TTL, y as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, J as OAuthError, d as OAuthProvider, K as OAuthProviderConfig, a as OAuthProxy, L as OAuthProxyConfig, p as OAuthProxyError, O as OAuthSession, M as ProxyDCRClient, R as RefreshRequest, S as SessionAuth, N as TokenMapping, Q as TokenRequest, U as TokenResponse, V as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-
|
|
1
|
+
import { q as OAuthTransaction, C as ConsentData, T as TokenStorage, s as TokenVerifier, t as TokenVerificationResult, P as PKCEPair } from '../OAuthProvider-STkC4R2N.js';
|
|
2
|
+
export { A as AuthProvider, j as AuthProviderConfig, z as AuthorizationParams, b as AzureProvider, k as AzureProviderConfig, l as AzureSession, B as ClientCode, u as ClientIdMetadataOptions, E as CustomClaimsPassthroughConfig, F as DCRClientMetadata, H as DCRRequest, I as DCRResponse, D as DEFAULT_ACCESS_TOKEN_TTL, v as DEFAULT_ACCESS_TOKEN_TTL_NO_REFRESH, w as DEFAULT_AUTHORIZATION_CODE_TTL, x as DEFAULT_REFRESH_TOKEN_TTL, y as DEFAULT_TRANSACTION_TTL, m as GenericOAuthProviderConfig, G as GitHubProvider, n as GitHubSession, c as GoogleProvider, o as GoogleSession, J as OAuthError, d as OAuthProvider, K as OAuthProviderConfig, a as OAuthProxy, L as OAuthProxyConfig, p as OAuthProxyError, O as OAuthSession, M as ProxyDCRClient, R as RefreshRequest, S as SessionAuth, N as TokenMapping, Q as TokenRequest, U as TokenResponse, V as UpstreamTokenSet, g as getAuthSession, r as requireAll, e as requireAny, f as requireAuth, h as requireRole, i as requireScopes } from '../OAuthProvider-STkC4R2N.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Consent Management
|
|
@@ -14,8 +14,15 @@ declare class ConsentManager {
|
|
|
14
14
|
constructor(signingKey: string);
|
|
15
15
|
/**
|
|
16
16
|
* Create HTTP response with consent screen
|
|
17
|
+
*
|
|
18
|
+
* `cookie` is a `Set-Cookie` value that ties the request to the browser the
|
|
19
|
+
* screen is shown to. The screen may not be framed: a page that embeds it
|
|
20
|
+
* could have the user approve without seeing what they are approving.
|
|
17
21
|
*/
|
|
18
|
-
createConsentResponse(transaction: OAuthTransaction, provider: string
|
|
22
|
+
createConsentResponse(transaction: OAuthTransaction, provider: string, options?: {
|
|
23
|
+
clientName?: string;
|
|
24
|
+
cookie?: string;
|
|
25
|
+
}): Response;
|
|
19
26
|
/**
|
|
20
27
|
* Generate HTML for consent screen
|
|
21
28
|
*
|
|
@@ -33,6 +40,13 @@ declare class ConsentManager {
|
|
|
33
40
|
* Validate and parse consent cookie
|
|
34
41
|
*/
|
|
35
42
|
validateConsentCookie(cookie: string): ConsentData | null;
|
|
43
|
+
/**
|
|
44
|
+
* Where a redirect URI leads, as the browser will read it rather than as it
|
|
45
|
+
* was typed: the parsed host, so that a look-alike character, a tab or a
|
|
46
|
+
* backslash shows for what it does. A long host keeps its end, which is the
|
|
47
|
+
* part that says whose it is.
|
|
48
|
+
*/
|
|
49
|
+
private describeDestination;
|
|
36
50
|
/**
|
|
37
51
|
* Escape HTML to prevent XSS
|
|
38
52
|
*/
|
package/dist/auth/index.js
CHANGED
package/dist/bin/vitemcp.cjs
CHANGED
package/dist/bin/vitemcp.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/server/server/dist/bin/vitemcp.cjs","../../src/bin/vitemcp.ts","../../src/bin/devCommand.ts","../../src/bin/validateCommand.ts"],"names":["yargs"],"mappings":"AAAA;AACA;AACA;ACAA,8BAAsB;AACtB,uCAAuC;AACvC,wBAAuB;AACvB,4BAAqB;AACrB,4EAAkB;AAClB,wCAAwB;ADExB;AACA;AEqBO,IAAM,gBAAA,EAAkB,KAAA;AAWxB,IAAM,eAAA,EAAiB,CAAC,IAAA,EAAA,GAC7B,IAAA,CAAK,SAAA;AAAA,EACH;AAAA,IACE,UAAA,EAAY;AAAA,MACV,CAAC,eAAe,CAAA,EAAG;AAAA,QACjB,IAAA,EAAM,CAAC,KAAA,EAAO,IAAI,CAAA;AAAA,QAClB,OAAA,EAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF,CAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAA;AAeK,IAAM,gBAAA,EAAkB,CAC7B,OAAA,EAAA,GAC0B;AAC1B,EAAA,MAAM,EAAE,UAAA,EAAY,IAAA,EAAM,IAAA,EAAM,QAAA,EAAU,MAAA,EAAQ,MAAM,EAAA,EAAI,OAAA;AAE5D,EAAA,GAAA,CAAI,IAAA,EAAM;AACR,IAAA,GAAA,CAAI,CAAC,UAAA,EAAY;AACf,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,MACF,CAAA;AAAA,IACF;AAEA,IAAA,OAAO;AAAA,MACL,KAAA;AAAA,MACA,gBAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAA;AAAA,MACA,WAAA;AAAA,MACA,CAAA,EAAA;AACA,MAAA;AACF,IAAA;AACF,EAAA;AAKA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACI,IAAA;AACJ,IAAA;AACF,E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ACA,MAAA;AACA,MAAA;AACA,MAAA;AACD,IAAA;AACL,EAAA;AAEA,EAAA;AACE,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AAEA,MAAA;AACE,QAAA;AACA,QAAA;AACF,MAAA;AAEA,MAAA;AAEA,MAAA;AAEA,MAAA;AACE,QAAA;AAEA,QAAA;AAEA,QAAA;AACE,UAAA;AAAyB,QAAA;AAG3B,QAAA;AACF,MAAA;AAEA,MAAA;AAEA,MAAA;AACA,MAAA;AAA6C,QAAA;AAC3C,QAAA;AAEF,MAAA;AACA,MAAA;AAAoE,QAAA;AAEnE,MAAA;AAED,MAAA;AAIE,QAAA;AAEA,QAAA;AACE,UAAA;AAAoB,QAAA;AAEpB,UAAA;AACA,UAAA;AAAQ,YAAA;AACN,UAAA;AACF,QAAA;AAGF,QAAA;AAEA,QAAA;AACE,UAAA;AAAkB,QAAA;AAGpB,QAAA;AACF,MAAA;AAEA,MAAA;AAAQ,QAAA;AAER,MAAA;AACF,IAAA;AACE,MAAA;AAAQ,QAAA;AACN,QAAA;AAEF,MAAA;AAEA,MAAA;AACF,IAAA;AACF,EAAA;AAGI","file":"/home/runner/work/server/server/dist/bin/vitemcp.cjs","sourcesContent":[null,"#!/usr/bin/env node\n\nimport { execa } from \"execa\";\nimport { mkdtemp, rm, writeFile } from \"fs/promises\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\n\nimport { buildDevCommand, buildDevConfig } from \"./devCommand.js\";\nimport {\n buildStructureCheckCommand,\n formatCommandFailure,\n missingTsxHint,\n resolveTsxLoader,\n runTypeCheck,\n} from \"./validateCommand.js\";\n\nawait yargs(hideBin(process.argv))\n .scriptName(\"vitemcp\")\n .command(\n \"dev <file>\",\n \"Start a development server\",\n (yargs) => {\n return yargs\n .positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n })\n\n .option(\"args\", {\n describe:\n \"JSON arguments passed to the tool (requires --tool), e.g. '{\\\"a\\\":1}'\",\n type: \"string\",\n })\n\n .option(\"tool\", {\n alias: \"t\",\n describe:\n \"Call a tool non-interactively instead of launching the inspector\",\n type: \"string\",\n })\n\n .option(\"watch\", {\n alias: \"w\",\n default: false,\n describe: \"Watch for file changes and restart server\",\n type: \"boolean\",\n })\n\n .option(\"verbose\", {\n alias: \"v\",\n default: false,\n describe: \"Enable verbose logging\",\n type: \"boolean\",\n });\n },\n\n async (argv) => {\n let configDir: string | undefined;\n\n try {\n if (argv.args !== undefined && !argv.tool) {\n console.error(\"[ViteMCP Error] --args requires --tool\");\n process.exitCode = 1;\n return;\n }\n\n if (argv.tool && argv.watch) {\n console.warn(\n \"[ViteMCP] --watch is ignored when calling a tool with --tool: the server runs for a single call.\",\n );\n }\n\n let configPath: string | undefined;\n\n if (argv.tool) {\n configDir = await mkdtemp(join(tmpdir(), \"vitemcp-dev-\"));\n configPath = join(configDir, \"mcp-cli.json\");\n await writeFile(configPath, buildDevConfig(argv.file), \"utf8\");\n }\n\n const [command, ...commandArgs] = buildDevCommand({\n configPath,\n file: argv.file,\n tool: argv.tool,\n toolArgs: argv.args,\n watch: argv.watch,\n });\n\n if (argv.verbose) {\n console.log(\n `[ViteMCP] Starting server: ${[command, ...commandArgs].join(\" \")}`,\n );\n console.log(`[ViteMCP] File: ${argv.file}`);\n console.log(\n `[ViteMCP] Watch mode: ${argv.watch ? \"enabled\" : \"disabled\"}`,\n );\n\n if (argv.tool) {\n console.log(`[ViteMCP] Tool: ${argv.tool}`);\n }\n }\n\n await execa(command, commandArgs, {\n stderr: \"inherit\",\n stdin: \"inherit\",\n stdout: \"inherit\",\n });\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Failed to start development server:\",\n error instanceof Error ? error.message : String(error),\n );\n\n if (argv.verbose && error instanceof Error && error.stack) {\n console.error(\"[ViteMCP Debug] Stack trace:\", error.stack);\n }\n\n // Not process.exit(): that would skip the `finally` block below and\n // leak the temporary config directory on every failed tool call.\n process.exitCode = 1;\n } finally {\n if (configDir) {\n await rm(configDir, { force: true, recursive: true });\n }\n }\n },\n )\n\n .command(\n \"inspect <file>\",\n \"Inspect a server file\",\n (yargs) => {\n return yargs.positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n });\n },\n\n async (argv) => {\n try {\n await execa({\n stderr: \"inherit\",\n stdout: \"inherit\",\n })`npx @modelcontextprotocol/inspector npx tsx ${argv.file}`;\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Failed to inspect server:\",\n error instanceof Error ? error.message : String(error),\n );\n\n process.exit(1);\n }\n },\n )\n\n .command(\n \"validate <file>\",\n \"Validate a ViteMCP server file for syntax and basic structure\",\n (yargs) => {\n return yargs\n .positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n })\n\n .option(\"strict\", {\n alias: \"s\",\n default: false,\n describe: \"Enable strict validation (type checking)\",\n type: \"boolean\",\n });\n },\n\n async (argv) => {\n try {\n const { existsSync } = await import(\"fs\");\n const { resolve } = await import(\"path\");\n const filePath = resolve(argv.file);\n\n if (!existsSync(filePath)) {\n console.error(`[ViteMCP Error] File not found: ${filePath}`);\n process.exit(1);\n }\n\n console.log(`[ViteMCP] Validating server file: ${filePath}`);\n\n const typeCheck = await runTypeCheck(filePath, argv.strict);\n\n if (typeCheck.failed) {\n console.error(\"[ViteMCP] ✗ TypeScript compilation failed\");\n\n const diagnostics = formatCommandFailure(typeCheck);\n\n if (diagnostics) {\n console.error(diagnostics);\n }\n\n process.exit(1);\n }\n\n console.log(\"[ViteMCP] ✓ TypeScript compilation successful\");\n\n const tsxLoader = resolveTsxLoader(filePath);\n const [structureCommand, ...structureArgs] = buildStructureCheckCommand(\n filePath,\n { tsxLoader },\n );\n const structureCheck = await execa(structureCommand, structureArgs, {\n reject: false,\n });\n\n if (structureCheck.failed) {\n // The child explains the failure on stderr, which execa captures.\n // Without replaying it the user only ever sees the generic hint, even\n // when their server file has an error they could act on.\n const reason = formatCommandFailure(structureCheck);\n\n if (reason) {\n console.error(reason);\n } else {\n console.error(\"[ViteMCP] ✗ Server structure validation failed\");\n console.error(\n \"Make sure the file properly imports and uses ViteMCP\",\n );\n }\n\n const hint = missingTsxHint(filePath, tsxLoader);\n\n if (hint) {\n console.error(hint);\n }\n\n process.exit(1);\n }\n\n console.log(\n \"[ViteMCP] ✓ All validations passed! Server file looks good.\",\n );\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Validation failed:\",\n error instanceof Error ? error.message : String(error),\n );\n\n process.exit(1);\n }\n },\n )\n\n .help()\n .parseAsync();\n","export type DevCommandOptions = {\n /**\n * Path to a temporary mcp-cli config file that registers the dev server.\n * Only used in non-interactive mode (when `tool` is set).\n */\n configPath?: string;\n /**\n * Path to the server file to run.\n */\n file: string;\n /**\n * Name of the tool to call non-interactively. When omitted, the dev\n * command launches the interactive mcp-cli inspector instead.\n */\n tool?: string;\n /**\n * JSON string of arguments forwarded to the tool via mcp-cli `--args`.\n * Only used in non-interactive mode.\n */\n toolArgs?: string;\n /**\n * Watch the file for changes and restart the server. Only used in\n * interactive mode; a non-interactive call runs the server once.\n */\n watch?: boolean;\n};\n\n/**\n * The server name registered in the generated mcp-cli config. mcp-cli\n * addresses non-interactive targets as `<server-name>:<tool>`.\n */\nexport const DEV_SERVER_NAME = \"dev\";\n\n/**\n * Build the JSON config that registers the dev server with mcp-cli so it can\n * be invoked non-interactively. mcp-cli's non-interactive mode resolves the\n * server by name from a config file's `mcpServers` map, so an inline command\n * cannot be passed directly alongside `call-tool`.\n *\n * The server is never started in watch mode here: a non-interactive call\n * connects, calls one tool, and exits, so there is nothing to restart into.\n */\nexport const buildDevConfig = (file: string): string =>\n JSON.stringify(\n {\n mcpServers: {\n [DEV_SERVER_NAME]: {\n args: [\"tsx\", file],\n command: \"npx\",\n },\n },\n },\n null,\n 2,\n );\n\n/**\n * Build the argv that the dev command runs.\n *\n * This is an argv array rather than a shell string so that nothing has to be\n * quoted: file paths, tool names and JSON `--args` are passed to the child\n * process verbatim. Quoting through a shell would be wrong on Windows, where\n * cmd.exe treats single quotes as literal characters rather than as quoting.\n *\n * - Without `tool`: launches the interactive @wong2/mcp-cli inspector\n * against an inline `npx tsx <file>` server (existing behaviour).\n * - With `tool`: runs @wong2/mcp-cli in non-interactive mode against a\n * generated config file, calling the named tool and forwarding `--args`.\n */\nexport const buildDevCommand = (\n options: DevCommandOptions,\n): [string, ...string[]] => {\n const { configPath, file, tool, toolArgs, watch = false } = options;\n\n if (tool) {\n if (!configPath) {\n throw new Error(\n \"configPath is required when calling a tool non-interactively\",\n );\n }\n\n return [\n \"npx\",\n \"@wong2/mcp-cli\",\n \"-c\",\n configPath,\n \"call-tool\",\n `${DEV_SERVER_NAME}:${tool}`,\n ...(toolArgs === undefined ? [] : [\"--args\", toolArgs]),\n ];\n }\n\n // `--` ends mcp-cli's own options. Its parser reads any flag it meets, known\n // or not, and takes the next word as that flag's value, so `--watch` and the\n // file never reached the server: `npx tsx` started with no file at all.\n return [\n \"npx\",\n \"@wong2/mcp-cli\",\n \"--\",\n \"npx\",\n \"tsx\",\n ...(watch ? [\"--watch\"] : []),\n file,\n ];\n};\n","import { randomUUID } from \"crypto\";\nimport { execa } from \"execa\";\nimport { existsSync } from \"fs\";\nimport { rm, writeFile } from \"fs/promises\";\nimport { createRequire } from \"module\";\nimport { dirname, join } from \"path\";\nimport { pathToFileURL } from \"url\";\n\n/**\n * The script `vitemcp validate` runs to check that a server file loads.\n *\n * The file arrives as `process.argv[1]` rather than being spliced into this\n * source. Spliced into a string literal, a Windows path loses its backslashes\n * to the child's own parser (`C:\\Users\\dev\\server.ts` reaches the import as\n * `C:Usersdevserver.ts`), and a quote or `#` in any path breaks the import —\n * each reported to the user as a problem with their file.\n *\n * It exits as soon as the import settles, once its verdict is flushed. A\n * server file normally starts its transport on load, which would otherwise\n * keep this process, and the command waiting on it, alive forever.\n */\nexport const STRUCTURE_CHECK_SCRIPT = `\n(async () => {\n let failure;\n\n try {\n await import(\"@vitemcp/server\");\n await import(process.argv[1]);\n } catch (error) {\n failure = error instanceof Error ? error.message : String(error);\n }\n\n if (failure === undefined) {\n process.stdout.write(\n \"[ViteMCP] ✓ Server structure validation passed\\\\n\",\n () => process.exit(0),\n );\n } else {\n process.stderr.write(\n \"[ViteMCP] ✗ Server structure validation failed: \" + failure + \"\\\\n\",\n () => process.exit(1),\n );\n }\n})();\n`;\n\n/**\n * Compiler options for a file with no `tsconfig.json` above it. The compiler's\n * own defaults target ES5, which rejects top-level await and the `#private`\n * members in `@vitemcp/server`'s declarations, so no server file could pass.\n */\nconst STANDALONE_COMPILER_OPTIONS = {\n allowImportingTsExtensions: true,\n module: \"esnext\",\n moduleResolution: \"bundler\",\n skipLibCheck: true,\n target: \"es2022\",\n};\n\n/**\n * What the throwaway config overrides in the project's own. `composite`\n * demands that every file the server imports be listed as a root, and only the\n * server file is; `incremental` writes a `.tsbuildinfo` named after the\n * throwaway config into the project.\n *\n * `composite` also implies `declaration`, which `declarationMap`,\n * `emitDeclarationOnly` and `isolatedDeclarations` each require, so a composite\n * project may set them without it — and with `composite` off, its check failed\n * with TS5069. Nothing is emitted, so they are switched off as well.\n */\nconst PROJECT_OVERRIDES = {\n composite: false,\n declarationMap: false,\n emitDeclarationOnly: false,\n incremental: false,\n isolatedDeclarations: false,\n};\n\n/**\n * Build the argv for the structure check.\n *\n * An argv array rather than a shell string, as in `buildDevCommand`, so nothing\n * has to be quoted. The file is converted to a `file:` URL here, so the child\n * imports it as given and never has to build the URL itself; and the child is\n * the Node binary running this CLI, so no PATH lookup is involved.\n *\n * Given the project's tsx loader (see `resolveTsxLoader`), the child imports\n * the file through it, so the file loads the way `vitemcp dev` runs it. tsx\n * registers itself with `module.register()`, which Node 26 deprecates\n * (DEP0205); that warning alone is switched off, because it would otherwise be\n * replayed with a failure as though the file had caused it.\n */\nexport const buildStructureCheckCommand = (\n file: string,\n {\n execPath = process.execPath,\n tsxLoader,\n }: { execPath?: string; tsxLoader?: string } = {},\n): [string, ...string[]] => [\n execPath,\n ...(tsxLoader ? [\"--disable-warning=DEP0205\", \"--import\", tsxLoader] : []),\n \"-e\",\n STRUCTURE_CHECK_SCRIPT,\n pathToFileURL(file).href,\n];\n\n/**\n * Build the argv for the type check. An argv array for the same reason as the\n * structure check: through a shell, a path containing a space reaches `tsc` as\n * several root files.\n */\nexport const buildTypeCheckCommand = (\n config: string,\n strict = false,\n): [string, ...string[]] => [\n \"npx\",\n \"tsc\",\n \"--noEmit\",\n \"--project\",\n config,\n ...(strict ? [\"--strict\"] : []),\n];\n\n/**\n * Build the throwaway config that type-checks one file.\n *\n * `tsc` ignores `tsconfig.json` whenever a file is named on its command line\n * and falls back to defaults no server file passes, so the file is named in a\n * config that extends the project's own instead. `include: []` keeps an\n * inherited `include` from pulling the rest of the project in.\n */\nexport const buildTypeCheckConfig = (file: string, tsconfig?: string): string =>\n JSON.stringify(\n tsconfig\n ? {\n compilerOptions: PROJECT_OVERRIDES,\n extends: tsconfig,\n files: [file],\n include: [],\n }\n : {\n compilerOptions: STANDALONE_COMPILER_OPTIONS,\n files: [file],\n include: [],\n },\n null,\n 2,\n );\n\n/**\n * The `tsconfig.json` that governs a file in `dir`: the nearest one at or above\n * it, which is also the one an editor checks the file against.\n */\nexport const findTsconfig = (dir: string): string | undefined => {\n for (let current = dir; ; current = dirname(current)) {\n const candidate = join(current, \"tsconfig.json\");\n\n if (existsSync(candidate)) {\n return candidate;\n }\n\n if (dirname(current) === current) {\n return undefined;\n }\n }\n};\n\n/**\n * The output of a failed check, for replaying to the user.\n *\n * `tsc` writes its diagnostics to stdout, and only a failure to launch it\n * reaches stderr, so reading stderr alone reported every real type error with\n * no detail. The structure check explains itself on stderr.\n */\nexport const formatCommandFailure = (result: {\n stderr?: unknown;\n stdout?: unknown;\n}): string =>\n [result.stderr, result.stdout]\n .map((output) => (typeof output === \"string\" ? output.trim() : \"\"))\n .filter(Boolean)\n .join(\"\\n\");\n\n/**\n * What to add when the structure check fails without tsx. Plain Node rejects\n * TypeScript that tsx runs, so the failure may be the loader's rather than the\n * file's. Nothing for a JavaScript file, which loads the same either way.\n */\nexport const missingTsxHint = (\n file: string,\n tsxLoader: string | undefined,\n): string | undefined =>\n tsxLoader || !/\\.[cm]?tsx?$/i.test(file)\n ? undefined\n : \"[ViteMCP] tsx is not installed in this project, so the file was loaded with plain Node, which rejects `.js` imports of `.ts` files and syntax such as enums. Install tsx to validate the file the way `vitemcp dev` runs it: npm install --save-dev tsx\";\n\n/**\n * The project's tsx loader, as a `file:` URL for `--import`, or `undefined`\n * when the project does not have tsx installed.\n *\n * `vitemcp dev` runs a server file with tsx, but plain Node only strips types:\n * it rejects a `.js` import of a `.ts` file, and syntax it would have to\n * transform, such as an enum. So without tsx, a file `dev` ran fine failed the\n * check.\n *\n * Looked up in the `node_modules` at or above the file, as an `import` from the\n * file would look, so it is the tsx of the project the file belongs to.\n * `require.resolve` alone also searches `NODE_PATH`, which can point outside\n * the project: pnpm's bin shims set it to a store. A URL, because `--import`\n * takes a specifier, which a Windows path is not.\n */\nexport const resolveTsxLoader = (file: string): string | undefined => {\n for (let current = dirname(file); ; current = dirname(current)) {\n const manifest = join(current, \"node_modules\", \"tsx\", \"package.json\");\n\n if (existsSync(manifest)) {\n try {\n return pathToFileURL(createRequire(manifest).resolve(\"tsx\")).href;\n } catch {\n // Installed, but without the loader `--import tsx` would load.\n return undefined;\n }\n }\n\n if (dirname(current) === current) {\n return undefined;\n }\n }\n};\n\n/**\n * Type-check `file` under the compiler options of the project it belongs to.\n *\n * The throwaway config is written beside the project's own rather than to the\n * OS temp directory, because the compiler resolves type packages — the `types`\n * option and every visible `@types` package — from the config's directory. It\n * is removed before this returns, so a caller may exit straight away.\n */\nexport const runTypeCheck = async (file: string, strict = false) => {\n const tsconfig = findTsconfig(dirname(file));\n const config = join(\n dirname(tsconfig ?? file),\n `tsconfig.vitemcp-validate-${randomUUID()}.json`,\n );\n\n await writeFile(config, buildTypeCheckConfig(file, tsconfig), {\n flag: \"wx\",\n });\n\n try {\n const [command, ...args] = buildTypeCheckCommand(config, strict);\n\n return await execa(command, args, { reject: false });\n } finally {\n await rm(config, { force: true });\n }\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/server/server/dist/bin/vitemcp.cjs","../../src/bin/vitemcp.ts","../../src/bin/devCommand.ts","../../src/bin/validateCommand.ts"],"names":["yargs"],"mappings":"AAAA;AACA;AACA;ACAA,8BAAsB;AACtB,uCAAuC;AACvC,wBAAuB;AACvB,4BAAqB;AACrB,4EAAkB;AAClB,wCAAwB;ADExB;AACA;AEqBO,IAAM,gBAAA,EAAkB,KAAA;AAWxB,IAAM,eAAA,EAAiB,CAAC,IAAA,EAAA,GAC7B,IAAA,CAAK,SAAA;AAAA,EACH;AAAA,IACE,UAAA,EAAY;AAAA,MACV,CAAC,eAAe,CAAA,EAAG;AAAA,QACjB,IAAA,EAAM,CAAC,KAAA,EAAO,IAAI,CAAA;AAAA,QAClB,OAAA,EAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF,CAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAA;AAeK,IAAM,gBAAA,EAAkB,CAC7B,OAAA,EAAA,GAC0B;AAC1B,EAAA,MAAM,EAAE,UAAA,EAAY,IAAA,EAAM,IAAA,EAAM,QAAA,EAAU,MAAA,EAAQ,MAAM,EAAA,EAAI,OAAA;AAE5D,EAAA,GAAA,CAAI,IAAA,EAAM;AACR,IAAA,GAAA,CAAI,CAAC,UAAA,EAAY;AACf,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,MACF,CAAA;AAAA,IACF;AAEA,IAAA,OAAO;AAAA,MACL,KAAA;AAAA,MACA,gBAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAA;AAAA,MACA,WAAA;AAAA,MACA,CAAA,EAAA;AACA,MAAA;AACF,IAAA;AACF,EAAA;AAKA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACI,IAAA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AA;AACC,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACD,IAAA;AACL,EAAA;AAEA,EAAA;AACE,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AAEA,MAAA;AACE,QAAA;AACA,QAAA;AACF,MAAA;AAEA,MAAA;AAEA,MAAA;AAEA,MAAA;AACE,QAAA;AAEA,QAAA;AAEA,QAAA;AACE,UAAA;AAAyB,QAAA;AAG3B,QAAA;AACF,MAAA;AAEA,MAAA;AAEA,MAAA;AACA,MAAA;AAA6C,QAAA;AAC3C,QAAA;AAEF,MAAA;AACA,MAAA;AAAoE,QAAA;AAEnE,MAAA;AAED,MAAA;AAIE,QAAA;AAEA,QAAA;AACE,UAAA;AAAoB,QAAA;AAEpB,UAAA;AACA,UAAA;AAAQ,YAAA;AACN,UAAA;AACF,QAAA;AAGF,QAAA;AAEA,QAAA;AACE,UAAA;AAAkB,QAAA;AAGpB,QAAA;AACF,MAAA;AAEA,MAAA;AAAQ,QAAA;AAER,MAAA;AACF,IAAA;AACE,MAAA;AAAQ,QAAA;AACN,QAAA;AAEF,MAAA;AAEA,MAAA;AACF,IAAA;AACF,EAAA;AAGI","file":"/home/runner/work/server/server/dist/bin/vitemcp.cjs","sourcesContent":[null,"#!/usr/bin/env node\n\nimport { execa } from \"execa\";\nimport { mkdtemp, rm, writeFile } from \"fs/promises\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\n\nimport { buildDevCommand, buildDevConfig } from \"./devCommand.js\";\nimport {\n buildStructureCheckCommand,\n formatCommandFailure,\n missingTsxHint,\n resolveTsxLoader,\n runTypeCheck,\n} from \"./validateCommand.js\";\n\nawait yargs(hideBin(process.argv))\n .scriptName(\"vitemcp\")\n .command(\n \"dev <file>\",\n \"Start a development server\",\n (yargs) => {\n return yargs\n .positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n })\n\n .option(\"args\", {\n describe:\n \"JSON arguments passed to the tool (requires --tool), e.g. '{\\\"a\\\":1}'\",\n type: \"string\",\n })\n\n .option(\"tool\", {\n alias: \"t\",\n describe:\n \"Call a tool non-interactively instead of launching the inspector\",\n type: \"string\",\n })\n\n .option(\"watch\", {\n alias: \"w\",\n default: false,\n describe: \"Watch for file changes and restart server\",\n type: \"boolean\",\n })\n\n .option(\"verbose\", {\n alias: \"v\",\n default: false,\n describe: \"Enable verbose logging\",\n type: \"boolean\",\n });\n },\n\n async (argv) => {\n let configDir: string | undefined;\n\n try {\n if (argv.args !== undefined && !argv.tool) {\n console.error(\"[ViteMCP Error] --args requires --tool\");\n process.exitCode = 1;\n return;\n }\n\n if (argv.tool && argv.watch) {\n console.warn(\n \"[ViteMCP] --watch is ignored when calling a tool with --tool: the server runs for a single call.\",\n );\n }\n\n let configPath: string | undefined;\n\n if (argv.tool) {\n configDir = await mkdtemp(join(tmpdir(), \"vitemcp-dev-\"));\n configPath = join(configDir, \"mcp-cli.json\");\n await writeFile(configPath, buildDevConfig(argv.file), \"utf8\");\n }\n\n const [command, ...commandArgs] = buildDevCommand({\n configPath,\n file: argv.file,\n tool: argv.tool,\n toolArgs: argv.args,\n watch: argv.watch,\n });\n\n if (argv.verbose) {\n console.log(\n `[ViteMCP] Starting server: ${[command, ...commandArgs].join(\" \")}`,\n );\n console.log(`[ViteMCP] File: ${argv.file}`);\n console.log(\n `[ViteMCP] Watch mode: ${argv.watch ? \"enabled\" : \"disabled\"}`,\n );\n\n if (argv.tool) {\n console.log(`[ViteMCP] Tool: ${argv.tool}`);\n }\n }\n\n await execa(command, commandArgs, {\n stderr: \"inherit\",\n stdin: \"inherit\",\n stdout: \"inherit\",\n });\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Failed to start development server:\",\n error instanceof Error ? error.message : String(error),\n );\n\n if (argv.verbose && error instanceof Error && error.stack) {\n console.error(\"[ViteMCP Debug] Stack trace:\", error.stack);\n }\n\n // Not process.exit(): that would skip the `finally` block below and\n // leak the temporary config directory on every failed tool call.\n process.exitCode = 1;\n } finally {\n if (configDir) {\n await rm(configDir, { force: true, recursive: true });\n }\n }\n },\n )\n\n .command(\n \"inspect <file>\",\n \"Inspect a server file\",\n (yargs) => {\n return yargs.positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n });\n },\n\n async (argv) => {\n try {\n await execa({\n stderr: \"inherit\",\n stdout: \"inherit\",\n })`npx @modelcontextprotocol/inspector npx tsx ${argv.file}`;\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Failed to inspect server:\",\n error instanceof Error ? error.message : String(error),\n );\n\n process.exit(1);\n }\n },\n )\n\n .command(\n \"validate <file>\",\n \"Validate a ViteMCP server file for syntax and basic structure\",\n (yargs) => {\n return yargs\n .positional(\"file\", {\n demandOption: true,\n describe: \"The path to the server file\",\n type: \"string\",\n })\n\n .option(\"strict\", {\n alias: \"s\",\n default: false,\n describe: \"Enable strict validation (type checking)\",\n type: \"boolean\",\n });\n },\n\n async (argv) => {\n try {\n const { existsSync } = await import(\"fs\");\n const { resolve } = await import(\"path\");\n const filePath = resolve(argv.file);\n\n if (!existsSync(filePath)) {\n console.error(`[ViteMCP Error] File not found: ${filePath}`);\n process.exit(1);\n }\n\n console.log(`[ViteMCP] Validating server file: ${filePath}`);\n\n const typeCheck = await runTypeCheck(filePath, argv.strict);\n\n if (typeCheck.failed) {\n console.error(\"[ViteMCP] ✗ TypeScript compilation failed\");\n\n const diagnostics = formatCommandFailure(typeCheck);\n\n if (diagnostics) {\n console.error(diagnostics);\n }\n\n process.exit(1);\n }\n\n console.log(\"[ViteMCP] ✓ TypeScript compilation successful\");\n\n const tsxLoader = resolveTsxLoader(filePath);\n const [structureCommand, ...structureArgs] = buildStructureCheckCommand(\n filePath,\n { tsxLoader },\n );\n const structureCheck = await execa(structureCommand, structureArgs, {\n reject: false,\n });\n\n if (structureCheck.failed) {\n // The child explains the failure on stderr, which execa captures.\n // Without replaying it the user only ever sees the generic hint, even\n // when their server file has an error they could act on.\n const reason = formatCommandFailure(structureCheck);\n\n if (reason) {\n console.error(reason);\n } else {\n console.error(\"[ViteMCP] ✗ Server structure validation failed\");\n console.error(\n \"Make sure the file properly imports and uses ViteMCP\",\n );\n }\n\n const hint = missingTsxHint(filePath, tsxLoader);\n\n if (hint) {\n console.error(hint);\n }\n\n process.exit(1);\n }\n\n console.log(\n \"[ViteMCP] ✓ All validations passed! Server file looks good.\",\n );\n } catch (error) {\n console.error(\n \"[ViteMCP Error] Validation failed:\",\n error instanceof Error ? error.message : String(error),\n );\n\n process.exit(1);\n }\n },\n )\n\n .help()\n .parseAsync();\n","export type DevCommandOptions = {\n /**\n * Path to a temporary mcp-cli config file that registers the dev server.\n * Only used in non-interactive mode (when `tool` is set).\n */\n configPath?: string;\n /**\n * Path to the server file to run.\n */\n file: string;\n /**\n * Name of the tool to call non-interactively. When omitted, the dev\n * command launches the interactive mcp-cli inspector instead.\n */\n tool?: string;\n /**\n * JSON string of arguments forwarded to the tool via mcp-cli `--args`.\n * Only used in non-interactive mode.\n */\n toolArgs?: string;\n /**\n * Watch the file for changes and restart the server. Only used in\n * interactive mode; a non-interactive call runs the server once.\n */\n watch?: boolean;\n};\n\n/**\n * The server name registered in the generated mcp-cli config. mcp-cli\n * addresses non-interactive targets as `<server-name>:<tool>`.\n */\nexport const DEV_SERVER_NAME = \"dev\";\n\n/**\n * Build the JSON config that registers the dev server with mcp-cli so it can\n * be invoked non-interactively. mcp-cli's non-interactive mode resolves the\n * server by name from a config file's `mcpServers` map, so an inline command\n * cannot be passed directly alongside `call-tool`.\n *\n * The server is never started in watch mode here: a non-interactive call\n * connects, calls one tool, and exits, so there is nothing to restart into.\n */\nexport const buildDevConfig = (file: string): string =>\n JSON.stringify(\n {\n mcpServers: {\n [DEV_SERVER_NAME]: {\n args: [\"tsx\", file],\n command: \"npx\",\n },\n },\n },\n null,\n 2,\n );\n\n/**\n * Build the argv that the dev command runs.\n *\n * This is an argv array rather than a shell string so that nothing has to be\n * quoted: file paths, tool names and JSON `--args` are passed to the child\n * process verbatim. Quoting through a shell would be wrong on Windows, where\n * cmd.exe treats single quotes as literal characters rather than as quoting.\n *\n * - Without `tool`: launches the interactive @wong2/mcp-cli inspector\n * against an inline `npx tsx <file>` server (existing behaviour).\n * - With `tool`: runs @wong2/mcp-cli in non-interactive mode against a\n * generated config file, calling the named tool and forwarding `--args`.\n */\nexport const buildDevCommand = (\n options: DevCommandOptions,\n): [string, ...string[]] => {\n const { configPath, file, tool, toolArgs, watch = false } = options;\n\n if (tool) {\n if (!configPath) {\n throw new Error(\n \"configPath is required when calling a tool non-interactively\",\n );\n }\n\n return [\n \"npx\",\n \"@wong2/mcp-cli\",\n \"-c\",\n configPath,\n \"call-tool\",\n `${DEV_SERVER_NAME}:${tool}`,\n ...(toolArgs === undefined ? [] : [\"--args\", toolArgs]),\n ];\n }\n\n // `--` ends mcp-cli's own options. Its parser reads any flag it meets, known\n // or not, and takes the next word as that flag's value, so `--watch` and the\n // file never reached the server: `npx tsx` started with no file at all.\n return [\n \"npx\",\n \"@wong2/mcp-cli\",\n \"--\",\n \"npx\",\n \"tsx\",\n ...(watch ? [\"--watch\"] : []),\n file,\n ];\n};\n","import { randomUUID } from \"crypto\";\nimport { execa } from \"execa\";\nimport { existsSync } from \"fs\";\nimport { rm, writeFile } from \"fs/promises\";\nimport { createRequire } from \"module\";\nimport { dirname, join } from \"path\";\nimport { pathToFileURL } from \"url\";\n\n/**\n * The script `vitemcp validate` runs to check that a server file loads.\n *\n * The file arrives as `process.argv[1]` rather than being spliced into this\n * source. Spliced into a string literal, a Windows path loses its backslashes\n * to the child's own parser (`C:\\Users\\dev\\server.ts` reaches the import as\n * `C:Usersdevserver.ts`), and a quote or `#` in any path breaks the import —\n * each reported to the user as a problem with their file.\n *\n * It exits as soon as the import settles, once its verdict is flushed. A\n * server file normally starts its transport on load, which would otherwise\n * keep this process, and the command waiting on it, alive forever.\n *\n * It imports nothing but the file. A bare specifier in a `-e` script resolves\n * from the working directory, not from the file, so importing\n * `@vitemcp/server` here failed any file whose project was not the directory\n * the command ran in — `vitemcp validate packages/app/server.ts` from the root\n * of a monorepo — before the file's own imports, which do resolve from beside\n * it, were tried.\n */\nexport const STRUCTURE_CHECK_SCRIPT = `\n(async () => {\n let failure;\n\n try {\n await import(process.argv[1]);\n } catch (error) {\n failure = error instanceof Error ? error.message : String(error);\n }\n\n if (failure === undefined) {\n process.stdout.write(\n \"[ViteMCP] ✓ Server structure validation passed\\\\n\",\n () => process.exit(0),\n );\n } else {\n process.stderr.write(\n \"[ViteMCP] ✗ Server structure validation failed: \" + failure + \"\\\\n\",\n () => process.exit(1),\n );\n }\n})();\n`;\n\n/**\n * Compiler options for a file with no `tsconfig.json` above it. The compiler's\n * own defaults target ES5, which rejects top-level await and the `#private`\n * members in `@vitemcp/server`'s declarations, so no server file could pass.\n */\nconst STANDALONE_COMPILER_OPTIONS = {\n allowImportingTsExtensions: true,\n module: \"esnext\",\n moduleResolution: \"bundler\",\n skipLibCheck: true,\n target: \"es2022\",\n};\n\n/**\n * What the throwaway config overrides in the project's own. `composite`\n * demands that every file the server imports be listed as a root, and only the\n * server file is; `incremental` writes a `.tsbuildinfo` named after the\n * throwaway config into the project.\n *\n * `composite` also implies `declaration`, which `declarationMap`,\n * `emitDeclarationOnly` and `isolatedDeclarations` each require, so a composite\n * project may set them without it — and with `composite` off, its check failed\n * with TS5069. Nothing is emitted, so they are switched off as well.\n */\nconst PROJECT_OVERRIDES = {\n composite: false,\n declarationMap: false,\n emitDeclarationOnly: false,\n incremental: false,\n isolatedDeclarations: false,\n};\n\n/**\n * Build the argv for the structure check.\n *\n * An argv array rather than a shell string, as in `buildDevCommand`, so nothing\n * has to be quoted. The file is converted to a `file:` URL here, so the child\n * imports it as given and never has to build the URL itself; and the child is\n * the Node binary running this CLI, so no PATH lookup is involved.\n *\n * Given the project's tsx loader (see `resolveTsxLoader`), the child imports\n * the file through it, so the file loads the way `vitemcp dev` runs it. tsx\n * registers itself with `module.register()`, which Node 26 deprecates\n * (DEP0205); that warning alone is switched off, because it would otherwise be\n * replayed with a failure as though the file had caused it.\n */\nexport const buildStructureCheckCommand = (\n file: string,\n {\n execPath = process.execPath,\n tsxLoader,\n }: { execPath?: string; tsxLoader?: string } = {},\n): [string, ...string[]] => [\n execPath,\n ...(tsxLoader ? [\"--disable-warning=DEP0205\", \"--import\", tsxLoader] : []),\n \"-e\",\n STRUCTURE_CHECK_SCRIPT,\n pathToFileURL(file).href,\n];\n\n/**\n * Build the argv for the type check. An argv array for the same reason as the\n * structure check: through a shell, a path containing a space reaches `tsc` as\n * several root files.\n */\nexport const buildTypeCheckCommand = (\n config: string,\n strict = false,\n): [string, ...string[]] => [\n \"npx\",\n \"tsc\",\n \"--noEmit\",\n \"--project\",\n config,\n ...(strict ? [\"--strict\"] : []),\n];\n\n/**\n * Build the throwaway config that type-checks one file.\n *\n * `tsc` ignores `tsconfig.json` whenever a file is named on its command line\n * and falls back to defaults no server file passes, so the file is named in a\n * config that extends the project's own instead. `include: []` keeps an\n * inherited `include` from pulling the rest of the project in.\n */\nexport const buildTypeCheckConfig = (file: string, tsconfig?: string): string =>\n JSON.stringify(\n tsconfig\n ? {\n compilerOptions: PROJECT_OVERRIDES,\n extends: tsconfig,\n files: [file],\n include: [],\n }\n : {\n compilerOptions: STANDALONE_COMPILER_OPTIONS,\n files: [file],\n include: [],\n },\n null,\n 2,\n );\n\n/**\n * The `tsconfig.json` that governs a file in `dir`: the nearest one at or above\n * it, which is also the one an editor checks the file against.\n */\nexport const findTsconfig = (dir: string): string | undefined => {\n for (let current = dir; ; current = dirname(current)) {\n const candidate = join(current, \"tsconfig.json\");\n\n if (existsSync(candidate)) {\n return candidate;\n }\n\n if (dirname(current) === current) {\n return undefined;\n }\n }\n};\n\n/**\n * The output of a failed check, for replaying to the user.\n *\n * `tsc` writes its diagnostics to stdout, and only a failure to launch it\n * reaches stderr, so reading stderr alone reported every real type error with\n * no detail. The structure check explains itself on stderr.\n */\nexport const formatCommandFailure = (result: {\n stderr?: unknown;\n stdout?: unknown;\n}): string =>\n [result.stderr, result.stdout]\n .map((output) => (typeof output === \"string\" ? output.trim() : \"\"))\n .filter(Boolean)\n .join(\"\\n\");\n\n/**\n * What to add when the structure check fails without tsx. Plain Node rejects\n * TypeScript that tsx runs, so the failure may be the loader's rather than the\n * file's. Nothing for a JavaScript file, which loads the same either way.\n */\nexport const missingTsxHint = (\n file: string,\n tsxLoader: string | undefined,\n): string | undefined =>\n tsxLoader || !/\\.[cm]?tsx?$/i.test(file)\n ? undefined\n : \"[ViteMCP] tsx is not installed in this project, so the file was loaded with plain Node, which rejects `.js` imports of `.ts` files and syntax such as enums. Install tsx to validate the file the way `vitemcp dev` runs it: npm install --save-dev tsx\";\n\n/**\n * The project's tsx loader, as a `file:` URL for `--import`, or `undefined`\n * when the project does not have tsx installed.\n *\n * `vitemcp dev` runs a server file with tsx, but plain Node only strips types:\n * it rejects a `.js` import of a `.ts` file, and syntax it would have to\n * transform, such as an enum. So without tsx, a file `dev` ran fine failed the\n * check.\n *\n * Looked up in the `node_modules` at or above the file, as an `import` from the\n * file would look, so it is the tsx of the project the file belongs to.\n * `require.resolve` alone also searches `NODE_PATH`, which can point outside\n * the project: pnpm's bin shims set it to a store. A URL, because `--import`\n * takes a specifier, which a Windows path is not.\n */\nexport const resolveTsxLoader = (file: string): string | undefined => {\n for (let current = dirname(file); ; current = dirname(current)) {\n const manifest = join(current, \"node_modules\", \"tsx\", \"package.json\");\n\n if (existsSync(manifest)) {\n try {\n return pathToFileURL(createRequire(manifest).resolve(\"tsx\")).href;\n } catch {\n // Installed, but without the loader `--import tsx` would load.\n return undefined;\n }\n }\n\n if (dirname(current) === current) {\n return undefined;\n }\n }\n};\n\n/**\n * Type-check `file` under the compiler options of the project it belongs to.\n *\n * The throwaway config is written beside the project's own rather than to the\n * OS temp directory, because the compiler resolves type packages — the `types`\n * option and every visible `@types` package — from the config's directory. It\n * is removed before this returns, so a caller may exit straight away.\n */\nexport const runTypeCheck = async (file: string, strict = false) => {\n const tsconfig = findTsconfig(dirname(file));\n const config = join(\n dirname(tsconfig ?? file),\n `tsconfig.vitemcp-validate-${randomUUID()}.json`,\n );\n\n await writeFile(config, buildTypeCheckConfig(file, tsconfig), {\n flag: \"wx\",\n });\n\n try {\n const [command, ...args] = buildTypeCheckCommand(config, strict);\n\n return await execa(command, args, { reject: false });\n } finally {\n await rm(config, { force: true });\n }\n};\n"]}
|