@mozilla-ai/mcpd 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.
@@ -0,0 +1,231 @@
1
+ import { McpdClientOptions, ServerHealth, Tool } from './types';
2
+ import { ServersNamespace } from './dynamicCaller';
3
+ import { AgentFunction } from './functionBuilder';
4
+ /**
5
+ * Client for interacting with MCP (Model Context Protocol) servers through an mcpd daemon.
6
+ *
7
+ * The McpdClient provides a high-level interface to discover, inspect, and invoke tools
8
+ * exposed by MCP servers running behind an mcpd daemon proxy/gateway.
9
+ *
10
+ * Thread Safety:
11
+ * This client is safe to use from multiple async contexts. The internal health
12
+ * check cache is protected by the LRUCache implementation.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { McpdClient } from '@mozilla-ai/mcpd';
17
+ *
18
+ * // Initialize client
19
+ * const client = new McpdClient({
20
+ * apiEndpoint: 'http://localhost:8090',
21
+ * apiKey: 'optional-key',
22
+ * healthCacheTtl: 10,
23
+ * serverCacheTtl: 60
24
+ * });
25
+ *
26
+ * // List available servers
27
+ * const servers = await client.listServers();
28
+ * console.log(servers); // ['time', 'fetch', 'git']
29
+ *
30
+ * // Invoke a tool dynamically
31
+ * const result = await client.servers.time.get_current_time({ timezone: 'UTC' });
32
+ * console.log(result); // { time: '2024-01-15T10:30:00Z' }
33
+ * ```
34
+ */
35
+ export declare class McpdClient {
36
+ #private;
37
+ /**
38
+ * Namespace for accessing MCP servers and their tools.
39
+ */
40
+ readonly servers: ServersNamespace;
41
+ /**
42
+ * Initialize a new McpdClient instance.
43
+ *
44
+ * @param options - Configuration options for the client
45
+ */
46
+ constructor(options: McpdClientOptions);
47
+ /**
48
+ * Get a list of all configured MCP servers.
49
+ *
50
+ * @returns Array of server names
51
+ * @throws {McpdError} If the request fails
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const servers = await client.listServers();
56
+ * console.log(servers); // ['time', 'fetch', 'git']
57
+ * ```
58
+ */
59
+ listServers(): Promise<string[]>;
60
+ /**
61
+ * Get tool schemas from all (or specific) MCP servers with transformed names.
62
+ *
63
+ * IMPORTANT: Tool names are transformed to `serverName__toolName` format to:
64
+ * 1. Prevent naming clashes when aggregating tools from multiple servers
65
+ * 2. Identify which server each tool belongs to
66
+ *
67
+ * This method automatically filters out unhealthy servers by checking their health
68
+ * status before fetching tools. Unhealthy servers are silently skipped to ensure
69
+ * the method returns quickly without waiting for timeouts on failed servers.
70
+ *
71
+ * Tool fetches from multiple servers are executed concurrently for optimal performance.
72
+ *
73
+ * This is useful for:
74
+ * - MCP servers that aggregate and re-expose tools from multiple upstream servers
75
+ * - Tool inspection and discovery across all servers
76
+ * - Custom tooling that needs raw MCP tool schemas
77
+ *
78
+ * @param options - Optional configuration
79
+ * @param options.servers - Array of server names to include. If not specified, includes all servers.
80
+ * @returns Array of tool schemas with transformed names (serverName__toolName). Only includes tools from healthy servers.
81
+ * @throws {ConnectionError} If unable to connect to the mcpd daemon
82
+ * @throws {TimeoutError} If requests to the daemon time out
83
+ * @throws {AuthenticationError} If API key authentication fails
84
+ * @throws {McpdError} If health check or initial server listing fails
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * // Get all tools from all servers
89
+ * const allTools = await client.getToolSchemas();
90
+ * // Returns: [
91
+ * // { name: "time__get_current_time", description: "...", ... },
92
+ * // { name: "fetch__fetch_url", description: "...", ... }
93
+ * // ]
94
+ *
95
+ * // Get tools from specific servers only
96
+ * const someTools = await client.getToolSchemas({ servers: ['time', 'fetch'] });
97
+ *
98
+ * // Original tool name "get_current_time" becomes "time__get_current_time"
99
+ * // This prevents clashes if multiple servers have tools with the same name
100
+ * ```
101
+ */
102
+ getToolSchemas(options?: {
103
+ servers?: string[];
104
+ }): Promise<Tool[]>;
105
+ /**
106
+ * Get health information for one or all servers.
107
+ *
108
+ * @param serverName - Optional server name to get health for
109
+ * @returns Health information for the specified server or all servers
110
+ * @throws {ServerNotFoundError} If the specified server doesn't exist
111
+ * @throws {McpdError} If the request fails
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * // Get health for all servers
116
+ * const allHealth = await client.getServerHealth();
117
+ * console.log(allHealth); // { time: { status: 'ok' }, fetch: { status: 'ok' } }
118
+ *
119
+ * // Get health for a specific server
120
+ * const timeHealth = await client.getServerHealth('time');
121
+ * console.log(timeHealth); // { status: 'ok' }
122
+ * ```
123
+ */
124
+ getServerHealth(): Promise<Record<string, ServerHealth>>;
125
+ getServerHealth(serverName: string): Promise<ServerHealth>;
126
+ /**
127
+ * Check if a specific server is healthy.
128
+ *
129
+ * @param serverName - The name of the server to check
130
+ * @returns True if the server is healthy, false otherwise
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * if (await client.isServerHealthy('time')) {
135
+ * const time = await client.servers.time.get_current_time();
136
+ * }
137
+ * ```
138
+ */
139
+ isServerHealthy(serverName: string): Promise<boolean>;
140
+ /**
141
+ * Clear the cached agent tools functions.
142
+ * This should be called when the tool schemas might have changed.
143
+ */
144
+ clearAgentToolsCache(): void;
145
+ /**
146
+ * Clear the server health cache.
147
+ * This forces fresh health checks on the next getServerHealth() or isServerHealthy() call.
148
+ */
149
+ clearServerHealthCache(): void;
150
+ /**
151
+ * Generate callable functions for use with AI agent frameworks (internal).
152
+ *
153
+ * This method queries servers and creates self-contained, callable functions
154
+ * that can be passed to AI agent frameworks. Each function includes its schema
155
+ * as metadata and handles the MCP communication internally.
156
+ *
157
+ * This method automatically filters out unhealthy servers by checking their health
158
+ * status before fetching tools. Unhealthy servers are silently skipped to ensure
159
+ * the method returns quickly without waiting for timeouts on failed servers.
160
+ *
161
+ * Tool fetches from multiple servers are executed concurrently for optimal performance.
162
+ *
163
+ * @param servers - Optional list of server names to include. If not specified, includes all servers.
164
+ * @returns Array of callable functions with metadata. Only includes tools from healthy servers.
165
+ *
166
+ * @throws {ConnectionError} If unable to connect to the mcpd daemon
167
+ * @throws {TimeoutError} If requests to the daemon time out
168
+ * @throws {AuthenticationError} If API key authentication fails
169
+ * @throws {McpdError} If unable to retrieve health status, server list, or generate functions
170
+ * @internal
171
+ */
172
+ agentTools(servers?: string[]): Promise<AgentFunction[]>;
173
+ /**
174
+ * Generate callable functions for use with AI agent frameworks.
175
+ *
176
+ * This method queries servers and creates self-contained, callable functions
177
+ * that can be passed to AI agent frameworks. Each function includes its schema
178
+ * as metadata and handles the MCP communication internally.
179
+ *
180
+ * This method automatically filters out unhealthy servers by checking their health
181
+ * status before fetching tools. Unhealthy servers are silently skipped to ensure
182
+ * the method returns quickly without waiting for timeouts on failed servers.
183
+ *
184
+ * Tool fetches from multiple servers are executed concurrently for optimal performance.
185
+ *
186
+ * The generated functions are cached for performance. Use clearAgentToolsCache()
187
+ * to force regeneration if servers or tools have changed.
188
+ *
189
+ * @param options - Options for generating agent tools (format and server filtering)
190
+ * @returns Functions in the requested format (array, object, or map). Only includes tools from healthy servers.
191
+ *
192
+ * @throws {ConnectionError} If unable to connect to the mcpd daemon
193
+ * @throws {TimeoutError} If requests to the daemon time out
194
+ * @throws {AuthenticationError} If API key authentication fails
195
+ * @throws {McpdError} If unable to retrieve health status, server list, or generate functions
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * // Get all tools from all servers (default array format)
200
+ * const tools = await client.getAgentTools();
201
+ * console.log(`Generated ${tools.length} callable tools`);
202
+ *
203
+ * // Get tools from specific servers
204
+ * const tools = await client.getAgentTools({ servers: ['time', 'fetch'] });
205
+ *
206
+ * // Use with LangChain JS (array format)
207
+ * const langchainTools = await client.getAgentTools({ format: 'array' });
208
+ * const agent = await createOpenAIToolsAgent({ llm, tools: langchainTools, prompt });
209
+ *
210
+ * // Use with Vercel AI SDK (object format) from specific servers
211
+ * const vercelTools = await client.getAgentTools({
212
+ * servers: ['time'],
213
+ * format: 'object'
214
+ * });
215
+ * const result = await generateText({ model, tools: vercelTools, prompt });
216
+ * ```
217
+ */
218
+ getAgentTools(options?: {
219
+ format?: "array";
220
+ servers?: string[];
221
+ }): Promise<AgentFunction[]>;
222
+ getAgentTools(options: {
223
+ format: "object";
224
+ servers?: string[];
225
+ }): Promise<Record<string, AgentFunction>>;
226
+ getAgentTools(options: {
227
+ format: "map";
228
+ servers?: string[];
229
+ }): Promise<Map<string, AgentFunction>>;
230
+ }
231
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAYH,OAAO,EAEL,iBAAiB,EACjB,YAAY,EACZ,IAAI,EAKL,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,UAAU;;IAYrB;;OAEG;IACH,SAAgB,OAAO,EAAE,gBAAgB,CAAC;IAE1C;;;;OAIG;gBACS,OAAO,EAAE,iBAAiB;IAgJtC;;;;;;;;;;;OAWG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAItC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;IACG,cAAc,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IA2EvE;;;;;;;;;;;;;;;;;;OAkBG;IACG,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACxD,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAoDhE;;;;;;;;;;;;OAYG;IACG,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAiG3D;;;OAGG;IACH,oBAAoB,IAAI,IAAI;IAI5B;;;OAGG;IACH,sBAAsB,IAAI,IAAI;IAI9B;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IA2C9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CG;IACG,aAAa,CAAC,OAAO,CAAC,EAAE;QAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACpB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IACtB,aAAa,CAAC,OAAO,EAAE;QAC3B,MAAM,EAAE,QAAQ,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACpB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACpC,aAAa,CAAC,OAAO,EAAE;QAC3B,MAAM,EAAE,KAAK,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;KACpB,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAwBxC"}
@@ -0,0 +1,146 @@
1
+ import { Tool, PerformCallFn, GetToolsFn } from './types';
2
+ /**
3
+ * Namespace for accessing MCP servers via proxy.
4
+ *
5
+ * This class provides the `client.servers.*` namespace, allowing you to access
6
+ * servers and their tools with natural JavaScript syntax.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const client = new McpdClient({ apiEndpoint: 'http://localhost:8090' });
11
+ *
12
+ * // Access tools through the servers namespace
13
+ * const result = await client.servers.time.tools.get_current_time({ timezone: "UTC" });
14
+ *
15
+ * // Check if a tool exists
16
+ * if (await client.servers.time.hasTool("get_current_time")) {
17
+ * // ...
18
+ * }
19
+ * ```
20
+ */
21
+ export declare class ServersNamespace {
22
+ #private;
23
+ [serverName: string]: Server;
24
+ /**
25
+ * Initialize the ServersNamespace with injected functions.
26
+ *
27
+ * @param performCall - Function to execute tool calls
28
+ * @param getTools - Function to get tool schemas
29
+ */
30
+ constructor(performCall: PerformCallFn, getTools: GetToolsFn);
31
+ }
32
+ /**
33
+ * Represents a specific MCP server, providing access to its tools and operations.
34
+ *
35
+ * This class represents a specific MCP server and provides access to its tools
36
+ * through the `.tools` namespace, as well as server-level operations like listing tools.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // Server is created when you access a server:
41
+ * const timeServer = client.servers.time; // Returns Server(...)
42
+ *
43
+ * // List available tools
44
+ * const tools = await timeServer.listTools();
45
+ *
46
+ * // Call tools through the .tools namespace:
47
+ * await timeServer.tools.get_current_time({ timezone: "UTC" })
48
+ * ```
49
+ */
50
+ export declare class Server {
51
+ #private;
52
+ readonly tools: ToolsNamespace;
53
+ /**
54
+ * Initialize a Server for a specific server.
55
+ *
56
+ * @param performCall - Function to execute tool calls
57
+ * @param getTools - Function to get tool schemas
58
+ * @param serverName - The name of the MCP server
59
+ */
60
+ constructor(performCall: PerformCallFn, getTools: GetToolsFn, serverName: string);
61
+ /**
62
+ * List all tools available on this server.
63
+ *
64
+ * @returns Array of tool schemas
65
+ * @throws {ServerNotFoundError} If the server doesn't exist
66
+ * @throws {ServerUnhealthyError} If the server is unhealthy
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const tools = await client.servers.time.listTools();
71
+ * for (const tool of tools) {
72
+ * console.log(`${tool.name}: ${tool.description}`);
73
+ * }
74
+ * ```
75
+ */
76
+ listTools(): Promise<Tool[]>;
77
+ /**
78
+ * Check if a tool exists on this server.
79
+ *
80
+ * The tool name must match exactly as returned by the server.
81
+ *
82
+ * @param toolName - The exact name of the tool to check
83
+ * @returns True if the tool exists, false otherwise
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * if (await client.servers.time.hasTool('get_current_time')) {
88
+ * const result = await client.servers.time.callTool('get_current_time', { timezone: 'UTC' });
89
+ * }
90
+ * ```
91
+ */
92
+ hasTool(toolName: string): Promise<boolean>;
93
+ /**
94
+ * Call a tool by name with the given arguments.
95
+ *
96
+ * This method is useful for programmatic tool invocation when the tool name
97
+ * is in a variable. The tool name must match exactly as returned by the server.
98
+ *
99
+ * @param toolName - The exact name of the tool to call
100
+ * @param args - The arguments to pass to the tool
101
+ * @returns The tool's response
102
+ * @throws {ToolNotFoundError} If the tool doesn't exist on the server
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * // Call with explicit method (useful for dynamic tool names):
107
+ * const toolName = 'get_current_time';
108
+ * await client.servers.time.callTool(toolName, { timezone: 'UTC' });
109
+ *
110
+ * // Or with dynamic server name:
111
+ * const serverName = 'time';
112
+ * await client.servers[serverName].callTool(toolName, { timezone: 'UTC' });
113
+ * ```
114
+ */
115
+ callTool(toolName: string, args?: Record<string, unknown>): Promise<unknown>;
116
+ }
117
+ /**
118
+ * Namespace for accessing tools on a specific MCP server via proxy.
119
+ *
120
+ * This class provides the `.tools` namespace for a server, allowing you to call
121
+ * tools as if they were methods. All tool names must match exactly as returned
122
+ * by the MCP server.
123
+ *
124
+ * NOTE: Use `client.servers.foo.callTool()` and `client.servers.foo.hasTool()`
125
+ * instead of putting them in the `.tools` namespace to avoid collisions with
126
+ * actual tools named "callTool" or "hasTool".
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * // Call tools via .tools namespace with static names
131
+ * const result = await client.servers.time.tools.get_current_time({ timezone: "UTC" });
132
+ * ```
133
+ */
134
+ export declare class ToolsNamespace {
135
+ #private;
136
+ [toolName: string]: (args?: Record<string, unknown>) => Promise<unknown>;
137
+ /**
138
+ * Initialize a ToolsNamespace for a specific server.
139
+ *
140
+ * @param performCall - Function to execute tool calls
141
+ * @param getTools - Function to get tool schemas
142
+ * @param serverName - The name of the MCP server
143
+ */
144
+ constructor(performCall: PerformCallFn, getTools: GetToolsFn, serverName: string);
145
+ }
146
+ //# sourceMappingURL=dynamicCaller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamicCaller.d.ts","sourceRoot":"","sources":["../src/dynamicCaller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE/D;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,gBAAgB;;IAC3B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IAK7B;;;;;OAKG;gBACS,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU;CAc7D;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,MAAM;;IACjB,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAM/B;;;;;;OAMG;gBAED,WAAW,EAAE,aAAa,EAC1B,QAAQ,EAAE,UAAU,EACpB,UAAU,EAAE,MAAM;IAcpB;;;;;;;;;;;;;;OAcG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAIlC;;;;;;;;;;;;;;OAcG;IACG,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IASjD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,QAAQ,CACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAAC,OAAO,CAAC;CAiBpB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,cAAc;;IACzB,CAAC,QAAQ,EAAE,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAMzE;;;;;;OAMG;gBAED,WAAW,EAAE,aAAa,EAC1B,QAAQ,EAAE,UAAU,EACpB,UAAU,EAAE,MAAM;CAoCrB"}
@@ -0,0 +1,113 @@
1
+ import { ErrorModel } from './types';
2
+ /**
3
+ * Base exception for all mcpd SDK errors.
4
+ *
5
+ * This exception wraps all errors that occur during interaction with the mcpd daemon,
6
+ * including network failures, authentication errors, server errors, and tool execution
7
+ * failures. The original exception is preserved via the cause property for debugging.
8
+ */
9
+ export declare class McpdError extends Error {
10
+ constructor(message: string, cause?: Error);
11
+ }
12
+ /**
13
+ * Raised when unable to connect to the mcpd daemon.
14
+ *
15
+ * This typically indicates that:
16
+ * - The mcpd daemon is not running
17
+ * - The endpoint URL is incorrect
18
+ * - Network connectivity issues
19
+ * - Firewall blocking the connection
20
+ */
21
+ export declare class ConnectionError extends McpdError {
22
+ constructor(message: string, cause?: Error);
23
+ }
24
+ /**
25
+ * Raised when authentication with the mcpd daemon fails.
26
+ *
27
+ * This indicates that:
28
+ * - The API key is invalid or expired
29
+ * - The API key is missing but required
30
+ * - The authentication method is not supported
31
+ */
32
+ export declare class AuthenticationError extends McpdError {
33
+ constructor(message: string, cause?: Error);
34
+ }
35
+ /**
36
+ * Raised when a specified MCP server doesn't exist.
37
+ *
38
+ * This error occurs when trying to access a server that:
39
+ * - Is not configured in the mcpd daemon
40
+ * - Has been removed or renamed
41
+ * - Is temporarily unavailable
42
+ */
43
+ export declare class ServerNotFoundError extends McpdError {
44
+ readonly serverName: string | undefined;
45
+ constructor(message: string, serverName?: string, cause?: Error);
46
+ }
47
+ /**
48
+ * Raised when a specified MCP server is not healthy.
49
+ *
50
+ * This indicates that the server exists but is currently unhealthy:
51
+ * - The server is down or unreachable
52
+ * - Timeout occurred while checking health
53
+ * - No health data is available for the server
54
+ */
55
+ export declare class ServerUnhealthyError extends McpdError {
56
+ readonly serverName: string;
57
+ readonly healthStatus: string;
58
+ constructor(message: string, serverName: string, healthStatus: string, cause?: Error);
59
+ }
60
+ /**
61
+ * Raised when a specified tool doesn't exist on a server.
62
+ *
63
+ * This error occurs when trying to call a tool that:
64
+ * - Doesn't exist on the specified server
65
+ * - Has been removed or renamed
66
+ * - Is temporarily unavailable
67
+ */
68
+ export declare class ToolNotFoundError extends McpdError {
69
+ readonly serverName: string | undefined;
70
+ readonly toolName: string | undefined;
71
+ constructor(message: string, serverName?: string, toolName?: string, cause?: Error);
72
+ }
73
+ /**
74
+ * Raised when a tool execution fails on the server side.
75
+ *
76
+ * This indicates that the tool was found and called, but failed during execution:
77
+ * - Invalid parameters provided
78
+ * - Server-side error during tool execution
79
+ * - Tool returned an error response
80
+ * - Timeout during tool execution
81
+ */
82
+ export declare class ToolExecutionError extends McpdError {
83
+ readonly serverName: string | undefined;
84
+ readonly toolName: string | undefined;
85
+ readonly errorModel: ErrorModel | undefined;
86
+ constructor(message: string, serverName?: string, toolName?: string, errorModel?: ErrorModel, cause?: Error);
87
+ }
88
+ /**
89
+ * Raised when input validation fails.
90
+ *
91
+ * This occurs when:
92
+ * - Required parameters are missing
93
+ * - Parameter types don't match the schema
94
+ * - Parameter values don't meet constraints
95
+ */
96
+ export declare class ValidationError extends McpdError {
97
+ readonly validationErrors: string[];
98
+ constructor(message: string, validationErrors?: string[], cause?: Error);
99
+ }
100
+ /**
101
+ * Raised when an operation times out.
102
+ *
103
+ * This can occur during:
104
+ * - Long-running tool executions
105
+ * - Slow network connections
106
+ * - Unresponsive mcpd daemon
107
+ */
108
+ export declare class TimeoutError extends McpdError {
109
+ readonly operation: string | undefined;
110
+ readonly timeout: number | undefined;
111
+ constructor(message: string, operation?: string, timeout?: number, cause?: Error);
112
+ }
113
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;GAMG;AACH,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAM3C;AAED;;;;;;;;GAQG;AACH,qBAAa,eAAgB,SAAQ,SAAS;gBAChC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAK3C;AAED;;;;;;;GAOG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;gBACpC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAK3C;AAED;;;;;;;GAOG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,SAAgB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEnC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAMhE;AAED;;;;;;;GAOG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;IACjD,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,YAAY,EAAE,MAAM,CAAC;gBAGnC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,KAAK,CAAC,EAAE,KAAK;CAQhB;AAED;;;;;;;GAOG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C,SAAgB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/C,SAAgB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;gBAG3C,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,MAAM,EACjB,KAAK,CAAC,EAAE,KAAK;CAQhB;AAED;;;;;;;;GAQG;AACH,qBAAa,kBAAmB,SAAQ,SAAS;IAC/C,SAAgB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/C,SAAgB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7C,SAAgB,UAAU,EAAE,UAAU,GAAG,SAAS,CAAC;gBAGjD,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,UAAU,EACvB,KAAK,CAAC,EAAE,KAAK;CAShB;AAED;;;;;;;GAOG;AACH,qBAAa,eAAgB,SAAQ,SAAS;IAC5C,SAAgB,gBAAgB,EAAE,MAAM,EAAE,CAAC;gBAE/B,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK;CAMxE;AAED;;;;;;;GAOG;AACH,qBAAa,YAAa,SAAQ,SAAS;IACzC,SAAgB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,SAAgB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;gBAG1C,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,KAAK;CAQhB"}
@@ -0,0 +1,110 @@
1
+ import { z } from 'zod';
2
+ import { Tool, PerformCallFn } from './types';
3
+ /**
4
+ * Interface for generated agent functions with metadata.
5
+ * Compatible with both LangChain JS and Vercel AI SDK without conversion.
6
+ */
7
+ export interface AgentFunction {
8
+ (...args: unknown[]): Promise<unknown>;
9
+ name: string;
10
+ description: string;
11
+ schema: z.ZodSchema<any>;
12
+ invoke: (args: unknown) => Promise<unknown>;
13
+ lc_namespace: string[];
14
+ returnDirect: boolean;
15
+ inputSchema: z.ZodSchema<any>;
16
+ execute: (args: unknown) => Promise<unknown>;
17
+ _schema: Tool;
18
+ _serverName: string;
19
+ _toolName: string;
20
+ }
21
+ /**
22
+ * Builds callable JavaScript functions from MCP tool JSON schemas.
23
+ *
24
+ * This class generates self-contained functions that can be used with AI agent
25
+ * frameworks. The generated functions include parameter validation and
26
+ * comprehensive metadata based on the tool's JSON Schema definition.
27
+ *
28
+ * The generated functions are cached for performance, with cache invalidation
29
+ * controlled by the owning McpdClient via clearCache().
30
+ */
31
+ export declare class FunctionBuilder {
32
+ #private;
33
+ /**
34
+ * Initialize a FunctionBuilder with an injected function.
35
+ *
36
+ * @param performCall - Function to execute tool calls
37
+ */
38
+ constructor(performCall: PerformCallFn);
39
+ /**
40
+ * Convert a string into a safe JavaScript identifier.
41
+ *
42
+ * This method sanitizes arbitrary strings (like server names or tool names) to create
43
+ * valid JavaScript identifiers that can be used as function names.
44
+ * It replaces non-word characters and handles edge cases like leading digits.
45
+ *
46
+ * @param name - The string to convert into a safe identifier
47
+ * @returns A string that is a valid JavaScript identifier
48
+ */
49
+ private safeName;
50
+ /**
51
+ * Generate a unique function name from server and tool names.
52
+ *
53
+ * This method creates a qualified function name by combining the server name
54
+ * and tool name with a double underscore separator. Both names are sanitized
55
+ * using safeName() to ensure the result is a valid JavaScript identifier.
56
+ *
57
+ * @param serverName - The name of the MCP server hosting the tool
58
+ * @param schemaName - The name of the tool from the schema definition
59
+ * @returns A qualified function name in the format "{safe_server}__{safe_tool}"
60
+ */
61
+ private functionName;
62
+ /**
63
+ * Create a callable JavaScript function from an MCP tool's JSON Schema definition.
64
+ *
65
+ * This method generates a self-contained, callable function that validates parameters
66
+ * and executes the corresponding MCP tool. The function includes proper parameter
67
+ * validation and comprehensive metadata based on the tool's JSON Schema.
68
+ *
69
+ * Generated functions are cached for performance. If a function for the same
70
+ * server/tool combination already exists in the cache, it returns the cached function.
71
+ *
72
+ * @param schema - The MCP tool's JSON Schema definition
73
+ * @param serverName - The name of the MCP server hosting this tool
74
+ * @returns A callable JavaScript function with metadata
75
+ */
76
+ createFunctionFromSchema(schema: Tool, serverName: string): AgentFunction;
77
+ /**
78
+ * Build the actual function from the schema.
79
+ *
80
+ * @param schema - The tool schema
81
+ * @param serverName - The server name
82
+ * @returns The generated function with metadata
83
+ */
84
+ private buildFunction;
85
+ /**
86
+ * Generate a comprehensive docstring for the dynamically created function.
87
+ *
88
+ * This method builds a properly formatted docstring that includes the
89
+ * tool's description, parameter documentation with optional/required status,
90
+ * return value information, and exception documentation.
91
+ *
92
+ * @param schema - The MCP tool's JSON Schema definition
93
+ * @returns A multi-line string containing the complete docstring text
94
+ */
95
+ private createDocstring;
96
+ /**
97
+ * Clear the function cache.
98
+ *
99
+ * This method clears all cached generated functions, forcing them to be
100
+ * regenerated on the next call to createFunctionFromSchema().
101
+ */
102
+ clearCache(): void;
103
+ /**
104
+ * Get the current cache size.
105
+ *
106
+ * @returns The number of functions currently cached
107
+ */
108
+ getCacheSize(): number;
109
+ }
110
+ //# sourceMappingURL=functionBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"functionBuilder.d.ts","sourceRoot":"","sources":["../src/functionBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGnD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAGvC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IAIpB,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;IAItB,WAAW,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAG7C,OAAO,EAAE,IAAI,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,qBAAa,eAAe;;IAI1B;;;;OAIG;gBACS,WAAW,EAAE,aAAa;IA2EtC;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ;IAKhB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,YAAY;IAIpB;;;;;;;;;;;;;OAaG;IACH,wBAAwB,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,GAAG,aAAa;IAoBzE;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAoIrB;;;;;;;;;OASG;IACH,OAAO,CAAC,eAAe;IAoCvB;;;;;OAKG;IACH,UAAU,IAAI,IAAI;IAIlB;;;;OAIG;IACH,YAAY,IAAI,MAAM;CAGvB"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * mcpd JavaScript/TypeScript SDK.
3
+ *
4
+ * A JavaScript/TypeScript SDK for interacting with the mcpd daemon, which manages
5
+ * Model Context Protocol (MCP) servers and enables seamless tool execution
6
+ * through natural JavaScript syntax.
7
+ *
8
+ * This package provides:
9
+ * - McpdClient: Main client for server management and tool execution
10
+ * - Dynamic calling: Natural syntax like client.servers.time.get_current_time(args)
11
+ * - Agent-ready functions: Generate callable functions via getAgentTools() for AI frameworks
12
+ * - Type-safe function generation: Create callable functions from tool schemas
13
+ * - Comprehensive error handling: Detailed exceptions for different failure modes
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ export { McpdClient } from './client';
18
+ export { McpdError, AuthenticationError, ConnectionError, ServerNotFoundError, ServerUnhealthyError, TimeoutError, ToolExecutionError, ToolNotFoundError, ValidationError, } from './errors';
19
+ export { HealthStatus, HealthStatusHelpers, type JsonSchema, type Tool, type Tools, type ToolAnnotations, type ServerHealth, type ToolsResponse, type HealthResponse, type McpdClientOptions, type ErrorDetail, type ErrorModel, type ToolFormat, type AgentToolsOptions, type Resource, type Resources, type ResourceContent, type ResourceTemplate, type ResourceTemplates, type Prompt, type PromptArgument, type Prompts, type PromptMessage, type PromptGenerateArguments, type GeneratePromptResponseBody, } from './types';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,GAChB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,KAAK,UAAU,EACf,KAAK,IAAI,EACT,KAAK,KAAK,EACV,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,GAChC,MAAM,SAAS,CAAC"}