@kosha-ai/integration-mcp 0.4.2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assertAllowedUrl, defineIntegration, packageDirs, BlockedAddressError, s256Challenge, } from '@kosha-ai/integration-sdk';
|
|
2
2
|
const { docsPath, migrationsPath } = packageDirs(import.meta.url);
|
|
3
3
|
export class McpDiscoveryError extends Error {
|
|
4
4
|
constructor(message) {
|
|
@@ -17,13 +17,13 @@ function required(value, what) {
|
|
|
17
17
|
const MAX_REDIRECTS = 5;
|
|
18
18
|
/**
|
|
19
19
|
* `fetch`, but every URL — the one as typed, and each hop a redirect sends
|
|
20
|
-
* it to — goes through `
|
|
20
|
+
* it to — goes through `assertAllowedUrl` first: `mcpUrl` is operator-entered,
|
|
21
21
|
* and the endpoints discovered from it are server-controlled, so a request
|
|
22
|
-
* here that followed an unchecked redirect could be steered
|
|
23
|
-
*
|
|
22
|
+
* here that followed an unchecked redirect could be steered to cloud
|
|
23
|
+
* metadata (169.254.169.254).
|
|
24
24
|
*/
|
|
25
25
|
async function safeFetch(url, init) {
|
|
26
|
-
let target = await
|
|
26
|
+
let target = await assertAllowedUrl(url);
|
|
27
27
|
for (let redirects = 0;; redirects++) {
|
|
28
28
|
const response = await fetch(target.href, { ...init, redirect: 'manual' });
|
|
29
29
|
const location = response.headers.get('location');
|
|
@@ -33,7 +33,7 @@ async function safeFetch(url, init) {
|
|
|
33
33
|
if (redirects >= MAX_REDIRECTS) {
|
|
34
34
|
throw new McpDiscoveryError(`${target.href}: too many redirects`);
|
|
35
35
|
}
|
|
36
|
-
target = await
|
|
36
|
+
target = await assertAllowedUrl(new URL(location, target).href);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
async function fetchJson(url, init) {
|
|
@@ -65,7 +65,7 @@ async function discoverProtectedResource(mcpUrl) {
|
|
|
65
65
|
return await fetchJson(protectedResourceMetadataUrl(mcpUrl));
|
|
66
66
|
}
|
|
67
67
|
catch (error) {
|
|
68
|
-
if (error instanceof
|
|
68
|
+
if (error instanceof BlockedAddressError)
|
|
69
69
|
throw error;
|
|
70
70
|
return { authorization_servers: [mcpUrl.origin], resource: mcpUrl.href };
|
|
71
71
|
}
|
|
@@ -93,7 +93,7 @@ async function discoverAuthorizationServer(issuer) {
|
|
|
93
93
|
return await fetchJson(candidate);
|
|
94
94
|
}
|
|
95
95
|
catch (error) {
|
|
96
|
-
if (error instanceof
|
|
96
|
+
if (error instanceof BlockedAddressError)
|
|
97
97
|
throw error;
|
|
98
98
|
lastError = error;
|
|
99
99
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosha-ai/integration-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "MCP (Model Context Protocol) server integration for Kosha",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kosha",
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"key": "mcp"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@kosha-ai/integration-sdk": "0.
|
|
51
|
+
"@kosha-ai/integration-sdk": "0.5.1"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@kosha-ai/integration-sdk": "0.
|
|
54
|
+
"@kosha-ai/integration-sdk": "0.5.1"
|
|
55
55
|
}
|
|
56
56
|
}
|