@quint-security/core 0.3.0
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/auth-db.d.ts +17 -0
- package/dist/auth-db.d.ts.map +1 -0
- package/dist/auth-db.js +112 -0
- package/dist/auth-db.js.map +1 -0
- package/dist/auth.d.ts +41 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +101 -0
- package/dist/auth.js.map +1 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +143 -0
- package/dist/config.js.map +1 -0
- package/dist/crypto.d.ts +11 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +89 -0
- package/dist/crypto.js.map +1 -0
- package/dist/db.d.ts +31 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +157 -0
- package/dist/db.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/log.d.ts +15 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +36 -0
- package/dist/log.js.map +1 -0
- package/dist/risk.d.ts +72 -0
- package/dist/risk.d.ts.map +1 -0
- package/dist/risk.js +177 -0
- package/dist/risk.js.map +1 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +35 -0
- package/dist/types.js.map +1 -0
- package/package.json +25 -0
- package/src/auth-db.ts +130 -0
- package/src/auth.ts +113 -0
- package/src/config.ts +163 -0
- package/src/crypto.ts +96 -0
- package/src/db.ts +184 -0
- package/src/index.ts +8 -0
- package/src/log.ts +32 -0
- package/src/risk.ts +228 -0
- package/src/types.ts +133 -0
- package/tsconfig.json +9 -0
package/dist/db.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AuditDb = void 0;
|
|
7
|
+
exports.openAuditDb = openAuditDb;
|
|
8
|
+
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
9
|
+
const node_fs_1 = require("node:fs");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
const SCHEMA = `
|
|
12
|
+
CREATE TABLE IF NOT EXISTS audit_log (
|
|
13
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
14
|
+
timestamp TEXT NOT NULL,
|
|
15
|
+
server_name TEXT NOT NULL,
|
|
16
|
+
direction TEXT NOT NULL,
|
|
17
|
+
method TEXT NOT NULL,
|
|
18
|
+
message_id TEXT,
|
|
19
|
+
tool_name TEXT,
|
|
20
|
+
arguments_json TEXT,
|
|
21
|
+
response_json TEXT,
|
|
22
|
+
verdict TEXT NOT NULL,
|
|
23
|
+
risk_score INTEGER,
|
|
24
|
+
risk_level TEXT,
|
|
25
|
+
policy_hash TEXT NOT NULL DEFAULT '',
|
|
26
|
+
prev_hash TEXT NOT NULL DEFAULT '',
|
|
27
|
+
nonce TEXT NOT NULL DEFAULT '',
|
|
28
|
+
signature TEXT NOT NULL,
|
|
29
|
+
public_key TEXT NOT NULL
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
CREATE INDEX IF NOT EXISTS idx_timestamp ON audit_log(timestamp);
|
|
33
|
+
CREATE INDEX IF NOT EXISTS idx_server_name ON audit_log(server_name);
|
|
34
|
+
CREATE INDEX IF NOT EXISTS idx_tool_name ON audit_log(tool_name);
|
|
35
|
+
CREATE INDEX IF NOT EXISTS idx_verdict ON audit_log(verdict);
|
|
36
|
+
`;
|
|
37
|
+
// Migration: add columns if they don't exist (for DBs created before this version)
|
|
38
|
+
const MIGRATIONS = [
|
|
39
|
+
`ALTER TABLE audit_log ADD COLUMN policy_hash TEXT NOT NULL DEFAULT ''`,
|
|
40
|
+
`ALTER TABLE audit_log ADD COLUMN prev_hash TEXT NOT NULL DEFAULT ''`,
|
|
41
|
+
`ALTER TABLE audit_log ADD COLUMN nonce TEXT NOT NULL DEFAULT ''`,
|
|
42
|
+
`ALTER TABLE audit_log ADD COLUMN risk_score INTEGER`,
|
|
43
|
+
`ALTER TABLE audit_log ADD COLUMN risk_level TEXT`,
|
|
44
|
+
];
|
|
45
|
+
class AuditDb {
|
|
46
|
+
db;
|
|
47
|
+
constructor(dbPath) {
|
|
48
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(dbPath), { recursive: true });
|
|
49
|
+
this.db = new better_sqlite3_1.default(dbPath);
|
|
50
|
+
this.db.pragma("journal_mode = WAL");
|
|
51
|
+
this.db.exec(SCHEMA);
|
|
52
|
+
this.migrate();
|
|
53
|
+
}
|
|
54
|
+
migrate() {
|
|
55
|
+
for (const sql of MIGRATIONS) {
|
|
56
|
+
try {
|
|
57
|
+
this.db.exec(sql);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Column already exists — ignore
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** Get the signature of the last entry (for hash chaining) */
|
|
65
|
+
getLastSignature() {
|
|
66
|
+
const row = this.db.prepare("SELECT signature FROM audit_log ORDER BY id DESC LIMIT 1").get();
|
|
67
|
+
return row?.signature ?? null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Atomically read the last signature and insert a new entry.
|
|
71
|
+
* This prevents chain breaks when multiple proxy instances share a DB.
|
|
72
|
+
*/
|
|
73
|
+
insertAtomic(buildEntry) {
|
|
74
|
+
const insertStmt = this.db.prepare(`
|
|
75
|
+
INSERT INTO audit_log
|
|
76
|
+
(timestamp, server_name, direction, method, message_id, tool_name,
|
|
77
|
+
arguments_json, response_json, verdict, risk_score, risk_level,
|
|
78
|
+
policy_hash, prev_hash, nonce, signature, public_key)
|
|
79
|
+
VALUES
|
|
80
|
+
(@timestamp, @server_name, @direction, @method, @message_id, @tool_name,
|
|
81
|
+
@arguments_json, @response_json, @verdict, @risk_score, @risk_level,
|
|
82
|
+
@policy_hash, @prev_hash, @nonce, @signature, @public_key)
|
|
83
|
+
`);
|
|
84
|
+
const lastSigStmt = this.db.prepare("SELECT signature FROM audit_log ORDER BY id DESC LIMIT 1");
|
|
85
|
+
let rowId = 0;
|
|
86
|
+
this.db.transaction(() => {
|
|
87
|
+
const lastRow = lastSigStmt.get();
|
|
88
|
+
const entry = buildEntry(lastRow?.signature ?? null);
|
|
89
|
+
const result = insertStmt.run(entry);
|
|
90
|
+
rowId = result.lastInsertRowid;
|
|
91
|
+
})();
|
|
92
|
+
return rowId;
|
|
93
|
+
}
|
|
94
|
+
insert(entry) {
|
|
95
|
+
const stmt = this.db.prepare(`
|
|
96
|
+
INSERT INTO audit_log
|
|
97
|
+
(timestamp, server_name, direction, method, message_id, tool_name,
|
|
98
|
+
arguments_json, response_json, verdict, risk_score, risk_level,
|
|
99
|
+
policy_hash, prev_hash, nonce, signature, public_key)
|
|
100
|
+
VALUES
|
|
101
|
+
(@timestamp, @server_name, @direction, @method, @message_id, @tool_name,
|
|
102
|
+
@arguments_json, @response_json, @verdict, @risk_score, @risk_level,
|
|
103
|
+
@policy_hash, @prev_hash, @nonce, @signature, @public_key)
|
|
104
|
+
`);
|
|
105
|
+
const result = stmt.run(entry);
|
|
106
|
+
return result.lastInsertRowid;
|
|
107
|
+
}
|
|
108
|
+
getById(id) {
|
|
109
|
+
return this.db.prepare("SELECT * FROM audit_log WHERE id = ?").get(id);
|
|
110
|
+
}
|
|
111
|
+
/** Get entries in ID order (ascending) for chain verification */
|
|
112
|
+
getRange(startId, endId) {
|
|
113
|
+
return this.db.prepare("SELECT * FROM audit_log WHERE id >= ? AND id <= ? ORDER BY id ASC").all(startId, endId);
|
|
114
|
+
}
|
|
115
|
+
/** Get all entries in ID order (ascending) for chain verification */
|
|
116
|
+
getAll() {
|
|
117
|
+
return this.db.prepare("SELECT * FROM audit_log ORDER BY id ASC").all();
|
|
118
|
+
}
|
|
119
|
+
query(opts = {}) {
|
|
120
|
+
const conditions = [];
|
|
121
|
+
const params = {};
|
|
122
|
+
if (opts.server) {
|
|
123
|
+
conditions.push("server_name = @server");
|
|
124
|
+
params.server = opts.server;
|
|
125
|
+
}
|
|
126
|
+
if (opts.tool) {
|
|
127
|
+
conditions.push("tool_name = @tool");
|
|
128
|
+
params.tool = opts.tool;
|
|
129
|
+
}
|
|
130
|
+
if (opts.verdict) {
|
|
131
|
+
conditions.push("verdict = @verdict");
|
|
132
|
+
params.verdict = opts.verdict;
|
|
133
|
+
}
|
|
134
|
+
if (opts.since) {
|
|
135
|
+
conditions.push("timestamp >= @since");
|
|
136
|
+
params.since = opts.since;
|
|
137
|
+
}
|
|
138
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
139
|
+
const limit = opts.limit ?? 100;
|
|
140
|
+
return this.db.prepare(`SELECT * FROM audit_log ${where} ORDER BY id DESC LIMIT ${limit}`).all(params);
|
|
141
|
+
}
|
|
142
|
+
getLast(n) {
|
|
143
|
+
return this.db.prepare("SELECT * FROM audit_log ORDER BY id DESC LIMIT ?").all(n);
|
|
144
|
+
}
|
|
145
|
+
count() {
|
|
146
|
+
const row = this.db.prepare("SELECT COUNT(*) as cnt FROM audit_log").get();
|
|
147
|
+
return row.cnt;
|
|
148
|
+
}
|
|
149
|
+
close() {
|
|
150
|
+
this.db.close();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.AuditDb = AuditDb;
|
|
154
|
+
function openAuditDb(dataDir) {
|
|
155
|
+
return new AuditDb((0, node_path_1.join)(dataDir, "quint.db"));
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=db.js.map
|
package/dist/db.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":";;;;;;AAqLA,kCAEC;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KAAK;QACH,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;CACF;AA1ID,0BA0IC;AAED,SAAgB,WAAW,CAAC,OAAe;IACzC,OAAO,IAAI,OAAO,CAAC,IAAA,gBAAI,EAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./crypto.js";
|
|
3
|
+
export * from "./db.js";
|
|
4
|
+
export * from "./auth-db.js";
|
|
5
|
+
export * from "./auth.js";
|
|
6
|
+
export * from "./config.js";
|
|
7
|
+
export * from "./log.js";
|
|
8
|
+
export * from "./risk.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types.js"), exports);
|
|
18
|
+
__exportStar(require("./crypto.js"), exports);
|
|
19
|
+
__exportStar(require("./db.js"), exports);
|
|
20
|
+
__exportStar(require("./auth-db.js"), exports);
|
|
21
|
+
__exportStar(require("./auth.js"), exports);
|
|
22
|
+
__exportStar(require("./config.js"), exports);
|
|
23
|
+
__exportStar(require("./log.js"), exports);
|
|
24
|
+
__exportStar(require("./risk.js"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,8CAA4B;AAC5B,0CAAwB;AACxB,+CAA6B;AAC7B,4CAA0B;AAC1B,8CAA4B;AAC5B,2CAAyB;AACzB,4CAA0B"}
|
package/dist/log.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const LEVELS: {
|
|
2
|
+
readonly debug: 0;
|
|
3
|
+
readonly info: 1;
|
|
4
|
+
readonly warn: 2;
|
|
5
|
+
readonly error: 3;
|
|
6
|
+
};
|
|
7
|
+
type Level = keyof typeof LEVELS;
|
|
8
|
+
export declare function setLogLevel(level: Level): void;
|
|
9
|
+
export declare function getLogLevel(): Level;
|
|
10
|
+
export declare function logDebug(msg: string): void;
|
|
11
|
+
export declare function logInfo(msg: string): void;
|
|
12
|
+
export declare function logWarn(msg: string): void;
|
|
13
|
+
export declare function logError(msg: string): void;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,MAAM;;;;;CAAoD,CAAC;AACjE,KAAK,KAAK,GAAG,MAAM,OAAO,MAAM,CAAC;AAIjC,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAE9C;AAED,wBAAgB,WAAW,IAAI,KAAK,CAEnC;AAMD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE1C;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEzC;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEzC;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE1C"}
|
package/dist/log.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setLogLevel = setLogLevel;
|
|
4
|
+
exports.getLogLevel = getLogLevel;
|
|
5
|
+
exports.logDebug = logDebug;
|
|
6
|
+
exports.logInfo = logInfo;
|
|
7
|
+
exports.logWarn = logWarn;
|
|
8
|
+
exports.logError = logError;
|
|
9
|
+
const LEVELS = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
10
|
+
let currentLevel = "info";
|
|
11
|
+
function setLogLevel(level) {
|
|
12
|
+
currentLevel = level;
|
|
13
|
+
}
|
|
14
|
+
function getLogLevel() {
|
|
15
|
+
return currentLevel;
|
|
16
|
+
}
|
|
17
|
+
function shouldLog(level) {
|
|
18
|
+
return LEVELS[level] >= LEVELS[currentLevel];
|
|
19
|
+
}
|
|
20
|
+
function logDebug(msg) {
|
|
21
|
+
if (shouldLog("debug"))
|
|
22
|
+
process.stderr.write(`quint [debug]: ${msg}\n`);
|
|
23
|
+
}
|
|
24
|
+
function logInfo(msg) {
|
|
25
|
+
if (shouldLog("info"))
|
|
26
|
+
process.stderr.write(`quint: ${msg}\n`);
|
|
27
|
+
}
|
|
28
|
+
function logWarn(msg) {
|
|
29
|
+
if (shouldLog("warn"))
|
|
30
|
+
process.stderr.write(`quint [warn]: ${msg}\n`);
|
|
31
|
+
}
|
|
32
|
+
function logError(msg) {
|
|
33
|
+
if (shouldLog("error"))
|
|
34
|
+
process.stderr.write(`quint [error]: ${msg}\n`);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=log.js.map
|
package/dist/log.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":";;AAKA,kCAEC;AAED,kCAEC;AAMD,4BAEC;AAED,0BAEC;AAED,0BAEC;AAED,4BAEC;AA/BD,MAAM,MAAM,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAW,CAAC;AAGjE,IAAI,YAAY,GAAU,MAAM,CAAC;AAEjC,SAAgB,WAAW,CAAC,KAAY;IACtC,YAAY,GAAG,KAAK,CAAC;AACvB,CAAC;AAED,SAAgB,WAAW;IACzB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,SAAS,CAAC,KAAY;IAC7B,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC;AAC/C,CAAC;AAED,SAAgB,QAAQ,CAAC,GAAW;IAClC,IAAI,SAAS,CAAC,OAAO,CAAC;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;AAC1E,CAAC;AAED,SAAgB,OAAO,CAAC,GAAW;IACjC,IAAI,SAAS,CAAC,MAAM,CAAC;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;AACjE,CAAC;AAED,SAAgB,OAAO,CAAC,GAAW;IACjC,IAAI,SAAS,CAAC,MAAM,CAAC;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;AACxE,CAAC;AAED,SAAgB,QAAQ,CAAC,GAAW;IAClC,IAAI,SAAS,CAAC,OAAO,CAAC;QAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;AAC1E,CAAC"}
|
package/dist/risk.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Risk scoring engine.
|
|
3
|
+
*
|
|
4
|
+
* Each intercepted action gets a risk score from 0–100.
|
|
5
|
+
* The score is based on:
|
|
6
|
+
* 1. The method being called (tools/call is riskier than tools/list)
|
|
7
|
+
* 2. The tool name (some tools are inherently more dangerous)
|
|
8
|
+
* 3. The arguments (e.g. destructive keywords like "delete", "drop", "rm")
|
|
9
|
+
* 4. Accumulated behavior (repeated high-risk attempts escalate)
|
|
10
|
+
*
|
|
11
|
+
* If the score exceeds a threshold, the action can be:
|
|
12
|
+
* - Flagged for manual approval
|
|
13
|
+
* - Auto-denied
|
|
14
|
+
* - Trigger session/token revocation
|
|
15
|
+
*/
|
|
16
|
+
interface RiskPattern {
|
|
17
|
+
/** Glob pattern for tool name */
|
|
18
|
+
tool: string;
|
|
19
|
+
/** Base risk score for this tool (0-100) */
|
|
20
|
+
baseScore: number;
|
|
21
|
+
}
|
|
22
|
+
export interface RiskScore {
|
|
23
|
+
/** Final score 0-100 (capped) */
|
|
24
|
+
score: number;
|
|
25
|
+
/** Base score from tool pattern match */
|
|
26
|
+
baseScore: number;
|
|
27
|
+
/** Boost from argument analysis */
|
|
28
|
+
argBoost: number;
|
|
29
|
+
/** Boost from repeated high-risk behavior */
|
|
30
|
+
behaviorBoost: number;
|
|
31
|
+
/** Human-readable risk level */
|
|
32
|
+
level: "low" | "medium" | "high" | "critical";
|
|
33
|
+
/** Reasons contributing to the score */
|
|
34
|
+
reasons: string[];
|
|
35
|
+
}
|
|
36
|
+
export interface RiskThresholds {
|
|
37
|
+
/** Score at which action is flagged for review (default 60) */
|
|
38
|
+
flag: number;
|
|
39
|
+
/** Score at which action is auto-denied (default 85) */
|
|
40
|
+
deny: number;
|
|
41
|
+
/** Number of high-risk actions in window before revocation (default 5) */
|
|
42
|
+
revokeAfter: number;
|
|
43
|
+
/** Time window in ms for behavior tracking (default 5 minutes) */
|
|
44
|
+
windowMs: number;
|
|
45
|
+
}
|
|
46
|
+
export declare class RiskEngine {
|
|
47
|
+
private thresholds;
|
|
48
|
+
private tracker;
|
|
49
|
+
private customPatterns;
|
|
50
|
+
constructor(opts?: {
|
|
51
|
+
thresholds?: Partial<RiskThresholds>;
|
|
52
|
+
customPatterns?: RiskPattern[];
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Score a tool call.
|
|
56
|
+
* @param toolName The MCP tool being called
|
|
57
|
+
* @param argsJson JSON string of arguments (optional)
|
|
58
|
+
* @param subjectId Who is making the call (API key ID, session subject, or "anonymous")
|
|
59
|
+
*/
|
|
60
|
+
score(toolName: string, argsJson: string | null, subjectId?: string): RiskScore;
|
|
61
|
+
/**
|
|
62
|
+
* Check if the subject should be revoked based on repeated high-risk behavior.
|
|
63
|
+
*/
|
|
64
|
+
shouldRevoke(subjectId: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Determine the action based on risk score.
|
|
67
|
+
*/
|
|
68
|
+
evaluate(risk: RiskScore): "allow" | "flag" | "deny";
|
|
69
|
+
getThresholds(): RiskThresholds;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=risk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"risk.d.ts","sourceRoot":"","sources":["../src/risk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,UAAU,WAAW;IACnB,iCAAiC;IACjC,IAAI,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+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Risk scoring engine.
|
|
4
|
+
*
|
|
5
|
+
* Each intercepted action gets a risk score from 0–100.
|
|
6
|
+
* The score is based on:
|
|
7
|
+
* 1. The method being called (tools/call is riskier than tools/list)
|
|
8
|
+
* 2. The tool name (some tools are inherently more dangerous)
|
|
9
|
+
* 3. The arguments (e.g. destructive keywords like "delete", "drop", "rm")
|
|
10
|
+
* 4. Accumulated behavior (repeated high-risk attempts escalate)
|
|
11
|
+
*
|
|
12
|
+
* If the score exceeds a threshold, the action can be:
|
|
13
|
+
* - Flagged for manual approval
|
|
14
|
+
* - Auto-denied
|
|
15
|
+
* - Trigger session/token revocation
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.RiskEngine = void 0;
|
|
19
|
+
const DEFAULT_TOOL_RISKS = [
|
|
20
|
+
// Destructive file operations
|
|
21
|
+
{ tool: "Delete*", baseScore: 80 },
|
|
22
|
+
{ tool: "Remove*", baseScore: 80 },
|
|
23
|
+
{ tool: "Rm*", baseScore: 80 },
|
|
24
|
+
// Write operations
|
|
25
|
+
{ tool: "Write*", baseScore: 50 },
|
|
26
|
+
{ tool: "Create*", baseScore: 40 },
|
|
27
|
+
{ tool: "Update*", baseScore: 45 },
|
|
28
|
+
{ tool: "Edit*", baseScore: 45 },
|
|
29
|
+
// Database operations
|
|
30
|
+
{ tool: "*Sql*", baseScore: 60 },
|
|
31
|
+
{ tool: "*Query*", baseScore: 40 },
|
|
32
|
+
{ tool: "*Database*", baseScore: 55 },
|
|
33
|
+
// Execution
|
|
34
|
+
{ tool: "*Execute*", baseScore: 70 },
|
|
35
|
+
{ tool: "*Run*", baseScore: 65 },
|
|
36
|
+
{ tool: "*Shell*", baseScore: 75 },
|
|
37
|
+
{ tool: "*Bash*", baseScore: 75 },
|
|
38
|
+
{ tool: "*Command*", baseScore: 70 },
|
|
39
|
+
// Network
|
|
40
|
+
{ tool: "*Fetch*", baseScore: 35 },
|
|
41
|
+
{ tool: "*Http*", baseScore: 35 },
|
|
42
|
+
{ tool: "*Request*", baseScore: 35 },
|
|
43
|
+
// Read operations (low risk)
|
|
44
|
+
{ tool: "Read*", baseScore: 10 },
|
|
45
|
+
{ tool: "Get*", baseScore: 10 },
|
|
46
|
+
{ tool: "List*", baseScore: 5 },
|
|
47
|
+
{ tool: "Search*", baseScore: 10 },
|
|
48
|
+
];
|
|
49
|
+
// Argument keywords that bump the risk score
|
|
50
|
+
const DANGEROUS_ARG_KEYWORDS = [
|
|
51
|
+
{ pattern: /\bdrop\b/i, boost: 30 },
|
|
52
|
+
{ pattern: /\bdelete\b/i, boost: 25 },
|
|
53
|
+
{ pattern: /\btruncate\b/i, boost: 25 },
|
|
54
|
+
{ pattern: /\brm\s+-rf\b/i, boost: 30 },
|
|
55
|
+
{ pattern: /\bformat\b/i, boost: 20 },
|
|
56
|
+
{ pattern: /\b(sudo|chmod|chown)\b/i, boost: 25 },
|
|
57
|
+
{ pattern: /\bpassword\b/i, boost: 15 },
|
|
58
|
+
{ pattern: /\bsecret\b/i, boost: 15 },
|
|
59
|
+
{ pattern: /\btoken\b/i, boost: 10 },
|
|
60
|
+
{ pattern: /\b(\.env|credentials)\b/i, boost: 20 },
|
|
61
|
+
];
|
|
62
|
+
// ── Risk scoring logic ──────────────────────────────────────────
|
|
63
|
+
const config_js_1 = require("./config.js");
|
|
64
|
+
const DEFAULT_THRESHOLDS = {
|
|
65
|
+
flag: 60,
|
|
66
|
+
deny: 85,
|
|
67
|
+
revokeAfter: 5,
|
|
68
|
+
windowMs: 5 * 60 * 1000,
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* In-memory tracker for repeated high-risk behavior per subject.
|
|
72
|
+
*/
|
|
73
|
+
class BehaviorTracker {
|
|
74
|
+
// subjectId → timestamps of high-risk actions
|
|
75
|
+
history = new Map();
|
|
76
|
+
windowMs;
|
|
77
|
+
constructor(windowMs) {
|
|
78
|
+
this.windowMs = windowMs;
|
|
79
|
+
}
|
|
80
|
+
record(subjectId) {
|
|
81
|
+
const now = Date.now();
|
|
82
|
+
const entries = this.history.get(subjectId) ?? [];
|
|
83
|
+
entries.push(now);
|
|
84
|
+
this.history.set(subjectId, entries);
|
|
85
|
+
}
|
|
86
|
+
/** Count of high-risk actions within the sliding window. */
|
|
87
|
+
count(subjectId) {
|
|
88
|
+
const cutoff = Date.now() - this.windowMs;
|
|
89
|
+
const entries = this.history.get(subjectId) ?? [];
|
|
90
|
+
const recent = entries.filter((t) => t > cutoff);
|
|
91
|
+
// Prune old entries
|
|
92
|
+
this.history.set(subjectId, recent);
|
|
93
|
+
return recent.length;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
class RiskEngine {
|
|
97
|
+
thresholds;
|
|
98
|
+
tracker;
|
|
99
|
+
customPatterns;
|
|
100
|
+
constructor(opts) {
|
|
101
|
+
this.thresholds = { ...DEFAULT_THRESHOLDS, ...opts?.thresholds };
|
|
102
|
+
this.tracker = new BehaviorTracker(this.thresholds.windowMs);
|
|
103
|
+
this.customPatterns = opts?.customPatterns ?? [];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Score a tool call.
|
|
107
|
+
* @param toolName The MCP tool being called
|
|
108
|
+
* @param argsJson JSON string of arguments (optional)
|
|
109
|
+
* @param subjectId Who is making the call (API key ID, session subject, or "anonymous")
|
|
110
|
+
*/
|
|
111
|
+
score(toolName, argsJson, subjectId = "anonymous") {
|
|
112
|
+
const reasons = [];
|
|
113
|
+
let baseScore = 20; // default for unknown tools
|
|
114
|
+
// Check custom patterns first, then defaults
|
|
115
|
+
const allPatterns = [...this.customPatterns, ...DEFAULT_TOOL_RISKS];
|
|
116
|
+
for (const pattern of allPatterns) {
|
|
117
|
+
if ((0, config_js_1.globMatch)(pattern.tool, toolName)) {
|
|
118
|
+
baseScore = pattern.baseScore;
|
|
119
|
+
reasons.push(`tool "${toolName}" matches pattern "${pattern.tool}" (base=${pattern.baseScore})`);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (reasons.length === 0) {
|
|
124
|
+
reasons.push(`tool "${toolName}" — no pattern match, using default base score`);
|
|
125
|
+
}
|
|
126
|
+
// Argument analysis
|
|
127
|
+
let argBoost = 0;
|
|
128
|
+
if (argsJson) {
|
|
129
|
+
for (const kw of DANGEROUS_ARG_KEYWORDS) {
|
|
130
|
+
if (kw.pattern.test(argsJson)) {
|
|
131
|
+
argBoost += kw.boost;
|
|
132
|
+
reasons.push(`argument contains "${kw.pattern.source}" (+${kw.boost})`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Behavior escalation
|
|
137
|
+
let behaviorBoost = 0;
|
|
138
|
+
const recentCount = this.tracker.count(subjectId);
|
|
139
|
+
if (recentCount > 0) {
|
|
140
|
+
// Each prior high-risk action in the window adds 5 points
|
|
141
|
+
behaviorBoost = recentCount * 5;
|
|
142
|
+
reasons.push(`${recentCount} high-risk action(s) in window (+${behaviorBoost})`);
|
|
143
|
+
}
|
|
144
|
+
const raw = baseScore + argBoost + behaviorBoost;
|
|
145
|
+
const score = Math.min(100, Math.max(0, raw));
|
|
146
|
+
const level = score >= this.thresholds.deny ? "critical"
|
|
147
|
+
: score >= this.thresholds.flag ? "high"
|
|
148
|
+
: score >= 30 ? "medium"
|
|
149
|
+
: "low";
|
|
150
|
+
// Record if this was a high-risk action
|
|
151
|
+
if (score >= this.thresholds.flag) {
|
|
152
|
+
this.tracker.record(subjectId);
|
|
153
|
+
}
|
|
154
|
+
return { score, baseScore, argBoost, behaviorBoost, level, reasons };
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Check if the subject should be revoked based on repeated high-risk behavior.
|
|
158
|
+
*/
|
|
159
|
+
shouldRevoke(subjectId) {
|
|
160
|
+
return this.tracker.count(subjectId) >= this.thresholds.revokeAfter;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Determine the action based on risk score.
|
|
164
|
+
*/
|
|
165
|
+
evaluate(risk) {
|
|
166
|
+
if (risk.score >= this.thresholds.deny)
|
|
167
|
+
return "deny";
|
|
168
|
+
if (risk.score >= this.thresholds.flag)
|
|
169
|
+
return "flag";
|
|
170
|
+
return "allow";
|
|
171
|
+
}
|
|
172
|
+
getThresholds() {
|
|
173
|
+
return { ...this.thresholds };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.RiskEngine = RiskEngine;
|
|
177
|
+
//# sourceMappingURL=risk.js.map
|
package/dist/risk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"risk.js","sourceRoot":"","sources":["../src/risk.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAWH,MAAM,kBAAkB,GAAkB;IACxC,8BAA8B;IAC9B,EAAE,IAAI,EAAE,SAAS,EAAQ,SAAS,EAAE,EAAE,EAAE;IACxC,EAAE,IAAI,EAAE,SAAS,EAAQ,SAAS,EAAE,EAAE,EAAE;IACxC,EAAE,IAAI,EAAE,KAAK,EAAY,SAAS,EAAE,EAAE,EAAE;IACxC,mBAAmB;IACnB,EAAE,IAAI,EAAE,QAAQ,EAAS,SAAS,EAAE,EAAE,EAAE;IACxC,EAAE,IAAI,EAAE,SAAS,EAAQ,SAAS,EAAE,EAAE,EAAE;IACxC,EAAE,IAAI,EAAE,SAAS,EAAQ,SAAS,EAAE,EAAE,EAAE;IACxC,EAAE,IAAI,EAAE,OAAO,EAAU,SAAS,EAAE,EAAE,EAAE;IACxC,sBAAsB;IACtB,EAAE,IAAI,EAAE,OAAO,EAAU,SAAS,EAAE,EAAE,EAAE;IACxC,EAAE,IAAI,EAAE,SAAS,EAAQ,SAAS,EAAE,EAAE,EAAE;IACxC,EAAE,IAAI,EAAE,YAAY,EAAK,SAAS,EAAE,EAAE,EAAE;IACxC,YAAY;IACZ,EAAE,IAAI,EAAE,WAAW,EAAM,SAAS,EAAE,EAAE,EAA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AAS,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACvE,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,SAAiB;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;IACtE,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,IAAe;QACtB,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI;YAAE,OAAO,MAAM,CAAC;QACtD,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI;YAAE,OAAO,MAAM,CAAC;QACtD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,aAAa;QACX,OAAO,EAAE,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;IAChC,CAAC;CACF;AA1FD,gCA0FC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export interface JsonRpcRequest {
|
|
2
|
+
jsonrpc: "2.0";
|
|
3
|
+
id?: string | number | null;
|
|
4
|
+
method: string;
|
|
5
|
+
params?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface JsonRpcResponse {
|
|
8
|
+
jsonrpc: "2.0";
|
|
9
|
+
id: string | number | null;
|
|
10
|
+
result?: unknown;
|
|
11
|
+
error?: JsonRpcError;
|
|
12
|
+
}
|
|
13
|
+
export interface JsonRpcError {
|
|
14
|
+
code: number;
|
|
15
|
+
message: string;
|
|
16
|
+
data?: unknown;
|
|
17
|
+
}
|
|
18
|
+
export type JsonRpcMessage = JsonRpcRequest | JsonRpcResponse;
|
|
19
|
+
export interface McpToolCallParams {
|
|
20
|
+
name: string;
|
|
21
|
+
arguments?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
export type Action = "allow" | "deny";
|
|
24
|
+
export type Verdict = "allow" | "deny" | "passthrough";
|
|
25
|
+
export interface ToolRule {
|
|
26
|
+
tool: string;
|
|
27
|
+
action: Action;
|
|
28
|
+
}
|
|
29
|
+
export interface ServerPolicy {
|
|
30
|
+
server: string;
|
|
31
|
+
default_action: Action;
|
|
32
|
+
tools: ToolRule[];
|
|
33
|
+
}
|
|
34
|
+
export interface PolicyConfig {
|
|
35
|
+
version: number;
|
|
36
|
+
data_dir: string;
|
|
37
|
+
log_level: "debug" | "info" | "warn" | "error";
|
|
38
|
+
servers: ServerPolicy[];
|
|
39
|
+
}
|
|
40
|
+
export interface AuditEntry {
|
|
41
|
+
id?: number;
|
|
42
|
+
timestamp: string;
|
|
43
|
+
server_name: string;
|
|
44
|
+
direction: "request" | "response";
|
|
45
|
+
method: string;
|
|
46
|
+
message_id: string | null;
|
|
47
|
+
tool_name: string | null;
|
|
48
|
+
arguments_json: string | null;
|
|
49
|
+
response_json: string | null;
|
|
50
|
+
verdict: Verdict;
|
|
51
|
+
risk_score: number | null;
|
|
52
|
+
risk_level: string | null;
|
|
53
|
+
policy_hash: string;
|
|
54
|
+
prev_hash: string;
|
|
55
|
+
nonce: string;
|
|
56
|
+
signature: string;
|
|
57
|
+
public_key: string;
|
|
58
|
+
}
|
|
59
|
+
export interface ApiKey {
|
|
60
|
+
id: string;
|
|
61
|
+
key_hash: string;
|
|
62
|
+
owner_id: string;
|
|
63
|
+
label: string;
|
|
64
|
+
scopes: string;
|
|
65
|
+
created_at: string;
|
|
66
|
+
expires_at: string | null;
|
|
67
|
+
revoked: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface Session {
|
|
70
|
+
id: string;
|
|
71
|
+
subject_id: string;
|
|
72
|
+
auth_method: string;
|
|
73
|
+
scopes: string;
|
|
74
|
+
issued_at: string;
|
|
75
|
+
expires_at: string;
|
|
76
|
+
revoked: boolean;
|
|
77
|
+
}
|
|
78
|
+
export interface KeyPair {
|
|
79
|
+
publicKey: string;
|
|
80
|
+
privateKey: string;
|
|
81
|
+
}
|
|
82
|
+
export declare function isJsonRpcRequest(msg: unknown): msg is JsonRpcRequest;
|
|
83
|
+
export declare function isJsonRpcResponse(msg: unknown): msg is JsonRpcResponse;
|
|
84
|
+
export declare function isToolCallRequest(msg: JsonRpcRequest): boolean;
|
|
85
|
+
export declare function extractToolInfo(msg: JsonRpcRequest): {
|
|
86
|
+
name: string;
|
|
87
|
+
args: Record<string, unknown>;
|
|
88
|
+
} | null;
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,eAAe,CAAC;AAI9D,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC;AAID,MAAM,MAAM,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AACtC,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,CAAC;AAEvD,MAAM,WAAW,QAAQ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AAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB;AAID,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAID,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CAIpE;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,eAAe,CAItE;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAE9D;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAAG,IAAI,CAQ3G"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ── JSON-RPC types ──────────────────────────────────────────────
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isJsonRpcRequest = isJsonRpcRequest;
|
|
5
|
+
exports.isJsonRpcResponse = isJsonRpcResponse;
|
|
6
|
+
exports.isToolCallRequest = isToolCallRequest;
|
|
7
|
+
exports.extractToolInfo = extractToolInfo;
|
|
8
|
+
// ── Helper: check if message is a JSON-RPC request ──────────────
|
|
9
|
+
function isJsonRpcRequest(msg) {
|
|
10
|
+
if (typeof msg !== "object" || msg === null)
|
|
11
|
+
return false;
|
|
12
|
+
const obj = msg;
|
|
13
|
+
return obj.jsonrpc === "2.0" && typeof obj.method === "string";
|
|
14
|
+
}
|
|
15
|
+
function isJsonRpcResponse(msg) {
|
|
16
|
+
if (typeof msg !== "object" || msg === null)
|
|
17
|
+
return false;
|
|
18
|
+
const obj = msg;
|
|
19
|
+
return obj.jsonrpc === "2.0" && ("result" in obj || "error" in obj);
|
|
20
|
+
}
|
|
21
|
+
function isToolCallRequest(msg) {
|
|
22
|
+
return msg.method === "tools/call";
|
|
23
|
+
}
|
|
24
|
+
function extractToolInfo(msg) {
|
|
25
|
+
if (!isToolCallRequest(msg))
|
|
26
|
+
return null;
|
|
27
|
+
const params = msg.params;
|
|
28
|
+
if (!params?.name)
|
|
29
|
+
return null;
|
|
30
|
+
return {
|
|
31
|
+
name: params.name,
|
|
32
|
+
args: params.arguments ?? {},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=types.js.map
|