@modeltoolsprotocol/mtpcli 1.3.3 → 1.3.4
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/LICENSE +1 -1
- package/dist/index.js +120 -88
- package/package.json +1 -1
package/LICENSE
CHANGED
package/dist/index.js
CHANGED
|
@@ -7574,47 +7574,62 @@ function generatePkce() {
|
|
|
7574
7574
|
const challenge = createHash("sha256").update(verifier).digest("base64url");
|
|
7575
7575
|
return { verifier, challenge };
|
|
7576
7576
|
}
|
|
7577
|
-
function
|
|
7577
|
+
function startCallbackServer() {
|
|
7578
7578
|
return new Promise((resolve, reject) => {
|
|
7579
|
-
const
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
const server = createServer((req, res) => {
|
|
7584
|
-
const url = new URL(req.url ?? "/", `http://127.0.0.1:${port}`);
|
|
7585
|
-
const code = url.searchParams.get("code");
|
|
7586
|
-
const error = url.searchParams.get("error");
|
|
7587
|
-
if (code) {
|
|
7588
|
-
const html = "<html><body><h2>Authentication successful!</h2>" + "<p>You can close this tab and return to your terminal.</p>" + "<script>window.close()</script></body></html>";
|
|
7589
|
-
res.writeHead(200, {
|
|
7590
|
-
"Content-Type": "text/html",
|
|
7591
|
-
"Content-Length": Buffer.byteLength(html).toString()
|
|
7592
|
-
});
|
|
7593
|
-
res.end(html);
|
|
7594
|
-
clearTimeout(timer);
|
|
7595
|
-
server.close();
|
|
7596
|
-
resolve({ code });
|
|
7597
|
-
return;
|
|
7598
|
-
}
|
|
7599
|
-
if (error) {
|
|
7600
|
-
const desc = url.searchParams.get("error_description") ?? "Unknown error";
|
|
7601
|
-
const html = `<html><body><h2>Authentication failed</h2><p>${desc}</p></body></html>`;
|
|
7602
|
-
res.writeHead(400, {
|
|
7603
|
-
"Content-Type": "text/html",
|
|
7604
|
-
"Content-Length": Buffer.byteLength(html).toString()
|
|
7605
|
-
});
|
|
7606
|
-
res.end(html);
|
|
7607
|
-
clearTimeout(timer);
|
|
7579
|
+
const server = createServer(() => {});
|
|
7580
|
+
server.listen(0, "127.0.0.1", () => {
|
|
7581
|
+
const addr = server.address();
|
|
7582
|
+
if (!addr || typeof addr === "string") {
|
|
7608
7583
|
server.close();
|
|
7609
|
-
|
|
7584
|
+
reject(new Error("failed to get callback server address"));
|
|
7610
7585
|
return;
|
|
7611
7586
|
}
|
|
7612
|
-
|
|
7613
|
-
|
|
7587
|
+
const port = addr.port;
|
|
7588
|
+
server.removeAllListeners("request");
|
|
7589
|
+
server.on("request", (req, res) => {
|
|
7590
|
+
const url = new URL(req.url ?? "/", `http://127.0.0.1:${port}`);
|
|
7591
|
+
const code = url.searchParams.get("code");
|
|
7592
|
+
const error = url.searchParams.get("error");
|
|
7593
|
+
if (code) {
|
|
7594
|
+
const html = "<html><body><h2>Authentication successful!</h2>" + "<p>You can close this tab and return to your terminal.</p>" + "<script>window.close()</script></body></html>";
|
|
7595
|
+
res.writeHead(200, {
|
|
7596
|
+
"Content-Type": "text/html",
|
|
7597
|
+
"Content-Length": Buffer.byteLength(html).toString()
|
|
7598
|
+
});
|
|
7599
|
+
res.end(html);
|
|
7600
|
+
server.emit("oauth-result", { code });
|
|
7601
|
+
return;
|
|
7602
|
+
}
|
|
7603
|
+
if (error) {
|
|
7604
|
+
const desc = url.searchParams.get("error_description") ?? "Unknown error";
|
|
7605
|
+
const html = `<html><body><h2>Authentication failed</h2><p>${desc}</p></body></html>`;
|
|
7606
|
+
res.writeHead(400, {
|
|
7607
|
+
"Content-Type": "text/html",
|
|
7608
|
+
"Content-Length": Buffer.byteLength(html).toString()
|
|
7609
|
+
});
|
|
7610
|
+
res.end(html);
|
|
7611
|
+
server.emit("oauth-result", { error });
|
|
7612
|
+
return;
|
|
7613
|
+
}
|
|
7614
|
+
res.writeHead(404);
|
|
7615
|
+
res.end();
|
|
7616
|
+
});
|
|
7617
|
+
resolve({
|
|
7618
|
+
port,
|
|
7619
|
+
wait: (timeoutSecs) => new Promise((res, rej) => {
|
|
7620
|
+
const timer = setTimeout(() => {
|
|
7621
|
+
server.close();
|
|
7622
|
+
rej(new Error("OAuth callback timed out"));
|
|
7623
|
+
}, timeoutSecs * 1000);
|
|
7624
|
+
server.on("oauth-result", (result) => {
|
|
7625
|
+
clearTimeout(timer);
|
|
7626
|
+
server.close();
|
|
7627
|
+
res(result);
|
|
7628
|
+
});
|
|
7629
|
+
})
|
|
7630
|
+
});
|
|
7614
7631
|
});
|
|
7615
|
-
server.listen(port, "127.0.0.1", () => {});
|
|
7616
7632
|
server.on("error", (e) => {
|
|
7617
|
-
clearTimeout(timer);
|
|
7618
7633
|
reject(new Error(`failed to bind callback server: ${e.message}`));
|
|
7619
7634
|
});
|
|
7620
7635
|
});
|
|
@@ -7684,13 +7699,14 @@ function parseTokenResponse(text) {
|
|
|
7684
7699
|
created_at: new Date().toISOString()
|
|
7685
7700
|
};
|
|
7686
7701
|
}
|
|
7687
|
-
async function oauth2Login(toolName, provider
|
|
7702
|
+
async function oauth2Login(toolName, provider) {
|
|
7688
7703
|
if (!provider.authorizationUrl)
|
|
7689
7704
|
throw new Error("provider missing authorizationUrl");
|
|
7690
7705
|
if (!provider.tokenUrl)
|
|
7691
7706
|
throw new Error("provider missing tokenUrl");
|
|
7692
7707
|
if (!provider.clientId)
|
|
7693
7708
|
throw new Error("provider missing clientId");
|
|
7709
|
+
const { port, wait } = await startCallbackServer();
|
|
7694
7710
|
const redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
7695
7711
|
const state = randomBytes(32).toString("base64url");
|
|
7696
7712
|
const params = new URLSearchParams({
|
|
@@ -7720,7 +7736,7 @@ ${fullUrl}
|
|
|
7720
7736
|
open_default(fullUrl).catch(() => {});
|
|
7721
7737
|
process.stderr.write(`Waiting for authentication callback on port ${port}...
|
|
7722
7738
|
`);
|
|
7723
|
-
const result = await
|
|
7739
|
+
const result = await wait(120);
|
|
7724
7740
|
if (result.error)
|
|
7725
7741
|
throw new Error(`OAuth error: ${result.error}`);
|
|
7726
7742
|
if (!result.code)
|
|
@@ -7776,13 +7792,13 @@ function apiKeyLogin(toolName, provider, tokenValue) {
|
|
|
7776
7792
|
});
|
|
7777
7793
|
});
|
|
7778
7794
|
}
|
|
7779
|
-
async function login(toolName, provider, token
|
|
7795
|
+
async function login(toolName, provider, token) {
|
|
7780
7796
|
switch (provider.type) {
|
|
7781
7797
|
case "oauth2":
|
|
7782
7798
|
case "oauth2-pkce":
|
|
7783
7799
|
if (token)
|
|
7784
7800
|
return apiKeyLogin(toolName, provider, token);
|
|
7785
|
-
return oauth2Login(toolName, provider
|
|
7801
|
+
return oauth2Login(toolName, provider);
|
|
7786
7802
|
case "api-key":
|
|
7787
7803
|
case "bearer":
|
|
7788
7804
|
return apiKeyLogin(toolName, provider, token);
|
|
@@ -7868,7 +7884,7 @@ async function runLogin(toolName, providerId, token) {
|
|
|
7868
7884
|
const provider = getProvider(auth, providerId);
|
|
7869
7885
|
if (!provider)
|
|
7870
7886
|
throw new Error("no matching auth provider found");
|
|
7871
|
-
await login(toolName, provider, token
|
|
7887
|
+
await login(toolName, provider, token);
|
|
7872
7888
|
}
|
|
7873
7889
|
async function runLogout(toolName) {
|
|
7874
7890
|
const auth = await getAuthConfig(toolName);
|
|
@@ -8111,7 +8127,7 @@ function storeClientRegistration(origin, client, metadata) {
|
|
|
8111
8127
|
store[origin] = { client, metadata };
|
|
8112
8128
|
saveClientStore(store);
|
|
8113
8129
|
}
|
|
8114
|
-
function
|
|
8130
|
+
function startCallbackServer2() {
|
|
8115
8131
|
return new Promise((resolve, reject) => {
|
|
8116
8132
|
let codeResolve;
|
|
8117
8133
|
let codeReject;
|
|
@@ -8183,7 +8199,7 @@ async function mcpOAuthFlow(serverUrl, wwwAuth, clientId) {
|
|
|
8183
8199
|
if (challengeMethods && !challengeMethods.includes("S256")) {
|
|
8184
8200
|
throw new Error("authorization server does not support S256 PKCE (required)");
|
|
8185
8201
|
}
|
|
8186
|
-
const callback = await
|
|
8202
|
+
const callback = await startCallbackServer2();
|
|
8187
8203
|
const redirectUri = `http://127.0.0.1:${callback.port}/callback`;
|
|
8188
8204
|
let resolvedClientId = clientId;
|
|
8189
8205
|
let registration;
|
|
@@ -8206,7 +8222,7 @@ async function mcpOAuthFlow(serverUrl, wwwAuth, clientId) {
|
|
|
8206
8222
|
} else {
|
|
8207
8223
|
callback.server.close();
|
|
8208
8224
|
resolvedClientId = await promptForClientId(serverUrl);
|
|
8209
|
-
const newCallback = await
|
|
8225
|
+
const newCallback = await startCallbackServer2();
|
|
8210
8226
|
return doOAuthLogin(metadata, resolvedClientId, `http://127.0.0.1:${newCallback.port}/callback`, newCallback, wwwParsed.scope, storageKey, origin);
|
|
8211
8227
|
}
|
|
8212
8228
|
}
|
|
@@ -8423,47 +8439,62 @@ function generatePkce2() {
|
|
|
8423
8439
|
const challenge = createHash2("sha256").update(verifier).digest("base64url");
|
|
8424
8440
|
return { verifier, challenge };
|
|
8425
8441
|
}
|
|
8426
|
-
function
|
|
8442
|
+
function startCallbackServer3() {
|
|
8427
8443
|
return new Promise((resolve, reject) => {
|
|
8428
|
-
const
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
const server = createServer3((req, res) => {
|
|
8433
|
-
const url = new URL(req.url ?? "/", `http://127.0.0.1:${port}`);
|
|
8434
|
-
const code = url.searchParams.get("code");
|
|
8435
|
-
const error = url.searchParams.get("error");
|
|
8436
|
-
if (code) {
|
|
8437
|
-
const html = "<html><body><h2>Authentication successful!</h2>" + "<p>You can close this tab and return to your terminal.</p>" + "<script>window.close()</script></body></html>";
|
|
8438
|
-
res.writeHead(200, {
|
|
8439
|
-
"Content-Type": "text/html",
|
|
8440
|
-
"Content-Length": Buffer.byteLength(html).toString()
|
|
8441
|
-
});
|
|
8442
|
-
res.end(html);
|
|
8443
|
-
clearTimeout(timer);
|
|
8444
|
-
server.close();
|
|
8445
|
-
resolve({ code });
|
|
8446
|
-
return;
|
|
8447
|
-
}
|
|
8448
|
-
if (error) {
|
|
8449
|
-
const desc = url.searchParams.get("error_description") ?? "Unknown error";
|
|
8450
|
-
const html = `<html><body><h2>Authentication failed</h2><p>${desc}</p></body></html>`;
|
|
8451
|
-
res.writeHead(400, {
|
|
8452
|
-
"Content-Type": "text/html",
|
|
8453
|
-
"Content-Length": Buffer.byteLength(html).toString()
|
|
8454
|
-
});
|
|
8455
|
-
res.end(html);
|
|
8456
|
-
clearTimeout(timer);
|
|
8444
|
+
const server = createServer3(() => {});
|
|
8445
|
+
server.listen(0, "127.0.0.1", () => {
|
|
8446
|
+
const addr = server.address();
|
|
8447
|
+
if (!addr || typeof addr === "string") {
|
|
8457
8448
|
server.close();
|
|
8458
|
-
|
|
8449
|
+
reject(new Error("failed to get callback server address"));
|
|
8459
8450
|
return;
|
|
8460
8451
|
}
|
|
8461
|
-
|
|
8462
|
-
|
|
8452
|
+
const port = addr.port;
|
|
8453
|
+
server.removeAllListeners("request");
|
|
8454
|
+
server.on("request", (req, res) => {
|
|
8455
|
+
const url = new URL(req.url ?? "/", `http://127.0.0.1:${port}`);
|
|
8456
|
+
const code = url.searchParams.get("code");
|
|
8457
|
+
const error = url.searchParams.get("error");
|
|
8458
|
+
if (code) {
|
|
8459
|
+
const html = "<html><body><h2>Authentication successful!</h2>" + "<p>You can close this tab and return to your terminal.</p>" + "<script>window.close()</script></body></html>";
|
|
8460
|
+
res.writeHead(200, {
|
|
8461
|
+
"Content-Type": "text/html",
|
|
8462
|
+
"Content-Length": Buffer.byteLength(html).toString()
|
|
8463
|
+
});
|
|
8464
|
+
res.end(html);
|
|
8465
|
+
server.emit("oauth-result", { code });
|
|
8466
|
+
return;
|
|
8467
|
+
}
|
|
8468
|
+
if (error) {
|
|
8469
|
+
const desc = url.searchParams.get("error_description") ?? "Unknown error";
|
|
8470
|
+
const html = `<html><body><h2>Authentication failed</h2><p>${desc}</p></body></html>`;
|
|
8471
|
+
res.writeHead(400, {
|
|
8472
|
+
"Content-Type": "text/html",
|
|
8473
|
+
"Content-Length": Buffer.byteLength(html).toString()
|
|
8474
|
+
});
|
|
8475
|
+
res.end(html);
|
|
8476
|
+
server.emit("oauth-result", { error });
|
|
8477
|
+
return;
|
|
8478
|
+
}
|
|
8479
|
+
res.writeHead(404);
|
|
8480
|
+
res.end();
|
|
8481
|
+
});
|
|
8482
|
+
resolve({
|
|
8483
|
+
port,
|
|
8484
|
+
wait: (timeoutSecs) => new Promise((res, rej) => {
|
|
8485
|
+
const timer = setTimeout(() => {
|
|
8486
|
+
server.close();
|
|
8487
|
+
rej(new Error("OAuth callback timed out"));
|
|
8488
|
+
}, timeoutSecs * 1000);
|
|
8489
|
+
server.on("oauth-result", (result) => {
|
|
8490
|
+
clearTimeout(timer);
|
|
8491
|
+
server.close();
|
|
8492
|
+
res(result);
|
|
8493
|
+
});
|
|
8494
|
+
})
|
|
8495
|
+
});
|
|
8463
8496
|
});
|
|
8464
|
-
server.listen(port, "127.0.0.1", () => {});
|
|
8465
8497
|
server.on("error", (e) => {
|
|
8466
|
-
clearTimeout(timer);
|
|
8467
8498
|
reject(new Error(`failed to bind callback server: ${e.message}`));
|
|
8468
8499
|
});
|
|
8469
8500
|
});
|
|
@@ -8533,13 +8564,14 @@ function parseTokenResponse2(text) {
|
|
|
8533
8564
|
created_at: new Date().toISOString()
|
|
8534
8565
|
};
|
|
8535
8566
|
}
|
|
8536
|
-
async function oauth2Login2(toolName, provider
|
|
8567
|
+
async function oauth2Login2(toolName, provider) {
|
|
8537
8568
|
if (!provider.authorizationUrl)
|
|
8538
8569
|
throw new Error("provider missing authorizationUrl");
|
|
8539
8570
|
if (!provider.tokenUrl)
|
|
8540
8571
|
throw new Error("provider missing tokenUrl");
|
|
8541
8572
|
if (!provider.clientId)
|
|
8542
8573
|
throw new Error("provider missing clientId");
|
|
8574
|
+
const { port, wait } = await startCallbackServer3();
|
|
8543
8575
|
const redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
8544
8576
|
const state = randomBytes3(32).toString("base64url");
|
|
8545
8577
|
const params = new URLSearchParams({
|
|
@@ -8569,7 +8601,7 @@ ${fullUrl}
|
|
|
8569
8601
|
open_default(fullUrl).catch(() => {});
|
|
8570
8602
|
process.stderr.write(`Waiting for authentication callback on port ${port}...
|
|
8571
8603
|
`);
|
|
8572
|
-
const result = await
|
|
8604
|
+
const result = await wait(120);
|
|
8573
8605
|
if (result.error)
|
|
8574
8606
|
throw new Error(`OAuth error: ${result.error}`);
|
|
8575
8607
|
if (!result.code)
|
|
@@ -8625,13 +8657,13 @@ function apiKeyLogin2(toolName, provider, tokenValue) {
|
|
|
8625
8657
|
});
|
|
8626
8658
|
});
|
|
8627
8659
|
}
|
|
8628
|
-
async function login2(toolName, provider, token
|
|
8660
|
+
async function login2(toolName, provider, token) {
|
|
8629
8661
|
switch (provider.type) {
|
|
8630
8662
|
case "oauth2":
|
|
8631
8663
|
case "oauth2-pkce":
|
|
8632
8664
|
if (token)
|
|
8633
8665
|
return apiKeyLogin2(toolName, provider, token);
|
|
8634
|
-
return oauth2Login2(toolName, provider
|
|
8666
|
+
return oauth2Login2(toolName, provider);
|
|
8635
8667
|
case "api-key":
|
|
8636
8668
|
case "bearer":
|
|
8637
8669
|
return apiKeyLogin2(toolName, provider, token);
|
|
@@ -8717,7 +8749,7 @@ async function runLogin2(toolName, providerId, token) {
|
|
|
8717
8749
|
const provider = getProvider2(auth, providerId);
|
|
8718
8750
|
if (!provider)
|
|
8719
8751
|
throw new Error("no matching auth provider found");
|
|
8720
|
-
await login2(toolName, provider, token
|
|
8752
|
+
await login2(toolName, provider, token);
|
|
8721
8753
|
}
|
|
8722
8754
|
async function runLogout2(toolName) {
|
|
8723
8755
|
const auth = await getAuthConfig2(toolName);
|
|
@@ -8843,7 +8875,7 @@ var init_mcp = __esm(() => {
|
|
|
8843
8875
|
});
|
|
8844
8876
|
|
|
8845
8877
|
// src/version.ts
|
|
8846
|
-
var VERSION2 = "1.3.
|
|
8878
|
+
var VERSION2 = "1.3.4";
|
|
8847
8879
|
|
|
8848
8880
|
// src/serve.ts
|
|
8849
8881
|
var exports_serve = {};
|
|
@@ -9306,7 +9338,7 @@ function storeClientRegistration2(origin, client, metadata) {
|
|
|
9306
9338
|
store[origin] = { client, metadata };
|
|
9307
9339
|
saveClientStore2(store);
|
|
9308
9340
|
}
|
|
9309
|
-
function
|
|
9341
|
+
function startCallbackServer4() {
|
|
9310
9342
|
return new Promise((resolve, reject) => {
|
|
9311
9343
|
let codeResolve;
|
|
9312
9344
|
let codeReject;
|
|
@@ -9378,7 +9410,7 @@ async function mcpOAuthFlow2(serverUrl, wwwAuth, clientId) {
|
|
|
9378
9410
|
if (challengeMethods && !challengeMethods.includes("S256")) {
|
|
9379
9411
|
throw new Error("authorization server does not support S256 PKCE (required)");
|
|
9380
9412
|
}
|
|
9381
|
-
const callback = await
|
|
9413
|
+
const callback = await startCallbackServer4();
|
|
9382
9414
|
const redirectUri = `http://127.0.0.1:${callback.port}/callback`;
|
|
9383
9415
|
let resolvedClientId = clientId;
|
|
9384
9416
|
let registration;
|
|
@@ -9401,7 +9433,7 @@ async function mcpOAuthFlow2(serverUrl, wwwAuth, clientId) {
|
|
|
9401
9433
|
} else {
|
|
9402
9434
|
callback.server.close();
|
|
9403
9435
|
resolvedClientId = await promptForClientId2(serverUrl);
|
|
9404
|
-
const newCallback = await
|
|
9436
|
+
const newCallback = await startCallbackServer4();
|
|
9405
9437
|
return doOAuthLogin2(metadata, resolvedClientId, `http://127.0.0.1:${newCallback.port}/callback`, newCallback, wwwParsed.scope, storageKey, origin);
|
|
9406
9438
|
}
|
|
9407
9439
|
}
|
|
@@ -10660,7 +10692,7 @@ function withDescribe(program2, options) {
|
|
|
10660
10692
|
}
|
|
10661
10693
|
|
|
10662
10694
|
// src/version.ts
|
|
10663
|
-
var VERSION = "1.3.
|
|
10695
|
+
var VERSION = "1.3.4";
|
|
10664
10696
|
|
|
10665
10697
|
// src/index.ts
|
|
10666
10698
|
var program2 = new Command().name("mtpcli").version(VERSION).description("Unified CLI for discovering, authenticating, and bridging --mtp-describe-compatible tools").addHelpText("after", `
|