@simulacra-ai/mcp 0.0.3 → 0.0.5

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 ADDED
@@ -0,0 +1,261 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ McpToolProvider: () => McpToolProvider,
24
+ convertJsonSchemaToParameters: () => convertJsonSchemaToParameters
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // src/schema-converter.ts
29
+ function convertProperty(name, prop, required) {
30
+ const param_type = convertType(prop, required);
31
+ const def = { ...param_type, name };
32
+ if (prop.description) {
33
+ def.description = prop.description;
34
+ }
35
+ return def;
36
+ }
37
+ function convertType(prop, required) {
38
+ if (prop.type === "object" && prop.properties) {
39
+ const nested = {};
40
+ for (const [key, value] of Object.entries(prop.properties)) {
41
+ const child_required = prop.required?.includes(key) ?? false;
42
+ nested[key] = convertType(value, child_required);
43
+ }
44
+ return {
45
+ type: "object",
46
+ required,
47
+ properties: nested,
48
+ ...prop.description ? { description: prop.description } : {}
49
+ };
50
+ }
51
+ if (prop.type === "array" && prop.items) {
52
+ return {
53
+ type: "array",
54
+ required,
55
+ items: convertType(prop.items, false),
56
+ ...prop.description ? { description: prop.description } : {}
57
+ };
58
+ }
59
+ if (prop.type === "string" && prop.enum) {
60
+ return required ? {
61
+ type: "string",
62
+ required: true,
63
+ enum: prop.enum,
64
+ ...prop.description ? { description: prop.description } : {}
65
+ } : {
66
+ type: "string",
67
+ required: false,
68
+ enum: prop.enum,
69
+ ...prop.description ? { description: prop.description } : {}
70
+ };
71
+ }
72
+ if (prop.type === "number" || prop.type === "integer") {
73
+ return required ? {
74
+ type: "number",
75
+ required: true,
76
+ ...prop.description ? { description: prop.description } : {}
77
+ } : {
78
+ type: "number",
79
+ required: false,
80
+ ...prop.description ? { description: prop.description } : {}
81
+ };
82
+ }
83
+ if (prop.type === "boolean") {
84
+ return required ? {
85
+ type: "boolean",
86
+ required: true,
87
+ ...prop.description ? { description: prop.description } : {}
88
+ } : {
89
+ type: "boolean",
90
+ required: false,
91
+ ...prop.description ? { description: prop.description } : {}
92
+ };
93
+ }
94
+ return required ? {
95
+ type: "string",
96
+ required: true,
97
+ ...prop.description ? { description: prop.description } : {}
98
+ } : {
99
+ type: "string",
100
+ required: false,
101
+ ...prop.description ? { description: prop.description } : {}
102
+ };
103
+ }
104
+ function convertJsonSchemaToParameters(schema) {
105
+ const s = schema;
106
+ if (!s.properties) {
107
+ return [];
108
+ }
109
+ const required_set = new Set(s.required ?? []);
110
+ return Object.entries(s.properties).map(
111
+ ([name, prop]) => convertProperty(name, prop, required_set.has(name))
112
+ );
113
+ }
114
+
115
+ // src/mcp-tool-provider.ts
116
+ var import_client = require("@modelcontextprotocol/sdk/client/index.js");
117
+ var import_stdio = require("@modelcontextprotocol/sdk/client/stdio.js");
118
+ var McpToolProvider = class {
119
+ #config;
120
+ #servers = [];
121
+ #tool_classes = [];
122
+ /**
123
+ * Creates a new MCP tool provider.
124
+ *
125
+ * @param config - Configuration specifying which MCP servers to connect to.
126
+ */
127
+ constructor(config) {
128
+ this.#config = config;
129
+ }
130
+ /**
131
+ * Establishes connections to all configured MCP servers and retrieves their tools.
132
+ *
133
+ * This method spawns each server process, establishes communication over stdio,
134
+ * and queries each server for its available tools. The tools are converted to
135
+ * Simulacra-compatible tool classes and stored internally.
136
+ *
137
+ * @returns A promise that resolves when all servers are connected and tools are loaded.
138
+ */
139
+ async connect() {
140
+ const connected = [];
141
+ const added_tool_classes = [];
142
+ try {
143
+ for (const server_config of this.#config.servers) {
144
+ const transport = new import_stdio.StdioClientTransport({
145
+ command: server_config.command,
146
+ args: server_config.args,
147
+ env: server_config.env
148
+ });
149
+ const client = new import_client.Client({ name: "simulacra", version: "0.1.0" }, { capabilities: {} });
150
+ await client.connect(transport);
151
+ const server = { config: server_config, client, transport };
152
+ connected.push(server);
153
+ this.#servers.push(server);
154
+ const tools_result = await client.listTools();
155
+ for (const mcp_tool of tools_result.tools) {
156
+ const tool_class = this.#create_tool_class(client, mcp_tool, server_config);
157
+ added_tool_classes.push(tool_class);
158
+ this.#tool_classes.push(tool_class);
159
+ }
160
+ }
161
+ } catch (error) {
162
+ for (const server of connected) {
163
+ await server.client.close().catch((close_error) => {
164
+ this.#config.on_error?.({
165
+ error: close_error,
166
+ operation: "disconnect",
167
+ context: { during: "connect_rollback" }
168
+ });
169
+ });
170
+ }
171
+ this.#servers = this.#servers.filter((s) => !connected.includes(s));
172
+ this.#tool_classes = this.#tool_classes.filter((t) => !added_tool_classes.includes(t));
173
+ throw error;
174
+ }
175
+ }
176
+ /**
177
+ * Closes all MCP server connections and clears the cached tool classes.
178
+ *
179
+ * This method gracefully shuts down all server processes and cleans up
180
+ * internal state. After calling this method, the tool classes are no longer
181
+ * available.
182
+ *
183
+ * @returns A promise that resolves when all servers are disconnected.
184
+ */
185
+ async disconnect() {
186
+ await Promise.allSettled(this.#servers.map((s) => s.client.close()));
187
+ this.#servers = [];
188
+ this.#tool_classes = [];
189
+ }
190
+ /**
191
+ * Enables automatic cleanup when the provider is disposed.
192
+ *
193
+ * This method implements the disposable pattern, allowing the provider to be
194
+ * used with explicit resource management syntax (using keyword). When disposed,
195
+ * it attempts to disconnect from all servers.
196
+ */
197
+ [Symbol.dispose]() {
198
+ this.disconnect().catch((error) => {
199
+ this.#config.on_error?.({ error, operation: "disconnect", context: { during: "dispose" } });
200
+ });
201
+ }
202
+ /**
203
+ * Retrieves all tool classes from connected MCP servers.
204
+ *
205
+ * This method returns a shallow copy of the internal tool classes array,
206
+ * containing Simulacra-compatible tool classes for all tools from all
207
+ * connected servers.
208
+ *
209
+ * @returns An array of tool classes ready to be used in a Simulacra workflow.
210
+ */
211
+ getToolClasses() {
212
+ return [...this.#tool_classes];
213
+ }
214
+ #create_tool_class(client, mcp_tool, server_config) {
215
+ const parameters = mcp_tool.inputSchema ? convertJsonSchemaToParameters(mcp_tool.inputSchema) : [];
216
+ const parallelizable = server_config.tool_overrides?.[mcp_tool.name]?.parallelizable;
217
+ const definition = {
218
+ name: mcp_tool.name,
219
+ description: mcp_tool.description ?? "",
220
+ parameters,
221
+ ...parallelizable !== void 0 ? { parallelizable } : {}
222
+ };
223
+ const McpTool = class {
224
+ static get_definition() {
225
+ return definition;
226
+ }
227
+ constructor(_context) {
228
+ }
229
+ async execute(params) {
230
+ try {
231
+ const result = await client.callTool({
232
+ name: mcp_tool.name,
233
+ arguments: params
234
+ });
235
+ if (result.isError) {
236
+ const text2 = result.content?.filter((c) => c.type === "text").map((c) => c.text ?? "").join("\n") || "MCP tool error";
237
+ return { result: false, message: text2 };
238
+ }
239
+ const text = result.content?.filter((c) => c.type === "text").map((c) => c.text ?? "").join("\n");
240
+ return {
241
+ result: true,
242
+ ...{ output: text || "success" }
243
+ };
244
+ } catch (error) {
245
+ return {
246
+ result: false,
247
+ message: error instanceof Error ? error.message : String(error),
248
+ error
249
+ };
250
+ }
251
+ }
252
+ };
253
+ return McpTool;
254
+ }
255
+ };
256
+ // Annotate the CommonJS export names for ESM import in node:
257
+ 0 && (module.exports = {
258
+ McpToolProvider,
259
+ convertJsonSchemaToParameters
260
+ });
261
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/schema-converter.ts","../src/mcp-tool-provider.ts"],"sourcesContent":["export * from \"./types.ts\";\nexport * from \"./schema-converter.ts\";\nexport * from \"./mcp-tool-provider.ts\";\n","import type { ToolParameterDefinition, ParameterType } from \"@simulacra-ai/core\";\n\ninterface JsonSchemaProperty {\n type?: string;\n description?: string;\n enum?: string[];\n properties?: Record<string, JsonSchemaProperty>;\n required?: string[];\n items?: JsonSchemaProperty;\n default?: unknown;\n}\n\ninterface JsonSchema {\n type?: string;\n properties?: Record<string, JsonSchemaProperty>;\n required?: string[];\n}\n\nfunction convertProperty(\n name: string,\n prop: JsonSchemaProperty,\n required: boolean,\n): ToolParameterDefinition {\n const param_type = convertType(prop, required);\n const def: ToolParameterDefinition = { ...param_type, name };\n if (prop.description) {\n def.description = prop.description;\n }\n return def;\n}\n\nfunction convertType(prop: JsonSchemaProperty, required: boolean): ParameterType {\n if (prop.type === \"object\" && prop.properties) {\n const nested: Record<string, ParameterType> = {};\n for (const [key, value] of Object.entries(prop.properties)) {\n const child_required = prop.required?.includes(key) ?? false;\n nested[key] = convertType(value, child_required);\n }\n return {\n type: \"object\",\n required,\n properties: nested,\n ...(prop.description ? { description: prop.description } : {}),\n };\n }\n\n if (prop.type === \"array\" && prop.items) {\n return {\n type: \"array\",\n required,\n items: convertType(prop.items, false),\n ...(prop.description ? { description: prop.description } : {}),\n };\n }\n\n if (prop.type === \"string\" && prop.enum) {\n return required\n ? {\n type: \"string\",\n required: true,\n enum: prop.enum,\n ...(prop.description ? { description: prop.description } : {}),\n }\n : {\n type: \"string\",\n required: false,\n enum: prop.enum,\n ...(prop.description ? { description: prop.description } : {}),\n };\n }\n\n if (prop.type === \"number\" || prop.type === \"integer\") {\n return required\n ? {\n type: \"number\",\n required: true,\n ...(prop.description ? { description: prop.description } : {}),\n }\n : {\n type: \"number\",\n required: false,\n ...(prop.description ? { description: prop.description } : {}),\n };\n }\n\n if (prop.type === \"boolean\") {\n return required\n ? {\n type: \"boolean\",\n required: true,\n ...(prop.description ? { description: prop.description } : {}),\n }\n : {\n type: \"boolean\",\n required: false,\n ...(prop.description ? { description: prop.description } : {}),\n };\n }\n\n // Default: treat as string (covers type === \"string\" and unknown types)\n return required\n ? {\n type: \"string\",\n required: true,\n ...(prop.description ? { description: prop.description } : {}),\n }\n : {\n type: \"string\",\n required: false,\n ...(prop.description ? { description: prop.description } : {}),\n };\n}\n\n/**\n * Converts a JSON Schema object into an array of Simulacra tool parameter definitions.\n *\n * This function transforms MCP tool input schemas (which use JSON Schema format)\n * into the parameter format expected by Simulacra tools. It handles nested objects,\n * arrays, enums, and all standard JSON Schema primitive types.\n *\n * @param schema - A JSON Schema object describing the tool's input parameters.\n * @returns An array of tool parameter definitions compatible with Simulacra.\n */\nexport function convertJsonSchemaToParameters(\n schema: Record<string, unknown>,\n): ToolParameterDefinition[] {\n const s = schema as unknown as JsonSchema;\n if (!s.properties) {\n return [];\n }\n\n const required_set = new Set(s.required ?? []);\n return Object.entries(s.properties).map(([name, prop]) =>\n convertProperty(name, prop, required_set.has(name)),\n );\n}\n","import { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { StdioClientTransport } from \"@modelcontextprotocol/sdk/client/stdio.js\";\nimport type {\n ToolClass,\n ToolDefinition,\n ToolContext,\n ToolSuccessResult,\n ToolErrorResult,\n} from \"@simulacra-ai/core\";\nimport { convertJsonSchemaToParameters } from \"./schema-converter.ts\";\nimport type { McpServerConfig, McpToolProviderConfig } from \"./types.ts\";\n\ninterface ConnectedServer {\n config: McpServerConfig;\n client: Client;\n transport: StdioClientTransport;\n}\n\n/**\n * A provider that connects to Model Context Protocol (MCP) servers and exposes\n * their tools as Simulacra-compatible tool classes.\n *\n * This class manages the lifecycle of MCP server connections, converts MCP tools\n * into the Simulacra tool format, and provides access to all tools from connected\n * servers.\n */\nexport class McpToolProvider {\n readonly #config: McpToolProviderConfig;\n #servers: ConnectedServer[] = [];\n #tool_classes: ToolClass[] = [];\n\n /**\n * Creates a new MCP tool provider.\n *\n * @param config - Configuration specifying which MCP servers to connect to.\n */\n constructor(config: McpToolProviderConfig) {\n this.#config = config;\n }\n\n /**\n * Establishes connections to all configured MCP servers and retrieves their tools.\n *\n * This method spawns each server process, establishes communication over stdio,\n * and queries each server for its available tools. The tools are converted to\n * Simulacra-compatible tool classes and stored internally.\n *\n * @returns A promise that resolves when all servers are connected and tools are loaded.\n */\n async connect(): Promise<void> {\n const connected: ConnectedServer[] = [];\n const added_tool_classes: ToolClass[] = [];\n try {\n for (const server_config of this.#config.servers) {\n const transport = new StdioClientTransport({\n command: server_config.command,\n args: server_config.args,\n env: server_config.env,\n });\n\n const client = new Client({ name: \"simulacra\", version: \"0.1.0\" }, { capabilities: {} });\n\n await client.connect(transport);\n\n const server: ConnectedServer = { config: server_config, client, transport };\n connected.push(server);\n this.#servers.push(server);\n\n const tools_result = await client.listTools();\n\n for (const mcp_tool of tools_result.tools) {\n const tool_class = this.#create_tool_class(client, mcp_tool, server_config);\n added_tool_classes.push(tool_class);\n this.#tool_classes.push(tool_class);\n }\n }\n } catch (error) {\n for (const server of connected) {\n await server.client.close().catch((close_error) => {\n this.#config.on_error?.({\n error: close_error,\n operation: \"disconnect\",\n context: { during: \"connect_rollback\" },\n });\n });\n }\n this.#servers = this.#servers.filter((s) => !connected.includes(s));\n this.#tool_classes = this.#tool_classes.filter((t) => !added_tool_classes.includes(t));\n throw error;\n }\n }\n\n /**\n * Closes all MCP server connections and clears the cached tool classes.\n *\n * This method gracefully shuts down all server processes and cleans up\n * internal state. After calling this method, the tool classes are no longer\n * available.\n *\n * @returns A promise that resolves when all servers are disconnected.\n */\n async disconnect(): Promise<void> {\n await Promise.allSettled(this.#servers.map((s) => s.client.close()));\n this.#servers = [];\n this.#tool_classes = [];\n }\n\n /**\n * Enables automatic cleanup when the provider is disposed.\n *\n * This method implements the disposable pattern, allowing the provider to be\n * used with explicit resource management syntax (using keyword). When disposed,\n * it attempts to disconnect from all servers.\n */\n [Symbol.dispose]() {\n this.disconnect().catch((error) => {\n this.#config.on_error?.({ error, operation: \"disconnect\", context: { during: \"dispose\" } });\n });\n }\n\n /**\n * Retrieves all tool classes from connected MCP servers.\n *\n * This method returns a shallow copy of the internal tool classes array,\n * containing Simulacra-compatible tool classes for all tools from all\n * connected servers.\n *\n * @returns An array of tool classes ready to be used in a Simulacra workflow.\n */\n getToolClasses(): ToolClass[] {\n return [...this.#tool_classes];\n }\n\n #create_tool_class(\n client: Client,\n mcp_tool: { name: string; description?: string; inputSchema?: unknown },\n server_config: McpServerConfig,\n ): ToolClass {\n const parameters = mcp_tool.inputSchema\n ? convertJsonSchemaToParameters(mcp_tool.inputSchema as Record<string, unknown>)\n : [];\n\n const parallelizable = server_config.tool_overrides?.[mcp_tool.name]?.parallelizable;\n\n const definition: ToolDefinition = {\n name: mcp_tool.name,\n description: mcp_tool.description ?? \"\",\n parameters,\n ...(parallelizable !== undefined ? { parallelizable } : {}),\n };\n\n const McpTool = class {\n static get_definition() {\n return definition;\n }\n\n constructor(_context: ToolContext) {}\n\n async execute(params: Record<string, unknown>): Promise<ToolSuccessResult | ToolErrorResult> {\n try {\n const result = await client.callTool({\n name: mcp_tool.name,\n arguments: params,\n });\n\n if (result.isError) {\n const text =\n (result.content as Array<{ type: string; text?: string }>)\n ?.filter((c) => c.type === \"text\")\n .map((c) => c.text ?? \"\")\n .join(\"\\n\") || \"MCP tool error\";\n return { result: false, message: text };\n }\n\n const text = (result.content as Array<{ type: string; text?: string }>)\n ?.filter((c) => c.type === \"text\")\n .map((c) => c.text ?? \"\")\n .join(\"\\n\");\n return {\n result: true,\n ...({ output: text || \"success\" } as Record<string, unknown>),\n } as ToolSuccessResult;\n } catch (error) {\n return {\n result: false,\n message: error instanceof Error ? error.message : String(error),\n error,\n };\n }\n }\n };\n\n return McpTool as unknown as ToolClass;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;A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BAAMA,QACH,OAAO,SACJ,OAAO,CAAC,MAAM,EAAE,SAAS,MAAM,EAChC,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,EACvB,KAAK,IAAI,KAAK;AACnB,mBAAO,EAAE,QAAQ,OAAO,SAASA,MAAK;AAAA,UACxC;AAEA,gBAAM,OAAQ,OAAO,SACjB,OAAO,CAAC,MAAM,EAAE,SAAS,MAAM,EAChC,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,EACvB,KAAK,IAAI;AACZ,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,GAAI,EAAE,QAAQ,QAAQ,UAAU;AAAA,UAClC;AAAA,QACF,SAAS,OAAO;AACd,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,YAC9D;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":["text"]}
@@ -0,0 +1,127 @@
1
+ import { LifecycleErrorEvent, ToolParameterDefinition, ToolClass } from '@simulacra-ai/core';
2
+
3
+ /**
4
+ * Configuration for a single Model Context Protocol (MCP) server connection.
5
+ *
6
+ * This interface defines how to connect to and configure an MCP server,
7
+ * including the command to execute, environment variables, and tool-specific
8
+ * overrides.
9
+ */
10
+ interface McpServerConfig {
11
+ /**
12
+ * A unique identifier for this MCP server.
13
+ */
14
+ name: string;
15
+ /**
16
+ * The command to execute to start the MCP server process.
17
+ */
18
+ command: string;
19
+ /**
20
+ * Command-line arguments to pass to the server command.
21
+ */
22
+ args?: string[];
23
+ /**
24
+ * Environment variables to set for the server process.
25
+ */
26
+ env?: Record<string, string>;
27
+ /**
28
+ * The transport mechanism used to communicate with the server.
29
+ * Currently only "stdio" is supported.
30
+ */
31
+ transport?: "stdio";
32
+ /**
33
+ * Tool-specific configuration overrides, keyed by tool name.
34
+ */
35
+ tool_overrides?: Record<string, {
36
+ /**
37
+ * Whether this tool can be executed in parallel with other tools.
38
+ */
39
+ parallelizable?: boolean;
40
+ }>;
41
+ }
42
+ /**
43
+ * Configuration for the MCP tool provider.
44
+ *
45
+ * This interface defines the configuration needed to connect to one or more
46
+ * MCP servers and make their tools available to a Simulacra workflow.
47
+ */
48
+ interface McpToolProviderConfig {
49
+ /**
50
+ * An array of MCP server configurations to connect to.
51
+ */
52
+ servers: McpServerConfig[];
53
+ /**
54
+ * Optional callback invoked when a background operation fails during cleanup or disposal.
55
+ */
56
+ on_error?: (event: LifecycleErrorEvent) => void;
57
+ }
58
+
59
+ /**
60
+ * Converts a JSON Schema object into an array of Simulacra tool parameter definitions.
61
+ *
62
+ * This function transforms MCP tool input schemas (which use JSON Schema format)
63
+ * into the parameter format expected by Simulacra tools. It handles nested objects,
64
+ * arrays, enums, and all standard JSON Schema primitive types.
65
+ *
66
+ * @param schema - A JSON Schema object describing the tool's input parameters.
67
+ * @returns An array of tool parameter definitions compatible with Simulacra.
68
+ */
69
+ declare function convertJsonSchemaToParameters(schema: Record<string, unknown>): ToolParameterDefinition[];
70
+
71
+ /**
72
+ * A provider that connects to Model Context Protocol (MCP) servers and exposes
73
+ * their tools as Simulacra-compatible tool classes.
74
+ *
75
+ * This class manages the lifecycle of MCP server connections, converts MCP tools
76
+ * into the Simulacra tool format, and provides access to all tools from connected
77
+ * servers.
78
+ */
79
+ declare class McpToolProvider {
80
+ #private;
81
+ /**
82
+ * Creates a new MCP tool provider.
83
+ *
84
+ * @param config - Configuration specifying which MCP servers to connect to.
85
+ */
86
+ constructor(config: McpToolProviderConfig);
87
+ /**
88
+ * Establishes connections to all configured MCP servers and retrieves their tools.
89
+ *
90
+ * This method spawns each server process, establishes communication over stdio,
91
+ * and queries each server for its available tools. The tools are converted to
92
+ * Simulacra-compatible tool classes and stored internally.
93
+ *
94
+ * @returns A promise that resolves when all servers are connected and tools are loaded.
95
+ */
96
+ connect(): Promise<void>;
97
+ /**
98
+ * Closes all MCP server connections and clears the cached tool classes.
99
+ *
100
+ * This method gracefully shuts down all server processes and cleans up
101
+ * internal state. After calling this method, the tool classes are no longer
102
+ * available.
103
+ *
104
+ * @returns A promise that resolves when all servers are disconnected.
105
+ */
106
+ disconnect(): Promise<void>;
107
+ /**
108
+ * Enables automatic cleanup when the provider is disposed.
109
+ *
110
+ * This method implements the disposable pattern, allowing the provider to be
111
+ * used with explicit resource management syntax (using keyword). When disposed,
112
+ * it attempts to disconnect from all servers.
113
+ */
114
+ [Symbol.dispose](): void;
115
+ /**
116
+ * Retrieves all tool classes from connected MCP servers.
117
+ *
118
+ * This method returns a shallow copy of the internal tool classes array,
119
+ * containing Simulacra-compatible tool classes for all tools from all
120
+ * connected servers.
121
+ *
122
+ * @returns An array of tool classes ready to be used in a Simulacra workflow.
123
+ */
124
+ getToolClasses(): ToolClass[];
125
+ }
126
+
127
+ export { type McpServerConfig, McpToolProvider, type McpToolProviderConfig, convertJsonSchemaToParameters };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,127 @@
1
- export * from "./types.ts";
2
- export * from "./schema-converter.ts";
3
- export * from "./mcp-tool-provider.ts";
4
- //# sourceMappingURL=index.d.ts.map
1
+ import { LifecycleErrorEvent, ToolParameterDefinition, ToolClass } from '@simulacra-ai/core';
2
+
3
+ /**
4
+ * Configuration for a single Model Context Protocol (MCP) server connection.
5
+ *
6
+ * This interface defines how to connect to and configure an MCP server,
7
+ * including the command to execute, environment variables, and tool-specific
8
+ * overrides.
9
+ */
10
+ interface McpServerConfig {
11
+ /**
12
+ * A unique identifier for this MCP server.
13
+ */
14
+ name: string;
15
+ /**
16
+ * The command to execute to start the MCP server process.
17
+ */
18
+ command: string;
19
+ /**
20
+ * Command-line arguments to pass to the server command.
21
+ */
22
+ args?: string[];
23
+ /**
24
+ * Environment variables to set for the server process.
25
+ */
26
+ env?: Record<string, string>;
27
+ /**
28
+ * The transport mechanism used to communicate with the server.
29
+ * Currently only "stdio" is supported.
30
+ */
31
+ transport?: "stdio";
32
+ /**
33
+ * Tool-specific configuration overrides, keyed by tool name.
34
+ */
35
+ tool_overrides?: Record<string, {
36
+ /**
37
+ * Whether this tool can be executed in parallel with other tools.
38
+ */
39
+ parallelizable?: boolean;
40
+ }>;
41
+ }
42
+ /**
43
+ * Configuration for the MCP tool provider.
44
+ *
45
+ * This interface defines the configuration needed to connect to one or more
46
+ * MCP servers and make their tools available to a Simulacra workflow.
47
+ */
48
+ interface McpToolProviderConfig {
49
+ /**
50
+ * An array of MCP server configurations to connect to.
51
+ */
52
+ servers: McpServerConfig[];
53
+ /**
54
+ * Optional callback invoked when a background operation fails during cleanup or disposal.
55
+ */
56
+ on_error?: (event: LifecycleErrorEvent) => void;
57
+ }
58
+
59
+ /**
60
+ * Converts a JSON Schema object into an array of Simulacra tool parameter definitions.
61
+ *
62
+ * This function transforms MCP tool input schemas (which use JSON Schema format)
63
+ * into the parameter format expected by Simulacra tools. It handles nested objects,
64
+ * arrays, enums, and all standard JSON Schema primitive types.
65
+ *
66
+ * @param schema - A JSON Schema object describing the tool's input parameters.
67
+ * @returns An array of tool parameter definitions compatible with Simulacra.
68
+ */
69
+ declare function convertJsonSchemaToParameters(schema: Record<string, unknown>): ToolParameterDefinition[];
70
+
71
+ /**
72
+ * A provider that connects to Model Context Protocol (MCP) servers and exposes
73
+ * their tools as Simulacra-compatible tool classes.
74
+ *
75
+ * This class manages the lifecycle of MCP server connections, converts MCP tools
76
+ * into the Simulacra tool format, and provides access to all tools from connected
77
+ * servers.
78
+ */
79
+ declare class McpToolProvider {
80
+ #private;
81
+ /**
82
+ * Creates a new MCP tool provider.
83
+ *
84
+ * @param config - Configuration specifying which MCP servers to connect to.
85
+ */
86
+ constructor(config: McpToolProviderConfig);
87
+ /**
88
+ * Establishes connections to all configured MCP servers and retrieves their tools.
89
+ *
90
+ * This method spawns each server process, establishes communication over stdio,
91
+ * and queries each server for its available tools. The tools are converted to
92
+ * Simulacra-compatible tool classes and stored internally.
93
+ *
94
+ * @returns A promise that resolves when all servers are connected and tools are loaded.
95
+ */
96
+ connect(): Promise<void>;
97
+ /**
98
+ * Closes all MCP server connections and clears the cached tool classes.
99
+ *
100
+ * This method gracefully shuts down all server processes and cleans up
101
+ * internal state. After calling this method, the tool classes are no longer
102
+ * available.
103
+ *
104
+ * @returns A promise that resolves when all servers are disconnected.
105
+ */
106
+ disconnect(): Promise<void>;
107
+ /**
108
+ * Enables automatic cleanup when the provider is disposed.
109
+ *
110
+ * This method implements the disposable pattern, allowing the provider to be
111
+ * used with explicit resource management syntax (using keyword). When disposed,
112
+ * it attempts to disconnect from all servers.
113
+ */
114
+ [Symbol.dispose](): void;
115
+ /**
116
+ * Retrieves all tool classes from connected MCP servers.
117
+ *
118
+ * This method returns a shallow copy of the internal tool classes array,
119
+ * containing Simulacra-compatible tool classes for all tools from all
120
+ * connected servers.
121
+ *
122
+ * @returns An array of tool classes ready to be used in a Simulacra workflow.
123
+ */
124
+ getToolClasses(): ToolClass[];
125
+ }
126
+
127
+ export { type McpServerConfig, McpToolProvider, type McpToolProviderConfig, convertJsonSchemaToParameters };
package/dist/index.js CHANGED
@@ -1,4 +1,233 @@
1
- export * from "./types.js";
2
- export * from "./schema-converter.js";
3
- export * from "./mcp-tool-provider.js";
1
+ // src/schema-converter.ts
2
+ function convertProperty(name, prop, required) {
3
+ const param_type = convertType(prop, required);
4
+ const def = { ...param_type, name };
5
+ if (prop.description) {
6
+ def.description = prop.description;
7
+ }
8
+ return def;
9
+ }
10
+ function convertType(prop, required) {
11
+ if (prop.type === "object" && prop.properties) {
12
+ const nested = {};
13
+ for (const [key, value] of Object.entries(prop.properties)) {
14
+ const child_required = prop.required?.includes(key) ?? false;
15
+ nested[key] = convertType(value, child_required);
16
+ }
17
+ return {
18
+ type: "object",
19
+ required,
20
+ properties: nested,
21
+ ...prop.description ? { description: prop.description } : {}
22
+ };
23
+ }
24
+ if (prop.type === "array" && prop.items) {
25
+ return {
26
+ type: "array",
27
+ required,
28
+ items: convertType(prop.items, false),
29
+ ...prop.description ? { description: prop.description } : {}
30
+ };
31
+ }
32
+ if (prop.type === "string" && prop.enum) {
33
+ return required ? {
34
+ type: "string",
35
+ required: true,
36
+ enum: prop.enum,
37
+ ...prop.description ? { description: prop.description } : {}
38
+ } : {
39
+ type: "string",
40
+ required: false,
41
+ enum: prop.enum,
42
+ ...prop.description ? { description: prop.description } : {}
43
+ };
44
+ }
45
+ if (prop.type === "number" || prop.type === "integer") {
46
+ return required ? {
47
+ type: "number",
48
+ required: true,
49
+ ...prop.description ? { description: prop.description } : {}
50
+ } : {
51
+ type: "number",
52
+ required: false,
53
+ ...prop.description ? { description: prop.description } : {}
54
+ };
55
+ }
56
+ if (prop.type === "boolean") {
57
+ return required ? {
58
+ type: "boolean",
59
+ required: true,
60
+ ...prop.description ? { description: prop.description } : {}
61
+ } : {
62
+ type: "boolean",
63
+ required: false,
64
+ ...prop.description ? { description: prop.description } : {}
65
+ };
66
+ }
67
+ return required ? {
68
+ type: "string",
69
+ required: true,
70
+ ...prop.description ? { description: prop.description } : {}
71
+ } : {
72
+ type: "string",
73
+ required: false,
74
+ ...prop.description ? { description: prop.description } : {}
75
+ };
76
+ }
77
+ function convertJsonSchemaToParameters(schema) {
78
+ const s = schema;
79
+ if (!s.properties) {
80
+ return [];
81
+ }
82
+ const required_set = new Set(s.required ?? []);
83
+ return Object.entries(s.properties).map(
84
+ ([name, prop]) => convertProperty(name, prop, required_set.has(name))
85
+ );
86
+ }
87
+
88
+ // src/mcp-tool-provider.ts
89
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
90
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
91
+ var McpToolProvider = class {
92
+ #config;
93
+ #servers = [];
94
+ #tool_classes = [];
95
+ /**
96
+ * Creates a new MCP tool provider.
97
+ *
98
+ * @param config - Configuration specifying which MCP servers to connect to.
99
+ */
100
+ constructor(config) {
101
+ this.#config = config;
102
+ }
103
+ /**
104
+ * Establishes connections to all configured MCP servers and retrieves their tools.
105
+ *
106
+ * This method spawns each server process, establishes communication over stdio,
107
+ * and queries each server for its available tools. The tools are converted to
108
+ * Simulacra-compatible tool classes and stored internally.
109
+ *
110
+ * @returns A promise that resolves when all servers are connected and tools are loaded.
111
+ */
112
+ async connect() {
113
+ const connected = [];
114
+ const added_tool_classes = [];
115
+ try {
116
+ for (const server_config of this.#config.servers) {
117
+ const transport = new StdioClientTransport({
118
+ command: server_config.command,
119
+ args: server_config.args,
120
+ env: server_config.env
121
+ });
122
+ const client = new Client({ name: "simulacra", version: "0.1.0" }, { capabilities: {} });
123
+ await client.connect(transport);
124
+ const server = { config: server_config, client, transport };
125
+ connected.push(server);
126
+ this.#servers.push(server);
127
+ const tools_result = await client.listTools();
128
+ for (const mcp_tool of tools_result.tools) {
129
+ const tool_class = this.#create_tool_class(client, mcp_tool, server_config);
130
+ added_tool_classes.push(tool_class);
131
+ this.#tool_classes.push(tool_class);
132
+ }
133
+ }
134
+ } catch (error) {
135
+ for (const server of connected) {
136
+ await server.client.close().catch((close_error) => {
137
+ this.#config.on_error?.({
138
+ error: close_error,
139
+ operation: "disconnect",
140
+ context: { during: "connect_rollback" }
141
+ });
142
+ });
143
+ }
144
+ this.#servers = this.#servers.filter((s) => !connected.includes(s));
145
+ this.#tool_classes = this.#tool_classes.filter((t) => !added_tool_classes.includes(t));
146
+ throw error;
147
+ }
148
+ }
149
+ /**
150
+ * Closes all MCP server connections and clears the cached tool classes.
151
+ *
152
+ * This method gracefully shuts down all server processes and cleans up
153
+ * internal state. After calling this method, the tool classes are no longer
154
+ * available.
155
+ *
156
+ * @returns A promise that resolves when all servers are disconnected.
157
+ */
158
+ async disconnect() {
159
+ await Promise.allSettled(this.#servers.map((s) => s.client.close()));
160
+ this.#servers = [];
161
+ this.#tool_classes = [];
162
+ }
163
+ /**
164
+ * Enables automatic cleanup when the provider is disposed.
165
+ *
166
+ * This method implements the disposable pattern, allowing the provider to be
167
+ * used with explicit resource management syntax (using keyword). When disposed,
168
+ * it attempts to disconnect from all servers.
169
+ */
170
+ [Symbol.dispose]() {
171
+ this.disconnect().catch((error) => {
172
+ this.#config.on_error?.({ error, operation: "disconnect", context: { during: "dispose" } });
173
+ });
174
+ }
175
+ /**
176
+ * Retrieves all tool classes from connected MCP servers.
177
+ *
178
+ * This method returns a shallow copy of the internal tool classes array,
179
+ * containing Simulacra-compatible tool classes for all tools from all
180
+ * connected servers.
181
+ *
182
+ * @returns An array of tool classes ready to be used in a Simulacra workflow.
183
+ */
184
+ getToolClasses() {
185
+ return [...this.#tool_classes];
186
+ }
187
+ #create_tool_class(client, mcp_tool, server_config) {
188
+ const parameters = mcp_tool.inputSchema ? convertJsonSchemaToParameters(mcp_tool.inputSchema) : [];
189
+ const parallelizable = server_config.tool_overrides?.[mcp_tool.name]?.parallelizable;
190
+ const definition = {
191
+ name: mcp_tool.name,
192
+ description: mcp_tool.description ?? "",
193
+ parameters,
194
+ ...parallelizable !== void 0 ? { parallelizable } : {}
195
+ };
196
+ const McpTool = class {
197
+ static get_definition() {
198
+ return definition;
199
+ }
200
+ constructor(_context) {
201
+ }
202
+ async execute(params) {
203
+ try {
204
+ const result = await client.callTool({
205
+ name: mcp_tool.name,
206
+ arguments: params
207
+ });
208
+ if (result.isError) {
209
+ const text2 = result.content?.filter((c) => c.type === "text").map((c) => c.text ?? "").join("\n") || "MCP tool error";
210
+ return { result: false, message: text2 };
211
+ }
212
+ const text = result.content?.filter((c) => c.type === "text").map((c) => c.text ?? "").join("\n");
213
+ return {
214
+ result: true,
215
+ ...{ output: text || "success" }
216
+ };
217
+ } catch (error) {
218
+ return {
219
+ result: false,
220
+ message: error instanceof Error ? error.message : String(error),
221
+ error
222
+ };
223
+ }
224
+ }
225
+ };
226
+ return McpTool;
227
+ }
228
+ };
229
+ export {
230
+ McpToolProvider,
231
+ convertJsonSchemaToParameters
232
+ };
4
233
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"sources":["../src/schema-converter.ts","../src/mcp-tool-provider.ts"],"sourcesContent":["import type { ToolParameterDefinition, ParameterType } from \"@simulacra-ai/core\";\n\ninterface JsonSchemaProperty {\n type?: string;\n description?: string;\n enum?: string[];\n properties?: Record<string, JsonSchemaProperty>;\n required?: string[];\n items?: JsonSchemaProperty;\n default?: unknown;\n}\n\ninterface JsonSchema {\n type?: string;\n properties?: Record<string, JsonSchemaProperty>;\n required?: string[];\n}\n\nfunction convertProperty(\n name: string,\n prop: JsonSchemaProperty,\n required: boolean,\n): ToolParameterDefinition {\n const param_type = convertType(prop, required);\n const def: ToolParameterDefinition = { ...param_type, name };\n if (prop.description) {\n def.description = prop.description;\n }\n return def;\n}\n\nfunction convertType(prop: JsonSchemaProperty, required: boolean): ParameterType {\n if (prop.type === \"object\" && prop.properties) {\n const nested: Record<string, ParameterType> = {};\n for (const [key, value] of Object.entries(prop.properties)) {\n const child_required = prop.required?.includes(key) ?? false;\n nested[key] = convertType(value, child_required);\n }\n return {\n type: \"object\",\n required,\n properties: nested,\n ...(prop.description ? { description: prop.description } : {}),\n };\n }\n\n if (prop.type === \"array\" && prop.items) {\n return {\n type: \"array\",\n required,\n items: convertType(prop.items, false),\n ...(prop.description ? { description: prop.description } : {}),\n };\n }\n\n if (prop.type === \"string\" && prop.enum) {\n return required\n ? {\n type: \"string\",\n required: true,\n enum: prop.enum,\n ...(prop.description ? { description: prop.description } : {}),\n }\n : {\n type: \"string\",\n required: false,\n enum: prop.enum,\n ...(prop.description ? { description: prop.description } : {}),\n };\n }\n\n if (prop.type === \"number\" || prop.type === \"integer\") {\n return required\n ? {\n type: \"number\",\n required: true,\n ...(prop.description ? { description: prop.description } : {}),\n }\n : {\n type: \"number\",\n required: false,\n ...(prop.description ? { description: prop.description } : {}),\n };\n }\n\n if (prop.type === \"boolean\") {\n return required\n ? {\n type: \"boolean\",\n required: true,\n ...(prop.description ? { description: prop.description } : {}),\n }\n : {\n type: \"boolean\",\n required: false,\n ...(prop.description ? { description: prop.description } : {}),\n };\n }\n\n // Default: treat as string (covers type === \"string\" and unknown types)\n return required\n ? {\n type: \"string\",\n required: true,\n ...(prop.description ? { description: prop.description } : {}),\n }\n : {\n type: \"string\",\n required: false,\n ...(prop.description ? { description: prop.description } : {}),\n };\n}\n\n/**\n * Converts a JSON Schema object into an array of Simulacra tool parameter definitions.\n *\n * This function transforms MCP tool input schemas (which use JSON Schema format)\n * into the parameter format expected by Simulacra tools. It handles nested objects,\n * arrays, enums, and all standard JSON Schema primitive types.\n *\n * @param schema - A JSON Schema object describing the tool's input parameters.\n * @returns An array of tool parameter definitions compatible with Simulacra.\n */\nexport function convertJsonSchemaToParameters(\n schema: Record<string, unknown>,\n): ToolParameterDefinition[] {\n const s = schema as unknown as JsonSchema;\n if (!s.properties) {\n return [];\n }\n\n const required_set = new Set(s.required ?? []);\n return Object.entries(s.properties).map(([name, prop]) =>\n convertProperty(name, prop, required_set.has(name)),\n );\n}\n","import { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { StdioClientTransport } from \"@modelcontextprotocol/sdk/client/stdio.js\";\nimport type {\n ToolClass,\n ToolDefinition,\n ToolContext,\n ToolSuccessResult,\n ToolErrorResult,\n} from \"@simulacra-ai/core\";\nimport { convertJsonSchemaToParameters } from \"./schema-converter.ts\";\nimport type { McpServerConfig, McpToolProviderConfig } from \"./types.ts\";\n\ninterface ConnectedServer {\n config: McpServerConfig;\n client: Client;\n transport: StdioClientTransport;\n}\n\n/**\n * A provider that connects to Model Context Protocol (MCP) servers and exposes\n * their tools as Simulacra-compatible tool classes.\n *\n * This class manages the lifecycle of MCP server connections, converts MCP tools\n * into the Simulacra tool format, and provides access to all tools from connected\n * servers.\n */\nexport class McpToolProvider {\n readonly #config: McpToolProviderConfig;\n #servers: ConnectedServer[] = [];\n #tool_classes: ToolClass[] = [];\n\n /**\n * Creates a new MCP tool provider.\n *\n * @param config - Configuration specifying which MCP servers to connect to.\n */\n constructor(config: McpToolProviderConfig) {\n this.#config = config;\n }\n\n /**\n * Establishes connections to all configured MCP servers and retrieves their tools.\n *\n * This method spawns each server process, establishes communication over stdio,\n * and queries each server for its available tools. The tools are converted to\n * Simulacra-compatible tool classes and stored internally.\n *\n * @returns A promise that resolves when all servers are connected and tools are loaded.\n */\n async connect(): Promise<void> {\n const connected: ConnectedServer[] = [];\n const added_tool_classes: ToolClass[] = [];\n try {\n for (const server_config of this.#config.servers) {\n const transport = new StdioClientTransport({\n command: server_config.command,\n args: server_config.args,\n env: server_config.env,\n });\n\n const client = new Client({ name: \"simulacra\", version: \"0.1.0\" }, { capabilities: {} });\n\n await client.connect(transport);\n\n const server: ConnectedServer = { config: server_config, client, transport };\n connected.push(server);\n this.#servers.push(server);\n\n const tools_result = await client.listTools();\n\n for (const mcp_tool of tools_result.tools) {\n const tool_class = this.#create_tool_class(client, mcp_tool, server_config);\n added_tool_classes.push(tool_class);\n this.#tool_classes.push(tool_class);\n }\n }\n } catch (error) {\n for (const server of connected) {\n await server.client.close().catch((close_error) => {\n this.#config.on_error?.({\n error: close_error,\n operation: \"disconnect\",\n context: { during: \"connect_rollback\" },\n });\n });\n }\n this.#servers = this.#servers.filter((s) => !connected.includes(s));\n this.#tool_classes = this.#tool_classes.filter((t) => !added_tool_classes.includes(t));\n throw error;\n }\n }\n\n /**\n * Closes all MCP server connections and clears the cached tool classes.\n *\n * This method gracefully shuts down all server processes and cleans up\n * internal state. After calling this method, the tool classes are no longer\n * available.\n *\n * @returns A promise that resolves when all servers are disconnected.\n */\n async disconnect(): Promise<void> {\n await Promise.allSettled(this.#servers.map((s) => s.client.close()));\n this.#servers = [];\n this.#tool_classes = [];\n }\n\n /**\n * Enables automatic cleanup when the provider is disposed.\n *\n * This method implements the disposable pattern, allowing the provider to be\n * used with explicit resource management syntax (using keyword). When disposed,\n * it attempts to disconnect from all servers.\n */\n [Symbol.dispose]() {\n this.disconnect().catch((error) => {\n this.#config.on_error?.({ error, operation: \"disconnect\", context: { during: \"dispose\" } });\n });\n }\n\n /**\n * Retrieves all tool classes from connected MCP servers.\n *\n * This method returns a shallow copy of the internal tool classes array,\n * containing Simulacra-compatible tool classes for all tools from all\n * connected servers.\n *\n * @returns An array of tool classes ready to be used in a Simulacra workflow.\n */\n getToolClasses(): ToolClass[] {\n return [...this.#tool_classes];\n }\n\n #create_tool_class(\n client: Client,\n mcp_tool: { name: string; description?: string; inputSchema?: unknown },\n server_config: McpServerConfig,\n ): ToolClass {\n const parameters = mcp_tool.inputSchema\n ? convertJsonSchemaToParameters(mcp_tool.inputSchema as Record<string, unknown>)\n : [];\n\n const parallelizable = server_config.tool_overrides?.[mcp_tool.name]?.parallelizable;\n\n const definition: ToolDefinition = {\n name: mcp_tool.name,\n description: mcp_tool.description ?? \"\",\n parameters,\n ...(parallelizable !== undefined ? { parallelizable } : {}),\n };\n\n const McpTool = class {\n static get_definition() {\n return definition;\n }\n\n constructor(_context: ToolContext) {}\n\n async execute(params: Record<string, unknown>): Promise<ToolSuccessResult | ToolErrorResult> {\n try {\n const result = await client.callTool({\n name: mcp_tool.name,\n arguments: params,\n });\n\n if (result.isError) {\n const text =\n (result.content as Array<{ type: string; text?: string }>)\n ?.filter((c) => c.type === \"text\")\n .map((c) => c.text ?? \"\")\n .join(\"\\n\") || \"MCP tool error\";\n return { result: false, message: text };\n }\n\n const text = (result.content as Array<{ type: string; text?: string }>)\n ?.filter((c) => c.type === \"text\")\n .map((c) => c.text ?? \"\")\n .join(\"\\n\");\n return {\n result: true,\n ...({ output: text || \"success\" } as Record<string, unknown>),\n } as ToolSuccessResult;\n } catch (error) {\n return {\n result: false,\n message: error instanceof Error ? error.message : String(error),\n error,\n };\n }\n }\n };\n\n return McpTool as unknown as ToolClass;\n }\n}\n"],"mappings":";AAkBA,SAAS,gBACP,MACA,MACA,UACyB;AACzB,QAAM,aAAa,YAAY,MAAM,QAAQ;AAC7C,QAA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vB,KAAK,IAAI,KAAK;AACnB,mBAAO,EAAE,QAAQ,OAAO,SAASA,MAAK;AAAA,UACxC;AAEA,gBAAM,OAAQ,OAAO,SACjB,OAAO,CAAC,MAAM,EAAE,SAAS,MAAM,EAChC,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,EACvB,KAAK,IAAI;AACZ,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,GAAI,EAAE,QAAQ,QAAQ,UAAU;AAAA,UAClC;AAAA,QACF,SAAS,OAAO;AACd,iBAAO;AAAA,YACL,QAAQ;AAAA,YACR,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,YAC9D;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":["text"]}
package/package.json CHANGED
@@ -1,23 +1,29 @@
1
1
  {
2
2
  "name": "@simulacra-ai/mcp",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "MCP (Model Context Protocol) client bridge for the Simulacra conversation engine",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
- "types": "./dist/index.d.ts",
9
- "default": "./dist/index.js"
8
+ "require": {
9
+ "types": "./dist/index.d.cts",
10
+ "default": "./dist/index.cjs"
11
+ },
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ }
10
16
  }
