@mappies/miniwat-mcp-core 0.8.0 → 0.10.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/index.cjs +51 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +51 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -41,6 +41,7 @@ var ToolDispatcher = class {
|
|
|
41
41
|
this.servers.push(new import_miniwat_agent_core.McpServer({ name: server, ...service }));
|
|
42
42
|
const pck = await import(service.package);
|
|
43
43
|
for (let t of service.tools) {
|
|
44
|
+
if (t.enabled === false) continue;
|
|
44
45
|
let definition = pck[t.import];
|
|
45
46
|
let tool = new import_miniwat_agent_core.Tool({
|
|
46
47
|
name: definition.name,
|
|
@@ -48,12 +49,61 @@ var ToolDispatcher = class {
|
|
|
48
49
|
schema: definition.inputSchema,
|
|
49
50
|
func: pck[definition.name],
|
|
50
51
|
service: server,
|
|
51
|
-
getInputText: pck[`${definition.name}InputText`]
|
|
52
|
+
getInputText: pck[`${definition.name}InputText`],
|
|
53
|
+
readOnly: definition.readOnly === true,
|
|
54
|
+
requiresApproval: definition.requiresApproval === true,
|
|
55
|
+
executionPolicy: this.resolveExecutionPolicy(server, definition, pck),
|
|
56
|
+
outcomeMapper: this.resolveOutcomeMapper(server, definition, pck)
|
|
52
57
|
});
|
|
53
58
|
this.tools.push(tool);
|
|
54
59
|
}
|
|
55
60
|
}
|
|
56
61
|
}
|
|
62
|
+
// Resolves a tool definition's named executionPolicy from the OWNING package's
|
|
63
|
+
// EXECUTION_POLICIES factory export. Validation is loud and happens at init — never deferred to
|
|
64
|
+
// tool invocation — so the app cannot reach agent.stream() with a partially resolved tool.
|
|
65
|
+
resolveExecutionPolicy(server, definition, pck) {
|
|
66
|
+
const name = definition.executionPolicy;
|
|
67
|
+
if (name === void 0) return void 0;
|
|
68
|
+
const factories = pck.EXECUTION_POLICIES;
|
|
69
|
+
if (factories === void 0 || typeof factories !== "object") {
|
|
70
|
+
throw new Error(`Tool '${definition.name}' on server '${server}' names executionPolicy '${name}' but its package exports no EXECUTION_POLICIES.`);
|
|
71
|
+
}
|
|
72
|
+
const factory = factories[name];
|
|
73
|
+
if (factory === void 0) {
|
|
74
|
+
throw new Error(`Tool '${definition.name}' on server '${server}' names executionPolicy '${name}' not found in the package's EXECUTION_POLICIES.`);
|
|
75
|
+
}
|
|
76
|
+
if (typeof factory !== "function") {
|
|
77
|
+
throw new Error(`EXECUTION_POLICIES['${name}'] on server '${server}' is not a factory function.`);
|
|
78
|
+
}
|
|
79
|
+
const policy = factory();
|
|
80
|
+
if (policy === void 0 || typeof policy.evaluate !== "function") {
|
|
81
|
+
throw new Error(`EXECUTION_POLICIES['${name}'] on server '${server}' did not produce a valid ExecutionPolicy.`);
|
|
82
|
+
}
|
|
83
|
+
return policy;
|
|
84
|
+
}
|
|
85
|
+
// Resolves a tool definition's named outcomeMapper from the OWNING package's OUTCOME_MAPPERS
|
|
86
|
+
// factory export. Validated loudly at init, mirroring resolveExecutionPolicy.
|
|
87
|
+
resolveOutcomeMapper(server, definition, pck) {
|
|
88
|
+
const name = definition.outcomeMapper;
|
|
89
|
+
if (name === void 0) return void 0;
|
|
90
|
+
const factories = pck.OUTCOME_MAPPERS;
|
|
91
|
+
if (factories === void 0 || typeof factories !== "object") {
|
|
92
|
+
throw new Error(`Tool '${definition.name}' on server '${server}' names outcomeMapper '${name}' but its package exports no OUTCOME_MAPPERS.`);
|
|
93
|
+
}
|
|
94
|
+
const factory = factories[name];
|
|
95
|
+
if (factory === void 0) {
|
|
96
|
+
throw new Error(`Tool '${definition.name}' on server '${server}' names outcomeMapper '${name}' not found in the package's OUTCOME_MAPPERS.`);
|
|
97
|
+
}
|
|
98
|
+
if (typeof factory !== "function") {
|
|
99
|
+
throw new Error(`OUTCOME_MAPPERS['${name}'] on server '${server}' is not a factory function.`);
|
|
100
|
+
}
|
|
101
|
+
const mapper = factory();
|
|
102
|
+
if (mapper === void 0 || typeof mapper.map !== "function") {
|
|
103
|
+
throw new Error(`OUTCOME_MAPPERS['${name}'] on server '${server}' did not produce a valid ToolOutcomeMapper.`);
|
|
104
|
+
}
|
|
105
|
+
return mapper;
|
|
106
|
+
}
|
|
57
107
|
async list() {
|
|
58
108
|
await this.init();
|
|
59
109
|
return this.tools;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/entities/toolDispatcher.ts"],"sourcesContent":["export { ToolDispatcher } from './entities/toolDispatcher';","import { Tool, McpServer } from \"@mappies/miniwat-agent-core\";\nimport { McpConfig } from \"../interfaces/mcpConfig\";\n\nexport class ToolDispatcher\n{\n private tools:Tool[]\n private servers:McpServer[]\n\n constructor(private mcp?:McpConfig)\n {\n this.tools = []\n this.servers = []\n }\n\n async init()\n {\n if(this.tools.length !== 0) return;\n\n this.tools = [];\n\n if(this.mcp === undefined) return;\n\n for(let server of Object.keys(this.mcp.mcpServers))\n {\n let service = this.mcp.mcpServers[server]\n\n this.servers.push(new McpServer({name: server, ...service}))\n \n const pck = await import(service.package);\n for(let t of service.tools)\n {\n let definition = pck[t.import];\n let tool = new Tool({ \n name: definition.name, \n description: definition.description, \n schema: definition.inputSchema, \n func: pck[definition.name],\n service: server,\n getInputText: pck[`${definition.name}InputText`]\n })\n \n this.tools.push(tool)\n }\n }\n }\n\n async list(): Promise<Tool[]>\n {\n await this.init()\n return this.tools;\n }\n\n async listServers(): Promise<McpServer[]>\n {\n await this.init()\n return this.servers;\n }\n\n async get(name:string): Promise<Tool|undefined>\n {\n await this.init()\n return this.tools.find(tool => tool.name === name);\n }\n\n async getInputText(name:string, input?:object): Promise<string>\n {\n const tool = await this.get(name);\n\n return tool?.getInputText?.(input) || '';\n }\n\n async execute(name:string, input?:object): Promise<string>\n {\n const tool = await this.get(name);\n \n if(!tool)\n {\n throw new Error(`Tool ${name} could not be found.`);\n }\n\n if(!tool.func)\n {\n throw new Error(`Tool ${name} does not have a function.`);\n }\n\n try\n {\n let result = await tool.func(input);\n return result;\n }\n catch(e:any)\n {\n throw new Error(`Failed to run ${name} tool: ${e?.message}`);\n }\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/entities/toolDispatcher.ts"],"sourcesContent":["export { ToolDispatcher } from './entities/toolDispatcher';\nexport { McpConfig, McpServer, McpToolImport } from './interfaces/mcpConfig';","import { Tool, McpServer, ExecutionPolicy, ExecutionPolicyFactory, ToolOutcomeMapper, ToolOutcomeMapperFactory } from \"@mappies/miniwat-agent-core\";\nimport { McpConfig } from \"../interfaces/mcpConfig\";\n\nexport class ToolDispatcher\n{\n private tools:Tool[]\n private servers:McpServer[]\n\n constructor(private mcp?:McpConfig)\n {\n this.tools = []\n this.servers = []\n }\n\n async init()\n {\n if(this.tools.length !== 0) return;\n\n this.tools = [];\n\n if(this.mcp === undefined) return;\n\n for(let server of Object.keys(this.mcp.mcpServers))\n {\n let service = this.mcp.mcpServers[server]\n\n this.servers.push(new McpServer({name: server, ...service}))\n \n const pck = await import(service.package);\n for(let t of service.tools)\n {\n // Host intent: a tool explicitly disabled in config is excluded here, during\n // discovery, so the planner never sees it.\n if(t.enabled === false) continue;\n\n let definition = pck[t.import];\n let tool = new Tool({ \n name: definition.name, \n description: definition.description, \n schema: definition.inputSchema, \n func: pck[definition.name],\n service: server,\n getInputText: pck[`${definition.name}InputText`],\n readOnly: definition.readOnly === true,\n requiresApproval: definition.requiresApproval === true,\n executionPolicy: this.resolveExecutionPolicy(server, definition, pck),\n outcomeMapper: this.resolveOutcomeMapper(server, definition, pck)\n })\n \n this.tools.push(tool)\n }\n }\n }\n\n // Resolves a tool definition's named executionPolicy from the OWNING package's\n // EXECUTION_POLICIES factory export. Validation is loud and happens at init — never deferred to\n // tool invocation — so the app cannot reach agent.stream() with a partially resolved tool.\n private resolveExecutionPolicy(server:string, definition:any, pck:any): ExecutionPolicy | undefined\n {\n const name:string | undefined = definition.executionPolicy;\n\n if(name === undefined) return undefined;\n\n const factories = pck.EXECUTION_POLICIES;\n\n if(factories === undefined || typeof factories !== \"object\")\n {\n throw new Error(`Tool '${definition.name}' on server '${server}' names executionPolicy '${name}' but its package exports no EXECUTION_POLICIES.`);\n }\n\n const factory:ExecutionPolicyFactory | undefined = factories[name];\n\n if(factory === undefined)\n {\n throw new Error(`Tool '${definition.name}' on server '${server}' names executionPolicy '${name}' not found in the package's EXECUTION_POLICIES.`);\n }\n\n if(typeof factory !== \"function\")\n {\n throw new Error(`EXECUTION_POLICIES['${name}'] on server '${server}' is not a factory function.`);\n }\n\n const policy = factory();\n\n if(policy === undefined || typeof policy.evaluate !== \"function\")\n {\n throw new Error(`EXECUTION_POLICIES['${name}'] on server '${server}' did not produce a valid ExecutionPolicy.`);\n }\n\n return policy;\n }\n\n // Resolves a tool definition's named outcomeMapper from the OWNING package's OUTCOME_MAPPERS\n // factory export. Validated loudly at init, mirroring resolveExecutionPolicy.\n private resolveOutcomeMapper(server:string, definition:any, pck:any): ToolOutcomeMapper | undefined\n {\n const name:string | undefined = definition.outcomeMapper;\n\n if(name === undefined) return undefined;\n\n const factories = pck.OUTCOME_MAPPERS;\n\n if(factories === undefined || typeof factories !== \"object\")\n {\n throw new Error(`Tool '${definition.name}' on server '${server}' names outcomeMapper '${name}' but its package exports no OUTCOME_MAPPERS.`);\n }\n\n const factory:ToolOutcomeMapperFactory | undefined = factories[name];\n\n if(factory === undefined)\n {\n throw new Error(`Tool '${definition.name}' on server '${server}' names outcomeMapper '${name}' not found in the package's OUTCOME_MAPPERS.`);\n }\n\n if(typeof factory !== \"function\")\n {\n throw new Error(`OUTCOME_MAPPERS['${name}'] on server '${server}' is not a factory function.`);\n }\n\n const mapper = factory();\n\n if(mapper === undefined || typeof mapper.map !== \"function\")\n {\n throw new Error(`OUTCOME_MAPPERS['${name}'] on server '${server}' did not produce a valid ToolOutcomeMapper.`);\n }\n\n return mapper;\n }\n\n async list(): Promise<Tool[]>\n {\n await this.init()\n return this.tools;\n }\n\n async listServers(): Promise<McpServer[]>\n {\n await this.init()\n return this.servers;\n }\n\n async get(name:string): Promise<Tool|undefined>\n {\n await this.init()\n return this.tools.find(tool => tool.name === name);\n }\n\n async getInputText(name:string, input?:object): Promise<string>\n {\n const tool = await this.get(name);\n\n return tool?.getInputText?.(input) || '';\n }\n\n async execute(name:string, input?:object): Promise<string>\n {\n const tool = await this.get(name);\n \n if(!tool)\n {\n throw new Error(`Tool ${name} could not be found.`);\n }\n\n if(!tool.func)\n {\n throw new Error(`Tool ${name} does not have a function.`);\n }\n\n try\n {\n let result = await tool.func(input);\n return result;\n }\n catch(e:any)\n {\n throw new Error(`Failed to run ${name} tool: ${e?.message}`);\n }\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gCAAsH;AAG/G,IAAM,iBAAN,MACP;AAAA,EAII,YAAoB,KACpB;AADoB;AAEhB,SAAK,QAAQ,CAAC;AACd,SAAK,UAAU,CAAC;AAAA,EACpB;AAAA,EAEA,MAAM,OACN;AACI,QAAG,KAAK,MAAM,WAAW,EAAG;AAE5B,SAAK,QAAQ,CAAC;AAEd,QAAG,KAAK,QAAQ,OAAW;AAE3B,aAAQ,UAAU,OAAO,KAAK,KAAK,IAAI,UAAU,GACjD;AACI,UAAI,UAAU,KAAK,IAAI,WAAW,MAAM;AAExC,WAAK,QAAQ,KAAK,IAAI,oCAAU,EAAC,MAAM,QAAQ,GAAG,QAAO,CAAC,CAAC;AAE3D,YAAM,MAAM,MAAM,OAAO,QAAQ;AACjC,eAAQ,KAAK,QAAQ,OACrB;AAGI,YAAG,EAAE,YAAY,MAAO;AAExB,YAAI,aAAa,IAAI,EAAE,MAAM;AAC7B,YAAI,OAAO,IAAI,+BAAK;AAAA,U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ACI,UAAI,SAAS,MAAM,KAAK,KAAK,KAAK;AAClC,aAAO;AAAA,IACX,SACM,GACN;AACI,YAAM,IAAI,MAAM,iBAAiB,IAAI,UAAU,GAAG,OAAO,EAAE;AAAA,IAC/D;AAAA,EACJ;AACJ;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,7 @@ interface McpServer {
|
|
|
11
11
|
}
|
|
12
12
|
interface McpToolImport {
|
|
13
13
|
import: string;
|
|
14
|
+
enabled?: boolean;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
declare class ToolDispatcher {
|
|
@@ -19,6 +20,8 @@ declare class ToolDispatcher {
|
|
|
19
20
|
private servers;
|
|
20
21
|
constructor(mcp?: McpConfig | undefined);
|
|
21
22
|
init(): Promise<void>;
|
|
23
|
+
private resolveExecutionPolicy;
|
|
24
|
+
private resolveOutcomeMapper;
|
|
22
25
|
list(): Promise<Tool[]>;
|
|
23
26
|
listServers(): Promise<McpServer$1[]>;
|
|
24
27
|
get(name: string): Promise<Tool | undefined>;
|
|
@@ -26,4 +29,4 @@ declare class ToolDispatcher {
|
|
|
26
29
|
execute(name: string, input?: object): Promise<string>;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
export { ToolDispatcher };
|
|
32
|
+
export { type McpConfig, type McpServer, type McpToolImport, ToolDispatcher };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ interface McpServer {
|
|
|
11
11
|
}
|
|
12
12
|
interface McpToolImport {
|
|
13
13
|
import: string;
|
|
14
|
+
enabled?: boolean;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
declare class ToolDispatcher {
|
|
@@ -19,6 +20,8 @@ declare class ToolDispatcher {
|
|
|
19
20
|
private servers;
|
|
20
21
|
constructor(mcp?: McpConfig | undefined);
|
|
21
22
|
init(): Promise<void>;
|
|
23
|
+
private resolveExecutionPolicy;
|
|
24
|
+
private resolveOutcomeMapper;
|
|
22
25
|
list(): Promise<Tool[]>;
|
|
23
26
|
listServers(): Promise<McpServer$1[]>;
|
|
24
27
|
get(name: string): Promise<Tool | undefined>;
|
|
@@ -26,4 +29,4 @@ declare class ToolDispatcher {
|
|
|
26
29
|
execute(name: string, input?: object): Promise<string>;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
export { ToolDispatcher };
|
|
32
|
+
export { type McpConfig, type McpServer, type McpToolImport, ToolDispatcher };
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var ToolDispatcher = class {
|
|
|
15
15
|
this.servers.push(new McpServer({ name: server, ...service }));
|
|
16
16
|
const pck = await import(service.package);
|
|
17
17
|
for (let t of service.tools) {
|
|
18
|
+
if (t.enabled === false) continue;
|
|
18
19
|
let definition = pck[t.import];
|
|
19
20
|
let tool = new Tool({
|
|
20
21
|
name: definition.name,
|
|
@@ -22,12 +23,61 @@ var ToolDispatcher = class {
|
|
|
22
23
|
schema: definition.inputSchema,
|
|
23
24
|
func: pck[definition.name],
|
|
24
25
|
service: server,
|
|
25
|
-
getInputText: pck[`${definition.name}InputText`]
|
|
26
|
+
getInputText: pck[`${definition.name}InputText`],
|
|
27
|
+
readOnly: definition.readOnly === true,
|
|
28
|
+
requiresApproval: definition.requiresApproval === true,
|
|
29
|
+
executionPolicy: this.resolveExecutionPolicy(server, definition, pck),
|
|
30
|
+
outcomeMapper: this.resolveOutcomeMapper(server, definition, pck)
|
|
26
31
|
});
|
|
27
32
|
this.tools.push(tool);
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
}
|
|
36
|
+
// Resolves a tool definition's named executionPolicy from the OWNING package's
|
|
37
|
+
// EXECUTION_POLICIES factory export. Validation is loud and happens at init — never deferred to
|
|
38
|
+
// tool invocation — so the app cannot reach agent.stream() with a partially resolved tool.
|
|
39
|
+
resolveExecutionPolicy(server, definition, pck) {
|
|
40
|
+
const name = definition.executionPolicy;
|
|
41
|
+
if (name === void 0) return void 0;
|
|
42
|
+
const factories = pck.EXECUTION_POLICIES;
|
|
43
|
+
if (factories === void 0 || typeof factories !== "object") {
|
|
44
|
+
throw new Error(`Tool '${definition.name}' on server '${server}' names executionPolicy '${name}' but its package exports no EXECUTION_POLICIES.`);
|
|
45
|
+
}
|
|
46
|
+
const factory = factories[name];
|
|
47
|
+
if (factory === void 0) {
|
|
48
|
+
throw new Error(`Tool '${definition.name}' on server '${server}' names executionPolicy '${name}' not found in the package's EXECUTION_POLICIES.`);
|
|
49
|
+
}
|
|
50
|
+
if (typeof factory !== "function") {
|
|
51
|
+
throw new Error(`EXECUTION_POLICIES['${name}'] on server '${server}' is not a factory function.`);
|
|
52
|
+
}
|
|
53
|
+
const policy = factory();
|
|
54
|
+
if (policy === void 0 || typeof policy.evaluate !== "function") {
|
|
55
|
+
throw new Error(`EXECUTION_POLICIES['${name}'] on server '${server}' did not produce a valid ExecutionPolicy.`);
|
|
56
|
+
}
|
|
57
|
+
return policy;
|
|
58
|
+
}
|
|
59
|
+
// Resolves a tool definition's named outcomeMapper from the OWNING package's OUTCOME_MAPPERS
|
|
60
|
+
// factory export. Validated loudly at init, mirroring resolveExecutionPolicy.
|
|
61
|
+
resolveOutcomeMapper(server, definition, pck) {
|
|
62
|
+
const name = definition.outcomeMapper;
|
|
63
|
+
if (name === void 0) return void 0;
|
|
64
|
+
const factories = pck.OUTCOME_MAPPERS;
|
|
65
|
+
if (factories === void 0 || typeof factories !== "object") {
|
|
66
|
+
throw new Error(`Tool '${definition.name}' on server '${server}' names outcomeMapper '${name}' but its package exports no OUTCOME_MAPPERS.`);
|
|
67
|
+
}
|
|
68
|
+
const factory = factories[name];
|
|
69
|
+
if (factory === void 0) {
|
|
70
|
+
throw new Error(`Tool '${definition.name}' on server '${server}' names outcomeMapper '${name}' not found in the package's OUTCOME_MAPPERS.`);
|
|
71
|
+
}
|
|
72
|
+
if (typeof factory !== "function") {
|
|
73
|
+
throw new Error(`OUTCOME_MAPPERS['${name}'] on server '${server}' is not a factory function.`);
|
|
74
|
+
}
|
|
75
|
+
const mapper = factory();
|
|
76
|
+
if (mapper === void 0 || typeof mapper.map !== "function") {
|
|
77
|
+
throw new Error(`OUTCOME_MAPPERS['${name}'] on server '${server}' did not produce a valid ToolOutcomeMapper.`);
|
|
78
|
+
}
|
|
79
|
+
return mapper;
|
|
80
|
+
}
|
|
31
81
|
async list() {
|
|
32
82
|
await this.init();
|
|
33
83
|
return this.tools;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/entities/toolDispatcher.ts"],"sourcesContent":["import { Tool, McpServer } from \"@mappies/miniwat-agent-core\";\nimport { McpConfig } from \"../interfaces/mcpConfig\";\n\nexport class ToolDispatcher\n{\n private tools:Tool[]\n private servers:McpServer[]\n\n constructor(private mcp?:McpConfig)\n {\n this.tools = []\n this.servers = []\n }\n\n async init()\n {\n if(this.tools.length !== 0) return;\n\n this.tools = [];\n\n if(this.mcp === undefined) return;\n\n for(let server of Object.keys(this.mcp.mcpServers))\n {\n let service = this.mcp.mcpServers[server]\n\n this.servers.push(new McpServer({name: server, ...service}))\n \n const pck = await import(service.package);\n for(let t of service.tools)\n {\n let definition = pck[t.import];\n let tool = new Tool({ \n name: definition.name, \n description: definition.description, \n schema: definition.inputSchema, \n func: pck[definition.name],\n service: server,\n getInputText: pck[`${definition.name}InputText`]\n })\n \n this.tools.push(tool)\n }\n }\n }\n\n async list(): Promise<Tool[]>\n {\n await this.init()\n return this.tools;\n }\n\n async listServers(): Promise<McpServer[]>\n {\n await this.init()\n return this.servers;\n }\n\n async get(name:string): Promise<Tool|undefined>\n {\n await this.init()\n return this.tools.find(tool => tool.name === name);\n }\n\n async getInputText(name:string, input?:object): Promise<string>\n {\n const tool = await this.get(name);\n\n return tool?.getInputText?.(input) || '';\n }\n\n async execute(name:string, input?:object): Promise<string>\n {\n const tool = await this.get(name);\n \n if(!tool)\n {\n throw new Error(`Tool ${name} could not be found.`);\n }\n\n if(!tool.func)\n {\n throw new Error(`Tool ${name} does not have a function.`);\n }\n\n try\n {\n let result = await tool.func(input);\n return result;\n }\n catch(e:any)\n {\n throw new Error(`Failed to run ${name} tool: ${e?.message}`);\n }\n }\n}"],"mappings":";AAAA,SAAS,MAAM,
|
|
1
|
+
{"version":3,"sources":["../src/entities/toolDispatcher.ts"],"sourcesContent":["import { Tool, McpServer, ExecutionPolicy, ExecutionPolicyFactory, ToolOutcomeMapper, ToolOutcomeMapperFactory } from \"@mappies/miniwat-agent-core\";\nimport { McpConfig } from \"../interfaces/mcpConfig\";\n\nexport class ToolDispatcher\n{\n private tools:Tool[]\n private servers:McpServer[]\n\n constructor(private mcp?:McpConfig)\n {\n this.tools = []\n this.servers = []\n }\n\n async init()\n {\n if(this.tools.length !== 0) return;\n\n this.tools = [];\n\n if(this.mcp === undefined) return;\n\n for(let server of Object.keys(this.mcp.mcpServers))\n {\n let service = this.mcp.mcpServers[server]\n\n this.servers.push(new McpServer({name: server, ...service}))\n \n const pck = await import(service.package);\n for(let t of service.tools)\n {\n // Host intent: a tool explicitly disabled in config is excluded here, during\n // discovery, so the planner never sees it.\n if(t.enabled === false) continue;\n\n let definition = pck[t.import];\n let tool = new Tool({ \n name: definition.name, \n description: definition.description, \n schema: definition.inputSchema, \n func: pck[definition.name],\n service: server,\n getInputText: pck[`${definition.name}InputText`],\n readOnly: definition.readOnly === true,\n requiresApproval: definition.requiresApproval === true,\n executionPolicy: this.resolveExecutionPolicy(server, definition, pck),\n outcomeMapper: this.resolveOutcomeMapper(server, definition, pck)\n })\n \n this.tools.push(tool)\n }\n }\n }\n\n // Resolves a tool definition's named executionPolicy from the OWNING package's\n // EXECUTION_POLICIES factory export. Validation is loud and happens at init — never deferred to\n // tool invocation — so the app cannot reach agent.stream() with a partially resolved tool.\n private resolveExecutionPolicy(server:string, definition:any, pck:any): ExecutionPolicy | undefined\n {\n const name:string | undefined = definition.executionPolicy;\n\n if(name === undefined) return undefined;\n\n const factories = pck.EXECUTION_POLICIES;\n\n if(factories === undefined || typeof factories !== \"object\")\n {\n throw new Error(`Tool '${definition.name}' on server '${server}' names executionPolicy '${name}' but its package exports no EXECUTION_POLICIES.`);\n }\n\n const factory:ExecutionPolicyFactory | undefined = factories[name];\n\n if(factory === undefined)\n {\n throw new Error(`Tool '${definition.name}' on server '${server}' names executionPolicy '${name}' not found in the package's EXECUTION_POLICIES.`);\n }\n\n if(typeof factory !== \"function\")\n {\n throw new Error(`EXECUTION_POLICIES['${name}'] on server '${server}' is not a factory function.`);\n }\n\n const policy = factory();\n\n if(policy === undefined || typeof policy.evaluate !== \"function\")\n {\n throw new Error(`EXECUTION_POLICIES['${name}'] on server '${server}' did not produce a valid ExecutionPolicy.`);\n }\n\n return policy;\n }\n\n // Resolves a tool definition's named outcomeMapper from the OWNING package's OUTCOME_MAPPERS\n // factory export. Validated loudly at init, mirroring resolveExecutionPolicy.\n private resolveOutcomeMapper(server:string, definition:any, pck:any): ToolOutcomeMapper | undefined\n {\n const name:string | undefined = definition.outcomeMapper;\n\n if(name === undefined) return undefined;\n\n const factories = pck.OUTCOME_MAPPERS;\n\n if(factories === undefined || typeof factories !== \"object\")\n {\n throw new Error(`Tool '${definition.name}' on server '${server}' names outcomeMapper '${name}' but its package exports no OUTCOME_MAPPERS.`);\n }\n\n const factory:ToolOutcomeMapperFactory | undefined = factories[name];\n\n if(factory === undefined)\n {\n throw new Error(`Tool '${definition.name}' on server '${server}' names outcomeMapper '${name}' not found in the package's OUTCOME_MAPPERS.`);\n }\n\n if(typeof factory !== \"function\")\n {\n throw new Error(`OUTCOME_MAPPERS['${name}'] on server '${server}' is not a factory function.`);\n }\n\n const mapper = factory();\n\n if(mapper === undefined || typeof mapper.map !== \"function\")\n {\n throw new Error(`OUTCOME_MAPPERS['${name}'] on server '${server}' did not produce a valid ToolOutcomeMapper.`);\n }\n\n return mapper;\n }\n\n async list(): Promise<Tool[]>\n {\n await this.init()\n return this.tools;\n }\n\n async listServers(): Promise<McpServer[]>\n {\n await this.init()\n return this.servers;\n }\n\n async get(name:string): Promise<Tool|undefined>\n {\n await this.init()\n return this.tools.find(tool => tool.name === name);\n }\n\n async getInputText(name:string, input?:object): Promise<string>\n {\n const tool = await this.get(name);\n\n return tool?.getInputText?.(input) || '';\n }\n\n async execute(name:string, input?:object): Promise<string>\n {\n const tool = await this.get(name);\n \n if(!tool)\n {\n throw new Error(`Tool ${name} could not be found.`);\n }\n\n if(!tool.func)\n {\n throw new Error(`Tool ${name} does not have a function.`);\n }\n\n try\n {\n let result = await tool.func(input);\n return result;\n }\n catch(e:any)\n {\n throw new Error(`Failed to run ${name} tool: ${e?.message}`);\n }\n }\n}"],"mappings":";AAAA,SAAS,MAAM,iBAAuG;AAG/G,IAAM,iBAAN,MACP;AAAA,EAII,YAAoB,KACpB;AADoB;AAEhB,SAAK,QAAQ,CAAC;AACd,SAAK,UAAU,CAAC;AAAA,EACpB;AAAA,EAEA,MAAM,OACN;AACI,QAAG,KAAK,MAAM,WAAW,EAAG;AAE5B,SAAK,QAAQ,CAAC;AAEd,QAAG,KAAK,QAAQ,OAAW;AAE3B,aAAQ,UAAU,OAAO,KAAK,KAAK,IAAI,UAAU,GACjD;AACI,UAAI,UAAU,KAAK,IAAI,WAAW,MAAM;AAExC,WAAK,QAAQ,KAAK,IAAI,UAAU,EAAC,MAAM,QAAQ,GAAG,QAAO,CAAC,CAAC;AAE3D,YAAM,MAAM,MAAM,OAAO,QAAQ;AACjC,eAAQ,KAAK,QAAQ,OACrB;AAGI,YAAG,EAAE,YAAY,MAAO;AAExB,YAAI,aAAa,IAAI,EAAE,MAAM;AAC7B,YAAI,OAAO,IAAI,KAAK;AAAA,UACI,MAAM,WAAW;AAAA,UACjB,aAAa,WAAW;AAAA,UACxB,QAAQ,WAAW;AAAA,UACnB,MAAM,IAAI,WAAW,IAAI;AAAA,UACzB,SAAS;AAAA,UACT,cAAc,IAAI,GAAG,WAAW,IAAI,WAAW;AAAA,UAC/C,UAAU,WAAW,aAAa;AAAA,UAClC,kBAAkB,WAAW,qBAAqB;AAAA,UAClD,iBA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appies/miniwat-mcp-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Shared entities and executor for Miniwat MCP",
|
|
5
5
|
"homepage": "https://gitlab.com/mappies/miniwat-mcp-core#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
"vitest": "^5.0.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@mappies/miniwat-agent-core": "^0.
|
|
46
|
+
"@mappies/miniwat-agent-core": "^0.20.0"
|
|
47
47
|
}
|
|
48
48
|
}
|