@simulacra-ai/mcp 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # Simulacra MCP Bridge
2
+
3
+ MCP (Model Context Protocol) client bridge for the Simulacra conversation engine. Connects to MCP servers and exposes their tools as Simulacra tool classes.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @simulacra-ai/core @simulacra-ai/mcp @modelcontextprotocol/sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { Conversation, WorkflowManager } from "@simulacra-ai/core";
15
+ import { AnthropicProvider } from "@simulacra-ai/anthropic";
16
+ import Anthropic from "@anthropic-ai/sdk";
17
+ import { McpToolProvider } from "@simulacra-ai/mcp";
18
+
19
+ const mcp = new McpToolProvider({
20
+ servers: [
21
+ {
22
+ name: "filesystem",
23
+ command: "npx",
24
+ args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
25
+ },
26
+ ],
27
+ });
28
+
29
+ await mcp.connect();
30
+
31
+ const provider = new AnthropicProvider(new Anthropic(), { model: MODEL_NAME });
32
+ const conversation = new Conversation(provider);
33
+ conversation.toolkit = [...conversation.toolkit, ...mcp.getToolClasses()];
34
+ const manager = new WorkflowManager(conversation);
35
+
36
+ await conversation.prompt("List the files in /tmp");
37
+
38
+ await mcp.disconnect();
39
+ ```
40
+
41
+ ### Multiple Servers
42
+
43
+ ```typescript
44
+ const mcp = new McpToolProvider({
45
+ servers: [
46
+ {
47
+ name: "filesystem",
48
+ command: "npx",
49
+ args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
50
+ },
51
+ {
52
+ name: "database",
53
+ command: "node",
54
+ args: ["./my-db-server.js"],
55
+ env: { DATABASE_URL: "postgres://localhost/mydb" },
56
+ },
57
+ ],
58
+ });
59
+ ```
60
+
61
+ ### Tool Overrides
62
+
63
+ By default, all MCP tools are `parallelizable: true`. Override specific tools with side effects or ordering requirements:
64
+
65
+ ```typescript
66
+ {
67
+ name: "database",
68
+ command: "node",
69
+ args: ["./my-db-server.js"],
70
+ tool_overrides: {
71
+ "execute_query": { parallelizable: false },
72
+ "create_table": { parallelizable: false },
73
+ },
74
+ }
75
+ ```
76
+
77
+ ## License
78
+
79
+ MIT
@@ -0,0 +1,4 @@
1
+ export * from "./types.ts";
2
+ export * from "./schema-converter.ts";
3
+ export * from "./mcp-tool-provider.ts";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./types.js";
2
+ export * from "./schema-converter.js";
3
+ export * from "./mcp-tool-provider.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,58 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,159 @@
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
@@ -0,0 +1 @@
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,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,SAAS,GAAsB,EAAE,CAAC;QACxC,MAAM,kBAAkB,GAAgB,EAAE,CAAC;QAC3C,IAAI,CAAC;YACH,KAAK,MAAM,aAAa,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;gBACjD,MAAM,SAAS,GAAG,IAAI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AC,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"}
@@ -0,0 +1,13 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,103 @@
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
@@ -0,0 +1 @@
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,CAAC;QACjD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC3D,MAAM,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C,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"}
@@ -0,0 +1,57 @@
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
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@simulacra-ai/mcp",
3
+ "version": "0.0.1",
4
+ "description": "MCP (Model Context Protocol) client bridge for the Simulacra conversation engine",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc -p tsconfig.json",
17
+ "clean": "rm -rf dist *.tsbuildinfo"
18
+ },
19
+ "peerDependencies": {
20
+ "@simulacra-ai/core": "0.0.1",
21
+ "@modelcontextprotocol/sdk": ">=1.0.0"
22
+ },
23
+ "license": "MIT"
24
+ }