11
17
  },
12
18
  "files": [
13
19
  "dist"
14
20
  ],
15
21
  "scripts": {
16
- "build": "tsc -p tsconfig.json",
22
+ "build": "tsup",
17
23
  "clean": "rm -rf dist *.tsbuildinfo"
18
24
  },
19
25
  "peerDependencies": {
20
- "@simulacra-ai/core": "0.0.3",
26
+ "@simulacra-ai/core": "0.0.5",
21
27
  "@modelcontextprotocol/sdk": ">=1.0.0"
22
28
  },
23
29
  "repository": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC"}
@@ -1,58 +0,0 @@
1
- import type { ToolClass } from "@simulacra-ai/core";
2
- import type { McpToolProviderConfig } from "./types.ts";
3
- /**
4
- * A provider that connects to Model Context Protocol (MCP) servers and exposes
5
- * their tools as Simulacra-compatible tool classes.
6
- *
7
- * This class manages the lifecycle of MCP server connections, converts MCP tools
8
- * into the Simulacra tool format, and provides access to all tools from connected
9
- * servers.
10
- */
11
- export declare class McpToolProvider {
12
- #private;
13
- /**
14
- * Creates a new MCP tool provider.
15
- *
16
- * @param config - Configuration specifying which MCP servers to connect to.
17
- */
18
- constructor(config: McpToolProviderConfig);
19
- /**
20
- * Establishes connections to all configured MCP servers and retrieves their tools.
21
- *
22
- * This method spawns each server process, establishes communication over stdio,
23
- * and queries each server for its available tools. The tools are converted to
24
- * Simulacra-compatible tool classes and stored internally.
25
- *
26
- * @returns A promise that resolves when all servers are connected and tools are loaded.
27
- */
28
- connect(): Promise<void>;
29
- /**
30
- * Closes all MCP server connections and clears the cached tool classes.
31
- *
32
- * This method gracefully shuts down all server processes and cleans up
33
- * internal state. After calling this method, the tool classes are no longer
34
- * available.
35
- *
36
- * @returns A promise that resolves when all servers are disconnected.
37
- */
38
- disconnect(): Promise<void>;
39
- /**
40
- * Enables automatic cleanup when the provider is disposed.
41
- *
42
- * This method implements the disposable pattern, allowing the provider to be
43
- * used with explicit resource management syntax (using keyword). When disposed,
44
- * it attempts to disconnect from all servers.
45
- */
46
- [Symbol.dispose](): void;
47
- /**
48
- * Retrieves all tool classes from connected MCP servers.
49
- *
50
- * This method returns a shallow copy of the internal tool classes array,
51
- * containing Simulacra-compatible tool classes for all tools from all
52
- * connected servers.
53
- *
54
- * @returns An array of tool classes ready to be used in a Simulacra workflow.
55
- */
56
- getToolClasses(): ToolClass[];
57
- }
58
- //# sourceMappingURL=mcp-tool-provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-tool-provider.d.ts","sourceRoot":"","sources":["../src/mcp-tool-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EAKV,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAmB,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAQzE;;;;;;;GAOG;AACH,qBAAa,eAAe;;IAK1B;;;;OAIG;gBACS,MAAM,EAAE,qBAAqB;IAIzC;;;;;;;;OAQG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2C9B;;;;;;;;OAQG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC;;;;;;OAMG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;IAMhB;;;;;;;;OAQG;IACH,cAAc,IAAI,SAAS,EAAE;CAiE9B"}
@@ -1,159 +0,0 @@
1
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
- import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
3
- import { convertJsonSchemaToParameters } from "./schema-converter.js";
4
- /**
5
- * A provider that connects to Model Context Protocol (MCP) servers and exposes
6
- * their tools as Simulacra-compatible tool classes.
7
- *
8
- * This class manages the lifecycle of MCP server connections, converts MCP tools
9
- * into the Simulacra tool format, and provides access to all tools from connected
10
- * servers.
11
- */
12
- export class McpToolProvider {
13
- #config;
14
- #servers = [];
15
- #tool_classes = [];
16
- /**
17
- * Creates a new MCP tool provider.
18
- *
19
- * @param config - Configuration specifying which MCP servers to connect to.
20
- */
21
- constructor(config) {
22
- this.#config = config;
23
- }
24
- /**
25
- * Establishes connections to all configured MCP servers and retrieves their tools.
26
- *
27
- * This method spawns each server process, establishes communication over stdio,
28
- * and queries each server for its available tools. The tools are converted to
29
- * Simulacra-compatible tool classes and stored internally.
30
- *
31
- * @returns A promise that resolves when all servers are connected and tools are loaded.
32
- */
33
- async connect() {
34
- const connected = [];
35
- const added_tool_classes = [];
36
- try {
37
- for (const server_config of this.#config.servers) {
38
- const transport = new StdioClientTransport({
39
- command: server_config.command,
40
- args: server_config.args,
41
- env: server_config.env,
42
- });
43
- const client = new Client({ name: "simulacra", version: "0.1.0" }, { capabilities: {} });
44
- await client.connect(transport);
45
- const server = { config: server_config, client, transport };
46
- connected.push(server);
47
- this.#servers.push(server);
48
- const tools_result = await client.listTools();
49
- for (const mcp_tool of tools_result.tools) {
50
- const tool_class = this.#create_tool_class(client, mcp_tool, server_config);
51
- added_tool_classes.push(tool_class);
52
- this.#tool_classes.push(tool_class);
53
- }
54
- }
55
- }
56
- catch (error) {
57
- for (const server of connected) {
58
- await server.client.close().catch((close_error) => {
59
- this.#config.on_error?.({
60
- error: close_error,
61
- operation: "disconnect",
62
- context: { during: "connect_rollback" },
63
- });
64
- });
65
- }
66
- this.#servers = this.#servers.filter((s) => !connected.includes(s));
67
- this.#tool_classes = this.#tool_classes.filter((t) => !added_tool_classes.includes(t));
68
- throw error;
69
- }
70
- }
71
- /**
72
- * Closes all MCP server connections and clears the cached tool classes.
73
- *
74
- * This method gracefully shuts down all server processes and cleans up
75
- * internal state. After calling this method, the tool classes are no longer
76
- * available.
77
- *
78
- * @returns A promise that resolves when all servers are disconnected.
79
- */
80
- async disconnect() {
81
- await Promise.allSettled(this.#servers.map((s) => s.client.close()));
82
- this.#servers = [];
83
- this.#tool_classes = [];
84
- }
85
- /**
86
- * Enables automatic cleanup when the provider is disposed.
87
- *
88
- * This method implements the disposable pattern, allowing the provider to be
89
- * used with explicit resource management syntax (using keyword). When disposed,
90
- * it attempts to disconnect from all servers.
91
- */
92
- [Symbol.dispose]() {
93
- this.disconnect().catch((error) => {
94
- this.#config.on_error?.({ error, operation: "disconnect", context: { during: "dispose" } });
95
- });
96
- }
97
- /**
98
- * Retrieves all tool classes from connected MCP servers.
99
- *
100
- * This method returns a shallow copy of the internal tool classes array,
101
- * containing Simulacra-compatible tool classes for all tools from all
102
- * connected servers.
103
- *
104
- * @returns An array of tool classes ready to be used in a Simulacra workflow.
105
- */
106
- getToolClasses() {
107
- return [...this.#tool_classes];
108
- }
109
- #create_tool_class(client, mcp_tool, server_config) {
110
- const parameters = mcp_tool.inputSchema
111
- ? convertJsonSchemaToParameters(mcp_tool.inputSchema)
112
- : [];
113
- const parallelizable = server_config.tool_overrides?.[mcp_tool.name]?.parallelizable;
114
- const definition = {
115
- name: mcp_tool.name,
116
- description: mcp_tool.description ?? "",
117
- parameters,
118
- ...(parallelizable !== undefined ? { parallelizable } : {}),
119
- };
120
- const McpTool = class {
121
- static get_definition() {
122
- return definition;
123
- }
124
- constructor(_context) { }
125
- async execute(params) {
126
- try {
127
- const result = await client.callTool({
128
- name: mcp_tool.name,
129
- arguments: params,
130
- });
131
- if (result.isError) {
132
- const text = result.content
133
- ?.filter((c) => c.type === "text")
134
- .map((c) => c.text ?? "")
135
- .join("\n") || "MCP tool error";
136
- return { result: false, message: text };
137
- }
138
- const text = result.content
139
- ?.filter((c) => c.type === "text")
140
- .map((c) => c.text ?? "")
141
- .join("\n");
142
- return {
143
- result: true,
144
- ...{ output: text || "success" },
145
- };
146
- }
147
- catch (error) {
148
- return {
149
- result: false,
150
- message: error instanceof Error ? error.message : String(error),
151
- error,
152
- };
153
- }
154
- }
155
- };
156
- return McpTool;
157
- }
158
- }
159
- //# sourceMappingURL=mcp-tool-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mcp-tool-provider.js","sourceRoot":"","sources":["../src/mcp-tool-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAQjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAStE;;;;;;;GAOG;AACH,MAAM,OAAO,eAAe;IACjB,OAAO,CAAwB;IACxC,QAAQ,GAAsB,EAAE,CAAC;IACjC,aAAa,GAAgB,EAAE,CAAC;IAEhC;;;;OAIG;IACH,YAAY,MAA6B;QACvC,IAAI,CAAC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AAC,IAAI,IAAI,EAAE,CAAC;6BACxB,IAAI,CAAC,IAAI,CAAC,IAAI,gBAAgB,CAAC;wBACpC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;oBAC1C,CAAC;oBAED,MAAM,IAAI,GAAI,MAAM,CAAC,OAAkD;wBACrE,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC;yBACjC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;yBACxB,IAAI,CAAC,IAAI,CAAC,CAAC;oBACd,OAAO;wBACL,MAAM,EAAE,IAAI;wBACZ,GAAI,EAAE,MAAM,EAAE,IAAI,IAAI,SAAS,EAA8B;qBACzC,CAAC;gBACzB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO;wBACL,MAAM,EAAE,KAAK;wBACb,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;wBAC/D,KAAK;qBACN,CAAC;gBACJ,CAAC;YACH,CAAC;SACF,CAAC;QAEF,OAAO,OAA+B,CAAC;IACzC,CAAC;CACF"}
@@ -1,13 +0,0 @@
1
- import type { ToolParameterDefinition } from "@simulacra-ai/core";
2
- /**
3
- * Converts a JSON Schema object into an array of Simulacra tool parameter definitions.
4
- *
5
- * This function transforms MCP tool input schemas (which use JSON Schema format)
6
- * into the parameter format expected by Simulacra tools. It handles nested objects,
7
- * arrays, enums, and all standard JSON Schema primitive types.
8
- *
9
- * @param schema - A JSON Schema object describing the tool's input parameters.
10
- * @returns An array of tool parameter definitions compatible with Simulacra.
11
- */
12
- export declare function convertJsonSchemaToParameters(schema: Record<string, unknown>): ToolParameterDefinition[];
13
- //# sourceMappingURL=schema-converter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema-converter.d.ts","sourceRoot":"","sources":["../src/schema-converter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAiB,MAAM,oBAAoB,CAAC;AAiHjF;;;;;;;;;GASG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,uBAAuB,EAAE,CAU3B"}
@@ -1,103 +0,0 @@
1
- function convertProperty(name, prop, required) {
2
- const param_type = convertType(prop, required);
3
- const def = { ...param_type, name };
4
- if (prop.description) {
5
- def.description = prop.description;
6
- }
7
- return def;
8
- }
9
- function convertType(prop, required) {
10
- if (prop.type === "object" && prop.properties) {
11
- const nested = {};
12
- for (const [key, value] of Object.entries(prop.properties)) {
13
- const child_required = prop.required?.includes(key) ?? false;
14
- nested[key] = convertType(value, child_required);
15
- }
16
- return {
17
- type: "object",
18
- required,
19
- properties: nested,
20
- ...(prop.description ? { description: prop.description } : {}),
21
- };
22
- }
23
- if (prop.type === "array" && prop.items) {
24
- return {
25
- type: "array",
26
- required,
27
- items: convertType(prop.items, false),
28
- ...(prop.description ? { description: prop.description } : {}),
29
- };
30
- }
31
- if (prop.type === "string" && prop.enum) {
32
- return required
33
- ? {
34
- type: "string",
35
- required: true,
36
- enum: prop.enum,
37
- ...(prop.description ? { description: prop.description } : {}),
38
- }
39
- : {
40
- type: "string",
41
- required: false,
42
- enum: prop.enum,
43
- ...(prop.description ? { description: prop.description } : {}),
44
- };
45
- }
46
- if (prop.type === "number" || prop.type === "integer") {
47
- return required
48
- ? {
49
- type: "number",
50
- required: true,
51
- ...(prop.description ? { description: prop.description } : {}),
52
- }
53
- : {
54
- type: "number",
55
- required: false,
56
- ...(prop.description ? { description: prop.description } : {}),
57
- };
58
- }
59
- if (prop.type === "boolean") {
60
- return required
61
- ? {
62
- type: "boolean",
63
- required: true,
64
- ...(prop.description ? { description: prop.description } : {}),
65
- }
66
- : {
67
- type: "boolean",
68
- required: false,
69
- ...(prop.description ? { description: prop.description } : {}),
70
- };
71
- }
72
- // Default: treat as string (covers type === "string" and unknown types)
73
- return required
74
- ? {
75
- type: "string",
76
- required: true,
77
- ...(prop.description ? { description: prop.description } : {}),
78
- }
79
- : {
80
- type: "string",
81
- required: false,
82
- ...(prop.description ? { description: prop.description } : {}),
83
- };
84
- }
85
- /**
86
- * Converts a JSON Schema object into an array of Simulacra tool parameter definitions.
87
- *
88
- * This function transforms MCP tool input schemas (which use JSON Schema format)
89
- * into the parameter format expected by Simulacra tools. It handles nested objects,
90
- * arrays, enums, and all standard JSON Schema primitive types.
91
- *
92
- * @param schema - A JSON Schema object describing the tool's input parameters.
93
- * @returns An array of tool parameter definitions compatible with Simulacra.
94
- */
95
- export function convertJsonSchemaToParameters(schema) {
96
- const s = schema;
97
- if (!s.properties) {
98
- return [];
99
- }
100
- const required_set = new Set(s.required ?? []);
101
- return Object.entries(s.properties).map(([name, prop]) => convertProperty(name, prop, required_set.has(name)));
102
- }
103
- //# sourceMappingURL=schema-converter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schema-converter.js","sourceRoot":"","sources":["../src/schema-converter.ts"],"names":[],"mappings":"AAkBA,SAAS,eAAe,CACtB,IAAY,EACZ,IAAwB,EACxB,QAAiB;IAEjB,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC/C,MAAM,GAAG,GAA4B,EAAE,GAAG,UAAU,EAAE,IAAI,EAAE,CAAC;IAC7D,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;QACrB,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,WAAW,CAAC,IAAwB,EAAE,QAAiB;IAC9D,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAkC,EAAE,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ACR,CAAC;IAED,wEAAwE;IACxE,OAAO,QAAQ;QACb,CAAC,CAAC;YACE,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,IAAI;YACd,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/D;QACH,CAAC,CAAC;YACE,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,KAAK;YACf,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/D,CAAC;AACR,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,6BAA6B,CAC3C,MAA+B;IAE/B,MAAM,CAAC,GAAG,MAA+B,CAAC;IAC1C,IAAI,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IAC/C,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CACvD,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CACpD,CAAC;AACJ,CAAC"}
package/dist/types.d.ts DELETED
@@ -1,57 +0,0 @@
1
- import type { LifecycleErrorEvent } from "@simulacra-ai/core";
2
- /**
3
- * Configuration for a single Model Context Protocol (MCP) server connection.
4
- *
5
- * This interface defines how to connect to and configure an MCP server,
6
- * including the command to execute, environment variables, and tool-specific
7
- * overrides.
8
- */
9
- export interface McpServerConfig {
10
- /**
11
- * A unique identifier for this MCP server.
12
- */
13
- name: string;
14
- /**
15
- * The command to execute to start the MCP server process.
16
- */
17
- command: string;
18
- /**
19
- * Command-line arguments to pass to the server command.
20
- */
21
- args?: string[];
22
- /**
23
- * Environment variables to set for the server process.
24
- */
25
- env?: Record<string, string>;
26
- /**
27
- * The transport mechanism used to communicate with the server.
28
- * Currently only "stdio" is supported.
29
- */
30
- transport?: "stdio";
31
- /**
32
- * Tool-specific configuration overrides, keyed by tool name.
33
- */
34
- tool_overrides?: Record<string, {
35
- /**
36
- * Whether this tool can be executed in parallel with other tools.
37
- */
38
- parallelizable?: boolean;
39
- }>;
40
- }
41
- /**
42
- * Configuration for the MCP tool provider.
43
- *
44
- * This interface defines the configuration needed to connect to one or more
45
- * MCP servers and make their tools available to a Simulacra workflow.
46
- */
47
- export interface McpToolProviderConfig {
48
- /**
49
- * An array of MCP server configurations to connect to.
50
- */
51
- servers: McpServerConfig[];
52
- /**
53
- * Optional callback invoked when a background operation fails during cleanup or disposal.
54
- */
55
- on_error?: (event: LifecycleErrorEvent) => void;
56
- }
57
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE7B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CACrB,MAAM,EACN;QACE;;WAEG;QACH,cAAc,CAAC,EAAE,OAAO,CAAC;KAC1B,CACF,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,OAAO,EAAE,eAAe,EAAE,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI,CAAC;CACjD"}
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}