@kadoa/mcp 0.3.7-rc.3 → 0.3.7-rc.5
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 +36 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -49072,9 +49072,11 @@ function resolveApiKey(apiKey) {
|
|
|
49072
49072
|
}
|
|
49073
49073
|
function createKadoaClient(auth) {
|
|
49074
49074
|
let client;
|
|
49075
|
+
let teamId;
|
|
49075
49076
|
if (typeof auth === "object" && auth !== null) {
|
|
49076
49077
|
if ("jwt" in auth) {
|
|
49077
49078
|
client = new KadoaClient({ bearerToken: auth.jwt });
|
|
49079
|
+
teamId = auth.teamId;
|
|
49078
49080
|
} else {
|
|
49079
49081
|
client = new KadoaClient({ apiKey: auth.apiKey });
|
|
49080
49082
|
}
|
|
@@ -49083,6 +49085,9 @@ function createKadoaClient(auth) {
|
|
|
49083
49085
|
}
|
|
49084
49086
|
client.axiosInstance.interceptors.request.use((config2) => {
|
|
49085
49087
|
config2.headers["x-kadoa-source"] = "mcp";
|
|
49088
|
+
if (teamId) {
|
|
49089
|
+
config2.headers["x-team-id"] = teamId;
|
|
49090
|
+
}
|
|
49086
49091
|
return config2;
|
|
49087
49092
|
});
|
|
49088
49093
|
return client;
|
|
@@ -49116,6 +49121,19 @@ function saveConfig(config2) {
|
|
|
49116
49121
|
mkdirSync2(dirname2(configFile), { recursive: true });
|
|
49117
49122
|
writeFileSync2(configFile, JSON.stringify(config2, null, 2), "utf-8");
|
|
49118
49123
|
}
|
|
49124
|
+
function decodeJwtClaims(jwt2) {
|
|
49125
|
+
try {
|
|
49126
|
+
const payload = JSON.parse(Buffer.from(jwt2.split(".")[1], "base64url").toString());
|
|
49127
|
+
return {
|
|
49128
|
+
sub: payload.sub,
|
|
49129
|
+
email: payload.email,
|
|
49130
|
+
activeTeamId: payload.active_team_id ?? payload.app_metadata?.active_team_id,
|
|
49131
|
+
exp: payload.exp
|
|
49132
|
+
};
|
|
49133
|
+
} catch {
|
|
49134
|
+
return {};
|
|
49135
|
+
}
|
|
49136
|
+
}
|
|
49119
49137
|
function isJwtExpired(jwt2) {
|
|
49120
49138
|
try {
|
|
49121
49139
|
const payload = JSON.parse(Buffer.from(jwt2.split(".")[1], "base64url").toString());
|
|
@@ -49291,6 +49309,19 @@ function registerTools(server, ctx) {
|
|
|
49291
49309
|
return async (...args) => {
|
|
49292
49310
|
try {
|
|
49293
49311
|
await getValidJwt(ctx);
|
|
49312
|
+
if (ctx.teamId && ctx.supabaseJwt) {
|
|
49313
|
+
const claims = decodeJwtClaims(ctx.supabaseJwt);
|
|
49314
|
+
if (claims.activeTeamId && claims.activeTeamId !== ctx.teamId) {
|
|
49315
|
+
console.error(`[TEAM_SYNC] JWT active_team_id (${claims.activeTeamId}) != ctx.teamId (${ctx.teamId}), calling setActiveTeam + refresh`);
|
|
49316
|
+
await ctx.client.setActiveTeam(ctx.teamId);
|
|
49317
|
+
const newJwt = await refreshSupabaseJwt(ctx);
|
|
49318
|
+
if (newJwt) {
|
|
49319
|
+
console.error(`[TEAM_SYNC] OK: refreshed JWT now has active_team_id=${decodeJwtClaims(newJwt).activeTeamId}`);
|
|
49320
|
+
} else {
|
|
49321
|
+
console.error(`[TEAM_SYNC] WARN: JWT refresh failed after setActiveTeam, request will use stale JWT`);
|
|
49322
|
+
}
|
|
49323
|
+
}
|
|
49324
|
+
}
|
|
49294
49325
|
return await handler(...args);
|
|
49295
49326
|
} catch (error48) {
|
|
49296
49327
|
let message = classifyError(error48);
|
|
@@ -50000,9 +50031,10 @@ function registerTools(server, ctx) {
|
|
|
50000
50031
|
}
|
|
50001
50032
|
await ctx.client.setActiveTeam(match.id);
|
|
50002
50033
|
ctx.teamId = match.id;
|
|
50003
|
-
|
|
50004
|
-
|
|
50005
|
-
|
|
50034
|
+
try {
|
|
50035
|
+
await ctx.persist?.({ teamId: match.id });
|
|
50036
|
+
} catch (e) {
|
|
50037
|
+
console.error("[TEAM_SWITCH] WARN: persist failed:", e);
|
|
50006
50038
|
}
|
|
50007
50039
|
const config2 = loadConfig2();
|
|
50008
50040
|
config2.teamId = match.id;
|
|
@@ -55230,7 +55262,7 @@ function createServer(auth) {
|
|
|
55230
55262
|
let ctx;
|
|
55231
55263
|
if (typeof auth === "object" && auth !== null && "jwt" in auth) {
|
|
55232
55264
|
ctx = {
|
|
55233
|
-
client: createKadoaClient({ jwt: auth.jwt }),
|
|
55265
|
+
client: createKadoaClient({ jwt: auth.jwt, teamId: auth.teamId }),
|
|
55234
55266
|
supabaseJwt: auth.jwt,
|
|
55235
55267
|
supabaseRefreshToken: auth.refreshToken,
|
|
55236
55268
|
teamId: auth.teamId,
|