@codemieai/code 0.0.54 → 0.0.56
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 +34 -0
- package/bin/codemie-mcp-proxy.js +91 -0
- package/dist/agents/core/AgentCLI.d.ts.map +1 -1
- package/dist/agents/core/AgentCLI.js +10 -2
- package/dist/agents/core/AgentCLI.js.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.js +23 -6
- package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
- package/dist/agents/core/session/ensure-session.d.ts.map +1 -1
- package/dist/agents/core/session/ensure-session.js +7 -2
- package/dist/agents/core/session/ensure-session.js.map +1 -1
- package/dist/agents/core/session/types.d.ts +1 -0
- package/dist/agents/core/session/types.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude.plugin.js +4 -4
- package/dist/agents/plugins/claude/claude.plugin.js.map +1 -1
- package/dist/agents/plugins/claude/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/agents/plugins/claude/plugin/skills/codemie-html-report/SKILL.md +273 -0
- package/dist/agents/plugins/claude/plugin/skills/codemie-html-report/style-guide/css/base.css +166 -0
- package/dist/agents/plugins/claude/plugin/skills/codemie-html-report/style-guide/css/buttons.css +253 -0
- package/dist/agents/plugins/claude/plugin/skills/codemie-html-report/style-guide/css/components.css +605 -0
- package/dist/agents/plugins/claude/plugin/skills/codemie-html-report/style-guide/css/forms.css +550 -0
- package/dist/agents/plugins/claude/plugin/skills/codemie-html-report/style-guide/css/layout.css +410 -0
- package/dist/agents/plugins/claude/plugin/skills/codemie-html-report/style-guide/css/tokens.css +323 -0
- package/dist/agents/plugins/claude/plugin/skills/codemie-html-report/style-guide/css/typography.css +155 -0
- package/dist/agents/plugins/claude/plugin/skills/codemie-html-report/style-guide/css/utilities.css +238 -0
- package/dist/agents/plugins/claude/plugin/skills/msgraph/scripts/msgraph.js +1 -0
- package/dist/cli/commands/hook.d.ts +2 -0
- package/dist/cli/commands/hook.d.ts.map +1 -1
- package/dist/cli/commands/hook.js +36 -31
- package/dist/cli/commands/hook.js.map +1 -1
- package/dist/cli/commands/mcp/index.d.ts +3 -0
- package/dist/cli/commands/mcp/index.d.ts.map +1 -0
- package/dist/cli/commands/mcp/index.js +103 -0
- package/dist/cli/commands/mcp/index.js.map +1 -0
- package/dist/cli/commands/mcp-proxy.d.ts +13 -0
- package/dist/cli/commands/mcp-proxy.d.ts.map +1 -0
- package/dist/cli/commands/mcp-proxy.js +53 -0
- package/dist/cli/commands/mcp-proxy.js.map +1 -0
- package/dist/cli/commands/setup.js +11 -1
- package/dist/cli/commands/setup.js.map +1 -1
- package/dist/cli/index.js +4 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/mcp/auth/callback-server.d.ts +22 -0
- package/dist/mcp/auth/callback-server.d.ts.map +1 -0
- package/dist/mcp/auth/callback-server.js +87 -0
- package/dist/mcp/auth/callback-server.js.map +1 -0
- package/dist/mcp/auth/mcp-oauth-provider.d.ts +49 -0
- package/dist/mcp/auth/mcp-oauth-provider.d.ts.map +1 -0
- package/dist/mcp/auth/mcp-oauth-provider.js +156 -0
- package/dist/mcp/auth/mcp-oauth-provider.js.map +1 -0
- package/dist/mcp/constants.d.ts +5 -0
- package/dist/mcp/constants.d.ts.map +1 -0
- package/dist/mcp/constants.js +7 -0
- package/dist/mcp/constants.js.map +1 -0
- package/dist/mcp/proxy-logger.d.ts +7 -0
- package/dist/mcp/proxy-logger.d.ts.map +1 -0
- package/dist/mcp/proxy-logger.js +32 -0
- package/dist/mcp/proxy-logger.js.map +1 -0
- package/dist/mcp/stdio-http-bridge.d.ts +63 -0
- package/dist/mcp/stdio-http-bridge.d.ts.map +1 -0
- package/dist/mcp/stdio-http-bridge.js +307 -0
- package/dist/mcp/stdio-http-bridge.js.map +1 -0
- package/dist/providers/core/codemie-auth-helpers.d.ts +22 -0
- package/dist/providers/core/codemie-auth-helpers.d.ts.map +1 -0
- package/dist/providers/core/codemie-auth-helpers.js +118 -0
- package/dist/providers/core/codemie-auth-helpers.js.map +1 -0
- package/dist/providers/core/index.d.ts +1 -0
- package/dist/providers/core/index.d.ts.map +1 -1
- package/dist/providers/core/index.js +1 -0
- package/dist/providers/core/index.js.map +1 -1
- package/dist/providers/core/types.d.ts +4 -0
- package/dist/providers/core/types.d.ts.map +1 -1
- package/dist/providers/core/types.js.map +1 -1
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/plugins/anthropic-subscription/anthropic-subscription.auth.d.ts +11 -0
- package/dist/providers/plugins/anthropic-subscription/anthropic-subscription.auth.d.ts.map +1 -0
- package/dist/providers/plugins/anthropic-subscription/anthropic-subscription.auth.js +30 -0
- package/dist/providers/plugins/anthropic-subscription/anthropic-subscription.auth.js.map +1 -0
- package/dist/providers/plugins/anthropic-subscription/anthropic-subscription.setup-steps.d.ts +8 -0
- package/dist/providers/plugins/anthropic-subscription/anthropic-subscription.setup-steps.d.ts.map +1 -0
- package/dist/providers/plugins/anthropic-subscription/anthropic-subscription.setup-steps.js +88 -0
- package/dist/providers/plugins/anthropic-subscription/anthropic-subscription.setup-steps.js.map +1 -0
- package/dist/providers/plugins/anthropic-subscription/anthropic-subscription.template.d.ts +11 -0
- package/dist/providers/plugins/anthropic-subscription/anthropic-subscription.template.d.ts.map +1 -0
- package/dist/providers/plugins/anthropic-subscription/anthropic-subscription.template.js +119 -0
- package/dist/providers/plugins/anthropic-subscription/anthropic-subscription.template.js.map +1 -0
- package/dist/providers/plugins/anthropic-subscription/index.d.ts +9 -0
- package/dist/providers/plugins/anthropic-subscription/index.d.ts.map +1 -0
- package/dist/providers/plugins/anthropic-subscription/index.js +9 -0
- package/dist/providers/plugins/anthropic-subscription/index.js.map +1 -0
- package/dist/providers/plugins/jwt/jwt.setup-steps.js +1 -1
- package/dist/providers/plugins/jwt/jwt.setup-steps.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/claude-thinking-transformer.plugin.d.ts +30 -0
- package/dist/providers/plugins/sso/proxy/plugins/claude-thinking-transformer.plugin.d.ts.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/claude-thinking-transformer.plugin.js +111 -0
- package/dist/providers/plugins/sso/proxy/plugins/claude-thinking-transformer.plugin.js.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/index.d.ts +3 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.js +5 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/mcp-auth.plugin.d.ts +34 -0
- package/dist/providers/plugins/sso/proxy/plugins/mcp-auth.plugin.d.ts.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/mcp-auth.plugin.js +1200 -0
- package/dist/providers/plugins/sso/proxy/plugins/mcp-auth.plugin.js.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.js +9 -7
- package/dist/providers/plugins/sso/proxy/plugins/sso.session-sync.plugin.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/types.d.ts +19 -1
- package/dist/providers/plugins/sso/proxy/plugins/types.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/proxy-types.d.ts +2 -0
- package/dist/providers/plugins/sso/proxy/proxy-types.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/sso.proxy.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/sso.proxy.js +42 -2
- package/dist/providers/plugins/sso/proxy/sso.proxy.js.map +1 -1
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-aggregator.js +1 -1
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-aggregator.js.map +1 -1
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-api-client.d.ts +2 -2
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-api-client.d.ts.map +1 -1
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-api-client.js +4 -4
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-api-client.js.map +1 -1
- package/dist/providers/plugins/sso/sso.auth.d.ts +0 -4
- package/dist/providers/plugins/sso/sso.auth.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.auth.js +3 -13
- package/dist/providers/plugins/sso/sso.auth.js.map +1 -1
- package/dist/providers/plugins/sso/sso.http-client.d.ts +3 -42
- package/dist/providers/plugins/sso/sso.http-client.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.http-client.js +4 -75
- package/dist/providers/plugins/sso/sso.http-client.js.map +1 -1
- package/dist/providers/plugins/sso/sso.setup-steps.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.setup-steps.js +15 -66
- package/dist/providers/plugins/sso/sso.setup-steps.js.map +1 -1
- package/dist/providers/plugins/sso/sso.template.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.template.js +2 -1
- package/dist/providers/plugins/sso/sso.template.js.map +1 -1
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +17 -0
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/exec.d.ts +1 -0
- package/dist/utils/exec.d.ts.map +1 -1
- package/dist/utils/exec.js +13 -5
- package/dist/utils/exec.js.map +1 -1
- package/dist/utils/processes.d.ts +9 -0
- package/dist/utils/processes.d.ts.map +1 -1
- package/dist/utils/processes.js +21 -0
- package/dist/utils/processes.js.map +1 -1
- package/package.json +7 -4
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP OAuth Client Provider
|
|
3
|
+
*
|
|
4
|
+
* Implements the OAuthClientProvider interface from the MCP SDK for browser-based
|
|
5
|
+
* OAuth authorization code flow. All state is memory-only (no persistent storage).
|
|
6
|
+
*
|
|
7
|
+
* Flow: 401 → resource metadata → auth server metadata → dynamic client registration
|
|
8
|
+
* (client_name from MCP_CLIENT_NAME env var, default "CodeMie CLI") → browser authorization → callback → token exchange.
|
|
9
|
+
*/
|
|
10
|
+
import { execFile } from 'child_process';
|
|
11
|
+
import { logger } from '../../utils/logger.js';
|
|
12
|
+
import { getMcpClientName } from '../constants.js';
|
|
13
|
+
import { startCallbackServer } from './callback-server.js';
|
|
14
|
+
/**
|
|
15
|
+
* In-memory OAuth provider for MCP authorization code flow.
|
|
16
|
+
* Tokens and client info are stored in memory only — re-auth required each session.
|
|
17
|
+
*/
|
|
18
|
+
export class McpOAuthProvider {
|
|
19
|
+
_redirectUrl;
|
|
20
|
+
_clientInfo;
|
|
21
|
+
_tokens;
|
|
22
|
+
_codeVerifier;
|
|
23
|
+
// Callback server state (active during authorization)
|
|
24
|
+
callbackWait;
|
|
25
|
+
callbackClose;
|
|
26
|
+
get redirectUrl() {
|
|
27
|
+
return this._redirectUrl;
|
|
28
|
+
}
|
|
29
|
+
get clientMetadata() {
|
|
30
|
+
return {
|
|
31
|
+
client_name: getMcpClientName(),
|
|
32
|
+
redirect_uris: this._redirectUrl ? [this._redirectUrl] : [],
|
|
33
|
+
grant_types: ['authorization_code', 'refresh_token'],
|
|
34
|
+
response_types: ['code'],
|
|
35
|
+
token_endpoint_auth_method: 'none',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Pre-start the callback server so that clientMetadata.redirect_uris is
|
|
40
|
+
* populated before the SDK calls registerClient(). Must be called before
|
|
41
|
+
* connecting the HTTP transport.
|
|
42
|
+
*/
|
|
43
|
+
async ensureCallbackServer() {
|
|
44
|
+
if (this.callbackWait)
|
|
45
|
+
return;
|
|
46
|
+
const { redirectUrl, waitForCallback, close } = await startCallbackServer();
|
|
47
|
+
this._redirectUrl = redirectUrl;
|
|
48
|
+
this.callbackWait = waitForCallback;
|
|
49
|
+
this.callbackClose = close;
|
|
50
|
+
logger.debug(`[mcp-proxy] Callback server pre-started: ${redirectUrl}`);
|
|
51
|
+
}
|
|
52
|
+
clientInformation() {
|
|
53
|
+
return this._clientInfo;
|
|
54
|
+
}
|
|
55
|
+
saveClientInformation(info) {
|
|
56
|
+
this._clientInfo = info;
|
|
57
|
+
logger.debug('[mcp-proxy] Saved client information (memory-only)');
|
|
58
|
+
}
|
|
59
|
+
tokens() {
|
|
60
|
+
return this._tokens;
|
|
61
|
+
}
|
|
62
|
+
saveTokens(tokens) {
|
|
63
|
+
this._tokens = tokens;
|
|
64
|
+
logger.debug('[mcp-proxy] Saved OAuth tokens (memory-only)');
|
|
65
|
+
}
|
|
66
|
+
async redirectToAuthorization(authorizationUrl) {
|
|
67
|
+
// Start ephemeral callback server if not already running
|
|
68
|
+
if (!this.callbackWait) {
|
|
69
|
+
const { redirectUrl, waitForCallback, close } = await startCallbackServer();
|
|
70
|
+
this._redirectUrl = redirectUrl;
|
|
71
|
+
this.callbackWait = waitForCallback;
|
|
72
|
+
this.callbackClose = close;
|
|
73
|
+
}
|
|
74
|
+
const url = authorizationUrl.toString();
|
|
75
|
+
logger.debug(`[mcp-proxy] Opening browser for authorization`);
|
|
76
|
+
console.error('[mcp-proxy] Opening browser for MCP server authorization...');
|
|
77
|
+
openBrowser(url);
|
|
78
|
+
}
|
|
79
|
+
saveCodeVerifier(codeVerifier) {
|
|
80
|
+
this._codeVerifier = codeVerifier;
|
|
81
|
+
}
|
|
82
|
+
codeVerifier() {
|
|
83
|
+
return this._codeVerifier || '';
|
|
84
|
+
}
|
|
85
|
+
invalidateCredentials(scope) {
|
|
86
|
+
if (scope === 'all' || scope === 'tokens') {
|
|
87
|
+
this._tokens = undefined;
|
|
88
|
+
}
|
|
89
|
+
if (scope === 'all' || scope === 'client') {
|
|
90
|
+
this._clientInfo = undefined;
|
|
91
|
+
}
|
|
92
|
+
if (scope === 'all' || scope === 'verifier') {
|
|
93
|
+
this._codeVerifier = undefined;
|
|
94
|
+
}
|
|
95
|
+
logger.debug(`[mcp-proxy] Invalidated credentials: ${scope}`);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Wait for the OAuth callback after browser redirect.
|
|
99
|
+
* Returns the authorization code from the callback.
|
|
100
|
+
* This is called externally by the bridge after auth() returns 'REDIRECT'.
|
|
101
|
+
*/
|
|
102
|
+
async waitForAuthorizationCode() {
|
|
103
|
+
if (!this.callbackWait) {
|
|
104
|
+
throw new Error('No active authorization flow — callback server not started');
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const result = await this.callbackWait;
|
|
108
|
+
logger.debug('[mcp-proxy] Received authorization callback');
|
|
109
|
+
return result.code;
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
this.callbackWait = undefined;
|
|
113
|
+
this.callbackClose = undefined;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Clean up the callback server if still running (e.g., on shutdown).
|
|
118
|
+
*/
|
|
119
|
+
dispose() {
|
|
120
|
+
this.callbackClose?.();
|
|
121
|
+
this.callbackWait = undefined;
|
|
122
|
+
this.callbackClose = undefined;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Open a URL in the system default browser.
|
|
127
|
+
* Cross-platform: macOS (open), Windows (start), Linux (xdg-open).
|
|
128
|
+
*/
|
|
129
|
+
function openBrowser(url) {
|
|
130
|
+
const platform = process.platform;
|
|
131
|
+
let command;
|
|
132
|
+
let args;
|
|
133
|
+
if (platform === 'darwin') {
|
|
134
|
+
command = 'open';
|
|
135
|
+
args = [url];
|
|
136
|
+
}
|
|
137
|
+
else if (platform === 'win32') {
|
|
138
|
+
// Use PowerShell Start-Process to avoid CMD metacharacter parsing:
|
|
139
|
+
// `cmd /c start "" url` splits on `&`, truncating auth URLs with query params.
|
|
140
|
+
// PowerShell passes the URL directly to the OS shell handler, preserving all chars.
|
|
141
|
+
const escapedUrl = url.replace(/'/g, "''"); // PowerShell single-quote escaping
|
|
142
|
+
command = 'powershell';
|
|
143
|
+
args = ['-NoProfile', '-Command', `Start-Process '${escapedUrl}'`];
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
command = 'xdg-open';
|
|
147
|
+
args = [url];
|
|
148
|
+
}
|
|
149
|
+
execFile(command, args, (error) => {
|
|
150
|
+
if (error) {
|
|
151
|
+
// Don't fail — user can manually copy the URL from stderr
|
|
152
|
+
console.error(`[mcp-proxy] Could not open browser automatically. Please open this URL:\n${url}`);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=mcp-oauth-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-oauth-provider.js","sourceRoot":"","sources":["../../../src/mcp/auth/mcp-oauth-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAuB,MAAM,sBAAsB,CAAC;AAShF;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IACnB,YAAY,CAAqB;IACjC,WAAW,CAA0C;IACrD,OAAO,CAA0B;IACjC,aAAa,CAAqB;IAE1C,sDAAsD;IAC9C,YAAY,CAAsC;IAClD,aAAa,CAA2B;IAEhD,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,IAAI,cAAc;QAChB,OAAO;YACL,WAAW,EAAE,gBAAgB,EAAE;YAC/B,aAAa,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE;YAC3D,WAAW,EAAE,CAAC,oBAAoB,EAAE,eAAe,CAAC;YACpD,cAAc,EAAE,CAAC,MAAM,CAAC;YACxB,0BA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IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,SAAS,CAAC;IACjC,CAAC;CACF;AAED;;;GAGG;AACH,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,IAAI,OAAe,CAAC;IACpB,IAAI,IAAc,CAAC;IAEnB,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1B,OAAO,GAAG,MAAM,CAAC;QACjB,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;SAAM,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QAChC,mEAAmE;QACnE,+EAA+E;QAC/E,oFAAoF;QACpF,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,mCAAmC;QAC/E,OAAO,GAAG,YAAY,CAAC;QACvB,IAAI,GAAG,CAAC,YAAY,EAAE,UAAU,EAAE,kBAAkB,UAAU,GAAG,CAAC,CAAC;IACrE,CAAC;SAAM,CAAC;QACN,OAAO,GAAG,UAAU,CAAC;QACrB,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IAED,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;QAChC,IAAI,KAAK,EAAE,CAAC;YACV,0DAA0D;YAC1D,OAAO,CAAC,KAAK,CAAC,4EAA4E,GAAG,EAAE,CAAC,CAAC;QACnG,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Default client_name for MCP OAuth dynamic client registration. Overridable via MCP_CLIENT_NAME env var. */
|
|
2
|
+
export declare const DEFAULT_MCP_CLIENT_NAME = "CodeMie CLI";
|
|
3
|
+
/** Get the MCP client name from env var or default. */
|
|
4
|
+
export declare function getMcpClientName(): string;
|
|
5
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/mcp/constants.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAErD,uDAAuD;AACvD,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Default client_name for MCP OAuth dynamic client registration. Overridable via MCP_CLIENT_NAME env var. */
|
|
2
|
+
export const DEFAULT_MCP_CLIENT_NAME = 'CodeMie CLI';
|
|
3
|
+
/** Get the MCP client name from env var or default. */
|
|
4
|
+
export function getMcpClientName() {
|
|
5
|
+
return process.env.MCP_CLIENT_NAME || DEFAULT_MCP_CLIENT_NAME;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/mcp/constants.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAErD,uDAAuD;AACvD,MAAM,UAAU,gBAAgB;IAC9B,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,uBAAuB,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple file logger for the MCP proxy.
|
|
3
|
+
* Writes to ~/.codemie/mcp-proxy.log — independent of the main logger.
|
|
4
|
+
* Enabled when CODEMIE_DEBUG=true or MCP_PROXY_DEBUG=true.
|
|
5
|
+
*/
|
|
6
|
+
export declare function proxyLog(message: string): void;
|
|
7
|
+
//# sourceMappingURL=proxy-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-logger.d.ts","sourceRoot":"","sources":["../../src/mcp/proxy-logger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoBH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAQ9C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple file logger for the MCP proxy.
|
|
3
|
+
* Writes to ~/.codemie/mcp-proxy.log — independent of the main logger.
|
|
4
|
+
* Enabled when CODEMIE_DEBUG=true or MCP_PROXY_DEBUG=true.
|
|
5
|
+
*/
|
|
6
|
+
import { appendFileSync, mkdirSync } from 'fs';
|
|
7
|
+
import { join } from 'path';
|
|
8
|
+
import { homedir } from 'os';
|
|
9
|
+
const enabled = process.env.CODEMIE_DEBUG === 'true'
|
|
10
|
+
|| process.env.CODEMIE_DEBUG === '1'
|
|
11
|
+
|| process.env.MCP_PROXY_DEBUG === 'true'
|
|
12
|
+
|| process.env.MCP_PROXY_DEBUG === '1';
|
|
13
|
+
const logDir = join(homedir(), '.codemie', 'logs');
|
|
14
|
+
const logFile = join(logDir, 'mcp-proxy.log');
|
|
15
|
+
try {
|
|
16
|
+
mkdirSync(logDir, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// ignore
|
|
20
|
+
}
|
|
21
|
+
export function proxyLog(message) {
|
|
22
|
+
if (!enabled)
|
|
23
|
+
return;
|
|
24
|
+
const line = `[${new Date().toISOString()}] ${message}\n`;
|
|
25
|
+
try {
|
|
26
|
+
appendFileSync(logFile, line);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// ignore — can't log if file write fails
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=proxy-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-logger.js","sourceRoot":"","sources":["../../src/mcp/proxy-logger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAE7B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,MAAM;OAC/C,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,GAAG;OACjC,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,MAAM;OACtC,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,GAAG,CAAC;AAEzC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;AACnD,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE9C,IAAI,CAAC;IACH,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC;AAAC,MAAM,CAAC;IACP,SAAS;AACX,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,OAAe;IACtC,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,MAAM,IAAI,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,OAAO,IAAI,CAAC;IAC1D,IAAI,CAAC;QACH,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,yCAAyC;IAC3C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stdio-to-HTTP MCP Bridge
|
|
3
|
+
*
|
|
4
|
+
* Pipes JSON-RPC messages between a StdioServerTransport (Claude Code side)
|
|
5
|
+
* and a StreamableHTTPClientTransport (real MCP server side).
|
|
6
|
+
*
|
|
7
|
+
* Lazy connect: the HTTP transport is created and started only when the first
|
|
8
|
+
* stdio message arrives. If the server requires OAuth, the auth flow runs during
|
|
9
|
+
* that first connection (blocking the first message until auth completes).
|
|
10
|
+
*
|
|
11
|
+
* Cookie jar: Node's fetch doesn't persist cookies between requests. Some MCP
|
|
12
|
+
* auth gateways set session cookies during the OAuth flow that must be sent with
|
|
13
|
+
* subsequent requests. The bridge maintains a per-origin cookie jar automatically.
|
|
14
|
+
*/
|
|
15
|
+
export interface BridgeOptions {
|
|
16
|
+
/** The real MCP server URL to connect to */
|
|
17
|
+
serverUrl: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class StdioHttpBridge {
|
|
20
|
+
private stdioTransport;
|
|
21
|
+
private httpTransport;
|
|
22
|
+
private oauthProvider;
|
|
23
|
+
private serverUrl;
|
|
24
|
+
private cookieJar;
|
|
25
|
+
private connected;
|
|
26
|
+
private connecting;
|
|
27
|
+
private shuttingDown;
|
|
28
|
+
private pendingMessages;
|
|
29
|
+
constructor(options: BridgeOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Start the bridge: begin listening on stdio immediately.
|
|
32
|
+
* HTTP connection is deferred until the first message arrives.
|
|
33
|
+
*/
|
|
34
|
+
start(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Handle a message from Claude Code (stdio side).
|
|
37
|
+
* On the first message, lazily connect the HTTP transport.
|
|
38
|
+
*/
|
|
39
|
+
private handleStdioMessage;
|
|
40
|
+
/**
|
|
41
|
+
* Lazily create and connect the HTTP transport to the real MCP server.
|
|
42
|
+
* Handles OAuth authorization if the server returns 401.
|
|
43
|
+
*/
|
|
44
|
+
private connectHttpTransport;
|
|
45
|
+
/**
|
|
46
|
+
* Create an HTTP transport with cookie jar and logging.
|
|
47
|
+
*/
|
|
48
|
+
private createHttpTransport;
|
|
49
|
+
/**
|
|
50
|
+
* Handle the OAuth authorization code flow.
|
|
51
|
+
*/
|
|
52
|
+
private handleOAuthFlow;
|
|
53
|
+
/**
|
|
54
|
+
* Forward any messages that arrived while we were connecting/authenticating.
|
|
55
|
+
* UnauthorizedError is re-thrown so the caller can handle the OAuth flow.
|
|
56
|
+
*/
|
|
57
|
+
private flushPendingMessages;
|
|
58
|
+
/**
|
|
59
|
+
* Graceful shutdown: close both transports. Idempotent.
|
|
60
|
+
*/
|
|
61
|
+
shutdown(): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=stdio-http-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdio-http-bridge.d.ts","sourceRoot":"","sources":["../../src/mcp/stdio-http-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAoEH,MAAM,WAAW,aAAa;IAC5B,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,aAAa,CAA8C;IACnE,OAAO,CAAC,aAAa,CAAmB;IACxC,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,eAAe,CAAwB;gBAEnC,OAAO,EAAE,aAAa;IAOlC;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB5B;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IA6B1B;;;OAGG;YACW,oBAAoB;IA8ClC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAoE3B;;OAEG;YACW,eAAe;IAS7B;;;OAGG;YACW,oBAAoB;IAuBlC;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAwBhC"}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stdio-to-HTTP MCP Bridge
|
|
3
|
+
*
|
|
4
|
+
* Pipes JSON-RPC messages between a StdioServerTransport (Claude Code side)
|
|
5
|
+
* and a StreamableHTTPClientTransport (real MCP server side).
|
|
6
|
+
*
|
|
7
|
+
* Lazy connect: the HTTP transport is created and started only when the first
|
|
8
|
+
* stdio message arrives. If the server requires OAuth, the auth flow runs during
|
|
9
|
+
* that first connection (blocking the first message until auth completes).
|
|
10
|
+
*
|
|
11
|
+
* Cookie jar: Node's fetch doesn't persist cookies between requests. Some MCP
|
|
12
|
+
* auth gateways set session cookies during the OAuth flow that must be sent with
|
|
13
|
+
* subsequent requests. The bridge maintains a per-origin cookie jar automatically.
|
|
14
|
+
*/
|
|
15
|
+
import { StreamableHTTPClientTransport, UnauthorizedError, } from '@modelcontextprotocol/client';
|
|
16
|
+
import { StdioServerTransport } from '@modelcontextprotocol/server';
|
|
17
|
+
import { logger } from '../utils/logger.js';
|
|
18
|
+
import { proxyLog } from './proxy-logger.js';
|
|
19
|
+
import { McpOAuthProvider } from './auth/mcp-oauth-provider.js';
|
|
20
|
+
function log(msg) {
|
|
21
|
+
logger.debug(msg);
|
|
22
|
+
proxyLog(msg);
|
|
23
|
+
}
|
|
24
|
+
/** Serialize an error with all available details (message, cause, status, body, stack). */
|
|
25
|
+
function errorDetail(error) {
|
|
26
|
+
if (!(error instanceof Error))
|
|
27
|
+
return String(error);
|
|
28
|
+
const parts = [`${error.constructor.name}: ${error.message}`];
|
|
29
|
+
for (const key of ['status', 'statusCode', 'code', 'body', 'response', 'statusText', 'data']) {
|
|
30
|
+
const val = error[key];
|
|
31
|
+
if (val !== undefined)
|
|
32
|
+
parts.push(` ${key}: ${JSON.stringify(val).slice(0, 500)}`);
|
|
33
|
+
}
|
|
34
|
+
if (error.cause)
|
|
35
|
+
parts.push(` cause: ${errorDetail(error.cause)}`);
|
|
36
|
+
if (error.stack)
|
|
37
|
+
parts.push(` stack: ${error.stack}`);
|
|
38
|
+
return parts.join('\n');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Minimal cookie jar: stores Set-Cookie values keyed by origin, sends them
|
|
42
|
+
* back on subsequent requests to the same origin.
|
|
43
|
+
*/
|
|
44
|
+
class CookieJar {
|
|
45
|
+
/** origin → Map<cookie-name, full-cookie-string> */
|
|
46
|
+
cookies = new Map();
|
|
47
|
+
/** Extract and store cookies from a response's Set-Cookie headers. */
|
|
48
|
+
capture(requestUrl, response) {
|
|
49
|
+
const origin = new URL(requestUrl).origin;
|
|
50
|
+
// getSetCookie() returns individual Set-Cookie header values
|
|
51
|
+
const setCookies = response.headers.getSetCookie?.() ?? [];
|
|
52
|
+
if (setCookies.length === 0)
|
|
53
|
+
return;
|
|
54
|
+
let jar = this.cookies.get(origin);
|
|
55
|
+
if (!jar) {
|
|
56
|
+
jar = new Map();
|
|
57
|
+
this.cookies.set(origin, jar);
|
|
58
|
+
}
|
|
59
|
+
for (const raw of setCookies) {
|
|
60
|
+
const name = raw.split('=')[0]?.trim();
|
|
61
|
+
if (name) {
|
|
62
|
+
jar.set(name, raw.split(';')[0]); // store "name=value" only
|
|
63
|
+
log(`[mcp-proxy] Cookie stored for ${origin}: ${name}=***`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Build a Cookie header value for the given request URL. */
|
|
68
|
+
headerFor(requestUrl) {
|
|
69
|
+
const origin = new URL(requestUrl).origin;
|
|
70
|
+
const jar = this.cookies.get(origin);
|
|
71
|
+
if (!jar || jar.size === 0)
|
|
72
|
+
return undefined;
|
|
73
|
+
return [...jar.values()].join('; ');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export class StdioHttpBridge {
|
|
77
|
+
stdioTransport;
|
|
78
|
+
httpTransport = null;
|
|
79
|
+
oauthProvider;
|
|
80
|
+
serverUrl;
|
|
81
|
+
cookieJar = new CookieJar();
|
|
82
|
+
connected = false;
|
|
83
|
+
connecting = false;
|
|
84
|
+
shuttingDown = false;
|
|
85
|
+
pendingMessages = [];
|
|
86
|
+
constructor(options) {
|
|
87
|
+
this.serverUrl = new URL(options.serverUrl);
|
|
88
|
+
this.oauthProvider = new McpOAuthProvider();
|
|
89
|
+
this.stdioTransport = new StdioServerTransport();
|
|
90
|
+
log(`[mcp-proxy] Bridge created for ${this.serverUrl}`);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Start the bridge: begin listening on stdio immediately.
|
|
94
|
+
* HTTP connection is deferred until the first message arrives.
|
|
95
|
+
*/
|
|
96
|
+
async start() {
|
|
97
|
+
this.stdioTransport.onmessage = (message) => {
|
|
98
|
+
this.handleStdioMessage(message);
|
|
99
|
+
};
|
|
100
|
+
this.stdioTransport.onclose = () => {
|
|
101
|
+
log('[mcp-proxy] Stdio transport closed');
|
|
102
|
+
this.shutdown();
|
|
103
|
+
};
|
|
104
|
+
this.stdioTransport.onerror = (error) => {
|
|
105
|
+
log(`[mcp-proxy] Stdio transport error: ${error.message}`);
|
|
106
|
+
};
|
|
107
|
+
await this.stdioTransport.start();
|
|
108
|
+
log('[mcp-proxy] Stdio transport started, waiting for messages');
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Handle a message from Claude Code (stdio side).
|
|
112
|
+
* On the first message, lazily connect the HTTP transport.
|
|
113
|
+
*/
|
|
114
|
+
handleStdioMessage(message) {
|
|
115
|
+
if (this.shuttingDown)
|
|
116
|
+
return;
|
|
117
|
+
log(`[mcp-proxy] Received stdio message: ${JSON.stringify(message).slice(0, 200)}`);
|
|
118
|
+
if (this.connected && this.httpTransport) {
|
|
119
|
+
this.httpTransport.send(message).catch((error) => {
|
|
120
|
+
log(`[mcp-proxy] Error forwarding to HTTP:\n${errorDetail(error)}`);
|
|
121
|
+
this.shutdown();
|
|
122
|
+
});
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.pendingMessages.push(message);
|
|
126
|
+
log(`[mcp-proxy] Queued message (${this.pendingMessages.length} pending), connecting=${this.connecting}`);
|
|
127
|
+
if (!this.connecting) {
|
|
128
|
+
this.connecting = true;
|
|
129
|
+
this.connectHttpTransport().catch((error) => {
|
|
130
|
+
if (this.shuttingDown) {
|
|
131
|
+
log(`[mcp-proxy] Connection aborted during shutdown: ${errorDetail(error)}`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
log(`[mcp-proxy] Failed to connect to MCP server:\n${errorDetail(error)}`);
|
|
135
|
+
process.exit(1);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Lazily create and connect the HTTP transport to the real MCP server.
|
|
141
|
+
* Handles OAuth authorization if the server returns 401.
|
|
142
|
+
*/
|
|
143
|
+
async connectHttpTransport() {
|
|
144
|
+
log(`[mcp-proxy] Connecting to MCP server: ${this.serverUrl}`);
|
|
145
|
+
await this.oauthProvider.ensureCallbackServer();
|
|
146
|
+
log('[mcp-proxy] Callback server pre-started');
|
|
147
|
+
this.httpTransport = this.createHttpTransport(this.oauthProvider);
|
|
148
|
+
log('[mcp-proxy] HTTP transport created with auth provider');
|
|
149
|
+
try {
|
|
150
|
+
log('[mcp-proxy] Starting HTTP transport...');
|
|
151
|
+
await this.httpTransport.start();
|
|
152
|
+
log('[mcp-proxy] HTTP transport started');
|
|
153
|
+
this.connected = true;
|
|
154
|
+
log('[mcp-proxy] HTTP transport connected');
|
|
155
|
+
try {
|
|
156
|
+
await this.flushPendingMessages();
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
if (error instanceof UnauthorizedError) {
|
|
160
|
+
log('[mcp-proxy] Auth required on first send, completing OAuth flow');
|
|
161
|
+
await this.handleOAuthFlow(this.httpTransport);
|
|
162
|
+
log('[mcp-proxy] OAuth complete, retrying queued messages');
|
|
163
|
+
await this.flushPendingMessages();
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (error instanceof UnauthorizedError) {
|
|
172
|
+
log('[mcp-proxy] Auth required on start, completing OAuth flow');
|
|
173
|
+
await this.handleOAuthFlow(this.httpTransport);
|
|
174
|
+
this.connected = true;
|
|
175
|
+
log('[mcp-proxy] HTTP transport connected after OAuth');
|
|
176
|
+
await this.flushPendingMessages();
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
this.connecting = false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Create an HTTP transport with cookie jar and logging.
|
|
188
|
+
*/
|
|
189
|
+
createHttpTransport(authProvider) {
|
|
190
|
+
const jar = this.cookieJar;
|
|
191
|
+
// Wrap fetch to: (1) inject cookies, (2) capture Set-Cookie, (3) log details
|
|
192
|
+
const cookieFetch = async (input, init) => {
|
|
193
|
+
const reqUrl = typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url;
|
|
194
|
+
const method = init?.method ?? 'GET';
|
|
195
|
+
log(`[mcp-proxy] HTTP ${method} ${reqUrl}`);
|
|
196
|
+
if (init?.body)
|
|
197
|
+
log(`[mcp-proxy] Request body: ${String(init.body).slice(0, 300)}`);
|
|
198
|
+
// Inject stored cookies into the request
|
|
199
|
+
const cookieHeader = jar.headerFor(reqUrl);
|
|
200
|
+
if (cookieHeader && init?.headers) {
|
|
201
|
+
const headers = init.headers instanceof Headers ? init.headers : new Headers(init.headers);
|
|
202
|
+
headers.set('Cookie', cookieHeader);
|
|
203
|
+
init = { ...init, headers };
|
|
204
|
+
log(`[mcp-proxy] Injected cookies for ${new URL(reqUrl).origin}`);
|
|
205
|
+
}
|
|
206
|
+
// Log auth header presence (not value)
|
|
207
|
+
if (init?.headers instanceof Headers) {
|
|
208
|
+
log(`[mcp-proxy] Has Authorization: ${init.headers.has('Authorization')}`);
|
|
209
|
+
log(`[mcp-proxy] Request headers: ${[...init.headers.keys()].join(', ')}`);
|
|
210
|
+
}
|
|
211
|
+
const response = await fetch(input, init);
|
|
212
|
+
log(`[mcp-proxy] HTTP response: ${response.status} ${response.statusText}`);
|
|
213
|
+
const ct = response.headers.get('content-type');
|
|
214
|
+
if (ct)
|
|
215
|
+
log(`[mcp-proxy] Response content-type: ${ct}`);
|
|
216
|
+
// Capture any Set-Cookie headers from the response
|
|
217
|
+
jar.capture(reqUrl, response);
|
|
218
|
+
// Log error response bodies
|
|
219
|
+
if (!response.ok) {
|
|
220
|
+
const cloned = response.clone();
|
|
221
|
+
const errorBody = await cloned.text().catch(() => '(unreadable)');
|
|
222
|
+
log(`[mcp-proxy] Error response body: ${errorBody.slice(0, 500)}`);
|
|
223
|
+
}
|
|
224
|
+
return response;
|
|
225
|
+
};
|
|
226
|
+
const transport = new StreamableHTTPClientTransport(this.serverUrl, {
|
|
227
|
+
fetch: cookieFetch,
|
|
228
|
+
...(authProvider ? { authProvider } : {}),
|
|
229
|
+
});
|
|
230
|
+
transport.onmessage = (message) => {
|
|
231
|
+
log(`[mcp-proxy] Received HTTP message: ${JSON.stringify(message).slice(0, 200)}`);
|
|
232
|
+
this.stdioTransport.send(message).catch((error) => {
|
|
233
|
+
log(`[mcp-proxy] Error forwarding to stdio: ${error.message}`);
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
transport.onclose = () => {
|
|
237
|
+
log('[mcp-proxy] HTTP transport closed');
|
|
238
|
+
this.shutdown();
|
|
239
|
+
};
|
|
240
|
+
transport.onerror = (error) => {
|
|
241
|
+
log(`[mcp-proxy] HTTP transport error:\n${errorDetail(error)}`);
|
|
242
|
+
};
|
|
243
|
+
return transport;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Handle the OAuth authorization code flow.
|
|
247
|
+
*/
|
|
248
|
+
async handleOAuthFlow(transport) {
|
|
249
|
+
log('[mcp-proxy] Waiting for authorization code from browser...');
|
|
250
|
+
const code = await this.oauthProvider.waitForAuthorizationCode();
|
|
251
|
+
log('[mcp-proxy] Authorization code received, exchanging for token');
|
|
252
|
+
await transport.finishAuth(code);
|
|
253
|
+
log('[mcp-proxy] Token exchange complete, transport ready');
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Forward any messages that arrived while we were connecting/authenticating.
|
|
257
|
+
* UnauthorizedError is re-thrown so the caller can handle the OAuth flow.
|
|
258
|
+
*/
|
|
259
|
+
async flushPendingMessages() {
|
|
260
|
+
const messages = this.pendingMessages;
|
|
261
|
+
this.pendingMessages = [];
|
|
262
|
+
for (const message of messages) {
|
|
263
|
+
try {
|
|
264
|
+
await this.httpTransport.send(message);
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
if (error instanceof UnauthorizedError) {
|
|
268
|
+
const remaining = messages.slice(messages.indexOf(message));
|
|
269
|
+
this.pendingMessages = remaining.concat(this.pendingMessages);
|
|
270
|
+
log(`[mcp-proxy] UnauthorizedError during flush, re-queued ${remaining.length} message(s)`);
|
|
271
|
+
throw error;
|
|
272
|
+
}
|
|
273
|
+
log(`[mcp-proxy] Error flushing pending message:\n${errorDetail(error)}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (messages.length > 0) {
|
|
277
|
+
log(`[mcp-proxy] Flushed ${messages.length} pending message(s)`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Graceful shutdown: close both transports. Idempotent.
|
|
282
|
+
*/
|
|
283
|
+
async shutdown() {
|
|
284
|
+
if (this.shuttingDown)
|
|
285
|
+
return;
|
|
286
|
+
this.shuttingDown = true;
|
|
287
|
+
log('[mcp-proxy] Shutting down bridge');
|
|
288
|
+
this.oauthProvider.dispose();
|
|
289
|
+
try {
|
|
290
|
+
if (this.httpTransport) {
|
|
291
|
+
await this.httpTransport.terminateSession();
|
|
292
|
+
await this.httpTransport.close();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
log(`[mcp-proxy] Error closing HTTP transport: ${error.message}`);
|
|
297
|
+
}
|
|
298
|
+
try {
|
|
299
|
+
await this.stdioTransport.close();
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
log(`[mcp-proxy] Error closing stdio transport: ${error.message}`);
|
|
303
|
+
}
|
|
304
|
+
log('[mcp-proxy] Bridge shutdown complete');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=stdio-http-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdio-http-bridge.js","sourceRoot":"","sources":["../../src/mcp/stdio-http-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,SAAS,GAAG,CAAC,GAAW;IACtB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClB,QAAQ,CAAC,GAAG,CAAC,CAAC;AAChB,CAAC;AAED,2FAA2F;AAC3F,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACpD,MAAM,KAAK,GAAa,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACxE,KAAK,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,CAAC;QAC7F,MAAM,GAAG,GAAI,KAA4C,CAAC,GAAG,CAAC,CAAC;QAC/D,IAAI,GAAG,KAAK,SAAS;YAAE,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GA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YAAE,OAAO;QAC9B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAEzB,GAAG,CAAC,kCAAkC,CAAC,CAAC;QACxC,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;QAE7B,IAAI,CAAC;YACH,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;gBACvB,MAAM,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC;gBAC5C,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;YACnC,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,6CAA8C,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/E,CAAC;QAED,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QACpC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,8CAA+C,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;QAChF,CAAC;QAED,GAAG,CAAC,sCAAsC,CAAC,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SSOAuthResult } from './types.js';
|
|
2
|
+
export declare const DEFAULT_CODEMIE_BASE_URL = "https://codemie.lab.epam.com";
|
|
3
|
+
export interface CodeMieUserInfo {
|
|
4
|
+
userId: string;
|
|
5
|
+
name: string;
|
|
6
|
+
username: string;
|
|
7
|
+
isAdmin: boolean;
|
|
8
|
+
applications: string[];
|
|
9
|
+
applications_admin: string[];
|
|
10
|
+
applicationsAdmin?: string[];
|
|
11
|
+
picture: string;
|
|
12
|
+
knowledgeBases: string[];
|
|
13
|
+
userType?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function ensureApiBase(rawUrl: string): string;
|
|
16
|
+
export declare function buildAuthHeaders(auth: Record<string, string> | string): Record<string, string>;
|
|
17
|
+
export declare function promptForCodeMieUrl(defaultUrl?: string, message?: string): Promise<string>;
|
|
18
|
+
export declare function authenticateWithCodeMie(codeMieUrl: string, timeout?: number): Promise<SSOAuthResult>;
|
|
19
|
+
export declare function fetchCodeMieUserInfo(apiUrl: string, cookies: Record<string, string>): Promise<CodeMieUserInfo>;
|
|
20
|
+
export declare function fetchCodeMieUserInfo(apiUrl: string, jwtToken: string): Promise<CodeMieUserInfo>;
|
|
21
|
+
export declare function selectCodeMieProject(authResult: SSOAuthResult): Promise<string>;
|
|
22
|
+
//# sourceMappingURL=codemie-auth-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codemie-auth-helpers.d.ts","sourceRoot":"","sources":["../../../src/providers/core/codemie-auth-helpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,eAAO,MAAM,wBAAwB,iCAAiC,CAAC;AAEvE,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMpD;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAkB9F;AAED,wBAAsB,mBAAmB,CACvC,UAAU,GAAE,MAAiC,EAC7C,OAAO,GAAE,MAAoC,GAC5C,OAAO,CAAC,MAAM,CAAC,CAoBjB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