@hazeljs/mcp 0.7.9 → 0.8.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/README.md CHANGED
@@ -52,7 +52,7 @@ export class SupportAgent {
52
52
  description: 'Open a new support ticket',
53
53
  parameters: [
54
54
  { name: 'customer_id', type: 'string', description: 'Customer ID', required: true },
55
- { name: 'subject', type: 'string', description: 'Ticket subject', required: true },
55
+ { name: 'subject', type: 'string', description: 'Ticket subject', required: true },
56
56
  ],
57
57
  })
58
58
  async createTicket(input: Record<string, unknown>) {
@@ -113,10 +113,18 @@ import type { IToolRegistry, HazelTool } from '@hazeljs/mcp';
113
113
  class SimpleRegistry implements IToolRegistry {
114
114
  private tools = new Map<string, HazelTool>();
115
115
 
116
- register(tool: HazelTool) { this.tools.set(tool.name, tool); }
117
- getAllTools() { return [...this.tools.values()]; }
118
- getTool(name: string) { return this.tools.get(name); }
119
- hasTool(name: string) { return this.tools.has(name); }
116
+ register(tool: HazelTool) {
117
+ this.tools.set(tool.name, tool);
118
+ }
119
+ getAllTools() {
120
+ return [...this.tools.values()];
121
+ }
122
+ getTool(name: string) {
123
+ return this.tools.get(name);
124
+ }
125
+ hasTool(name: string) {
126
+ return this.tools.has(name);
127
+ }
120
128
  }
121
129
 
122
130
  const registry = new SimpleRegistry();
@@ -125,7 +133,7 @@ registry.register({
125
133
  name: 'add',
126
134
  description: 'Returns the sum of two numbers',
127
135
  parameters: [
128
- { name: 'a', type: 'number', description: 'First operand', required: true },
136
+ { name: 'a', type: 'number', description: 'First operand', required: true },
129
137
  { name: 'b', type: 'number', description: 'Second operand', required: true },
130
138
  ],
131
139
  target: {},
@@ -180,9 +188,9 @@ AI assistant in Cursor looks up customers, checks orders, and files tickets —
180
188
  // AI does this automatically when you ask:
181
189
  // "Alice says her order hasn't arrived. Check the status and open a ticket."
182
190
 
183
- await adapter.invoke('lookup_customer', { email: 'alice@example.com' });
191
+ await adapter.invoke('lookup_customer', { email: 'alice@example.com' });
184
192
  await adapter.invoke('get_order_status', { order_id: 'ORD-1001' });
185
- await adapter.invoke('create_ticket', { customer_id: 'cust_001', subject: 'Order not arrived' });
193
+ await adapter.invoke('create_ticket', { customer_id: 'cust_001', subject: 'Order not arrived' });
186
194
  ```
187
195
 
188
196
  ### On-call runbook automation
@@ -213,15 +221,15 @@ async exportUserData(input: { userId: string }) { ... }
213
221
 
214
222
  ## Hazel → MCP field mapping
215
223
 
216
- | Hazel (`ToolMetadata`) | MCP (`McpToolDefinition`) |
217
- |---|---|
218
- | `name` | `name` |
219
- | `description` | `description` |
220
- | `parameters[].name` | `inputSchema.properties.<key>` |
221
- | `parameters[].type` | `inputSchema.properties.<key>.type` |
224
+ | Hazel (`ToolMetadata`) | MCP (`McpToolDefinition`) |
225
+ | -------------------------- | ------------------------------------------ |
226
+ | `name` | `name` |
227
+ | `description` | `description` |
228
+ | `parameters[].name` | `inputSchema.properties.<key>` |
229
+ | `parameters[].type` | `inputSchema.properties.<key>.type` |
222
230
  | `parameters[].description` | `inputSchema.properties.<key>.description` |
223
- | `parameters[].enum` | `inputSchema.properties.<key>.enum` |
224
- | `parameters[].required` | `inputSchema.required[]` |
231
+ | `parameters[].enum` | `inputSchema.properties.<key>.enum` |
232
+ | `parameters[].required` | `inputSchema.required[]` |
225
233
 
226
234
  If a tool has no `parameters`, an open schema is emitted that accepts any JSON object.
227
235
 
@@ -235,13 +243,13 @@ If a tool has no `parameters`, an open schema is emitted that accepts any JSON o
235
243
  function createMcpServer(options: McpServerOptions): McpServer;
236
244
 
237
245
  interface McpServerOptions {
238
- name: string; // server name advertised during MCP initialize
239
- version: string; // server version advertised during MCP initialize
246
+ name: string; // server name advertised during MCP initialize
247
+ version: string; // server version advertised during MCP initialize
240
248
  toolRegistry: IToolRegistry;
241
249
  }
242
250
 
243
251
  interface McpServer {
244
- listenStdio(): void; // attach to process.stdin / process.stdout
252
+ listenStdio(): void; // attach to process.stdin / process.stdout
245
253
  listTools(): McpToolDefinition[]; // inspect registered tools without serving
246
254
  }
247
255
  ```
@@ -273,7 +281,13 @@ interface IToolRegistry {
273
281
  interface HazelTool {
274
282
  name: string;
275
283
  description: string;
276
- parameters?: Array<{ name: string; type: string; description: string; required?: boolean; enum?: unknown[] }>;
284
+ parameters?: Array<{
285
+ name: string;
286
+ type: string;
287
+ description: string;
288
+ required?: boolean;
289
+ enum?: unknown[];
290
+ }>;
277
291
  target: object;
278
292
  method: Function;
279
293
  }
@@ -281,23 +295,23 @@ interface HazelTool {
281
295
 
282
296
  ### Supported MCP methods
283
297
 
284
- | Method | Description |
285
- |---|---|
286
- | `initialize` | Handshake — returns server info and capabilities |
287
- | `ping` | Liveness probe |
288
- | `tools/list` | Returns all registered tool definitions |
298
+ | Method | Description |
299
+ | ------------ | --------------------------------------------------- |
300
+ | `initialize` | Handshake — returns server info and capabilities |
301
+ | `ping` | Liveness probe |
302
+ | `tools/list` | Returns all registered tool definitions |
289
303
  | `tools/call` | Invokes a tool and returns a content block response |
290
304
 
291
305
  ### Error codes
292
306
 
293
- | Code | Constant | Meaning |
294
- |---|---|---|
295
- | -32700 | `PARSE_ERROR` | stdin line could not be parsed as JSON |
296
- | -32600 | `INVALID_REQUEST` | Not a valid JSON-RPC 2.0 request |
297
- | -32601 | `METHOD_NOT_FOUND` | No handler for the given method |
298
- | -32602 | `INVALID_PARAMS` | Required parameter missing or malformed |
299
- | -32603 | `INTERNAL_ERROR` | Unexpected exception inside a handler |
300
- | -32001 | `TOOL_NOT_FOUND` | Named tool is not registered |
307
+ | Code | Constant | Meaning |
308
+ | ------ | ------------------ | --------------------------------------- |
309
+ | -32700 | `PARSE_ERROR` | stdin line could not be parsed as JSON |
310
+ | -32600 | `INVALID_REQUEST` | Not a valid JSON-RPC 2.0 request |
311
+ | -32601 | `METHOD_NOT_FOUND` | No handler for the given method |
312
+ | -32602 | `INVALID_PARAMS` | Required parameter missing or malformed |
313
+ | -32603 | `INTERNAL_ERROR` | Unexpected exception inside a handler |
314
+ | -32001 | `TOOL_NOT_FOUND` | Named tool is not registered |
301
315
 
302
316
  ---
303
317
 
@@ -0,0 +1,75 @@
1
+ /**
2
+ * MCP Client — Connect to external MCP servers
3
+ *
4
+ * Allows HazelJS agents to discover and invoke tools from external
5
+ * MCP-compatible servers via STDIO or HTTP transport.
6
+ *
7
+ * @example STDIO transport (e.g., connect to a local MCP server):
8
+ * ```ts
9
+ * const client = new McpClient({ name: 'my-app', version: '1.0.0' });
10
+ *
11
+ * await client.connectStdio({
12
+ * id: 'github',
13
+ * name: 'GitHub MCP',
14
+ * transport: {
15
+ * type: 'stdio',
16
+ * command: 'npx',
17
+ * args: ['-y', '@modelcontextprotocol/server-github'],
18
+ * env: { GITHUB_TOKEN: process.env.GITHUB_TOKEN! },
19
+ * },
20
+ * });
21
+ *
22
+ * const tools = client.listTools(); // discover available tools
23
+ * const result = await client.callTool('github.create_issue', { title: 'Bug' });
24
+ * ```
25
+ *
26
+ * @example Register MCP tools into an agent's ToolRegistry:
27
+ * ```ts
28
+ * import { ToolRegistry } from '@hazeljs/agent';
29
+ * const registry = new ToolRegistry();
30
+ * client.registerToolsInto(registry);
31
+ * ```
32
+ */
33
+ import type { McpClientOptions, McpServerConfig, McpRemoteTool, McpToolCallResult } from './types';
34
+ export declare class McpClient {
35
+ private readonly clientInfo;
36
+ private servers;
37
+ private nextId;
38
+ constructor(options: McpClientOptions);
39
+ /**
40
+ * Connect to an MCP server using the specified transport.
41
+ * Performs the initialize handshake and discovers available tools.
42
+ */
43
+ connect(config: McpServerConfig): Promise<void>;
44
+ private connectStdio;
45
+ private connectHttp;
46
+ /**
47
+ * List all tools from all connected servers.
48
+ */
49
+ listTools(): McpRemoteTool[];
50
+ /**
51
+ * List tools from a specific server.
52
+ */
53
+ listServerTools(serverId: string): McpRemoteTool[];
54
+ /**
55
+ * Call a tool by its qualified name (e.g., "github.create_issue").
56
+ */
57
+ callTool(qualifiedName: string, args?: Record<string, unknown>): Promise<McpToolCallResult>;
58
+ /**
59
+ * Check if a tool exists by qualified name.
60
+ */
61
+ hasTool(qualifiedName: string): boolean;
62
+ /**
63
+ * Disconnect from a specific server.
64
+ */
65
+ disconnect(serverId: string): void;
66
+ /**
67
+ * Disconnect from all servers.
68
+ */
69
+ disconnectAll(): void;
70
+ /**
71
+ * Get connected server IDs.
72
+ */
73
+ getConnectedServers(): string[];
74
+ }
75
+ //# sourceMappingURL=mcp-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/client/mcp-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAKH,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,iBAAiB,EAGlB,MAAM,SAAS,CAAC;AAyBjB,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,OAAO,CAA2C;IAC1D,OAAO,CAAC,MAAM,CAAK;gBAEP,OAAO,EAAE,gBAAgB;IAQrC;;;OAGG;IACG,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;YAkBvC,YAAY;YA8GZ,WAAW;IAwEzB;;OAEG;IACH,SAAS,IAAI,aAAa,EAAE;IAQ5B;;OAEG;IACH,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,EAAE;IAKlD;;OAEG;IACG,QAAQ,CACZ,aAAa,EAAE,MAAM,EACrB,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACjC,OAAO,CAAC,iBAAiB,CAAC;IAsB7B;;OAEG;IACH,OAAO,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO;IAQvC;;OAEG;IACH,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAQlC;;OAEG;IACH,aAAa,IAAI,IAAI;IAMrB;;OAEG;IACH,mBAAmB,IAAI,MAAM,EAAE;CAGhC"}
@@ -0,0 +1,275 @@
1
+ "use strict";
2
+ /**
3
+ * MCP Client — Connect to external MCP servers
4
+ *
5
+ * Allows HazelJS agents to discover and invoke tools from external
6
+ * MCP-compatible servers via STDIO or HTTP transport.
7
+ *
8
+ * @example STDIO transport (e.g., connect to a local MCP server):
9
+ * ```ts
10
+ * const client = new McpClient({ name: 'my-app', version: '1.0.0' });
11
+ *
12
+ * await client.connectStdio({
13
+ * id: 'github',
14
+ * name: 'GitHub MCP',
15
+ * transport: {
16
+ * type: 'stdio',
17
+ * command: 'npx',
18
+ * args: ['-y', '@modelcontextprotocol/server-github'],
19
+ * env: { GITHUB_TOKEN: process.env.GITHUB_TOKEN! },
20
+ * },
21
+ * });
22
+ *
23
+ * const tools = client.listTools(); // discover available tools
24
+ * const result = await client.callTool('github.create_issue', { title: 'Bug' });
25
+ * ```
26
+ *
27
+ * @example Register MCP tools into an agent's ToolRegistry:
28
+ * ```ts
29
+ * import { ToolRegistry } from '@hazeljs/agent';
30
+ * const registry = new ToolRegistry();
31
+ * client.registerToolsInto(registry);
32
+ * ```
33
+ */
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.McpClient = void 0;
36
+ const child_process_1 = require("child_process");
37
+ const readline_1 = require("readline");
38
+ class McpClient {
39
+ constructor(options) {
40
+ this.servers = new Map();
41
+ this.nextId = 1;
42
+ this.clientInfo = options;
43
+ }
44
+ // -------------------------------------------------------------------------
45
+ // Connect
46
+ // -------------------------------------------------------------------------
47
+ /**
48
+ * Connect to an MCP server using the specified transport.
49
+ * Performs the initialize handshake and discovers available tools.
50
+ */
51
+ async connect(config) {
52
+ if (this.servers.has(config.id)) {
53
+ throw new Error(`Server "${config.id}" is already connected`);
54
+ }
55
+ if (config.transport.type === 'stdio') {
56
+ await this.connectStdio(config, config.transport);
57
+ }
58
+ else if (config.transport.type === 'http') {
59
+ await this.connectHttp(config, config.transport);
60
+ }
61
+ else {
62
+ throw new Error(`Unknown transport type: ${config.transport.type}`);
63
+ }
64
+ }
65
+ // -------------------------------------------------------------------------
66
+ // STDIO Transport
67
+ // -------------------------------------------------------------------------
68
+ async connectStdio(config, transport) {
69
+ const child = (0, child_process_1.spawn)(transport.command, transport.args ?? [], {
70
+ stdio: ['pipe', 'pipe', 'pipe'],
71
+ env: { ...process.env, ...(transport.env ?? {}) },
72
+ cwd: transport.cwd,
73
+ });
74
+ if (!child.stdin || !child.stdout) {
75
+ throw new Error(`Failed to spawn STDIO process for server "${config.id}"`);
76
+ }
77
+ const pendingRequests = new Map();
78
+ // Read line-delimited JSON responses
79
+ const rl = (0, readline_1.createInterface)({ input: child.stdout });
80
+ rl.on('line', (line) => {
81
+ try {
82
+ const response = JSON.parse(line);
83
+ const pending = pendingRequests.get(response.id);
84
+ if (pending) {
85
+ clearTimeout(pending.timer);
86
+ pendingRequests.delete(response.id);
87
+ if (response.error) {
88
+ pending.reject(new Error(`MCP error: ${response.error.message}`));
89
+ }
90
+ else {
91
+ pending.resolve(response.result);
92
+ }
93
+ }
94
+ }
95
+ catch {
96
+ // Ignore non-JSON lines (server logs, etc.)
97
+ }
98
+ });
99
+ const requestFn = (method, params) => {
100
+ return new Promise((resolve, reject) => {
101
+ const id = this.nextId++;
102
+ const request = {
103
+ jsonrpc: '2.0',
104
+ id,
105
+ method,
106
+ ...(params !== undefined ? { params } : {}),
107
+ };
108
+ // Timeout after 30s
109
+ const timer = setTimeout(() => {
110
+ if (pendingRequests.has(id)) {
111
+ pendingRequests.delete(id);
112
+ reject(new Error(`MCP request timed out: ${method}`));
113
+ }
114
+ }, 30000);
115
+ pendingRequests.set(id, { resolve, reject, timer });
116
+ child.stdin.write(JSON.stringify(request) + '\n');
117
+ });
118
+ };
119
+ const disconnectFn = () => {
120
+ rl.close();
121
+ child.kill();
122
+ };
123
+ // Initialize handshake
124
+ await requestFn('initialize', {
125
+ protocolVersion: '2024-11-05',
126
+ capabilities: {},
127
+ clientInfo: { name: this.clientInfo.name, version: this.clientInfo.version },
128
+ });
129
+ // Send initialized notification
130
+ child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'initialized' }) + '\n');
131
+ // Discover tools
132
+ const toolsResult = (await requestFn('tools/list'));
133
+ const tools = (toolsResult.tools ?? []).map((t) => ({
134
+ qualifiedName: `${config.id}.${t.name}`,
135
+ name: t.name,
136
+ serverId: config.id,
137
+ description: t.description,
138
+ inputSchema: t.inputSchema,
139
+ }));
140
+ this.servers.set(config.id, {
141
+ config,
142
+ tools,
143
+ request: requestFn,
144
+ disconnect: disconnectFn,
145
+ });
146
+ }
147
+ // -------------------------------------------------------------------------
148
+ // HTTP Transport
149
+ // -------------------------------------------------------------------------
150
+ async connectHttp(config, transport) {
151
+ const requestFn = async (method, params) => {
152
+ const id = this.nextId++;
153
+ const body = {
154
+ jsonrpc: '2.0',
155
+ id,
156
+ method,
157
+ ...(params !== undefined ? { params } : {}),
158
+ };
159
+ const response = await fetch(transport.url, {
160
+ method: 'POST',
161
+ headers: {
162
+ 'Content-Type': 'application/json',
163
+ ...(transport.headers ?? {}),
164
+ },
165
+ body: JSON.stringify(body),
166
+ });
167
+ if (!response.ok) {
168
+ throw new Error(`MCP HTTP error: ${response.status} ${response.statusText}`);
169
+ }
170
+ const result = (await response.json());
171
+ if (result.error) {
172
+ throw new Error(`MCP error: ${result.error.message}`);
173
+ }
174
+ return result.result;
175
+ };
176
+ // Initialize handshake
177
+ await requestFn('initialize', {
178
+ protocolVersion: '2024-11-05',
179
+ capabilities: {},
180
+ clientInfo: { name: this.clientInfo.name, version: this.clientInfo.version },
181
+ });
182
+ // Discover tools
183
+ const toolsResult = (await requestFn('tools/list'));
184
+ const tools = (toolsResult.tools ?? []).map((t) => ({
185
+ qualifiedName: `${config.id}.${t.name}`,
186
+ name: t.name,
187
+ serverId: config.id,
188
+ description: t.description,
189
+ inputSchema: t.inputSchema,
190
+ }));
191
+ this.servers.set(config.id, {
192
+ config,
193
+ tools,
194
+ request: requestFn,
195
+ disconnect: () => {
196
+ /* HTTP is stateless */
197
+ },
198
+ });
199
+ }
200
+ // -------------------------------------------------------------------------
201
+ // Tool Operations
202
+ // -------------------------------------------------------------------------
203
+ /**
204
+ * List all tools from all connected servers.
205
+ */
206
+ listTools() {
207
+ const tools = [];
208
+ for (const server of this.servers.values()) {
209
+ tools.push(...server.tools);
210
+ }
211
+ return tools;
212
+ }
213
+ /**
214
+ * List tools from a specific server.
215
+ */
216
+ listServerTools(serverId) {
217
+ const server = this.servers.get(serverId);
218
+ return server?.tools ?? [];
219
+ }
220
+ /**
221
+ * Call a tool by its qualified name (e.g., "github.create_issue").
222
+ */
223
+ async callTool(qualifiedName, args = {}) {
224
+ const [serverId, ...nameParts] = qualifiedName.split('.');
225
+ const toolName = nameParts.join('.');
226
+ const server = this.servers.get(serverId);
227
+ if (!server) {
228
+ throw new Error(`Server not connected: ${serverId}`);
229
+ }
230
+ const tool = server.tools.find((t) => t.name === toolName);
231
+ if (!tool) {
232
+ throw new Error(`Tool not found: ${qualifiedName}`);
233
+ }
234
+ const result = (await server.request('tools/call', {
235
+ name: toolName,
236
+ arguments: args,
237
+ }));
238
+ return result;
239
+ }
240
+ /**
241
+ * Check if a tool exists by qualified name.
242
+ */
243
+ hasTool(qualifiedName) {
244
+ return this.listTools().some((t) => t.qualifiedName === qualifiedName);
245
+ }
246
+ // -------------------------------------------------------------------------
247
+ // Server Management
248
+ // -------------------------------------------------------------------------
249
+ /**
250
+ * Disconnect from a specific server.
251
+ */
252
+ disconnect(serverId) {
253
+ const server = this.servers.get(serverId);
254
+ if (server) {
255
+ server.disconnect();
256
+ this.servers.delete(serverId);
257
+ }
258
+ }
259
+ /**
260
+ * Disconnect from all servers.
261
+ */
262
+ disconnectAll() {
263
+ for (const [id] of this.servers) {
264
+ this.disconnect(id);
265
+ }
266
+ }
267
+ /**
268
+ * Get connected server IDs.
269
+ */
270
+ getConnectedServers() {
271
+ return Array.from(this.servers.keys());
272
+ }
273
+ }
274
+ exports.McpClient = McpClient;
275
+ //# sourceMappingURL=mcp-client.js.map
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,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;CACF;AA7SD,8BA6SC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * MCP Client Types
3
+ *
4
+ * Types for connecting to external MCP servers as a client,
5
+ * allowing HazelJS agents to consume tools from other systems.
6
+ */
7
+ export interface McpClientOptions {
8
+ /** Human-readable name for this client */
9
+ name: string;
10
+ /** Client version */
11
+ version: string;
12
+ }
13
+ /** Configuration for connecting to an MCP server */
14
+ export interface McpServerConfig {
15
+ /** Unique identifier for this server connection */
16
+ id: string;
17
+ /** Human-readable name */
18
+ name: string;
19
+ /** Transport type */
20
+ transport: McpTransportConfig;
21
+ }
22
+ export type McpTransportConfig = McpStdioTransportConfig | McpHttpTransportConfig;
23
+ export interface McpStdioTransportConfig {
24
+ type: 'stdio';
25
+ /** Command to spawn the MCP server */
26
+ command: string;
27
+ /** Arguments to the command */
28
+ args?: string[];
29
+ /** Environment variables */
30
+ env?: Record<string, string>;
31
+ /** Working directory */
32
+ cwd?: string;
33
+ }
34
+ export interface McpHttpTransportConfig {
35
+ type: 'http';
36
+ /** URL of the MCP server */
37
+ url: string;
38
+ /** HTTP headers to include */
39
+ headers?: Record<string, string>;
40
+ }
41
+ export interface McpRemoteTool {
42
+ /** Server ID + tool name (e.g., "github.create_issue") */
43
+ qualifiedName: string;
44
+ /** Original tool name from the server */
45
+ name: string;
46
+ /** Server ID this tool belongs to */
47
+ serverId: string;
48
+ /** Tool description */
49
+ description: string;
50
+ /** JSON Schema for input */
51
+ inputSchema: {
52
+ type: 'object';
53
+ properties: Record<string, {
54
+ type: string;
55
+ description: string;
56
+ enum?: unknown[];
57
+ }>;
58
+ required: string[];
59
+ };
60
+ }
61
+ /** Result of calling a remote MCP tool */
62
+ export interface McpToolCallResult {
63
+ content: Array<{
64
+ type: string;
65
+ text?: string;
66
+ data?: unknown;
67
+ }>;
68
+ isError: boolean;
69
+ }
70
+ //# s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CAAC;QACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,WAAW,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA;SAAE,CAAC,CAAC;QACpF,QAAQ,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC;CACH;AAED,0CAA0C;AAC1C,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAChE,OAAO,EAAE,OAAO,CAAC;CAClB"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * MCP Client Types
4
+ *
5
+ * Types for connecting to external MCP servers as a client,
6
+ * allowing HazelJS agents to consume tools from other systems.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @hazeljs/mcp — Public API
3
+ *
4
+ * MCP Server: Expose HazelJS tools as MCP tools over STDIO/HTTP.
5
+ * MCP Client: Connect to external MCP servers and consume their tools.
6
+ *
7
+ * Quickstart (Server):
8
+ * import { createMcpServer } from '@hazeljs/mcp';
9
+ * const server = createMcpServer({ name: 'my-server', version: '1.0.0', toolRegistry });
10
+ * server.listenStdio();
11
+ *
12
+ * Quickstart (Client):
13
+ * import { McpClient } from '@hazeljs/mcp';
14
+ * const client = new McpClient({ name: 'my-app', version: '1.0.0' });
15
+ * await client.connect({ id: 'github', name: 'GitHub', transport: { type: 'stdio', command: 'npx', args: ['-y', '@modelcontextprotocol/server-github'] } });
16
+ * const tools = client.listTools();
17
+ */
18
+ export { createMcpServer } from './server/createMcpServer';
19
+ export { HazelToolAdapter } from './server/hazelToolAdapter';
20
+ export { ErrorCode, makeError, makeErrorResponse, parseError, invalidRequestError, methodNotFoundError, invalidParamsError, toolNotFoundError, internalError, } from './server/errors';
21
+ export { McpClient } from './client/mcp-client';
22
+ export type { McpServer, McpServerOptions, McpToolDefinition, McpRequest, McpResponse, McpError, McpErrorResponse, CallToolParams, InitializeParams, ServerCapabilities, JsonSchemaProperty, IToolRegistry, HazelTool, } from './server/types';
23
+ export type { McpClientOptions, McpServerConfig, McpTransportConfig, McpStdioTransportConfig, McpHttpTransportConfig, McpRemoteTool, McpToolCallResult, } from './client/types';
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAOH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAG3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,EACL,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,GACd,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAMhD,YAAY,EAEV,SAAS,EACT,gBAAgB,EAEhB,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAElB,aAAa,EACb,SAAS,GACV,MAAM,gBAAgB,CAAC;AAExB,YAAY,EAEV,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,EACtB,aAAa,EACb,iBAAiB,GAClB,MAAM,gBAAgB,CAAC"}