slimmcp-proxy 0.0.0-stage → 1.0.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/README.md +32 -2
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +201 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/config.d.ts +6 -0
- package/dist/src/config.js +81 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +11 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/indexer.d.ts +22 -0
- package/dist/src/indexer.js +131 -0
- package/dist/src/indexer.js.map +1 -0
- package/dist/src/ledger.d.ts +28 -0
- package/dist/src/ledger.js +106 -0
- package/dist/src/ledger.js.map +1 -0
- package/dist/src/policy.d.ts +81 -0
- package/dist/src/policy.js +148 -0
- package/dist/src/policy.js.map +1 -0
- package/dist/src/redactor.d.ts +2 -0
- package/dist/src/redactor.js +297 -0
- package/dist/src/redactor.js.map +1 -0
- package/dist/src/server.d.ts +45 -0
- package/dist/src/server.js +355 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/tokenizer.d.ts +11 -0
- package/dist/src/tokenizer.js +37 -0
- package/dist/src/tokenizer.js.map +1 -0
- package/dist/src/types.d.ts +80 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/upstream.d.ts +37 -0
- package/dist/src/upstream.js +317 -0
- package/dist/src/upstream.js.map +1 -0
- package/dist/src/version.d.ts +1 -0
- package/dist/src/version.js +23 -0
- package/dist/src/version.js.map +1 -0
- package/package.json +40 -4
- package/slimmcp.config.example.json +24 -0
- package/slimmcp.policy.example.json +19 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ToolIndexer } from './indexer.js';
|
|
2
|
+
import { MetricsLedger } from './ledger.js';
|
|
3
|
+
import { PolicyGuard } from './policy.js';
|
|
4
|
+
import type { RawMcpTool, SlimMcpConfig } from './types.js';
|
|
5
|
+
import { UpstreamManager } from './upstream.js';
|
|
6
|
+
export declare const META_TOOLS: RawMcpTool[];
|
|
7
|
+
export interface SlimProxyRuntimeOptions {
|
|
8
|
+
config: SlimMcpConfig;
|
|
9
|
+
upstream: UpstreamManager;
|
|
10
|
+
indexer: ToolIndexer;
|
|
11
|
+
policyGuard: PolicyGuard;
|
|
12
|
+
ledger: MetricsLedger;
|
|
13
|
+
sessionId: number;
|
|
14
|
+
}
|
|
15
|
+
export declare class SlimProxyCore {
|
|
16
|
+
private opts;
|
|
17
|
+
private sessionBaselineCredited;
|
|
18
|
+
constructor(opts: SlimProxyRuntimeOptions);
|
|
19
|
+
private computeSessionTokensSaved;
|
|
20
|
+
handleListTools(): Promise<{
|
|
21
|
+
tools: RawMcpTool[];
|
|
22
|
+
}>;
|
|
23
|
+
handleCallTool(name: string, rawArgs: unknown): Promise<{
|
|
24
|
+
content: Array<{
|
|
25
|
+
type: string;
|
|
26
|
+
text?: string;
|
|
27
|
+
[k: string]: unknown;
|
|
28
|
+
}>;
|
|
29
|
+
isError?: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
export declare function computeSchemaSavings(serverTools: Array<{
|
|
33
|
+
serverId: string;
|
|
34
|
+
tools: RawMcpTool[];
|
|
35
|
+
}>): {
|
|
36
|
+
rawToolsCount: number;
|
|
37
|
+
rawSchemaBytes: number;
|
|
38
|
+
rawSchemaTokens: number;
|
|
39
|
+
slimToolsCount: number;
|
|
40
|
+
slimExposedBytes: number;
|
|
41
|
+
slimExposedTokens: number;
|
|
42
|
+
tokensSaved: number;
|
|
43
|
+
reductionPercent: number;
|
|
44
|
+
};
|
|
45
|
+
export declare function startStdioProxyServer(core: SlimProxyCore, upstream: UpstreamManager, ledger: MetricsLedger): Promise<void>;
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { redactSecrets } from './redactor.js';
|
|
6
|
+
import { countUtf8Bytes, estimateTokens } from './tokenizer.js';
|
|
7
|
+
import { SLIMMCP_VERSION } from './version.js';
|
|
8
|
+
export const META_TOOLS = [
|
|
9
|
+
{
|
|
10
|
+
name: 'discover_tools',
|
|
11
|
+
description: 'Search connected MCP tools by keyword or intent. Returns compact tool names, 1-line summaries, and required argument names without loading full JSON schemas.',
|
|
12
|
+
inputSchema: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
query: {
|
|
16
|
+
type: 'string',
|
|
17
|
+
description: 'Search keywords or "*" to list tools.'
|
|
18
|
+
},
|
|
19
|
+
server: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'Optional upstream server ID filter.'
|
|
22
|
+
},
|
|
23
|
+
limit: {
|
|
24
|
+
type: 'number',
|
|
25
|
+
description: 'Max results to return (1-25, default 8).'
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
required: ['query']
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'inspect_tool_schema',
|
|
33
|
+
description: 'Fetch the exact JSON inputSchema for a single discovered MCP tool before invoking it.',
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: 'object',
|
|
36
|
+
properties: {
|
|
37
|
+
server: { type: 'string', description: 'Upstream server ID.' },
|
|
38
|
+
tool: { type: 'string', description: 'Exact tool name.' }
|
|
39
|
+
},
|
|
40
|
+
required: ['server', 'tool']
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'invoke_tool',
|
|
45
|
+
description: 'Execute a specific upstream MCP tool with secret redaction and local RBAC policy/spend-cap enforcement.',
|
|
46
|
+
inputSchema: {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: {
|
|
49
|
+
server: { type: 'string', description: 'Upstream server ID.' },
|
|
50
|
+
tool: { type: 'string', description: 'Exact tool name.' },
|
|
51
|
+
arguments: {
|
|
52
|
+
type: 'object',
|
|
53
|
+
description: 'Arguments object matching inspect_tool_schema.'
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
required: ['server', 'tool']
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
const DiscoverInputSchema = z.object({
|
|
61
|
+
query: z.string().default('*'),
|
|
62
|
+
server: z.string().optional(),
|
|
63
|
+
limit: z.number().int().min(1).max(25).optional()
|
|
64
|
+
});
|
|
65
|
+
const InspectInputSchema = z.object({
|
|
66
|
+
server: z.string().min(1),
|
|
67
|
+
tool: z.string().min(1)
|
|
68
|
+
});
|
|
69
|
+
const InvokeInputSchema = z.object({
|
|
70
|
+
server: z.string().min(1),
|
|
71
|
+
tool: z.string().min(1),
|
|
72
|
+
arguments: z.record(z.unknown()).optional()
|
|
73
|
+
});
|
|
74
|
+
export class SlimProxyCore {
|
|
75
|
+
opts;
|
|
76
|
+
sessionBaselineCredited = false;
|
|
77
|
+
constructor(opts) {
|
|
78
|
+
this.opts = opts;
|
|
79
|
+
}
|
|
80
|
+
computeSessionTokensSaved(payloadTokens) {
|
|
81
|
+
if (this.sessionBaselineCredited)
|
|
82
|
+
return 0;
|
|
83
|
+
this.sessionBaselineCredited = true;
|
|
84
|
+
const rawTokens = this.opts.indexer
|
|
85
|
+
.getAllTools()
|
|
86
|
+
.reduce((sum, tool) => sum + tool.rawTokens, 0);
|
|
87
|
+
const slimTokens = estimateTokens({ tools: META_TOOLS });
|
|
88
|
+
return Math.max(0, rawTokens - slimTokens - payloadTokens);
|
|
89
|
+
}
|
|
90
|
+
async handleListTools() {
|
|
91
|
+
return { tools: META_TOOLS };
|
|
92
|
+
}
|
|
93
|
+
async handleCallTool(name, rawArgs) {
|
|
94
|
+
const start = performance.now();
|
|
95
|
+
const { config, upstream, indexer, policyGuard, ledger, sessionId } = this.opts;
|
|
96
|
+
const redactionEnabled = config.redaction?.enabled ?? true;
|
|
97
|
+
const sanitizeError = (msg) => {
|
|
98
|
+
if (!redactionEnabled)
|
|
99
|
+
return { text: msg, count: 0 };
|
|
100
|
+
const res = redactSecrets(msg);
|
|
101
|
+
return { text: res.sanitized, count: res.redactionCount };
|
|
102
|
+
};
|
|
103
|
+
if (name === 'discover_tools') {
|
|
104
|
+
const parsed = DiscoverInputSchema.safeParse(rawArgs ?? {});
|
|
105
|
+
if (!parsed.success) {
|
|
106
|
+
const errText = sanitizeError(`Invalid discover_tools args: ${parsed.error.message}`).text;
|
|
107
|
+
return {
|
|
108
|
+
isError: true,
|
|
109
|
+
content: [{ type: 'text', text: errText }]
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const matches = indexer.search(parsed.data.query, {
|
|
113
|
+
server: parsed.data.server,
|
|
114
|
+
limit: parsed.data.limit
|
|
115
|
+
});
|
|
116
|
+
const rawResponseText = JSON.stringify({
|
|
117
|
+
matches,
|
|
118
|
+
totalIndexedTools: indexer.getAllTools().length
|
|
119
|
+
});
|
|
120
|
+
const redactRes = redactionEnabled ? redactSecrets(rawResponseText) : null;
|
|
121
|
+
const responseText = redactRes ? redactRes.sanitized : rawResponseText;
|
|
122
|
+
const elapsed = performance.now() - start;
|
|
123
|
+
const tokensSaved = this.computeSessionTokensSaved(estimateTokens(responseText));
|
|
124
|
+
ledger.recordEvent({
|
|
125
|
+
sessionId,
|
|
126
|
+
kind: 'discover_tools',
|
|
127
|
+
tokensSaved,
|
|
128
|
+
status: 'allowed',
|
|
129
|
+
latencyMs: elapsed,
|
|
130
|
+
redactionsCount: redactRes?.redactionCount ?? 0
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
content: [
|
|
134
|
+
{
|
|
135
|
+
type: 'text',
|
|
136
|
+
text: responseText
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (name === 'inspect_tool_schema') {
|
|
142
|
+
const parsed = InspectInputSchema.safeParse(rawArgs ?? {});
|
|
143
|
+
if (!parsed.success) {
|
|
144
|
+
const errText = sanitizeError(`Invalid inspect_tool_schema args: ${parsed.error.message}`).text;
|
|
145
|
+
return {
|
|
146
|
+
isError: true,
|
|
147
|
+
content: [{ type: 'text', text: errText }]
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const tool = indexer.getTool(parsed.data.server, parsed.data.tool);
|
|
151
|
+
const elapsed = performance.now() - start;
|
|
152
|
+
if (!tool) {
|
|
153
|
+
ledger.recordEvent({
|
|
154
|
+
sessionId,
|
|
155
|
+
kind: 'inspect_tool_schema',
|
|
156
|
+
serverId: parsed.data.server,
|
|
157
|
+
toolName: parsed.data.tool,
|
|
158
|
+
tokensSaved: 0,
|
|
159
|
+
status: 'error',
|
|
160
|
+
latencyMs: elapsed
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
isError: true,
|
|
164
|
+
content: [
|
|
165
|
+
{
|
|
166
|
+
type: 'text',
|
|
167
|
+
text: `Tool "${parsed.data.server}:${parsed.data.tool}" not found. Call discover_tools first.`
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const rawResponseText = JSON.stringify({
|
|
173
|
+
server: tool.serverId,
|
|
174
|
+
tool: tool.name,
|
|
175
|
+
description: tool.description,
|
|
176
|
+
inputSchema: tool.inputSchema
|
|
177
|
+
});
|
|
178
|
+
const redactRes = redactionEnabled ? redactSecrets(rawResponseText) : null;
|
|
179
|
+
const responseText = redactRes ? redactRes.sanitized : rawResponseText;
|
|
180
|
+
const tokensSaved = this.computeSessionTokensSaved(estimateTokens(responseText));
|
|
181
|
+
ledger.recordEvent({
|
|
182
|
+
sessionId,
|
|
183
|
+
kind: 'inspect_tool_schema',
|
|
184
|
+
serverId: tool.serverId,
|
|
185
|
+
toolName: tool.name,
|
|
186
|
+
tokensSaved,
|
|
187
|
+
status: 'allowed',
|
|
188
|
+
latencyMs: elapsed,
|
|
189
|
+
redactionsCount: redactRes?.redactionCount ?? 0
|
|
190
|
+
});
|
|
191
|
+
return {
|
|
192
|
+
content: [
|
|
193
|
+
{
|
|
194
|
+
type: 'text',
|
|
195
|
+
text: responseText
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (name === 'invoke_tool') {
|
|
201
|
+
const parsed = InvokeInputSchema.safeParse(rawArgs ?? {});
|
|
202
|
+
if (!parsed.success) {
|
|
203
|
+
const errText = sanitizeError(`Invalid invoke_tool args: ${parsed.error.message}`).text;
|
|
204
|
+
return {
|
|
205
|
+
isError: true,
|
|
206
|
+
content: [{ type: 'text', text: errText }]
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
const { server, tool } = parsed.data;
|
|
210
|
+
const indexedTool = indexer.getTool(server, tool);
|
|
211
|
+
if (!indexedTool) {
|
|
212
|
+
return {
|
|
213
|
+
isError: true,
|
|
214
|
+
content: [
|
|
215
|
+
{
|
|
216
|
+
type: 'text',
|
|
217
|
+
text: `Tool "${server}:${tool}" not found. Call discover_tools first.`
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const decision = policyGuard.evaluate(server, tool);
|
|
223
|
+
if (!decision.allowed) {
|
|
224
|
+
const elapsed = performance.now() - start;
|
|
225
|
+
const status = decision.code === 'DENIED_BY_POLICY'
|
|
226
|
+
? 'blocked_policy'
|
|
227
|
+
: 'blocked_cap';
|
|
228
|
+
ledger.recordEvent({
|
|
229
|
+
sessionId,
|
|
230
|
+
kind: 'invoke_tool',
|
|
231
|
+
serverId: server,
|
|
232
|
+
toolName: tool,
|
|
233
|
+
tokensSaved: 0,
|
|
234
|
+
status,
|
|
235
|
+
latencyMs: elapsed
|
|
236
|
+
});
|
|
237
|
+
return {
|
|
238
|
+
isError: true,
|
|
239
|
+
content: [{ type: 'text', text: `[${decision.code}] ${decision.reason}` }]
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
const redactInputs = redactionEnabled && (config.redaction?.redactInputs ?? true);
|
|
243
|
+
const redactOutputs = redactionEnabled && (config.redaction?.redactOutputs ?? true);
|
|
244
|
+
let callArgs = parsed.data.arguments ?? {};
|
|
245
|
+
let redactionsCount = 0;
|
|
246
|
+
if (redactInputs) {
|
|
247
|
+
const res = redactSecrets(callArgs);
|
|
248
|
+
callArgs = res.sanitized;
|
|
249
|
+
redactionsCount += res.redactionCount;
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
let upstreamResult = await upstream.callTool(server, tool, callArgs);
|
|
253
|
+
if (redactOutputs) {
|
|
254
|
+
const outRes = redactSecrets(upstreamResult);
|
|
255
|
+
upstreamResult = outRes.sanitized;
|
|
256
|
+
redactionsCount += outRes.redactionCount;
|
|
257
|
+
}
|
|
258
|
+
const elapsed = performance.now() - start;
|
|
259
|
+
const tokensSaved = this.computeSessionTokensSaved(0);
|
|
260
|
+
ledger.recordEvent({
|
|
261
|
+
sessionId,
|
|
262
|
+
kind: 'invoke_tool',
|
|
263
|
+
serverId: server,
|
|
264
|
+
toolName: tool,
|
|
265
|
+
tokensSaved,
|
|
266
|
+
status: 'allowed',
|
|
267
|
+
latencyMs: elapsed,
|
|
268
|
+
redactionsCount
|
|
269
|
+
});
|
|
270
|
+
return upstreamResult;
|
|
271
|
+
}
|
|
272
|
+
catch (err) {
|
|
273
|
+
const elapsed = performance.now() - start;
|
|
274
|
+
const rawErr = `Upstream error calling ${server}:${tool}: ${err instanceof Error ? err.message : String(err)}`;
|
|
275
|
+
const sanitizedErr = sanitizeError(rawErr);
|
|
276
|
+
redactionsCount += sanitizedErr.count;
|
|
277
|
+
ledger.recordEvent({
|
|
278
|
+
sessionId,
|
|
279
|
+
kind: 'invoke_tool',
|
|
280
|
+
serverId: server,
|
|
281
|
+
toolName: tool,
|
|
282
|
+
tokensSaved: 0,
|
|
283
|
+
status: 'error',
|
|
284
|
+
latencyMs: elapsed,
|
|
285
|
+
redactionsCount
|
|
286
|
+
});
|
|
287
|
+
return {
|
|
288
|
+
isError: true,
|
|
289
|
+
content: [
|
|
290
|
+
{
|
|
291
|
+
type: 'text',
|
|
292
|
+
text: sanitizedErr.text
|
|
293
|
+
}
|
|
294
|
+
]
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
isError: true,
|
|
300
|
+
content: [{ type: 'text', text: `Unknown meta-tool "${name}".` }]
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
export function computeSchemaSavings(serverTools) {
|
|
305
|
+
const allRawTools = serverTools.flatMap((s) => s.tools);
|
|
306
|
+
const rawPayload = { tools: allRawTools };
|
|
307
|
+
const slimPayload = { tools: META_TOOLS };
|
|
308
|
+
const rawSchemaBytes = countUtf8Bytes(rawPayload);
|
|
309
|
+
const rawSchemaTokens = estimateTokens(rawPayload);
|
|
310
|
+
const slimExposedBytes = countUtf8Bytes(slimPayload);
|
|
311
|
+
const slimExposedTokens = estimateTokens(slimPayload);
|
|
312
|
+
const tokensSaved = Math.max(0, rawSchemaTokens - slimExposedTokens);
|
|
313
|
+
const reductionPercent = rawSchemaTokens > 0
|
|
314
|
+
? Number(((tokensSaved / rawSchemaTokens) * 100).toFixed(2))
|
|
315
|
+
: 0;
|
|
316
|
+
return {
|
|
317
|
+
rawToolsCount: allRawTools.length,
|
|
318
|
+
rawSchemaBytes,
|
|
319
|
+
rawSchemaTokens,
|
|
320
|
+
slimToolsCount: META_TOOLS.length,
|
|
321
|
+
slimExposedBytes,
|
|
322
|
+
slimExposedTokens,
|
|
323
|
+
tokensSaved,
|
|
324
|
+
reductionPercent
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
export async function startStdioProxyServer(core, upstream, ledger) {
|
|
328
|
+
const server = new Server({ name: 'slimmcp-proxy', version: SLIMMCP_VERSION }, { capabilities: { tools: {} } });
|
|
329
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
330
|
+
return core.handleListTools();
|
|
331
|
+
});
|
|
332
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
333
|
+
return core.handleCallTool(request.params.name, request.params.arguments);
|
|
334
|
+
});
|
|
335
|
+
const transport = new StdioServerTransport();
|
|
336
|
+
let closed = false;
|
|
337
|
+
const shutdown = async () => {
|
|
338
|
+
if (closed)
|
|
339
|
+
return;
|
|
340
|
+
closed = true;
|
|
341
|
+
await upstream.closeAll();
|
|
342
|
+
ledger.close();
|
|
343
|
+
process.exit(0);
|
|
344
|
+
};
|
|
345
|
+
server.onclose = () => {
|
|
346
|
+
void shutdown();
|
|
347
|
+
};
|
|
348
|
+
process.stdin.on('end', () => {
|
|
349
|
+
void shutdown();
|
|
350
|
+
});
|
|
351
|
+
process.on('SIGINT', () => void shutdown());
|
|
352
|
+
process.on('SIGTERM', () => void shutdown());
|
|
353
|
+
await server.connect(transport);
|
|
354
|
+
}
|
|
355
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,CAAC,MAAM,UAAU,GAAiB;IACtC;QACE,IAAI,EAAE,gBAAgB;QACtB,WAAW,EACT,+JAA+J;QACjK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,OAAO,GAAG,GAAG,EAAE;QACpB,KAAK,QAAQ,EAAE,CAAC;IAClB,CAAC,CAAC;IACF,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;QAC3B,KAAK,QAAQ,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAC;IAC5C,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAC;IAE7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic UTF-8 byte & heuristic token estimator (~4 UTF-8 bytes per token).
|
|
3
|
+
* Always reports exact UTF-8 byte counts alongside heuristic token estimates.
|
|
4
|
+
*/
|
|
5
|
+
export declare function countUtf8Bytes(value: unknown): number;
|
|
6
|
+
export declare function estimateTokens(value: unknown): number;
|
|
7
|
+
export declare function compactToolSummary(description: string | undefined, inputSchema: Record<string, unknown> | undefined): {
|
|
8
|
+
summary: string;
|
|
9
|
+
requiredArgs: string[];
|
|
10
|
+
optionalArgCount: number;
|
|
11
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic UTF-8 byte & heuristic token estimator (~4 UTF-8 bytes per token).
|
|
3
|
+
* Always reports exact UTF-8 byte counts alongside heuristic token estimates.
|
|
4
|
+
*/
|
|
5
|
+
export function countUtf8Bytes(value) {
|
|
6
|
+
const serialized = typeof value === 'string' ? value : JSON.stringify(value ?? '');
|
|
7
|
+
return Buffer.byteLength(serialized, 'utf8');
|
|
8
|
+
}
|
|
9
|
+
export function estimateTokens(value) {
|
|
10
|
+
const bytes = countUtf8Bytes(value);
|
|
11
|
+
if (bytes === 0)
|
|
12
|
+
return 0;
|
|
13
|
+
return Math.ceil(bytes / 4);
|
|
14
|
+
}
|
|
15
|
+
export function compactToolSummary(description, inputSchema) {
|
|
16
|
+
const cleanDesc = (description ?? '')
|
|
17
|
+
.replace(/\s+/g, ' ')
|
|
18
|
+
.trim();
|
|
19
|
+
const firstSentence = cleanDesc.split(/(?<=[.!?])\s+/)[0] ?? cleanDesc;
|
|
20
|
+
const summary = firstSentence.length > 140
|
|
21
|
+
? `${firstSentence.slice(0, 137)}...`
|
|
22
|
+
: firstSentence || 'No description provided.';
|
|
23
|
+
const props = inputSchema && typeof inputSchema.properties === 'object' && inputSchema.properties !== null
|
|
24
|
+
? Object.keys(inputSchema.properties)
|
|
25
|
+
: [];
|
|
26
|
+
const requiredSet = new Set(Array.isArray(inputSchema?.required)
|
|
27
|
+
? inputSchema.required.filter((r) => typeof r === 'string')
|
|
28
|
+
: []);
|
|
29
|
+
const requiredArgs = props.filter((p) => requiredSet.has(p));
|
|
30
|
+
for (const r of requiredSet) {
|
|
31
|
+
if (!requiredArgs.includes(r))
|
|
32
|
+
requiredArgs.push(r);
|
|
33
|
+
}
|
|
34
|
+
const optionalArgCount = Math.max(0, props.length - requiredArgs.length);
|
|
35
|
+
return { summary, requiredArgs, optionalArgCount };
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=tokenizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenizer.js","sourceRoot":"","sources":["../../src/tokenizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,UAAU,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IACnF,OAAO,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,cAA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KAAK,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;QAC5B,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;YAAE,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;IACD,MAAM,gBAAgB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IAEzE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export interface UpstreamServerConfig {
|
|
2
|
+
id: string;
|
|
3
|
+
transport?: 'stdio' | 'streamable-http' | 'sse';
|
|
4
|
+
command?: string;
|
|
5
|
+
args?: string[];
|
|
6
|
+
env?: Record<string, string>;
|
|
7
|
+
envAllowlist?: string[];
|
|
8
|
+
cwd?: string;
|
|
9
|
+
url?: string;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
connectTimeoutMs?: number;
|
|
12
|
+
requestTimeoutMs?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SlimMcpConfig {
|
|
15
|
+
servers: UpstreamServerConfig[];
|
|
16
|
+
redaction?: {
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
redactInputs?: boolean;
|
|
19
|
+
redactOutputs?: boolean;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface RawMcpTool {
|
|
23
|
+
name: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
inputSchema?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export interface IndexedTool {
|
|
28
|
+
key: string;
|
|
29
|
+
serverId: string;
|
|
30
|
+
name: string;
|
|
31
|
+
description: string;
|
|
32
|
+
summary: string;
|
|
33
|
+
requiredArgs: string[];
|
|
34
|
+
optionalArgCount: number;
|
|
35
|
+
inputSchema: Record<string, unknown>;
|
|
36
|
+
rawBytes: number;
|
|
37
|
+
rawTokens: number;
|
|
38
|
+
}
|
|
39
|
+
export interface ToolMatch {
|
|
40
|
+
server: string;
|
|
41
|
+
tool: string;
|
|
42
|
+
summary: string;
|
|
43
|
+
requiredArgs: string[];
|
|
44
|
+
optionalArgCount: number;
|
|
45
|
+
score: number;
|
|
46
|
+
}
|
|
47
|
+
export interface PolicyRule {
|
|
48
|
+
pattern: string;
|
|
49
|
+
action: 'allow' | 'deny';
|
|
50
|
+
maxCallsPerSession?: number;
|
|
51
|
+
estimatedX402AtomicUsdc?: number;
|
|
52
|
+
}
|
|
53
|
+
export interface PolicyConfig {
|
|
54
|
+
defaultAction: 'allow' | 'deny';
|
|
55
|
+
sessionLimits?: {
|
|
56
|
+
maxCallsPerSession?: number;
|
|
57
|
+
maxX402AtomicUsdcPerSession?: number;
|
|
58
|
+
};
|
|
59
|
+
rules?: PolicyRule[];
|
|
60
|
+
}
|
|
61
|
+
export interface RedactionResult<T = unknown> {
|
|
62
|
+
sanitized: T;
|
|
63
|
+
redactionCount: number;
|
|
64
|
+
matchedRules: string[];
|
|
65
|
+
}
|
|
66
|
+
export interface StatsSummary {
|
|
67
|
+
sessionsCount: number;
|
|
68
|
+
totalEvents: number;
|
|
69
|
+
allowedCalls: number;
|
|
70
|
+
blockedPolicyCalls: number;
|
|
71
|
+
blockedCapCalls: number;
|
|
72
|
+
totalRedactions: number;
|
|
73
|
+
latestRawSchemaBytes: number;
|
|
74
|
+
latestRawSchemaTokens: number;
|
|
75
|
+
latestSlimExposedBytes: number;
|
|
76
|
+
latestSlimExposedTokens: number;
|
|
77
|
+
latestReductionPercent: number;
|
|
78
|
+
cumulativeTokensSaved: number;
|
|
79
|
+
avgLatencyMs: number;
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RawMcpTool, UpstreamServerConfig } from './types.js';
|
|
2
|
+
export declare const DEFAULT_CONNECT_TIMEOUT_MS = 15000;
|
|
3
|
+
export declare const DEFAULT_REQUEST_TIMEOUT_MS = 30000;
|
|
4
|
+
export declare const DEFAULT_ENV_ALLOWLIST: readonly ["PATH", "HOME", "USERPROFILE", "SYSTEMROOT", "COMSPEC", "TMP", "TEMP", "LANG", "NODE_ENV"];
|
|
5
|
+
export interface UpstreamManagerOptions {
|
|
6
|
+
connectTimeoutMs?: number;
|
|
7
|
+
requestTimeoutMs?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Builds an isolated child environment using only a minimal safe allowlist,
|
|
11
|
+
* optional per-server allowlisted keys, and explicit `spec.env` overrides.
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildIsolatedChildEnv(explicitEnv?: Record<string, string>, envAllowlist?: string[], sourceEnv?: NodeJS.ProcessEnv): Record<string, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Validates that an upstream remote URL uses http:/https: and does not target
|
|
16
|
+
* cloud instance metadata or link-local metadata endpoints (including IPv4-mapped IPv6).
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateUpstreamUrl(urlStr: string): URL;
|
|
19
|
+
export declare class UpstreamManager {
|
|
20
|
+
private connections;
|
|
21
|
+
private defaultConnectTimeoutMs;
|
|
22
|
+
private defaultRequestTimeoutMs;
|
|
23
|
+
constructor(options?: UpstreamManagerOptions);
|
|
24
|
+
connectAll(configs: UpstreamServerConfig[]): Promise<Array<{
|
|
25
|
+
serverId: string;
|
|
26
|
+
tools: RawMcpTool[];
|
|
27
|
+
}>>;
|
|
28
|
+
callTool(serverId: string, toolName: string, args: Record<string, unknown>): Promise<{
|
|
29
|
+
content: Array<{
|
|
30
|
+
type: string;
|
|
31
|
+
text?: string;
|
|
32
|
+
[k: string]: unknown;
|
|
33
|
+
}>;
|
|
34
|
+
isError?: boolean;
|
|
35
|
+
}>;
|
|
36
|
+
closeAll(): Promise<void>;
|
|
37
|
+
}
|