supersendtx-mcp 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +30 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -907,12 +907,21 @@ async function runStdioServer() {
|
|
|
907
907
|
|
|
908
908
|
// src/oauth-metadata.ts
|
|
909
909
|
var MCP_HTTP_PATH = "/mcp";
|
|
910
|
+
function appOriginForMcpOrigin(mcpOrigin) {
|
|
911
|
+
try {
|
|
912
|
+
const host = new URL(mcpOrigin).hostname.toLowerCase();
|
|
913
|
+
if (host === "mcp.ranla.ai") return "https://app.ranla.ai";
|
|
914
|
+
if (host === "mcp.supersendtx.com") return "https://app.supersendtx.com";
|
|
915
|
+
} catch {
|
|
916
|
+
}
|
|
917
|
+
return (process.env.SUPERSENDTX_OAUTH_ISSUER?.trim() || process.env.SUPERSENDTX_APP_URL?.trim() || "https://app.supersendtx.com").replace(/\/$/, "");
|
|
918
|
+
}
|
|
910
919
|
function buildProtectedResourceMetadata(origin) {
|
|
911
920
|
const resource = `${origin.replace(/\/$/, "")}${MCP_HTTP_PATH}`;
|
|
912
|
-
const appOrigin =
|
|
921
|
+
const appOrigin = appOriginForMcpOrigin(origin);
|
|
913
922
|
return {
|
|
914
923
|
resource,
|
|
915
|
-
authorization_servers: [appOrigin
|
|
924
|
+
authorization_servers: [appOrigin],
|
|
916
925
|
scopes_supported: ["full"],
|
|
917
926
|
bearer_methods_supported: ["header"]
|
|
918
927
|
};
|
|
@@ -923,14 +932,24 @@ function buildWwwAuthenticateChallenge(origin) {
|
|
|
923
932
|
}
|
|
924
933
|
|
|
925
934
|
// src/oauth-resolve.ts
|
|
926
|
-
function
|
|
927
|
-
|
|
928
|
-
|
|
935
|
+
function appOriginForMcpOrigin2(mcpOrigin) {
|
|
936
|
+
if (mcpOrigin) {
|
|
937
|
+
try {
|
|
938
|
+
const host = new URL(mcpOrigin).hostname.toLowerCase();
|
|
939
|
+
if (host === "mcp.ranla.ai") return "https://app.ranla.ai";
|
|
940
|
+
if (host === "mcp.supersendtx.com") return "https://app.supersendtx.com";
|
|
941
|
+
} catch {
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
return (process.env.SUPERSENDTX_APP_URL?.trim() || process.env.SUPERSENDTX_OAUTH_ISSUER?.trim() || "https://app.supersendtx.com").replace(/\/$/, "");
|
|
945
|
+
}
|
|
946
|
+
function getOAuthResolveUrl(mcpOrigin) {
|
|
947
|
+
return `${appOriginForMcpOrigin2(mcpOrigin)}/api/mcp/oauth/resolve`;
|
|
929
948
|
}
|
|
930
|
-
async function resolveOAuthAccessToken(accessToken) {
|
|
949
|
+
async function resolveOAuthAccessToken(accessToken, mcpOrigin) {
|
|
931
950
|
const resolveSecret = process.env.SUPERSENDTX_MCP_RESOLVE_SECRET?.trim() || process.env.SUPERSENDTX_CREDENTIALS_ENCRYPTION_KEY?.trim() || (process.env.NODE_ENV === "production" ? "" : "supersendtx-dev-mcp-resolve");
|
|
932
951
|
if (!resolveSecret) return null;
|
|
933
|
-
const response = await fetch(getOAuthResolveUrl(), {
|
|
952
|
+
const response = await fetch(getOAuthResolveUrl(mcpOrigin), {
|
|
934
953
|
method: "POST",
|
|
935
954
|
headers: {
|
|
936
955
|
authorization: `Bearer ${accessToken}`,
|
|
@@ -965,11 +984,11 @@ function getRequestOrigin(req) {
|
|
|
965
984
|
const proto = firstHeaderValue(req.headers["x-forwarded-proto"]) || "http";
|
|
966
985
|
return `${proto}://${host}`;
|
|
967
986
|
}
|
|
968
|
-
async function resolveApiKeyFromAuthorization(authorization, baseUrl) {
|
|
987
|
+
async function resolveApiKeyFromAuthorization(authorization, baseUrl, mcpOrigin) {
|
|
969
988
|
const bearer = parseBearerToken(authorization);
|
|
970
989
|
if (!bearer) return null;
|
|
971
990
|
if (isSuperSendTxApiKey(bearer)) return bearer;
|
|
972
|
-
return resolveOAuthAccessToken(bearer);
|
|
991
|
+
return resolveOAuthAccessToken(bearer, mcpOrigin);
|
|
973
992
|
}
|
|
974
993
|
async function handleHttpRequest(req, res, options = {}) {
|
|
975
994
|
const origin = getRequestOrigin(req);
|
|
@@ -999,7 +1018,8 @@ async function handleHttpRequest(req, res, options = {}) {
|
|
|
999
1018
|
}
|
|
1000
1019
|
const apiKey = await resolveApiKeyFromAuthorization(
|
|
1001
1020
|
typeof req.headers.authorization === "string" ? req.headers.authorization : void 0,
|
|
1002
|
-
options.baseUrl
|
|
1021
|
+
options.baseUrl,
|
|
1022
|
+
origin
|
|
1003
1023
|
);
|
|
1004
1024
|
if (!apiKey) {
|
|
1005
1025
|
sendJson(
|