@haneinfo/mcp-server 3.5.0 → 4.0.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/README.md +177 -12
- package/dist/admin-access.d.ts +24 -0
- package/dist/admin-access.d.ts.map +1 -0
- package/dist/admin-access.js +54 -0
- package/dist/admin-access.js.map +1 -0
- package/dist/authenticator.d.ts +31 -0
- package/dist/authenticator.d.ts.map +1 -0
- package/dist/authenticator.js +37 -0
- package/dist/authenticator.js.map +1 -0
- package/dist/deployment-config.d.ts +67 -0
- package/dist/deployment-config.d.ts.map +1 -0
- package/dist/deployment-config.js +157 -0
- package/dist/deployment-config.js.map +1 -0
- package/dist/discovery-push.service.d.ts +11 -9
- package/dist/discovery-push.service.d.ts.map +1 -1
- package/dist/discovery-push.service.js +27 -11
- package/dist/discovery-push.service.js.map +1 -1
- package/dist/enabled-resources.d.ts +53 -0
- package/dist/enabled-resources.d.ts.map +1 -0
- package/dist/enabled-resources.js +243 -0
- package/dist/enabled-resources.js.map +1 -0
- package/dist/iam-authenticator.d.ts +29 -0
- package/dist/iam-authenticator.d.ts.map +1 -0
- package/dist/iam-authenticator.js +269 -0
- package/dist/iam-authenticator.js.map +1 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/mcp-tool.registry.d.ts +21 -76
- package/dist/mcp-tool.registry.d.ts.map +1 -1
- package/dist/mcp-tool.registry.js +66 -240
- package/dist/mcp-tool.registry.js.map +1 -1
- package/dist/mcp.controller.d.ts +21 -5
- package/dist/mcp.controller.d.ts.map +1 -1
- package/dist/mcp.controller.js +273 -48
- package/dist/mcp.controller.js.map +1 -1
- package/dist/mcp.module.d.ts +5 -0
- package/dist/mcp.module.d.ts.map +1 -1
- package/dist/mcp.module.js +71 -8
- package/dist/mcp.module.js.map +1 -1
- package/dist/mcp.service.d.ts +31 -18
- package/dist/mcp.service.d.ts.map +1 -1
- package/dist/mcp.service.js +784 -194
- package/dist/mcp.service.js.map +1 -1
- package/dist/pg-rate-limiter.d.ts +46 -0
- package/dist/pg-rate-limiter.d.ts.map +1 -0
- package/dist/pg-rate-limiter.js +161 -0
- package/dist/pg-rate-limiter.js.map +1 -0
- package/dist/plugin.d.ts +41 -4
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +26 -14
- package/dist/plugin.js.map +1 -1
- package/dist/prm.controller.d.ts +17 -0
- package/dist/prm.controller.d.ts.map +1 -0
- package/dist/prm.controller.js +77 -0
- package/dist/prm.controller.js.map +1 -0
- package/dist/protocol-config.d.ts +36 -0
- package/dist/protocol-config.d.ts.map +1 -0
- package/dist/protocol-config.js +142 -0
- package/dist/protocol-config.js.map +1 -0
- package/dist/rate-limit-config.d.ts +25 -0
- package/dist/rate-limit-config.d.ts.map +1 -0
- package/dist/rate-limit-config.js +85 -0
- package/dist/rate-limit-config.js.map +1 -0
- package/dist/rate-limit-http.d.ts +11 -0
- package/dist/rate-limit-http.d.ts.map +1 -0
- package/dist/rate-limit-http.js +68 -0
- package/dist/rate-limit-http.js.map +1 -0
- package/dist/request-state.d.ts +14 -9
- package/dist/request-state.d.ts.map +1 -1
- package/dist/request-state.js +37 -3
- package/dist/request-state.js.map +1 -1
- package/dist/types.d.ts +24 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -1
- package/dist/write-confirmation.d.ts +82 -0
- package/dist/write-confirmation.d.ts.map +1 -0
- package/dist/write-confirmation.js +207 -0
- package/dist/write-confirmation.js.map +1 -0
- package/haneinfo.plugin.json +19 -11
- package/package.json +23 -11
- package/prisma/mcp-rate-limit.prisma +34 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InMemoryConcurrencyLimiter = exports.DEFAULT_MCP_MAX_BODY_BYTES = exports.DEFAULT_MCP_MAX_CONCURRENT_PER_SOURCE = exports.MCP_PROTOCOL_CONFIG = void 0;
|
|
4
|
+
exports.parseExactOrigin = parseExactOrigin;
|
|
5
|
+
exports.loadMcpProtocolConfig = loadMcpProtocolConfig;
|
|
6
|
+
exports.validateOriginHeader = validateOriginHeader;
|
|
7
|
+
exports.MCP_PROTOCOL_CONFIG = Symbol.for('haneinfo.mcp-server.protocol-config');
|
|
8
|
+
exports.DEFAULT_MCP_MAX_CONCURRENT_PER_SOURCE = 20;
|
|
9
|
+
exports.DEFAULT_MCP_MAX_BODY_BYTES = 1_048_576;
|
|
10
|
+
function readPositiveIntEnv(env, name, fallback) {
|
|
11
|
+
const raw = env[name];
|
|
12
|
+
if (raw === undefined) {
|
|
13
|
+
return fallback;
|
|
14
|
+
}
|
|
15
|
+
const trimmed = raw.trim();
|
|
16
|
+
if (!/^[1-9]\d*$/.test(trimmed)) {
|
|
17
|
+
throw new Error(`Invalid ${name}: expected a positive integer, received "${raw}"`);
|
|
18
|
+
}
|
|
19
|
+
const parsed = Number(trimmed);
|
|
20
|
+
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
21
|
+
throw new Error(`Invalid ${name}: expected a safe positive integer, received "${raw}"`);
|
|
22
|
+
}
|
|
23
|
+
return parsed;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Parses and validates a single origin entry (`scheme://host[:port]`).
|
|
27
|
+
* Rejects paths, queries, fragments, userinfo, and wildcards.
|
|
28
|
+
*/
|
|
29
|
+
function parseExactOrigin(raw) {
|
|
30
|
+
if (raw.length === 0 || raw === 'null' || raw.includes('*') || /\s/.test(raw)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const schemeSep = raw.indexOf('://');
|
|
34
|
+
if (schemeSep <= 0) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const afterScheme = raw.slice(schemeSep + 3);
|
|
38
|
+
if (afterScheme.length === 0 ||
|
|
39
|
+
afterScheme.includes('/') ||
|
|
40
|
+
afterScheme.includes('?') ||
|
|
41
|
+
afterScheme.includes('#') ||
|
|
42
|
+
afterScheme.includes('@')) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
let parsed;
|
|
46
|
+
try {
|
|
47
|
+
parsed = new URL(raw);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (parsed.username.length > 0 ||
|
|
56
|
+
parsed.password.length > 0 ||
|
|
57
|
+
parsed.pathname !== '/' ||
|
|
58
|
+
parsed.search.length > 0 ||
|
|
59
|
+
parsed.hash.length > 0 ||
|
|
60
|
+
parsed.origin === 'null') {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return parsed.origin;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Loads and validates protocol-layer configuration from environment variables.
|
|
67
|
+
* Fails fast at startup if `MCP_ALLOWED_ORIGIN_HOSTNAMES` is still set without
|
|
68
|
+
* `MCP_ALLOWED_ORIGINS`, or if any origin / numeric limit is invalid.
|
|
69
|
+
*/
|
|
70
|
+
function loadMcpProtocolConfig(env = process.env) {
|
|
71
|
+
const legacyOrigins = env.MCP_ALLOWED_ORIGIN_HOSTNAMES?.trim();
|
|
72
|
+
const rawOrigins = env.MCP_ALLOWED_ORIGINS?.trim();
|
|
73
|
+
if (legacyOrigins && (!rawOrigins || rawOrigins.length === 0)) {
|
|
74
|
+
throw new Error('MCP_ALLOWED_ORIGIN_HOSTNAMES was removed in @haneinfo/mcp-server 4.0; set MCP_ALLOWED_ORIGINS with full origins (scheme://host[:port]) instead');
|
|
75
|
+
}
|
|
76
|
+
const allowedOrigins = [];
|
|
77
|
+
if (rawOrigins && rawOrigins.length > 0) {
|
|
78
|
+
for (const entry of rawOrigins.split(',')) {
|
|
79
|
+
const trimmed = entry.trim();
|
|
80
|
+
if (trimmed.length === 0)
|
|
81
|
+
continue;
|
|
82
|
+
const normalized = parseExactOrigin(trimmed);
|
|
83
|
+
if (!normalized) {
|
|
84
|
+
throw new Error(`Invalid MCP_ALLOWED_ORIGINS entry "${trimmed}": expected exact scheme://host[:port] without path, query, fragment, or wildcard`);
|
|
85
|
+
}
|
|
86
|
+
allowedOrigins.push(normalized);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
allowedOrigins,
|
|
91
|
+
maxConcurrentPerSource: readPositiveIntEnv(env, 'MCP_MAX_CONCURRENT_PER_SOURCE', exports.DEFAULT_MCP_MAX_CONCURRENT_PER_SOURCE),
|
|
92
|
+
maxBodyBytes: readPositiveIntEnv(env, 'MCP_MAX_BODY_BYTES', exports.DEFAULT_MCP_MAX_BODY_BYTES),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Validates the HTTP `Origin` header against the exact allowed origin list.
|
|
97
|
+
* Requests without an `Origin` header are allowed (non-browser MCP clients).
|
|
98
|
+
* Empty strings, `null`, multiple values, malformed URLs, or non-matching
|
|
99
|
+
* scheme/host/port values are rejected.
|
|
100
|
+
*/
|
|
101
|
+
function validateOriginHeader(originHeader, allowedOrigins) {
|
|
102
|
+
if (originHeader === undefined) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (typeof originHeader !== 'string' || originHeader.includes(',')) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
const normalized = parseExactOrigin(originHeader);
|
|
109
|
+
if (!normalized) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
return allowedOrigins.includes(normalized);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Per-replica in-memory concurrency tracker keyed by source IP + normalized resource path.
|
|
116
|
+
*/
|
|
117
|
+
class InMemoryConcurrencyLimiter {
|
|
118
|
+
constructor() {
|
|
119
|
+
this.active = new Map();
|
|
120
|
+
}
|
|
121
|
+
tryAcquire(key, limit) {
|
|
122
|
+
const current = this.active.get(key) ?? 0;
|
|
123
|
+
if (current >= limit) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
this.active.set(key, current + 1);
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
release(key) {
|
|
130
|
+
const current = this.active.get(key) ?? 0;
|
|
131
|
+
if (current <= 1) {
|
|
132
|
+
this.active.delete(key);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.active.set(key, current - 1);
|
|
136
|
+
}
|
|
137
|
+
count(key) {
|
|
138
|
+
return this.active.get(key) ?? 0;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.InMemoryConcurrencyLimiter = InMemoryConcurrencyLimiter;
|
|
142
|
+
//# sourceMappingURL=protocol-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-config.js","sourceRoot":"","sources":["../src/protocol-config.ts"],"names":[],"mappings":";;;AAmCA,4CAuCC;AAOD,sDAoCC;AAQD,oDAeC;AA5IY,QAAA,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;AAExE,QAAA,qCAAqC,GAAG,EAAE,CAAC;AAC3C,QAAA,0BAA0B,GAAG,SAAS,CAAC;AAQpD,SAAS,kBAAkB,CACzB,GAAuC,EACvC,IAAY,EACZ,QAAgB;IAEhB,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;IACtB,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,4CAA4C,GAAG,GAAG,CAAC,CAAC;IACrF,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AAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACxB,OAAO;QACT,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,GAAW;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;CACF;AAxBD,gEAwBC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const MCP_RATE_LIMIT_CONFIG: unique symbol;
|
|
2
|
+
export interface McpRateLimitBucketConfig {
|
|
3
|
+
readonly limit: number;
|
|
4
|
+
readonly windowSeconds: number;
|
|
5
|
+
}
|
|
6
|
+
export interface McpRateLimitConfig {
|
|
7
|
+
readonly preAuth: McpRateLimitBucketConfig;
|
|
8
|
+
readonly postAuth: McpRateLimitBucketConfig;
|
|
9
|
+
readonly publicMeta: McpRateLimitBucketConfig;
|
|
10
|
+
readonly defaultCost: number;
|
|
11
|
+
readonly toolsCallCost: number;
|
|
12
|
+
readonly timeoutMs: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const DEFAULT_MCP_RATE_LIMIT_CONFIG: McpRateLimitConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Loads and validates rate-limit configuration from environment variables.
|
|
17
|
+
* Throws during startup if any configured value is invalid.
|
|
18
|
+
*/
|
|
19
|
+
export declare function loadMcpRateLimitConfig(env?: Record<string, string | undefined>): McpRateLimitConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Computes the rate-limit cost for an MCP JSON-RPC payload.
|
|
22
|
+
* `tools/call` carries a higher cost than metadata/read methods, and batch arrays sum item costs.
|
|
23
|
+
*/
|
|
24
|
+
export declare function computeMcpRequestCost(body: unknown, config: Pick<McpRateLimitConfig, 'defaultCost' | 'toolsCallCost'>): number;
|
|
25
|
+
//# sourceMappingURL=rate-limit-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit-config.d.ts","sourceRoot":"","sources":["../src/rate-limit-config.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,eAAsD,CAAC;AAEzF,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;IAC3C,QAAQ,CAAC,QAAQ,EAAE,wBAAwB,CAAC;IAC5C,QAAQ,CAAC,UAAU,EAAE,wBAAwB,CAAC;IAC9C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,6BAA6B,EAAE,kBAO3C,CAAC;AAsBF;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,kBAAkB,CAsEpB;AAYD;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,aAAa,GAAG,eAAe,CAAC,GAChE,MAAM,CAYR"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_MCP_RATE_LIMIT_CONFIG = exports.MCP_RATE_LIMIT_CONFIG = void 0;
|
|
4
|
+
exports.loadMcpRateLimitConfig = loadMcpRateLimitConfig;
|
|
5
|
+
exports.computeMcpRequestCost = computeMcpRequestCost;
|
|
6
|
+
exports.MCP_RATE_LIMIT_CONFIG = Symbol.for('haneinfo.mcp-server.rate-limit-config');
|
|
7
|
+
exports.DEFAULT_MCP_RATE_LIMIT_CONFIG = {
|
|
8
|
+
preAuth: { limit: 120, windowSeconds: 60 },
|
|
9
|
+
postAuth: { limit: 120, windowSeconds: 60 },
|
|
10
|
+
publicMeta: { limit: 60, windowSeconds: 60 },
|
|
11
|
+
defaultCost: 1,
|
|
12
|
+
toolsCallCost: 5,
|
|
13
|
+
timeoutMs: 1000,
|
|
14
|
+
};
|
|
15
|
+
function readPositiveIntEnv(env, name, fallback) {
|
|
16
|
+
const raw = env[name];
|
|
17
|
+
if (raw === undefined) {
|
|
18
|
+
return fallback;
|
|
19
|
+
}
|
|
20
|
+
const trimmed = raw.trim();
|
|
21
|
+
if (!/^[1-9]\d*$/.test(trimmed)) {
|
|
22
|
+
throw new Error(`Invalid ${name}: expected a positive integer, received "${raw}"`);
|
|
23
|
+
}
|
|
24
|
+
const parsed = Number(trimmed);
|
|
25
|
+
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
26
|
+
throw new Error(`Invalid ${name}: expected a safe positive integer, received "${raw}"`);
|
|
27
|
+
}
|
|
28
|
+
return parsed;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Loads and validates rate-limit configuration from environment variables.
|
|
32
|
+
* Throws during startup if any configured value is invalid.
|
|
33
|
+
*/
|
|
34
|
+
function loadMcpRateLimitConfig(env = process.env) {
|
|
35
|
+
const preAuth = {
|
|
36
|
+
limit: readPositiveIntEnv(env, 'MCP_RATE_LIMIT_PRE_AUTH_LIMIT', exports.DEFAULT_MCP_RATE_LIMIT_CONFIG.preAuth.limit),
|
|
37
|
+
windowSeconds: readPositiveIntEnv(env, 'MCP_RATE_LIMIT_PRE_AUTH_WINDOW_SECONDS', exports.DEFAULT_MCP_RATE_LIMIT_CONFIG.preAuth.windowSeconds),
|
|
38
|
+
};
|
|
39
|
+
const postAuth = {
|
|
40
|
+
limit: readPositiveIntEnv(env, 'MCP_RATE_LIMIT_POST_AUTH_LIMIT', exports.DEFAULT_MCP_RATE_LIMIT_CONFIG.postAuth.limit),
|
|
41
|
+
windowSeconds: readPositiveIntEnv(env, 'MCP_RATE_LIMIT_POST_AUTH_WINDOW_SECONDS', exports.DEFAULT_MCP_RATE_LIMIT_CONFIG.postAuth.windowSeconds),
|
|
42
|
+
};
|
|
43
|
+
const publicMeta = {
|
|
44
|
+
limit: readPositiveIntEnv(env, 'MCP_RATE_LIMIT_PUBLIC_META_LIMIT', exports.DEFAULT_MCP_RATE_LIMIT_CONFIG.publicMeta.limit),
|
|
45
|
+
windowSeconds: readPositiveIntEnv(env, 'MCP_RATE_LIMIT_PUBLIC_META_WINDOW_SECONDS', exports.DEFAULT_MCP_RATE_LIMIT_CONFIG.publicMeta.windowSeconds),
|
|
46
|
+
};
|
|
47
|
+
const defaultCost = readPositiveIntEnv(env, 'MCP_RATE_LIMIT_DEFAULT_COST', exports.DEFAULT_MCP_RATE_LIMIT_CONFIG.defaultCost);
|
|
48
|
+
const toolsCallCost = readPositiveIntEnv(env, 'MCP_RATE_LIMIT_TOOLS_CALL_COST', exports.DEFAULT_MCP_RATE_LIMIT_CONFIG.toolsCallCost);
|
|
49
|
+
if (toolsCallCost <= defaultCost) {
|
|
50
|
+
throw new Error(`Invalid MCP_RATE_LIMIT_TOOLS_CALL_COST: must be greater than MCP_RATE_LIMIT_DEFAULT_COST (${defaultCost})`);
|
|
51
|
+
}
|
|
52
|
+
const timeoutMs = readPositiveIntEnv(env, 'MCP_RATE_LIMIT_TIMEOUT_MS', exports.DEFAULT_MCP_RATE_LIMIT_CONFIG.timeoutMs);
|
|
53
|
+
return {
|
|
54
|
+
preAuth,
|
|
55
|
+
postAuth,
|
|
56
|
+
publicMeta,
|
|
57
|
+
defaultCost,
|
|
58
|
+
toolsCallCost,
|
|
59
|
+
timeoutMs,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function itemCost(item, config) {
|
|
63
|
+
if (item && typeof item === 'object' && item.method === 'tools/call') {
|
|
64
|
+
return config.toolsCallCost;
|
|
65
|
+
}
|
|
66
|
+
return config.defaultCost;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Computes the rate-limit cost for an MCP JSON-RPC payload.
|
|
70
|
+
* `tools/call` carries a higher cost than metadata/read methods, and batch arrays sum item costs.
|
|
71
|
+
*/
|
|
72
|
+
function computeMcpRequestCost(body, config) {
|
|
73
|
+
if (Array.isArray(body)) {
|
|
74
|
+
if (body.length === 0) {
|
|
75
|
+
return config.defaultCost;
|
|
76
|
+
}
|
|
77
|
+
let total = 0;
|
|
78
|
+
for (const item of body) {
|
|
79
|
+
total += itemCost(item, config);
|
|
80
|
+
}
|
|
81
|
+
return total;
|
|
82
|
+
}
|
|
83
|
+
return itemCost(body, config);
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=rate-limit-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit-config.js","sourceRoot":"","sources":["../src/rate-limit-config.ts"],"names":[],"mappings":";;;AAiDA,wDAwEC;AAgBD,sDAeC;AAxJY,QAAA,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AAgB5E,QAAA,6BAA6B,GAAuB;IAC/D,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE;IAC1C,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE;IAC3C,UAAU,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE;IAC5C,WAAW,EAAE,CAAC;IACd,aAAa,EAAE,CAAC;IAChB,SAAS,EAAE,IAAI;CAChB,CAAC;AAEF,SAAS,kBAAkB,CACzB,GAAuC,EACvC,IAAY,EACZ,QAAgB;IAEhB,MAAM,GAAG,GAAG,GAAG,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QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { McpRateLimiterPort, RateLimitConsumeInput } from '@haneinfo/plugin-api';
|
|
2
|
+
import type { Request, Response } from 'express';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the client IP solely from Express `req.ip` (governed by `trust proxy`).
|
|
5
|
+
* Never parses `X-Forwarded-For` directly.
|
|
6
|
+
*/
|
|
7
|
+
export declare function extractClientIp(req?: Request): string;
|
|
8
|
+
export declare function normalizeRequestPath(req: Request): string;
|
|
9
|
+
export declare function enforceRateLimitOrThrow(rateLimiter: McpRateLimiterPort | undefined, res: Response, input: RateLimitConsumeInput): Promise<void>;
|
|
10
|
+
export declare function enforceRateLimitOrSend(rateLimiter: McpRateLimiterPort | undefined, res: Response, input: RateLimitConsumeInput, sendJson: (res: Response, status: number, body: Record<string, unknown>, headers?: Record<string, string>) => void): Promise<boolean>;
|
|
11
|
+
//# sourceMappingURL=rate-limit-http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit-http.d.ts","sourceRoot":"","sources":["../src/rate-limit-http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EAEtB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,CASrD;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAOzD;AAOD,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,kBAAkB,GAAG,SAAS,EAC3C,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,IAAI,CAAC,CAaf;AAED,wBAAsB,sBAAsB,CAC1C,WAAW,EAAE,kBAAkB,GAAG,SAAS,EAC3C,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,qBAAqB,EAC5B,QAAQ,EAAE,CACR,GAAG,EAAE,QAAQ,EACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAC7B,IAAI,GACR,OAAO,CAAC,OAAO,CAAC,CAoBlB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractClientIp = extractClientIp;
|
|
4
|
+
exports.normalizeRequestPath = normalizeRequestPath;
|
|
5
|
+
exports.enforceRateLimitOrThrow = enforceRateLimitOrThrow;
|
|
6
|
+
exports.enforceRateLimitOrSend = enforceRateLimitOrSend;
|
|
7
|
+
const common_1 = require("@nestjs/common");
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the client IP solely from Express `req.ip` (governed by `trust proxy`).
|
|
10
|
+
* Never parses `X-Forwarded-For` directly.
|
|
11
|
+
*/
|
|
12
|
+
function extractClientIp(req) {
|
|
13
|
+
if (!req) {
|
|
14
|
+
return 'unknown';
|
|
15
|
+
}
|
|
16
|
+
if (typeof req.ip === 'string' && req.ip.length > 0) {
|
|
17
|
+
return req.ip;
|
|
18
|
+
}
|
|
19
|
+
const remoteAddress = req.socket?.remoteAddress;
|
|
20
|
+
return typeof remoteAddress === 'string' && remoteAddress.length > 0 ? remoteAddress : 'unknown';
|
|
21
|
+
}
|
|
22
|
+
function normalizeRequestPath(req) {
|
|
23
|
+
if (typeof req.path === 'string' && req.path.length > 0) {
|
|
24
|
+
return req.path;
|
|
25
|
+
}
|
|
26
|
+
const url = req.originalUrl ?? req.url ?? '';
|
|
27
|
+
const queryIndex = url.indexOf('?');
|
|
28
|
+
return queryIndex >= 0 ? url.slice(0, queryIndex) : url;
|
|
29
|
+
}
|
|
30
|
+
function formatRetryAfter(retryAfterSeconds) {
|
|
31
|
+
const value = retryAfterSeconds === undefined ? 1 : Math.ceil(retryAfterSeconds);
|
|
32
|
+
return String(Math.max(1, value));
|
|
33
|
+
}
|
|
34
|
+
async function enforceRateLimitOrThrow(rateLimiter, res, input) {
|
|
35
|
+
// A missing limiter is treated like an unavailable one: fail closed, never skip the check.
|
|
36
|
+
let result;
|
|
37
|
+
try {
|
|
38
|
+
if (!rateLimiter)
|
|
39
|
+
throw new Error('MCP rate limiter is not configured');
|
|
40
|
+
result = await rateLimiter.consume(input);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
throw new common_1.ServiceUnavailableException({ error: 'rate_limiter_unavailable' });
|
|
44
|
+
}
|
|
45
|
+
if (!result.allowed) {
|
|
46
|
+
res.setHeader('Retry-After', formatRetryAfter(result.retryAfterSeconds));
|
|
47
|
+
throw new common_1.HttpException({ error: 'rate_limited' }, common_1.HttpStatus.TOO_MANY_REQUESTS);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function enforceRateLimitOrSend(rateLimiter, res, input, sendJson) {
|
|
51
|
+
// A missing limiter is treated like an unavailable one: fail closed, never skip the check.
|
|
52
|
+
let result;
|
|
53
|
+
try {
|
|
54
|
+
if (!rateLimiter)
|
|
55
|
+
throw new Error('MCP rate limiter is not configured');
|
|
56
|
+
result = await rateLimiter.consume(input);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
sendJson(res, 503, { error: 'rate_limiter_unavailable' });
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (!result.allowed) {
|
|
63
|
+
sendJson(res, 429, { error: 'rate_limited' }, { 'Retry-After': formatRetryAfter(result.retryAfterSeconds) });
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingUR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AO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,QAAQ,CACN,GAAG,EACH,GAAG,EACH,EAAE,KAAK,EAAE,cAAc,EAAE,EACzB,EAAE,aAAa,EAAE,gBAAgB,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAC9D,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/request-state.d.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import type { ServerContext } from '@modelcontextprotocol/server';
|
|
2
|
+
export declare const DEFAULT_REQUEST_STATE_TTL_SECONDS = 120;
|
|
2
3
|
export interface McpRequestStateOptions {
|
|
3
|
-
/**
|
|
4
|
+
/** At least 32 bytes. Same key must be available to every instance of this app that may
|
|
4
5
|
* receive an echoed requestState (i.e. every replica behind the same deployment). */
|
|
5
6
|
key: Uint8Array;
|
|
6
|
-
/** @default
|
|
7
|
+
/** @default 120 (2 minutes) */
|
|
7
8
|
ttlSeconds?: number;
|
|
8
9
|
/** Handler re-entries a single flow may go through before resume() refuses it.
|
|
9
10
|
* @default 8 */
|
|
10
11
|
maxRounds?: number;
|
|
11
|
-
/** The authenticated caller to bind minted state to
|
|
12
|
-
* `ctx.mcpReq.method`) -- pass the caller's own resolved identity (e.g.
|
|
13
|
-
* McpCallContext.sub from mcp.controller.ts's ApiKeyGuard-validated user), not something
|
|
14
|
-
* read off the SDK's transport-level `ctx.http.authInfo`: that field is populated by
|
|
15
|
-
* whichever transport adapter is in front of a given request (toNodeHandler reading
|
|
16
|
-
* Express's `req.auth`), and a caller-supplied principal is the one binding source that
|
|
17
|
-
* doesn't depend on that propagation path actually running for a given entry point. */
|
|
12
|
+
/** The authenticated caller's subject (`sub`) to bind minted state to. */
|
|
18
13
|
principal: string;
|
|
14
|
+
/** Verified OIDC issuer URL; when paired with `resource`, binds `(method, issuer, subject, resource)`. */
|
|
15
|
+
issuer?: string;
|
|
16
|
+
/** Canonical MCP resource URL; when paired with `issuer`, binds `(method, issuer, subject, resource)`. */
|
|
17
|
+
resource?: string;
|
|
19
18
|
}
|
|
20
19
|
export interface McpMultiRoundStatePayload<T = unknown> {
|
|
21
20
|
round: number;
|
|
@@ -38,4 +37,10 @@ export interface McpRequestStateCodec {
|
|
|
38
37
|
}
|
|
39
38
|
export declare function createMcpRequestStateStore(options: McpRequestStateOptions): McpRequestStateCodec;
|
|
40
39
|
export declare function readMcpRequestStateKey(): Uint8Array | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Non-throwing variant of {@link readMcpRequestStateKey} for server startup:
|
|
42
|
+
* returns `undefined` when `MCP_REQUEST_STATE_KEY` is missing or invalid (< 32 bytes)
|
|
43
|
+
* so the confirmation gate can fail closed with `-32092 confirmation_unavailable`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function tryReadMcpRequestStateKey(): Uint8Array | undefined;
|
|
41
46
|
//# sourceMappingURL=request-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-state.d.ts","sourceRoot":"","sources":["../src/request-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAmBlE,MAAM,WAAW,sBAAsB;IACrC;yFACqF;IACrF,GAAG,EAAE,UAAU,CAAC;IAChB
|
|
1
|
+
{"version":3,"file":"request-state.d.ts","sourceRoot":"","sources":["../src/request-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAmBlE,eAAO,MAAM,iCAAiC,MAAM,CAAC;AAErD,MAAM,WAAW,sBAAsB;IACrC;yFACqF;IACrF,GAAG,EAAE,UAAU,CAAC;IAChB,+BAA+B;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;oBACgB;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,SAAS,EAAE,MAAM,CAAC;IAClB,0GAA0G;IAC1G,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0GAA0G;IAC1G,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,yBAAyB,CAAC,CAAC,GAAG,OAAO;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,CAAC,CAAC;CACT;AAED,qBAAa,8BAA+B,SAAQ,KAAK;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM;gBAAjB,SAAS,EAAE,MAAM;CAIvC;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B;kFAC8E;IAC9E,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAC9E,8CAA8C;IAC9C,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACzD;+EAC2E;IAC3E,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1F;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,sBAAsB,GAAG,oBAAoB,CAmChG;AAMD,wBAAgB,sBAAsB,IAAI,UAAU,GAAG,SAAS,CAU/D;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,IAAI,UAAU,GAAG,SAAS,CAMlE"}
|
package/dist/request-state.js
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.McpRequestStateRoundLimitError = void 0;
|
|
3
|
+
exports.McpRequestStateRoundLimitError = exports.DEFAULT_REQUEST_STATE_TTL_SECONDS = void 0;
|
|
4
4
|
exports.createMcpRequestStateStore = createMcpRequestStateStore;
|
|
5
5
|
exports.readMcpRequestStateKey = readMcpRequestStateKey;
|
|
6
|
+
exports.tryReadMcpRequestStateKey = tryReadMcpRequestStateKey;
|
|
6
7
|
const server_1 = require("@modelcontextprotocol/server");
|
|
8
|
+
/// Wraps the SDK's own `createRequestStateCodec` (protocol revision 2026-07-28's
|
|
9
|
+
/// multi-round-trip `requestState`, spec: basic/patterns/mrtr) with the two properties it
|
|
10
|
+
/// deliberately leaves to the server author: the signing key (sourced from
|
|
11
|
+
/// `MCP_REQUEST_STATE_KEY`, one per app -- same convention as GATEWAY_VAULT_MASTER_KEY) and
|
|
12
|
+
/// a monotonic round counter, since the codec's own `mint`/`verify` are otherwise stateless
|
|
13
|
+
/// and have no way to cap how many times a single flow can re-enter across independent HTTP
|
|
14
|
+
/// requests (its `bind` option only proves the state wasn't forged or replayed under a
|
|
15
|
+
/// different principal/method, not how many times it's been echoed back).
|
|
16
|
+
///
|
|
17
|
+
/// Binding: every minted token is tied to `${method}\0${principal}` (following the SDK's own
|
|
18
|
+
/// documented `bind` pattern, but against the caller-supplied principal rather than
|
|
19
|
+
/// `ctx.http.authInfo` -- see McpRequestStateOptions.principal for why) -- a token minted for
|
|
20
|
+
/// one API key's `tools/call` cannot be resumed by a different key or a different method,
|
|
21
|
+
/// closing the cross-user-replay gap the 038 migration plan described but never actually
|
|
22
|
+
/// implemented.
|
|
23
|
+
exports.DEFAULT_REQUEST_STATE_TTL_SECONDS = 120;
|
|
7
24
|
class McpRequestStateRoundLimitError extends Error {
|
|
8
25
|
constructor(maxRounds) {
|
|
9
26
|
super(`MCP requestState round limit exceeded (max ${maxRounds})`);
|
|
@@ -17,10 +34,14 @@ function createMcpRequestStateStore(options) {
|
|
|
17
34
|
if (!Number.isInteger(maxRounds) || maxRounds <= 0) {
|
|
18
35
|
throw new RangeError('requestState maxRounds must be a positive integer');
|
|
19
36
|
}
|
|
37
|
+
const ttlSeconds = options.ttlSeconds ?? exports.DEFAULT_REQUEST_STATE_TTL_SECONDS;
|
|
38
|
+
const bind = options.issuer !== undefined && options.resource !== undefined
|
|
39
|
+
? (ctx) => JSON.stringify([ctx.mcpReq.method, options.issuer, options.principal, options.resource])
|
|
40
|
+
: (ctx) => `${ctx.mcpReq.method}\0${options.principal}`;
|
|
20
41
|
const codec = (0, server_1.createRequestStateCodec)({
|
|
21
42
|
key: options.key,
|
|
22
|
-
ttlSeconds
|
|
23
|
-
bind
|
|
43
|
+
ttlSeconds,
|
|
44
|
+
bind,
|
|
24
45
|
});
|
|
25
46
|
return {
|
|
26
47
|
maxRounds,
|
|
@@ -55,4 +76,17 @@ function readMcpRequestStateKey() {
|
|
|
55
76
|
}
|
|
56
77
|
return decoded;
|
|
57
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Non-throwing variant of {@link readMcpRequestStateKey} for server startup:
|
|
81
|
+
* returns `undefined` when `MCP_REQUEST_STATE_KEY` is missing or invalid (< 32 bytes)
|
|
82
|
+
* so the confirmation gate can fail closed with `-32092 confirmation_unavailable`.
|
|
83
|
+
*/
|
|
84
|
+
function tryReadMcpRequestStateKey() {
|
|
85
|
+
try {
|
|
86
|
+
return readMcpRequestStateKey();
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
58
92
|
//# sourceMappingURL=request-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-state.js","sourceRoot":"","sources":["../src/request-state.ts"],"names":[],"mappings":";;;AA8DA,
|
|
1
|
+
{"version":3,"file":"request-state.js","sourceRoot":"","sources":["../src/request-state.ts"],"names":[],"mappings":";;;AA8DA,gEAmCC;AAMD,wDAUC;AAOD,8DAMC;AA7HD,yDAAuE;AAEvE,iFAAiF;AACjF,0FAA0F;AAC1F,2EAA2E;AAC3E,4FAA4F;AAC5F,4FAA4F;AAC5F,4FAA4F;AAC5F,uFAAuF;AACvF,0EAA0E;AAC1E,GAAG;AACH,6F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,yBAAyB;IACvC,IAAI,CAAC;QACH,OAAO,sBAAsB,EAAE,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
+
import type { CommandRegistry } from '@haneinfo/commands';
|
|
2
|
+
import type { ConnectorManifest } from '@haneinfo/plugin-api';
|
|
1
3
|
import type { ZodType } from 'zod';
|
|
4
|
+
/** Injection token for {@link McpModuleOptions}. */
|
|
5
|
+
export declare const MCP_COMMANDS_OPTIONS: unique symbol;
|
|
6
|
+
/** Command execution options for `McpModule.forRoot`. */
|
|
7
|
+
export interface McpModuleOptions {
|
|
8
|
+
/** Sealed command registry providing `mcp` and `mcp-admin` tools. */
|
|
9
|
+
commands: CommandRegistry<any>;
|
|
10
|
+
/** Positive integer in milliseconds for step 5 write-transaction `lock_timeout`. */
|
|
11
|
+
lockTimeoutMs: number;
|
|
12
|
+
/** Connector manifest generated by `haneinfo build` (`.haneinfo/generated/connector-manifest.json`). */
|
|
13
|
+
connectorManifest: ConnectorManifest;
|
|
14
|
+
}
|
|
15
|
+
export type McpResourceKind = 'employee' | 'admin';
|
|
2
16
|
export interface McpMultiRoundContext {
|
|
3
17
|
resumed?: {
|
|
4
18
|
data: unknown;
|
|
@@ -8,14 +22,17 @@ export interface McpMultiRoundContext {
|
|
|
8
22
|
requestInput(inputRequests: Record<string, unknown>, data: unknown): Promise<unknown>;
|
|
9
23
|
}
|
|
10
24
|
export interface McpCallContext {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
principalKind?: 'm2m-api-key' | 'mcp-connection';
|
|
14
|
-
roleNames: string[];
|
|
15
|
-
actingUserId: string | null;
|
|
16
|
-
actingUserEmail?: string;
|
|
17
|
-
connectionId?: string;
|
|
25
|
+
kind: McpResourceKind;
|
|
26
|
+
issuer: string;
|
|
18
27
|
sub: string;
|
|
28
|
+
actingUserId: string;
|
|
29
|
+
actingUserEmail?: string;
|
|
30
|
+
resource: string;
|
|
31
|
+
clientId: string;
|
|
32
|
+
authTime: number | null;
|
|
33
|
+
mfa: boolean;
|
|
34
|
+
scopes: readonly string[];
|
|
35
|
+
tokenExp?: number;
|
|
19
36
|
workflowId: string | null;
|
|
20
37
|
}
|
|
21
38
|
export type McpToolCallContext = McpCallContext & {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,oDAAoD;AACpD,eAAO,MAAM,oBAAoB,eAAqD,CAAC;AAEvF,yDAAyD;AACzD,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,QAAQ,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC;IAC/B,oFAAoF;IACpF,aAAa,EAAE,MAAM,CAAC;IACtB,wGAAwG;IACxG,iBAAiB,EAAE,iBAAiB,CAAC;CACtC;AAED,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,OAAO,CAAC;AAOnD,MAAM,WAAW,oBAAoB;IAKnC,OAAO,CAAC,EAAE;QACR,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;QACd,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACzC,CAAC;IACF,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACvF;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAE1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAKlB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAOD,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAAG;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE,CAAC;AAEjF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,kBAAkB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACvE"}
|
package/dist/types.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCP_COMMANDS_OPTIONS = void 0;
|
|
4
|
+
/** Injection token for {@link McpModuleOptions}. */
|
|
5
|
+
exports.MCP_COMMANDS_OPTIONS = Symbol.for('haneinfo.mcp-server.commands-options');
|
|
3
6
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAIA,oDAAoD;AACvC,QAAA,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { AuthorizerTxClient } from '@haneinfo/commands';
|
|
2
|
+
import type { Logger } from '@nestjs/common';
|
|
3
|
+
export declare const CONFIRMATION_UNAVAILABLE_ERROR_CODE = -32092;
|
|
4
|
+
/**
|
|
5
|
+
* Test and tooling DDL. It must stay identical (apart from IF NOT EXISTS) to what
|
|
6
|
+
* `prisma migrate diff --from-empty` generates for prisma/mcp-rate-limit.prisma, which is what
|
|
7
|
+
* App migrations create; prisma-fragment.spec.ts guards the column types and defaults.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MCP_CONFIRMATION_RECEIPTS_TABLE_SQL: string;
|
|
10
|
+
export type ConfirmationReceiptStatus = 'pending' | 'committed' | 'declined' | 'cancelled' | 'expired';
|
|
11
|
+
export interface ConfirmationRequestStatePayload {
|
|
12
|
+
toolName: string;
|
|
13
|
+
schemaVersion: number;
|
|
14
|
+
argsDigest: string;
|
|
15
|
+
operationId: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ConfirmationReceiptRow {
|
|
18
|
+
operationId: string;
|
|
19
|
+
correlationId: string;
|
|
20
|
+
status: ConfirmationReceiptStatus;
|
|
21
|
+
issuer: string;
|
|
22
|
+
subject: string;
|
|
23
|
+
actingUserId: string;
|
|
24
|
+
clientId: string;
|
|
25
|
+
resource: string;
|
|
26
|
+
toolName: string;
|
|
27
|
+
schemaVersion: number;
|
|
28
|
+
argsDigest: string;
|
|
29
|
+
expiresAt: Date;
|
|
30
|
+
resultJson: unknown;
|
|
31
|
+
}
|
|
32
|
+
export interface ExpiredConfirmationReceipt {
|
|
33
|
+
operationId: string;
|
|
34
|
+
correlationId: string;
|
|
35
|
+
issuer: string;
|
|
36
|
+
subject: string;
|
|
37
|
+
actingUserId: string;
|
|
38
|
+
clientId: string;
|
|
39
|
+
resource: string;
|
|
40
|
+
toolName: string;
|
|
41
|
+
}
|
|
42
|
+
export type ConfirmationAuditEventType = 'confirmation_issued' | 'confirmation_accepted' | 'confirmation_declined' | 'confirmation_cancelled' | 'confirmation_expired' | 'confirmation_replayed' | 'confirmation_authz_denied' | 'confirmation_write_succeeded' | 'confirmation_write_failed' | 'confirmation_gate_rejected' | 'confirmation_binding_rejected';
|
|
43
|
+
export interface ConfirmationAuditEvent {
|
|
44
|
+
event: ConfirmationAuditEventType;
|
|
45
|
+
timestamp: string;
|
|
46
|
+
correlationId: string;
|
|
47
|
+
operationId: string | null;
|
|
48
|
+
resource: string;
|
|
49
|
+
issuer: string;
|
|
50
|
+
subject: string;
|
|
51
|
+
actingUserId: string;
|
|
52
|
+
clientId: string;
|
|
53
|
+
toolName: string;
|
|
54
|
+
resultCode: string;
|
|
55
|
+
/** External correlation field only; never proof of identity or confirmation (1A §6). */
|
|
56
|
+
workflowId: string | null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Produces a deterministic canonical JSON representation for normalized tool arguments
|
|
60
|
+
* so `argsDigest` is stable regardless of object key insertion order.
|
|
61
|
+
*/
|
|
62
|
+
export declare function canonicalizeJson(value: unknown): string;
|
|
63
|
+
export declare function computeArgsDigest(normalizedArgs: unknown): string;
|
|
64
|
+
export declare function parseConfirmationRequestStatePayload(raw: unknown): ConfirmationRequestStatePayload | null;
|
|
65
|
+
export declare function insertPendingConfirmationReceipt(tx: AuthorizerTxClient, receipt: Omit<ConfirmationReceiptRow, 'status' | 'resultJson'>): Promise<void>;
|
|
66
|
+
export declare function lockConfirmationReceiptForUpdate(tx: AuthorizerTxClient, operationId: string): Promise<ConfirmationReceiptRow | null>;
|
|
67
|
+
export declare function transitionConfirmationReceipt(tx: AuthorizerTxClient, params: {
|
|
68
|
+
operationId: string;
|
|
69
|
+
nextStatus: Exclude<ConfirmationReceiptStatus, 'pending'>;
|
|
70
|
+
resultJson?: unknown;
|
|
71
|
+
}): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Transitions all `pending` confirmation receipts whose `expires_at <= now` to `expired`
|
|
74
|
+
* using a single atomic `UPDATE ... WHERE status = 'pending'` statement, and optionally emits
|
|
75
|
+
* `confirmation_expired` audit events for each transitioned row.
|
|
76
|
+
*/
|
|
77
|
+
export declare function expirePendingConfirmationReceipts(prisma: AuthorizerTxClient, options?: {
|
|
78
|
+
now?: Date;
|
|
79
|
+
logger?: Logger;
|
|
80
|
+
}): Promise<ExpiredConfirmationReceipt[]>;
|
|
81
|
+
export declare function emitConfirmationAuditEvent(logger: Logger, event: Omit<ConfirmationAuditEvent, 'timestamp'>): void;
|
|
82
|
+
//# sourceMappingURL=write-confirmation.d.ts.map
|