@kadoa/mcp 0.3.7-rc.3 → 0.3.7-rc.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/dist/index.js +30 -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,13 @@ 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`);
|
|
49316
|
+
await ctx.client.setActiveTeam(ctx.teamId);
|
|
49317
|
+
}
|
|
49318
|
+
}
|
|
49294
49319
|
return await handler(...args);
|
|
49295
49320
|
} catch (error48) {
|
|
49296
49321
|
let message = classifyError(error48);
|
|
@@ -50000,9 +50025,10 @@ function registerTools(server, ctx) {
|
|
|
50000
50025
|
}
|
|
50001
50026
|
await ctx.client.setActiveTeam(match.id);
|
|
50002
50027
|
ctx.teamId = match.id;
|
|
50003
|
-
|
|
50004
|
-
|
|
50005
|
-
|
|
50028
|
+
try {
|
|
50029
|
+
await ctx.persist?.({ teamId: match.id });
|
|
50030
|
+
} catch (e) {
|
|
50031
|
+
console.error("[TEAM_SWITCH] WARN: persist failed:", e);
|
|
50006
50032
|
}
|
|
50007
50033
|
const config2 = loadConfig2();
|
|
50008
50034
|
config2.teamId = match.id;
|
|
@@ -55230,7 +55256,7 @@ function createServer(auth) {
|
|
|
55230
55256
|
let ctx;
|
|
55231
55257
|
if (typeof auth === "object" && auth !== null && "jwt" in auth) {
|
|
55232
55258
|
ctx = {
|
|
55233
|
-
client: createKadoaClient({ jwt: auth.jwt }),
|
|
55259
|
+
client: createKadoaClient({ jwt: auth.jwt, teamId: auth.teamId }),
|
|
55234
55260
|
supabaseJwt: auth.jwt,
|
|
55235
55261
|
supabaseRefreshToken: auth.refreshToken,
|
|
55236
55262
|
teamId: auth.teamId,
|