@agentforge-ai/core 0.1.0 → 0.2.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/agent.d.ts +22 -5
- package/dist/agent.js +1 -0
- package/dist/agent.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-server.d.ts +20 -2
- package/dist/mcp-server.js +12 -0
- package/dist/mcp-server.js.map +1 -1
- package/package.json +3 -2
package/dist/agent.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { LanguageModelV1 } from 'ai';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Supported model types for AgentForge agents.
|
|
5
|
+
*
|
|
6
|
+
* - `LanguageModelV1`: Any AI SDK v4 model instance (e.g., `openai('gpt-4o')`)
|
|
7
|
+
* - `string`: A Mastra model router ID (e.g., `'openai/gpt-4o'`)
|
|
8
|
+
*/
|
|
9
|
+
type AgentModel = LanguageModelV1 | string;
|
|
3
10
|
/**
|
|
4
11
|
* Configuration for creating an AgentForge Agent.
|
|
5
12
|
*/
|
|
@@ -11,19 +18,28 @@ interface AgentConfig {
|
|
|
11
18
|
/** The system prompt or instructions for the agent. */
|
|
12
19
|
instructions: string;
|
|
13
20
|
/**
|
|
14
|
-
* The language model to use.
|
|
15
|
-
* (e.g., from `@ai-sdk/openai
|
|
21
|
+
* The language model to use. Accepts either:
|
|
22
|
+
* - A `LanguageModelV1` instance (e.g., from `@ai-sdk/openai`)
|
|
23
|
+
* - A string model ID (e.g., `'openai/gpt-4o'`)
|
|
16
24
|
*
|
|
17
25
|
* @example
|
|
18
26
|
* ```typescript
|
|
19
27
|
* import { openai } from '@ai-sdk/openai';
|
|
28
|
+
*
|
|
29
|
+
* // Using an AI SDK model instance (BYOK)
|
|
20
30
|
* const agent = new Agent({
|
|
21
31
|
* model: openai('gpt-4o-mini'),
|
|
22
32
|
* // ...
|
|
23
33
|
* });
|
|
34
|
+
*
|
|
35
|
+
* // Using a Mastra model router string
|
|
36
|
+
* const agent = new Agent({
|
|
37
|
+
* model: 'openai/gpt-4o-mini',
|
|
38
|
+
* // ...
|
|
39
|
+
* });
|
|
24
40
|
* ```
|
|
25
41
|
*/
|
|
26
|
-
model:
|
|
42
|
+
model: AgentModel;
|
|
27
43
|
/** A dictionary of tools available to the agent. */
|
|
28
44
|
tools?: Record<string, unknown>;
|
|
29
45
|
}
|
|
@@ -48,7 +64,8 @@ interface StreamChunk {
|
|
|
48
64
|
*
|
|
49
65
|
* Wraps the Mastra Agent to provide a simplified, curated API for
|
|
50
66
|
* creating and interacting with AI agents. Supports any AI SDK-compatible
|
|
51
|
-
* model provider (OpenAI, Anthropic, Google, etc.) via BYOK (Bring Your Own Key)
|
|
67
|
+
* model provider (OpenAI, Anthropic, Google, etc.) via BYOK (Bring Your Own Key),
|
|
68
|
+
* or Mastra model router string IDs.
|
|
52
69
|
*
|
|
53
70
|
* @example
|
|
54
71
|
* ```typescript
|
|
@@ -90,4 +107,4 @@ declare class Agent {
|
|
|
90
107
|
stream(prompt: string): AsyncGenerator<StreamChunk>;
|
|
91
108
|
}
|
|
92
109
|
|
|
93
|
-
export { Agent, type AgentConfig, type AgentResponse, type StreamChunk };
|
|
110
|
+
export { Agent, type AgentConfig, type AgentModel, type AgentResponse, type StreamChunk };
|
package/dist/agent.js
CHANGED
package/dist/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/agent.ts"],"sourcesContent":["import { Agent as MastraAgent } from '@mastra/core/agent';\nimport type { LanguageModelV1 } from 'ai';\n\n/**\n * Configuration for creating an AgentForge Agent.\n */\nexport interface AgentConfig {\n /** A unique identifier for the agent. */\n id: string;\n /** A human-readable name for the agent. */\n name: string;\n /** The system prompt or instructions for the agent. */\n instructions: string;\n /**\n * The language model to use.
|
|
1
|
+
{"version":3,"sources":["../src/agent.ts"],"sourcesContent":["import { Agent as MastraAgent } from '@mastra/core/agent';\nimport type { LanguageModelV1 } from 'ai';\n\n/**\n * Supported model types for AgentForge agents.\n *\n * - `LanguageModelV1`: Any AI SDK v4 model instance (e.g., `openai('gpt-4o')`)\n * - `string`: A Mastra model router ID (e.g., `'openai/gpt-4o'`)\n */\nexport type AgentModel = LanguageModelV1 | string;\n\n/**\n * Configuration for creating an AgentForge Agent.\n */\nexport interface AgentConfig {\n /** A unique identifier for the agent. */\n id: string;\n /** A human-readable name for the agent. */\n name: string;\n /** The system prompt or instructions for the agent. */\n instructions: string;\n /**\n * The language model to use. Accepts either:\n * - A `LanguageModelV1` instance (e.g., from `@ai-sdk/openai`)\n * - A string model ID (e.g., `'openai/gpt-4o'`)\n *\n * @example\n * ```typescript\n * import { openai } from '@ai-sdk/openai';\n *\n * // Using an AI SDK model instance (BYOK)\n * const agent = new Agent({\n * model: openai('gpt-4o-mini'),\n * // ...\n * });\n *\n * // Using a Mastra model router string\n * const agent = new Agent({\n * model: 'openai/gpt-4o-mini',\n * // ...\n * });\n * ```\n */\n model: AgentModel;\n /** A dictionary of tools available to the agent. */\n tools?: Record<string, unknown>;\n}\n\n/**\n * Represents a structured response from an agent generation call.\n */\nexport interface AgentResponse {\n /** The text content of the response. */\n text: string;\n /** Optional tool call results. */\n toolResults?: unknown[];\n}\n\n/**\n * Represents a single chunk in a streaming response.\n */\nexport interface StreamChunk {\n /** The text content of this chunk. */\n content: string;\n}\n\n/**\n * The core Agent class for the AgentForge framework.\n *\n * Wraps the Mastra Agent to provide a simplified, curated API for\n * creating and interacting with AI agents. Supports any AI SDK-compatible\n * model provider (OpenAI, Anthropic, Google, etc.) via BYOK (Bring Your Own Key),\n * or Mastra model router string IDs.\n *\n * @example\n * ```typescript\n * import { openai } from '@ai-sdk/openai';\n *\n * const agent = new Agent({\n * id: 'my-agent',\n * name: 'My Agent',\n * instructions: 'You are a helpful assistant.',\n * model: openai('gpt-4o-mini'),\n * });\n *\n * const response = await agent.generate('Hello!');\n * ```\n */\nexport class Agent {\n /** The agent's unique ID. */\n public readonly id: string;\n\n /** The agent's human-readable name. */\n public readonly name: string;\n\n /** The underlying Mastra agent instance. */\n private mastraAgent: MastraAgent;\n\n /**\n * Creates a new AgentForge Agent.\n * @param config - The configuration for the agent.\n */\n constructor(config: AgentConfig) {\n this.id = config.id;\n this.name = config.name;\n\n this.mastraAgent = new MastraAgent({\n id: config.id,\n name: config.name,\n instructions: config.instructions,\n model: config.model as Parameters<typeof MastraAgent.prototype.generate>[0] extends { model?: infer M } ? M : never,\n ...(config.tools ? { tools: config.tools as Record<string, never> } : {}),\n });\n }\n\n /**\n * Generates a structured response from the agent.\n * @param prompt - The user's prompt or input.\n * @returns A promise that resolves to the agent's response.\n */\n async generate(prompt: string): Promise<AgentResponse> {\n const result = await this.mastraAgent.generate(prompt);\n return result as unknown as AgentResponse;\n }\n\n /**\n * Generates a streaming response from the agent.\n * @param prompt - The user's prompt or input.\n * @returns An async iterable that yields response chunks.\n */\n async *stream(prompt: string): AsyncGenerator<StreamChunk> {\n const result = await this.mastraAgent.stream(prompt);\n for await (const chunk of result.textStream) {\n yield { content: typeof chunk === 'string' ? chunk : String(chunk) };\n }\n }\n}\n"],"mappings":";AAAA,SAAS,SAAS,mBAAmB;AAwF9B,IAAM,QAAN,MAAY;AAAA;AAAA,EAED;AAAA;AAAA,EAGA;AAAA;AAAA,EAGR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMR,YAAY,QAAqB;AAC/B,SAAK,KAAK,OAAO;AACjB,SAAK,OAAO,OAAO;AAEnB,SAAK,cAAc,IAAI,YAAY;AAAA,MACjC,IAAI,OAAO;AAAA,MACX,MAAM,OAAO;AAAA,MACb,cAAc,OAAO;AAAA,MACrB,OAAO,OAAO;AAAA,MACd,GAAI,OAAO,QAAQ,EAAE,OAAO,OAAO,MAA+B,IAAI,CAAC;AAAA,IACzE,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAS,QAAwC;AACrD,UAAM,SAAS,MAAM,KAAK,YAAY,SAAS,MAAM;AACrD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,OAAO,QAA6C;AACzD,UAAM,SAAS,MAAM,KAAK,YAAY,OAAO,MAAM;AACnD,qBAAiB,SAAS,OAAO,YAAY;AAC3C,YAAM,EAAE,SAAS,OAAO,UAAU,WAAW,QAAQ,OAAO,KAAK,EAAE;AAAA,IACrE;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { Agent, AgentConfig, AgentResponse, StreamChunk } from './agent.js';
|
|
1
|
+
export { Agent, AgentConfig, AgentModel, AgentResponse, StreamChunk } from './agent.js';
|
|
2
2
|
export { SandboxConfig, SandboxExecutionError, SandboxManager, SandboxResult, SandboxRunOptions, TimeoutError } from './sandbox.js';
|
|
3
|
-
export { MCPServer, Tool, ToolSchema } from './mcp-server.js';
|
|
3
|
+
export { MCPServer, MCPServerConfig, Tool, ToolSchema } from './mcp-server.js';
|
|
4
4
|
import 'ai';
|
|
5
5
|
import 'zod';
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var Agent = class {
|
|
|
15
15
|
this.id = config.id;
|
|
16
16
|
this.name = config.name;
|
|
17
17
|
this.mastraAgent = new MastraAgent({
|
|
18
|
+
id: config.id,
|
|
18
19
|
name: config.name,
|
|
19
20
|
instructions: config.instructions,
|
|
20
21
|
model: config.model,
|
|
@@ -120,7 +121,19 @@ var SandboxManager = class {
|
|
|
120
121
|
// src/mcp-server.ts
|
|
121
122
|
import { z } from "zod";
|
|
122
123
|
var MCPServer = class {
|
|
124
|
+
/** The server name. */
|
|
125
|
+
name;
|
|
126
|
+
/** The server version. */
|
|
127
|
+
version;
|
|
123
128
|
tools = /* @__PURE__ */ new Map();
|
|
129
|
+
/**
|
|
130
|
+
* Creates a new MCP server instance.
|
|
131
|
+
* @param config - Optional server configuration.
|
|
132
|
+
*/
|
|
133
|
+
constructor(config) {
|
|
134
|
+
this.name = config?.name ?? "agentforge-mcp";
|
|
135
|
+
this.version = config?.version ?? "0.0.0";
|
|
136
|
+
}
|
|
124
137
|
/**
|
|
125
138
|
* Registers a new tool with the MCP server.
|
|
126
139
|
*
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/agent.ts","../src/sandbox.ts","../src/mcp-server.ts"],"sourcesContent":["import { Agent as MastraAgent } from '@mastra/core/agent';\nimport type { LanguageModelV1 } from 'ai';\n\n/**\n * Configuration for creating an AgentForge Agent.\n */\nexport interface AgentConfig {\n /** A unique identifier for the agent. */\n id: string;\n /** A human-readable name for the agent. */\n name: string;\n /** The system prompt or instructions for the agent. */\n instructions: string;\n /**\n * The language model to use. Pass a LanguageModelV1 instance\n * (e.g., from `@ai-sdk/openai`, `@ai-sdk/anthropic`, etc.).\n *\n * @example\n * ```typescript\n * import { openai } from '@ai-sdk/openai';\n * const agent = new Agent({\n * model: openai('gpt-4o-mini'),\n * // ...\n * });\n * ```\n */\n model: LanguageModelV1;\n /** A dictionary of tools available to the agent. */\n tools?: Record<string, unknown>;\n}\n\n/**\n * Represents a structured response from an agent generation call.\n */\nexport interface AgentResponse {\n /** The text content of the response. */\n text: string;\n /** Optional tool call results. */\n toolResults?: unknown[];\n}\n\n/**\n * Represents a single chunk in a streaming response.\n */\nexport interface StreamChunk {\n /** The text content of this chunk. */\n content: string;\n}\n\n/**\n * The core Agent class for the AgentForge framework.\n *\n * Wraps the Mastra Agent to provide a simplified, curated API for\n * creating and interacting with AI agents. Supports any AI SDK-compatible\n * model provider (OpenAI, Anthropic, Google, etc.) via BYOK (Bring Your Own Key).\n *\n * @example\n * ```typescript\n * import { openai } from '@ai-sdk/openai';\n *\n * const agent = new Agent({\n * id: 'my-agent',\n * name: 'My Agent',\n * instructions: 'You are a helpful assistant.',\n * model: openai('gpt-4o-mini'),\n * });\n *\n * const response = await agent.generate('Hello!');\n * ```\n */\nexport class Agent {\n /** The agent's unique ID. */\n public readonly id: string;\n\n /** The agent's human-readable name. */\n public readonly name: string;\n\n /** The underlying Mastra agent instance. */\n private mastraAgent: MastraAgent;\n\n /**\n * Creates a new AgentForge Agent.\n * @param config - The configuration for the agent.\n */\n constructor(config: AgentConfig) {\n this.id = config.id;\n this.name = config.name;\n\n this.mastraAgent = new MastraAgent({\n name: config.name,\n instructions: config.instructions,\n model: config.model,\n ...(config.tools ? { tools: config.tools as Record<string, never> } : {}),\n });\n }\n\n /**\n * Generates a structured response from the agent.\n * @param prompt - The user's prompt or input.\n * @returns A promise that resolves to the agent's response.\n */\n async generate(prompt: string): Promise<AgentResponse> {\n const result = await this.mastraAgent.generate(prompt);\n return result as unknown as AgentResponse;\n }\n\n /**\n * Generates a streaming response from the agent.\n * @param prompt - The user's prompt or input.\n * @returns An async iterable that yields response chunks.\n */\n async *stream(prompt: string): AsyncGenerator<StreamChunk> {\n const result = await this.mastraAgent.stream(prompt);\n for await (const chunk of result.textStream) {\n yield { content: typeof chunk === 'string' ? chunk : String(chunk) };\n }\n }\n}\n","import { Sandbox } from '@e2b/code-interpreter';\n\n/**\n * Configuration for the SandboxManager.\n */\nexport interface SandboxConfig {\n /**\n * The default execution timeout in milliseconds.\n * @default 30000\n */\n timeout?: number;\n}\n\n/**\n * Options for a specific sandbox run.\n */\nexport interface SandboxRunOptions {\n /**\n * The execution timeout in milliseconds for this specific run.\n */\n timeout?: number;\n}\n\n/**\n * Represents the result of a sandbox code execution.\n */\nexport interface SandboxResult {\n /** The output/results from the code execution. */\n output: unknown;\n /** Stdout logs produced during execution. */\n stdout?: string[];\n /** Stderr logs produced during execution. */\n stderr?: string[];\n}\n\n/**\n * A custom error class for sandbox timeouts.\n */\nexport class TimeoutError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n\n/**\n * A custom error class for sandbox execution errors.\n */\nexport class SandboxExecutionError extends Error {\n /** The name of the execution error (e.g., 'SyntaxError'). */\n public readonly errorName: string;\n /** The raw traceback from the sandbox. */\n public readonly traceback: string;\n\n constructor(name: string, value: string, traceback: string) {\n super(`${name}: ${value}`);\n this.name = 'SandboxExecutionError';\n this.errorName = name;\n this.traceback = traceback;\n }\n}\n\n/**\n * Manages the lifecycle of E2B sandboxes for secure code execution.\n *\n * All tool code execution in AgentForge MUST occur within an E2B sandbox\n * to ensure security isolation and prevent malicious code from affecting\n * the host system.\n *\n * @example\n * ```typescript\n * const manager = new SandboxManager({ timeout: 10000 });\n * const result = await manager.runCode('1 + 1');\n * console.log(result); // { output: [...], stdout: [], stderr: [] }\n * ```\n */\nexport class SandboxManager {\n private sandbox: Sandbox | null = null;\n private defaultTimeout: number;\n\n /**\n * Creates a new SandboxManager.\n * @param config - The configuration for the sandbox manager.\n */\n constructor(config: SandboxConfig = {}) {\n this.defaultTimeout = config.timeout ?? 30000;\n }\n\n /**\n * Executes a snippet of code within a secure E2B sandbox.\n *\n * @param code - The code to execute.\n * @param options - Options for this specific run.\n * @returns A promise that resolves to the result of the code execution.\n * @throws {SandboxExecutionError} If the code throws an error.\n */\n async runCode(code: string, options?: SandboxRunOptions): Promise<SandboxResult> {\n const timeoutMs = options?.timeout ?? this.defaultTimeout;\n\n try {\n this.sandbox = await Sandbox.create();\n const execution = await this.sandbox.runCode(code, { timeoutMs });\n\n if (execution.error) {\n throw new SandboxExecutionError(\n execution.error.name,\n execution.error.value,\n execution.error.traceback,\n );\n }\n\n return {\n output: execution.results,\n stdout: execution.logs.stdout,\n stderr: execution.logs.stderr,\n };\n } finally {\n if (this.sandbox) {\n await this.sandbox.kill();\n this.sandbox = null;\n }\n }\n }\n\n /**\n * Terminates the sandbox and releases all associated resources.\n * @returns A promise that resolves when the cleanup is complete.\n */\n async cleanup(): Promise<void> {\n if (this.sandbox) {\n await this.sandbox.kill();\n this.sandbox = null;\n }\n }\n}\n","import { z } from 'zod';\n\n/**\n * Schema descriptor for tool listing.\n */\nexport interface ToolSchema {\n /** The unique name of the tool. */\n name: string;\n /** A human-readable description of the tool. */\n description?: string;\n /** JSON Schema representation of the input. */\n inputSchema: Record<string, unknown>;\n /** JSON Schema representation of the output. */\n outputSchema: Record<string, unknown>;\n}\n\n/**\n * Represents a tool that can be registered and executed by the MCP server.\n *\n * @typeParam TInput - The Zod schema type for the tool's input.\n * @typeParam TOutput - The Zod schema type for the tool's output.\n */\nexport interface Tool<\n TInput extends z.ZodTypeAny = z.ZodTypeAny,\n TOutput extends z.ZodTypeAny = z.ZodTypeAny,\n> {\n /** The unique name of the tool. */\n name: string;\n /** A human-readable description of the tool. */\n description?: string;\n /** The Zod schema for the tool's input. */\n inputSchema: TInput;\n /** The Zod schema for the tool's output. */\n outputSchema: TOutput;\n /**\n * The function that implements the tool's logic.\n * @param input - The validated input matching the input schema.\n * @returns A promise that resolves with the tool's output.\n */\n handler: (input: z.infer<TInput>) => Promise<z.infer<TOutput>>;\n}\n\n/**\n * A server that implements the Model Context Protocol (MCP) for tool communication.\n *\n * Provides a central registry for tools that agents can discover and invoke.\n * All tool inputs and outputs are validated against their Zod schemas.\n *\n * @example\n * ```typescript\n * const server = new MCPServer();\n *\n * server.registerTool({\n * name: 'add',\n * description: 'Adds two numbers',\n * inputSchema: z.object({ a: z.number(), b: z.number() }),\n * outputSchema: z.number(),\n * handler: async ({ a, b }) => a + b,\n * });\n *\n * const result = await server.callTool('add', { a: 5, b: 3 });\n * // result === 8\n * ```\n */\nexport class MCPServer {\n private tools: Map<string, Tool> = new Map();\n\n /**\n * Registers a new tool with the MCP server.\n *\n * @param tool - The tool definition to register.\n * @throws {Error} If a tool with the same name is already registered.\n */\n public registerTool<\n TInput extends z.ZodTypeAny,\n TOutput extends z.ZodTypeAny,\n >(tool: Tool<TInput, TOutput>): void {\n if (this.tools.has(tool.name)) {\n throw new Error(`Tool with name '${tool.name}' is already registered.`);\n }\n this.tools.set(tool.name, tool as unknown as Tool);\n }\n\n /**\n * Retrieves a list of all registered tools and their schemas.\n *\n * @returns An array of tool schema descriptors.\n */\n public listTools(): ToolSchema[] {\n return Array.from(this.tools.values()).map((tool) => ({\n name: tool.name,\n description: tool.description,\n inputSchema: this.zodToJsonSchema(tool.inputSchema),\n outputSchema: this.zodToJsonSchema(tool.outputSchema),\n }));\n }\n\n /**\n * Invokes a specified tool with the provided input.\n *\n * @param toolName - The name of the tool to invoke.\n * @param input - The input to the tool (will be validated against the schema).\n * @returns A promise that resolves with the validated result.\n * @throws {Error} If the tool is not found or input/output validation fails.\n */\n public async callTool(toolName: string, input: unknown): Promise<unknown> {\n const tool = this.tools.get(toolName);\n if (!tool) {\n throw new Error(`Tool with name '${toolName}' not found.`);\n }\n\n const parsedInput = tool.inputSchema.safeParse(input);\n if (!parsedInput.success) {\n throw new Error(\n `Invalid input for tool '${toolName}': ${parsedInput.error.message}`\n );\n }\n\n const result = await tool.handler(parsedInput.data);\n\n const parsedOutput = tool.outputSchema.safeParse(result);\n if (!parsedOutput.success) {\n throw new Error(\n `Invalid output from tool '${toolName}': ${parsedOutput.error.message}`\n );\n }\n\n return parsedOutput.data;\n }\n\n /**\n * Converts a Zod schema to a simplified JSON Schema representation.\n * @param schema - The Zod schema to convert.\n * @returns A simplified JSON Schema object.\n */\n private zodToJsonSchema(schema: z.ZodTypeAny): Record<string, unknown> {\n // Simple conversion - in production, use zod-to-json-schema\n if (schema instanceof z.ZodObject) {\n const shape = schema.shape;\n const properties: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(shape)) {\n properties[key] = { type: this.getZodTypeName(value as z.ZodTypeAny) };\n }\n return { type: 'object', properties };\n }\n return { type: this.getZodTypeName(schema) };\n }\n\n /**\n * Gets the type name for a Zod schema.\n */\n private getZodTypeName(schema: z.ZodTypeAny): string {\n if (schema instanceof z.ZodString) return 'string';\n if (schema instanceof z.ZodNumber) return 'number';\n if (schema instanceof z.ZodBoolean) return 'boolean';\n if (schema instanceof z.ZodArray) return 'array';\n if (schema instanceof z.ZodObject) return 'object';\n return 'unknown';\n }\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;AAAA,EAKQ,eAAe,QAA8B;AACnD,QAAI,kBAAkB,EAAE,UAAW,QAAO;AAC1C,QAAI,kBAAkB,EAAE,UAAW,QAAO;AAC1C,QAAI,kBAAkB,EAAE,WAAY,QAAO;AAC3C,QAAI,kBAAkB,EAAE,SAAU,QAAO;AACzC,QAAI,kBAAkB,EAAE,UAAW,QAAO;AAC1C,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/agent.ts","../src/sandbox.ts","../src/mcp-server.ts"],"sourcesContent":["import { Agent as MastraAgent } from '@mastra/core/agent';\nimport type { LanguageModelV1 } from 'ai';\n\n/**\n * Supported model types for AgentForge agents.\n *\n * - `LanguageModelV1`: Any AI SDK v4 model instance (e.g., `openai('gpt-4o')`)\n * - `string`: A Mastra model router ID (e.g., `'openai/gpt-4o'`)\n */\nexport type AgentModel = LanguageModelV1 | string;\n\n/**\n * Configuration for creating an AgentForge Agent.\n */\nexport interface AgentConfig {\n /** A unique identifier for the agent. */\n id: string;\n /** A human-readable name for the agent. */\n name: string;\n /** The system prompt or instructions for the agent. */\n instructions: string;\n /**\n * The language model to use. Accepts either:\n * - A `LanguageModelV1` instance (e.g., from `@ai-sdk/openai`)\n * - A string model ID (e.g., `'openai/gpt-4o'`)\n *\n * @example\n * ```typescript\n * import { openai } from '@ai-sdk/openai';\n *\n * // Using an AI SDK model instance (BYOK)\n * const agent = new Agent({\n * model: openai('gpt-4o-mini'),\n * // ...\n * });\n *\n * // Using a Mastra model router string\n * const agent = new Agent({\n * model: 'openai/gpt-4o-mini',\n * // ...\n * });\n * ```\n */\n model: AgentModel;\n /** A dictionary of tools available to the agent. */\n tools?: Record<string, unknown>;\n}\n\n/**\n * Represents a structured response from an agent generation call.\n */\nexport interface AgentResponse {\n /** The text content of the response. */\n text: string;\n /** Optional tool call results. */\n toolResults?: unknown[];\n}\n\n/**\n * Represents a single chunk in a streaming response.\n */\nexport interface StreamChunk {\n /** The text content of this chunk. */\n content: string;\n}\n\n/**\n * The core Agent class for the AgentForge framework.\n *\n * Wraps the Mastra Agent to provide a simplified, curated API for\n * creating and interacting with AI agents. Supports any AI SDK-compatible\n * model provider (OpenAI, Anthropic, Google, etc.) via BYOK (Bring Your Own Key),\n * or Mastra model router string IDs.\n *\n * @example\n * ```typescript\n * import { openai } from '@ai-sdk/openai';\n *\n * const agent = new Agent({\n * id: 'my-agent',\n * name: 'My Agent',\n * instructions: 'You are a helpful assistant.',\n * model: openai('gpt-4o-mini'),\n * });\n *\n * const response = await agent.generate('Hello!');\n * ```\n */\nexport class Agent {\n /** The agent's unique ID. */\n public readonly id: string;\n\n /** The agent's human-readable name. */\n public readonly name: string;\n\n /** The underlying Mastra agent instance. */\n private mastraAgent: MastraAgent;\n\n /**\n * Creates a new AgentForge Agent.\n * @param config - The configuration for the agent.\n */\n constructor(config: AgentConfig) {\n this.id = config.id;\n this.name = config.name;\n\n this.mastraAgent = new MastraAgent({\n id: config.id,\n name: config.name,\n instructions: config.instructions,\n model: config.model as Parameters<typeof MastraAgent.prototype.generate>[0] extends { model?: infer M } ? M : never,\n ...(config.tools ? { tools: config.tools as Record<string, never> } : {}),\n });\n }\n\n /**\n * Generates a structured response from the agent.\n * @param prompt - The user's prompt or input.\n * @returns A promise that resolves to the agent's response.\n */\n async generate(prompt: string): Promise<AgentResponse> {\n const result = await this.mastraAgent.generate(prompt);\n return result as unknown as AgentResponse;\n }\n\n /**\n * Generates a streaming response from the agent.\n * @param prompt - The user's prompt or input.\n * @returns An async iterable that yields response chunks.\n */\n async *stream(prompt: string): AsyncGenerator<StreamChunk> {\n const result = await this.mastraAgent.stream(prompt);\n for await (const chunk of result.textStream) {\n yield { content: typeof chunk === 'string' ? chunk : String(chunk) };\n }\n }\n}\n","import { Sandbox } from '@e2b/code-interpreter';\n\n/**\n * Configuration for the SandboxManager.\n */\nexport interface SandboxConfig {\n /**\n * The default execution timeout in milliseconds.\n * @default 30000\n */\n timeout?: number;\n}\n\n/**\n * Options for a specific sandbox run.\n */\nexport interface SandboxRunOptions {\n /**\n * The execution timeout in milliseconds for this specific run.\n */\n timeout?: number;\n}\n\n/**\n * Represents the result of a sandbox code execution.\n */\nexport interface SandboxResult {\n /** The output/results from the code execution. */\n output: unknown;\n /** Stdout logs produced during execution. */\n stdout?: string[];\n /** Stderr logs produced during execution. */\n stderr?: string[];\n}\n\n/**\n * A custom error class for sandbox timeouts.\n */\nexport class TimeoutError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'TimeoutError';\n }\n}\n\n/**\n * A custom error class for sandbox execution errors.\n */\nexport class SandboxExecutionError extends Error {\n /** The name of the execution error (e.g., 'SyntaxError'). */\n public readonly errorName: string;\n /** The raw traceback from the sandbox. */\n public readonly traceback: string;\n\n constructor(name: string, value: string, traceback: string) {\n super(`${name}: ${value}`);\n this.name = 'SandboxExecutionError';\n this.errorName = name;\n this.traceback = traceback;\n }\n}\n\n/**\n * Manages the lifecycle of E2B sandboxes for secure code execution.\n *\n * All tool code execution in AgentForge MUST occur within an E2B sandbox\n * to ensure security isolation and prevent malicious code from affecting\n * the host system.\n *\n * @example\n * ```typescript\n * const manager = new SandboxManager({ timeout: 10000 });\n * const result = await manager.runCode('1 + 1');\n * console.log(result); // { output: [...], stdout: [], stderr: [] }\n * ```\n */\nexport class SandboxManager {\n private sandbox: Sandbox | null = null;\n private defaultTimeout: number;\n\n /**\n * Creates a new SandboxManager.\n * @param config - The configuration for the sandbox manager.\n */\n constructor(config: SandboxConfig = {}) {\n this.defaultTimeout = config.timeout ?? 30000;\n }\n\n /**\n * Executes a snippet of code within a secure E2B sandbox.\n *\n * @param code - The code to execute.\n * @param options - Options for this specific run.\n * @returns A promise that resolves to the result of the code execution.\n * @throws {SandboxExecutionError} If the code throws an error.\n */\n async runCode(code: string, options?: SandboxRunOptions): Promise<SandboxResult> {\n const timeoutMs = options?.timeout ?? this.defaultTimeout;\n\n try {\n this.sandbox = await Sandbox.create();\n const execution = await this.sandbox.runCode(code, { timeoutMs });\n\n if (execution.error) {\n throw new SandboxExecutionError(\n execution.error.name,\n execution.error.value,\n execution.error.traceback,\n );\n }\n\n return {\n output: execution.results,\n stdout: execution.logs.stdout,\n stderr: execution.logs.stderr,\n };\n } finally {\n if (this.sandbox) {\n await this.sandbox.kill();\n this.sandbox = null;\n }\n }\n }\n\n /**\n * Terminates the sandbox and releases all associated resources.\n * @returns A promise that resolves when the cleanup is complete.\n */\n async cleanup(): Promise<void> {\n if (this.sandbox) {\n await this.sandbox.kill();\n this.sandbox = null;\n }\n }\n}\n","import { z } from 'zod';\n\n/**\n * Configuration for creating an MCP server.\n */\nexport interface MCPServerConfig {\n /** The name of the MCP server. */\n name?: string;\n /** The version of the MCP server. */\n version?: string;\n}\n\n/**\n * Schema descriptor for tool listing.\n */\nexport interface ToolSchema {\n /** The unique name of the tool. */\n name: string;\n /** A human-readable description of the tool. */\n description?: string;\n /** JSON Schema representation of the input. */\n inputSchema: Record<string, unknown>;\n /** JSON Schema representation of the output. */\n outputSchema: Record<string, unknown>;\n}\n\n/**\n * Represents a tool that can be registered and executed by the MCP server.\n *\n * @typeParam TInput - The Zod schema type for the tool's input.\n * @typeParam TOutput - The Zod schema type for the tool's output.\n */\nexport interface Tool<\n TInput extends z.ZodTypeAny = z.ZodTypeAny,\n TOutput extends z.ZodTypeAny = z.ZodTypeAny,\n> {\n /** The unique name of the tool. */\n name: string;\n /** A human-readable description of the tool. */\n description?: string;\n /** The Zod schema for the tool's input. */\n inputSchema: TInput;\n /** The Zod schema for the tool's output. */\n outputSchema: TOutput;\n /**\n * The function that implements the tool's logic.\n * @param input - The validated input matching the input schema.\n * @returns A promise that resolves with the tool's output.\n */\n handler: (input: z.infer<TInput>) => Promise<z.infer<TOutput>>;\n}\n\n/**\n * A server that implements the Model Context Protocol (MCP) for tool communication.\n *\n * Provides a central registry for tools that agents can discover and invoke.\n * All tool inputs and outputs are validated against their Zod schemas.\n *\n * @example\n * ```typescript\n * const server = new MCPServer({ name: 'my-tools', version: '1.0.0' });\n *\n * server.registerTool({\n * name: 'add',\n * description: 'Adds two numbers',\n * inputSchema: z.object({ a: z.number(), b: z.number() }),\n * outputSchema: z.number(),\n * handler: async ({ a, b }) => a + b,\n * });\n *\n * const result = await server.callTool('add', { a: 5, b: 3 });\n * // result === 8\n * ```\n */\nexport class MCPServer {\n /** The server name. */\n public readonly name: string;\n /** The server version. */\n public readonly version: string;\n private tools: Map<string, Tool> = new Map();\n\n /**\n * Creates a new MCP server instance.\n * @param config - Optional server configuration.\n */\n constructor(config?: MCPServerConfig) {\n this.name = config?.name ?? 'agentforge-mcp';\n this.version = config?.version ?? '0.0.0';\n }\n\n /**\n * Registers a new tool with the MCP server.\n *\n * @param tool - The tool definition to register.\n * @throws {Error} If a tool with the same name is already registered.\n */\n public registerTool<\n TInput extends z.ZodTypeAny,\n TOutput extends z.ZodTypeAny,\n >(tool: Tool<TInput, TOutput>): void {\n if (this.tools.has(tool.name)) {\n throw new Error(`Tool with name '${tool.name}' is already registered.`);\n }\n this.tools.set(tool.name, tool as unknown as Tool);\n }\n\n /**\n * Retrieves a list of all registered tools and their schemas.\n *\n * @returns An array of tool schema descriptors.\n */\n public listTools(): ToolSchema[] {\n return Array.from(this.tools.values()).map((tool) => ({\n name: tool.name,\n description: tool.description,\n inputSchema: this.zodToJsonSchema(tool.inputSchema),\n outputSchema: this.zodToJsonSchema(tool.outputSchema),\n }));\n }\n\n /**\n * Invokes a specified tool with the provided input.\n *\n * @param toolName - The name of the tool to invoke.\n * @param input - The input to the tool (will be validated against the schema).\n * @returns A promise that resolves with the validated result.\n * @throws {Error} If the tool is not found or input/output validation fails.\n */\n public async callTool(toolName: string, input: unknown): Promise<unknown> {\n const tool = this.tools.get(toolName);\n if (!tool) {\n throw new Error(`Tool with name '${toolName}' not found.`);\n }\n\n const parsedInput = tool.inputSchema.safeParse(input);\n if (!parsedInput.success) {\n throw new Error(\n `Invalid input for tool '${toolName}': ${parsedInput.error.message}`\n );\n }\n\n const result = await tool.handler(parsedInput.data);\n\n const parsedOutput = tool.outputSchema.safeParse(result);\n if (!parsedOutput.success) {\n throw new Error(\n `Invalid output from tool '${toolName}': ${parsedOutput.error.message}`\n );\n }\n\n return parsedOutput.data;\n }\n\n /**\n * Converts a Zod schema to a simplified JSON Schema representation.\n * @param schema - The Zod schema to convert.\n * @returns A simplified JSON Schema object.\n */\n private zodToJsonSchema(schema: z.ZodTypeAny): Record<string, unknown> {\n if (schema instanceof z.ZodObject) {\n const shape = schema.shape;\n const properties: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(shape)) {\n properties[key] = { type: this.getZodTypeName(value as z.ZodTypeAny) };\n }\n return { type: 'object', properties };\n }\n return { type: this.getZodTypeName(schema) };\n }\n\n /**\n * Gets the type name for a Zod schema.\n */\n private getZodTypeName(schema: z.ZodTypeAny): string {\n if (schema instanceof z.ZodString) return 'string';\n if (schema instanceof z.ZodNumber) return 'number';\n if (schema instanceof z.ZodBoolean) return 'boolean';\n if (schema instanceof z.ZodArray) return 'array';\n if (schema instanceof z.ZodObject) return 'object';\n return 'unknown';\n }\n}\n"],"mappings":";AAAA,SAAS,SAAS,mBAAmB;AAwF9B,IAAM,QAAN,MAAY;AAAA;AAAA,EAED;AAAA;AAAA,EAGA;AAAA;AAAA,EAGR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMR,YAAY,QAAqB;AAC/B,SAAK,KAAK,OAAO;AACjB,SAAK,OAAO,OAAO;AAEnB,SAAK,cAAc,IAAI,YAAY;AAAA,MACjC,IAAI,OAAO;AAAA,MACX,MAAM,OAAO;AAAA,MACb,cAAc,OAAO;AAAA,MACrB,OAAO,OAAO;AAAA,MACd,GAAI,OAAO,QAAQ,EAAE,OAAO,OAAO,MAA+B,IAAI,CAAC;AAAA,IACzE,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,SAAS,QAAwC;AACrD,UAAM,SAAS,MAAM,KAAK,YAAY,SAAS,MAAM;AACrD,WAAO;AAAA,EACT;AAAA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P server.
|
|
5
|
+
*/
|
|
6
|
+
interface MCPServerConfig {
|
|
7
|
+
/** The name of the MCP server. */
|
|
8
|
+
name?: string;
|
|
9
|
+
/** The version of the MCP server. */
|
|
10
|
+
version?: string;
|
|
11
|
+
}
|
|
3
12
|
/**
|
|
4
13
|
* Schema descriptor for tool listing.
|
|
5
14
|
*/
|
|
@@ -43,7 +52,7 @@ interface Tool<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.Zod
|
|
|
43
52
|
*
|
|
44
53
|
* @example
|
|
45
54
|
* ```typescript
|
|
46
|
-
* const server = new MCPServer();
|
|
55
|
+
* const server = new MCPServer({ name: 'my-tools', version: '1.0.0' });
|
|
47
56
|
*
|
|
48
57
|
* server.registerTool({
|
|
49
58
|
* name: 'add',
|
|
@@ -58,7 +67,16 @@ interface Tool<TInput extends z.ZodTypeAny = z.ZodTypeAny, TOutput extends z.Zod
|
|
|
58
67
|
* ```
|
|
59
68
|
*/
|
|
60
69
|
declare class MCPServer {
|
|
70
|
+
/** The server name. */
|
|
71
|
+
readonly name: string;
|
|
72
|
+
/** The server version. */
|
|
73
|
+
readonly version: string;
|
|
61
74
|
private tools;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new MCP server instance.
|
|
77
|
+
* @param config - Optional server configuration.
|
|
78
|
+
*/
|
|
79
|
+
constructor(config?: MCPServerConfig);
|
|
62
80
|
/**
|
|
63
81
|
* Registers a new tool with the MCP server.
|
|
64
82
|
*
|
|
@@ -93,4 +111,4 @@ declare class MCPServer {
|
|
|
93
111
|
private getZodTypeName;
|
|
94
112
|
}
|
|
95
113
|
|
|
96
|
-
export { MCPServer, type Tool, type ToolSchema };
|
|
114
|
+
export { MCPServer, type MCPServerConfig, type Tool, type ToolSchema };
|
package/dist/mcp-server.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
// src/mcp-server.ts
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
var MCPServer = class {
|
|
4
|
+
/** The server name. */
|
|
5
|
+
name;
|
|
6
|
+
/** The server version. */
|
|
7
|
+
version;
|
|
4
8
|
tools = /* @__PURE__ */ new Map();
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new MCP server instance.
|
|
11
|
+
* @param config - Optional server configuration.
|
|
12
|
+
*/
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.name = config?.name ?? "agentforge-mcp";
|
|
15
|
+
this.version = config?.version ?? "0.0.0";
|
|
16
|
+
}
|
|
5
17
|
/**
|
|
6
18
|
* Registers a new tool with the MCP server.
|
|
7
19
|
*
|
package/dist/mcp-server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mcp-server.ts"],"sourcesContent":["import { z } from 'zod';\n\n/**\n * Schema descriptor for tool listing.\n */\nexport interface ToolSchema {\n /** The unique name of the tool. */\n name: string;\n /** A human-readable description of the tool. */\n description?: string;\n /** JSON Schema representation of the input. */\n inputSchema: Record<string, unknown>;\n /** JSON Schema representation of the output. */\n outputSchema: Record<string, unknown>;\n}\n\n/**\n * Represents a tool that can be registered and executed by the MCP server.\n *\n * @typeParam TInput - The Zod schema type for the tool's input.\n * @typeParam TOutput - The Zod schema type for the tool's output.\n */\nexport interface Tool<\n TInput extends z.ZodTypeAny = z.ZodTypeAny,\n TOutput extends z.ZodTypeAny = z.ZodTypeAny,\n> {\n /** The unique name of the tool. */\n name: string;\n /** A human-readable description of the tool. */\n description?: string;\n /** The Zod schema for the tool's input. */\n inputSchema: TInput;\n /** The Zod schema for the tool's output. */\n outputSchema: TOutput;\n /**\n * The function that implements the tool's logic.\n * @param input - The validated input matching the input schema.\n * @returns A promise that resolves with the tool's output.\n */\n handler: (input: z.infer<TInput>) => Promise<z.infer<TOutput>>;\n}\n\n/**\n * A server that implements the Model Context Protocol (MCP) for tool communication.\n *\n * Provides a central registry for tools that agents can discover and invoke.\n * All tool inputs and outputs are validated against their Zod schemas.\n *\n * @example\n * ```typescript\n * const server = new MCPServer();\n *\n * server.registerTool({\n * name: 'add',\n * description: 'Adds two numbers',\n * inputSchema: z.object({ a: z.number(), b: z.number() }),\n * outputSchema: z.number(),\n * handler: async ({ a, b }) => a + b,\n * });\n *\n * const result = await server.callTool('add', { a: 5, b: 3 });\n * // result === 8\n * ```\n */\nexport class MCPServer {\n private tools: Map<string, Tool> = new Map();\n\n /**\n * Registers a new tool with the MCP server.\n *\n * @param tool - The tool definition to register.\n * @throws {Error} If a tool with the same name is already registered.\n */\n public registerTool<\n TInput extends z.ZodTypeAny,\n TOutput extends z.ZodTypeAny,\n >(tool: Tool<TInput, TOutput>): void {\n if (this.tools.has(tool.name)) {\n throw new Error(`Tool with name '${tool.name}' is already registered.`);\n }\n this.tools.set(tool.name, tool as unknown as Tool);\n }\n\n /**\n * Retrieves a list of all registered tools and their schemas.\n *\n * @returns An array of tool schema descriptors.\n */\n public listTools(): ToolSchema[] {\n return Array.from(this.tools.values()).map((tool) => ({\n name: tool.name,\n description: tool.description,\n inputSchema: this.zodToJsonSchema(tool.inputSchema),\n outputSchema: this.zodToJsonSchema(tool.outputSchema),\n }));\n }\n\n /**\n * Invokes a specified tool with the provided input.\n *\n * @param toolName - The name of the tool to invoke.\n * @param input - The input to the tool (will be validated against the schema).\n * @returns A promise that resolves with the validated result.\n * @throws {Error} If the tool is not found or input/output validation fails.\n */\n public async callTool(toolName: string, input: unknown): Promise<unknown> {\n const tool = this.tools.get(toolName);\n if (!tool) {\n throw new Error(`Tool with name '${toolName}' not found.`);\n }\n\n const parsedInput = tool.inputSchema.safeParse(input);\n if (!parsedInput.success) {\n throw new Error(\n `Invalid input for tool '${toolName}': ${parsedInput.error.message}`\n );\n }\n\n const result = await tool.handler(parsedInput.data);\n\n const parsedOutput = tool.outputSchema.safeParse(result);\n if (!parsedOutput.success) {\n throw new Error(\n `Invalid output from tool '${toolName}': ${parsedOutput.error.message}`\n );\n }\n\n return parsedOutput.data;\n }\n\n /**\n * Converts a Zod schema to a simplified JSON Schema representation.\n * @param schema - The Zod schema to convert.\n * @returns A simplified JSON Schema object.\n */\n private zodToJsonSchema(schema: z.ZodTypeAny): Record<string, unknown> {\n
|
|
1
|
+
{"version":3,"sources":["../src/mcp-server.ts"],"sourcesContent":["import { z } from 'zod';\n\n/**\n * Configuration for creating an MCP server.\n */\nexport interface MCPServerConfig {\n /** The name of the MCP server. */\n name?: string;\n /** The version of the MCP server. */\n version?: string;\n}\n\n/**\n * Schema descriptor for tool listing.\n */\nexport interface ToolSchema {\n /** The unique name of the tool. */\n name: string;\n /** A human-readable description of the tool. */\n description?: string;\n /** JSON Schema representation of the input. */\n inputSchema: Record<string, unknown>;\n /** JSON Schema representation of the output. */\n outputSchema: Record<string, unknown>;\n}\n\n/**\n * Represents a tool that can be registered and executed by the MCP server.\n *\n * @typeParam TInput - The Zod schema type for the tool's input.\n * @typeParam TOutput - The Zod schema type for the tool's output.\n */\nexport interface Tool<\n TInput extends z.ZodTypeAny = z.ZodTypeAny,\n TOutput extends z.ZodTypeAny = z.ZodTypeAny,\n> {\n /** The unique name of the tool. */\n name: string;\n /** A human-readable description of the tool. */\n description?: string;\n /** The Zod schema for the tool's input. */\n inputSchema: TInput;\n /** The Zod schema for the tool's output. */\n outputSchema: TOutput;\n /**\n * The function that implements the tool's logic.\n * @param input - The validated input matching the input schema.\n * @returns A promise that resolves with the tool's output.\n */\n handler: (input: z.infer<TInput>) => Promise<z.infer<TOutput>>;\n}\n\n/**\n * A server that implements the Model Context Protocol (MCP) for tool communication.\n *\n * Provides a central registry for tools that agents can discover and invoke.\n * All tool inputs and outputs are validated against their Zod schemas.\n *\n * @example\n * ```typescript\n * const server = new MCPServer({ name: 'my-tools', version: '1.0.0' });\n *\n * server.registerTool({\n * name: 'add',\n * description: 'Adds two numbers',\n * inputSchema: z.object({ a: z.number(), b: z.number() }),\n * outputSchema: z.number(),\n * handler: async ({ a, b }) => a + b,\n * });\n *\n * const result = await server.callTool('add', { a: 5, b: 3 });\n * // result === 8\n * ```\n */\nexport class MCPServer {\n /** The server name. */\n public readonly name: string;\n /** The server version. */\n public readonly version: string;\n private tools: Map<string, Tool> = new Map();\n\n /**\n * Creates a new MCP server instance.\n * @param config - Optional server configuration.\n */\n constructor(config?: MCPServerConfig) {\n this.name = config?.name ?? 'agentforge-mcp';\n this.version = config?.version ?? '0.0.0';\n }\n\n /**\n * Registers a new tool with the MCP server.\n *\n * @param tool - The tool definition to register.\n * @throws {Error} If a tool with the same name is already registered.\n */\n public registerTool<\n TInput extends z.ZodTypeAny,\n TOutput extends z.ZodTypeAny,\n >(tool: Tool<TInput, TOutput>): void {\n if (this.tools.has(tool.name)) {\n throw new Error(`Tool with name '${tool.name}' is already registered.`);\n }\n this.tools.set(tool.name, tool as unknown as Tool);\n }\n\n /**\n * Retrieves a list of all registered tools and their schemas.\n *\n * @returns An array of tool schema descriptors.\n */\n public listTools(): ToolSchema[] {\n return Array.from(this.tools.values()).map((tool) => ({\n name: tool.name,\n description: tool.description,\n inputSchema: this.zodToJsonSchema(tool.inputSchema),\n outputSchema: this.zodToJsonSchema(tool.outputSchema),\n }));\n }\n\n /**\n * Invokes a specified tool with the provided input.\n *\n * @param toolName - The name of the tool to invoke.\n * @param input - The input to the tool (will be validated against the schema).\n * @returns A promise that resolves with the validated result.\n * @throws {Error} If the tool is not found or input/output validation fails.\n */\n public async callTool(toolName: string, input: unknown): Promise<unknown> {\n const tool = this.tools.get(toolName);\n if (!tool) {\n throw new Error(`Tool with name '${toolName}' not found.`);\n }\n\n const parsedInput = tool.inputSchema.safeParse(input);\n if (!parsedInput.success) {\n throw new Error(\n `Invalid input for tool '${toolName}': ${parsedInput.error.message}`\n );\n }\n\n const result = await tool.handler(parsedInput.data);\n\n const parsedOutput = tool.outputSchema.safeParse(result);\n if (!parsedOutput.success) {\n throw new Error(\n `Invalid output from tool '${toolName}': ${parsedOutput.error.message}`\n );\n }\n\n return parsedOutput.data;\n }\n\n /**\n * Converts a Zod schema to a simplified JSON Schema representation.\n * @param schema - The Zod schema to convert.\n * @returns A simplified JSON Schema object.\n */\n private zodToJsonSchema(schema: z.ZodTypeAny): Record<string, unknown> {\n if (schema instanceof z.ZodObject) {\n const shape = schema.shape;\n const properties: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(shape)) {\n properties[key] = { type: this.getZodTypeName(value as z.ZodTypeAny) };\n }\n return { type: 'object', properties };\n }\n return { type: this.getZodTypeName(schema) };\n }\n\n /**\n * Gets the type name for a Zod schema.\n */\n private getZodTypeName(schema: z.ZodTypeAny): string {\n if (schema instanceof z.ZodString) return 'string';\n if (schema instanceof z.ZodNumber) return 'number';\n if (schema instanceof z.ZodBoolean) return 'boolean';\n if (schema instanceof z.ZodArray) return 'array';\n if (schema instanceof z.ZodObject) return 'object';\n return 'unknown';\n }\n}\n"],"mappings":";AAAA,SAAS,SAAS;AA0EX,IAAM,YAAN,MAAgB;AAAA;AAAA,EAEL;AAAA;AAAA,EAEA;AAAA,EACR,QAA2B,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3C,YAAY,QAA0B;AACpC,SAAK,OAAO,QAAQ,QAAQ;AAC5B,SAAK,UAAU,QAAQ,WAAW;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,aAGL,MAAmC;AACnC,QAAI,KAAK,MAAM,IAAI,KAAK,IAAI,GAAG;AAC7B,YAAM,IAAI,MAAM,mBAAmB,KAAK,IAAI,0BAA0B;AAAA,IACxE;AACA,SAAK,MAAM,IAAI,KAAK,MAAM,IAAuB;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,YAA0B;AAC/B,WAAO,MAAM,KAAK,KAAK,MAAM,OAAO,CAAC,EAAE,IAAI,CAAC,UAAU;AAAA,MACpD,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK,gBAAgB,KAAK,WAAW;AAAA,MAClD,cAAc,KAAK,gBAAgB,KAAK,YAAY;AAAA,IACtD,EAAE;AAAA,EACJ;AAA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AAW,QAAO;AAC1C,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentforge-ai/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Core agent primitives, sandbox integration, and MCP server for AgentForge",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -30,13 +30,14 @@
|
|
|
30
30
|
"scripts": {
|
|
31
31
|
"build": "tsup",
|
|
32
32
|
"test": "vitest run",
|
|
33
|
+
"test:coverage": "vitest run --coverage",
|
|
33
34
|
"test:watch": "vitest",
|
|
34
35
|
"typecheck": "tsc --noEmit",
|
|
35
36
|
"lint": "eslint src/",
|
|
36
37
|
"clean": "rm -rf dist"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@mastra/core": "^
|
|
40
|
+
"@mastra/core": "^1.4.0",
|
|
40
41
|
"ai": "^4.0.0",
|
|
41
42
|
"@e2b/code-interpreter": "^1.0.0",
|
|
42
43
|
"zod": "^3.23.0"
|