isa-auth-mcp 0.0.0-stage → 0.2.2
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.d.ts +2 -0
- package/dist/index.js +351 -0
- package/package.json +37 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/index.ts
|
|
26
|
+
var import_server = require("@modelcontextprotocol/sdk/server/index.js");
|
|
27
|
+
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
28
|
+
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
29
|
+
var crypto = __toESM(require("crypto"));
|
|
30
|
+
function matchPermissionRule(userPermission, requiredRule) {
|
|
31
|
+
if (userPermission === "*" || userPermission === requiredRule) return true;
|
|
32
|
+
const userParts = userPermission.split(":");
|
|
33
|
+
const reqParts = requiredRule.split(":");
|
|
34
|
+
for (let i = 0; i < userParts.length; i++) {
|
|
35
|
+
if (userParts[i] === "*") return true;
|
|
36
|
+
if (i >= reqParts.length || userParts[i] !== reqParts[i]) return false;
|
|
37
|
+
}
|
|
38
|
+
return userParts.length === reqParts.length;
|
|
39
|
+
}
|
|
40
|
+
function resolveInheritedRoles(roles, hierarchy = {}) {
|
|
41
|
+
const result = /* @__PURE__ */ new Set();
|
|
42
|
+
const queue = [...roles];
|
|
43
|
+
while (queue.length > 0) {
|
|
44
|
+
const current = queue.shift();
|
|
45
|
+
if (!result.has(current)) {
|
|
46
|
+
result.add(current);
|
|
47
|
+
const inherited = hierarchy[current] || [];
|
|
48
|
+
queue.push(...inherited);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return Array.from(result);
|
|
52
|
+
}
|
|
53
|
+
function parseSiwe(message) {
|
|
54
|
+
try {
|
|
55
|
+
const lines = message.split("\n");
|
|
56
|
+
const headerLine = lines[0] || "";
|
|
57
|
+
const domainMatch = headerLine.match(/^(.+) wants you to sign in with your Ethereum account:/);
|
|
58
|
+
const domain = domainMatch ? domainMatch[1].trim() : "Unknown";
|
|
59
|
+
const address = lines[1]?.trim() || "";
|
|
60
|
+
let uri = "";
|
|
61
|
+
let chainId = 1;
|
|
62
|
+
let nonce = "";
|
|
63
|
+
let issuedAt = "";
|
|
64
|
+
for (const line of lines) {
|
|
65
|
+
const l = line.trim();
|
|
66
|
+
if (l.startsWith("URI: ")) uri = l.replace("URI: ", "");
|
|
67
|
+
if (l.startsWith("Chain ID: ")) chainId = parseInt(l.replace("Chain ID: ", ""), 10) || 1;
|
|
68
|
+
if (l.startsWith("Nonce: ")) nonce = l.replace("Nonce: ", "");
|
|
69
|
+
if (l.startsWith("Issued At: ")) issuedAt = l.replace("Issued At: ", "");
|
|
70
|
+
}
|
|
71
|
+
return { valid: true, domain, address, chainId, nonce, issuedAt };
|
|
72
|
+
} catch (err) {
|
|
73
|
+
return { valid: false, error: err.message };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
var server = new import_server.Server(
|
|
77
|
+
{
|
|
78
|
+
name: "isa-auth-mcp",
|
|
79
|
+
version: "0.2.2"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
capabilities: {
|
|
83
|
+
tools: {}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
server.setRequestHandler(import_types.ListToolsRequestSchema, async () => {
|
|
88
|
+
return {
|
|
89
|
+
tools: [
|
|
90
|
+
{
|
|
91
|
+
name: "isa_check_permission",
|
|
92
|
+
description: "Evaluates if an agent or user possesses a required permission rule using isa-auth wildcard RBAC and role hierarchy inheritance.",
|
|
93
|
+
inputSchema: {
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: {
|
|
96
|
+
userRoles: {
|
|
97
|
+
type: "array",
|
|
98
|
+
items: { type: "string" },
|
|
99
|
+
description: 'Roles currently assigned to the user/agent (e.g. ["ADMIN", "DEV"])'
|
|
100
|
+
},
|
|
101
|
+
userPermissions: {
|
|
102
|
+
type: "array",
|
|
103
|
+
items: { type: "string" },
|
|
104
|
+
description: 'Explicit permissions granted (e.g. ["users:*", "reports:read"])'
|
|
105
|
+
},
|
|
106
|
+
requiredRule: {
|
|
107
|
+
type: "string",
|
|
108
|
+
description: 'Required permission or role pattern to evaluate (e.g. "users:delete")'
|
|
109
|
+
},
|
|
110
|
+
roleHierarchy: {
|
|
111
|
+
type: "object",
|
|
112
|
+
description: 'Optional role inheritance map (e.g. { "SUPERADMIN": ["ADMIN"], "ADMIN": ["USER"] })'
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
required: ["requiredRule"]
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "isa_inspect_jwt",
|
|
120
|
+
description: "Decodes and inspects a JWT token structure, displaying header, payload, expiration status, remaining TTL, and optional secret verification.",
|
|
121
|
+
inputSchema: {
|
|
122
|
+
type: "object",
|
|
123
|
+
properties: {
|
|
124
|
+
token: {
|
|
125
|
+
type: "string",
|
|
126
|
+
description: "JWT token string to inspect"
|
|
127
|
+
},
|
|
128
|
+
secret: {
|
|
129
|
+
type: "string",
|
|
130
|
+
description: "Optional HMAC-SHA256 secret key to verify token authenticity"
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
required: ["token"]
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: "isa_verify_siwe",
|
|
138
|
+
description: "Parses and validates an Ethereum Sign-In with Ethereum (EIP-4361 SIWE) message format and matches it against an address.",
|
|
139
|
+
inputSchema: {
|
|
140
|
+
type: "object",
|
|
141
|
+
properties: {
|
|
142
|
+
message: {
|
|
143
|
+
type: "string",
|
|
144
|
+
description: "Raw SIWE message string"
|
|
145
|
+
},
|
|
146
|
+
expectedAddress: {
|
|
147
|
+
type: "string",
|
|
148
|
+
description: "Expected Ethereum wallet address (0x...)"
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
required: ["message", "expectedAddress"]
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: "isa_scaffold_provider",
|
|
156
|
+
description: "Generates frontend initialization snippets and environment variable templates for any of the 11 supported authentication providers.",
|
|
157
|
+
inputSchema: {
|
|
158
|
+
type: "object",
|
|
159
|
+
properties: {
|
|
160
|
+
provider: {
|
|
161
|
+
type: "string",
|
|
162
|
+
description: 'Target provider name (e.g. "google", "kakao", "naver", "github", "web3", "passkey", "world")'
|
|
163
|
+
},
|
|
164
|
+
storage: {
|
|
165
|
+
type: "string",
|
|
166
|
+
description: "Storage mode (memory, cookie, dev_insecure_localStorage)"
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
required: ["provider"]
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
server.setRequestHandler(import_types.CallToolRequestSchema, async (request) => {
|
|
176
|
+
const { name, arguments: args } = request.params;
|
|
177
|
+
switch (name) {
|
|
178
|
+
case "isa_check_permission": {
|
|
179
|
+
const userRoles = args?.userRoles || [];
|
|
180
|
+
const userPermissions = args?.userPermissions || [];
|
|
181
|
+
const requiredRule = args?.requiredRule || "";
|
|
182
|
+
const hierarchy = args?.roleHierarchy || {
|
|
183
|
+
SUPERADMIN: ["ADMIN"],
|
|
184
|
+
ADMIN: ["MANAGER", "USER"],
|
|
185
|
+
MANAGER: ["USER"]
|
|
186
|
+
};
|
|
187
|
+
const resolvedRoles = resolveInheritedRoles(userRoles, hierarchy);
|
|
188
|
+
if (resolvedRoles.includes(requiredRule)) {
|
|
189
|
+
return {
|
|
190
|
+
content: [
|
|
191
|
+
{
|
|
192
|
+
type: "text",
|
|
193
|
+
text: JSON.stringify({
|
|
194
|
+
granted: true,
|
|
195
|
+
reason: `Direct role match. Role "${requiredRule}" exists in resolved roles [${resolvedRoles.join(", ")}].`,
|
|
196
|
+
resolvedRoles
|
|
197
|
+
}, null, 2)
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const matchingPerm = userPermissions.find((perm) => matchPermissionRule(perm, requiredRule));
|
|
203
|
+
if (matchingPerm) {
|
|
204
|
+
return {
|
|
205
|
+
content: [
|
|
206
|
+
{
|
|
207
|
+
type: "text",
|
|
208
|
+
text: JSON.stringify({
|
|
209
|
+
granted: true,
|
|
210
|
+
reason: `Permission granted via pattern "${matchingPerm}" matching required rule "${requiredRule}".`,
|
|
211
|
+
matchedPattern: matchingPerm,
|
|
212
|
+
resolvedRoles
|
|
213
|
+
}, null, 2)
|
|
214
|
+
}
|
|
215
|
+
]
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
content: [
|
|
220
|
+
{
|
|
221
|
+
type: "text",
|
|
222
|
+
text: JSON.stringify({
|
|
223
|
+
granted: false,
|
|
224
|
+
reason: `Permission denied. Required rule "${requiredRule}" not satisfied by roles [${resolvedRoles.join(", ")}] or permissions [${userPermissions.join(", ")}].`,
|
|
225
|
+
resolvedRoles
|
|
226
|
+
}, null, 2)
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
case "isa_inspect_jwt": {
|
|
232
|
+
const token = args?.token || "";
|
|
233
|
+
const secret = args?.secret;
|
|
234
|
+
const parts = token.split(".");
|
|
235
|
+
if (parts.length !== 3) {
|
|
236
|
+
return {
|
|
237
|
+
content: [{ type: "text", text: JSON.stringify({ error: "Malformed JWT. Expected 3 dot-separated segments." }, null, 2) }]
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
try {
|
|
241
|
+
const header = JSON.parse(Buffer.from(parts[0], "base64").toString("utf8"));
|
|
242
|
+
const payload = JSON.parse(Buffer.from(parts[1], "base64").toString("utf8"));
|
|
243
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
244
|
+
const exp = payload.exp;
|
|
245
|
+
const isExpired = exp ? exp < now : false;
|
|
246
|
+
const ttlSeconds = exp ? exp - now : null;
|
|
247
|
+
let signatureValid = null;
|
|
248
|
+
if (secret) {
|
|
249
|
+
const dataToSign = `${parts[0]}.${parts[1]}`;
|
|
250
|
+
const expectedSig = crypto.createHmac("sha256", secret).update(dataToSign).digest("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
251
|
+
signatureValid = parts[2] === expectedSig;
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
content: [
|
|
255
|
+
{
|
|
256
|
+
type: "text",
|
|
257
|
+
text: JSON.stringify({
|
|
258
|
+
header,
|
|
259
|
+
payload,
|
|
260
|
+
isExpired,
|
|
261
|
+
ttlSeconds,
|
|
262
|
+
signatureValid
|
|
263
|
+
}, null, 2)
|
|
264
|
+
}
|
|
265
|
+
]
|
|
266
|
+
};
|
|
267
|
+
} catch (err) {
|
|
268
|
+
return {
|
|
269
|
+
content: [{ type: "text", text: JSON.stringify({ error: `Failed to parse JWT: ${err.message}` }, null, 2) }]
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
case "isa_verify_siwe": {
|
|
274
|
+
const message = args?.message || "";
|
|
275
|
+
const expectedAddress = (args?.expectedAddress || "").toLowerCase();
|
|
276
|
+
const parsed = parseSiwe(message);
|
|
277
|
+
if (!parsed.valid) {
|
|
278
|
+
return {
|
|
279
|
+
content: [{ type: "text", text: JSON.stringify({ valid: false, error: parsed.error }, null, 2) }]
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
const addressMatches = parsed.address.toLowerCase() === expectedAddress;
|
|
283
|
+
return {
|
|
284
|
+
content: [
|
|
285
|
+
{
|
|
286
|
+
type: "text",
|
|
287
|
+
text: JSON.stringify({
|
|
288
|
+
valid: addressMatches,
|
|
289
|
+
addressMatches,
|
|
290
|
+
parsed
|
|
291
|
+
}, null, 2)
|
|
292
|
+
}
|
|
293
|
+
]
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
case "isa_scaffold_provider": {
|
|
297
|
+
const provider = args?.provider || "google";
|
|
298
|
+
const storage = args?.storage || "memory";
|
|
299
|
+
const envKeys = {
|
|
300
|
+
google: "VITE_GOOGLE_CLIENT_ID",
|
|
301
|
+
apple: "VITE_APPLE_CLIENT_ID",
|
|
302
|
+
kakao: "VITE_KAKAO_CLIENT_ID",
|
|
303
|
+
naver: "VITE_NAVER_CLIENT_ID",
|
|
304
|
+
github: "VITE_GITHUB_CLIENT_ID",
|
|
305
|
+
discord: "VITE_DISCORD_CLIENT_ID",
|
|
306
|
+
meta: "VITE_META_CLIENT_ID",
|
|
307
|
+
line: "VITE_LINE_CLIENT_ID",
|
|
308
|
+
web3: "VITE_APP_DOMAIN",
|
|
309
|
+
world: "VITE_WORLD_ID_APP_ID",
|
|
310
|
+
passkey: "VITE_PASSKEY_RP_ID"
|
|
311
|
+
};
|
|
312
|
+
const codeSnippet = `import { IsaAuth } from 'isa-auth';
|
|
313
|
+
|
|
314
|
+
const auth = new IsaAuth({
|
|
315
|
+
storage: '${storage}', // 'memory' (Zero XSS) or 'cookie'
|
|
316
|
+
providers: {
|
|
317
|
+
${provider}: {
|
|
318
|
+
clientId: import.meta.env.${envKeys[provider] || "VITE_CLIENT_ID"},
|
|
319
|
+
callbackUrl: window.location.origin + '/callback',
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// Trigger login:
|
|
325
|
+
await auth.signIn('${provider}');
|
|
326
|
+
`;
|
|
327
|
+
return {
|
|
328
|
+
content: [
|
|
329
|
+
{
|
|
330
|
+
type: "text",
|
|
331
|
+
text: JSON.stringify({
|
|
332
|
+
provider,
|
|
333
|
+
requiredEnv: envKeys[provider] || "VITE_CLIENT_ID",
|
|
334
|
+
codeSnippet
|
|
335
|
+
}, null, 2)
|
|
336
|
+
}
|
|
337
|
+
]
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
default:
|
|
341
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
async function run() {
|
|
345
|
+
const transport = new import_stdio.StdioServerTransport();
|
|
346
|
+
await server.connect(transport);
|
|
347
|
+
}
|
|
348
|
+
run().catch((error) => {
|
|
349
|
+
console.error("[isa-auth-mcp] Fatal error:", error);
|
|
350
|
+
process.exit(1);
|
|
351
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isa-auth-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "Model Context Protocol (MCP) server for isa-auth, providing AI agents with RBAC permission checking, JWT inspection, Web3 SIWE verification, and auth scaffolding tools",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"isa-auth-mcp": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup",
|
|
15
|
+
"start": "node ./dist/index.js",
|
|
16
|
+
"type": "tsc --noEmit"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mcp",
|
|
20
|
+
"model-context-protocol",
|
|
21
|
+
"isa-auth",
|
|
22
|
+
"agent",
|
|
23
|
+
"ai",
|
|
24
|
+
"rbac",
|
|
25
|
+
"siwe",
|
|
26
|
+
"jwt",
|
|
27
|
+
"claude-desktop"
|
|
28
|
+
],
|
|
29
|
+
"author": "isa-auth contributors",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@modelcontextprotocol/sdk": "^1.32.1"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^26.6.5",
|
|
36
|
+
"tsup": "^8.5.1",
|
|
37
|
+
"typescript": "^5.8.2"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/README.md
DELETED