@mozilla-ai/mcpd 0.0.3 → 0.1.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
@@ -73,7 +73,6 @@ const client = new McpdClient({
73
73
  apiEndpoint: "http://localhost:8090",
74
74
  apiKey: "optional-key", // Optional API key
75
75
  healthCacheTtl: 10, // Cache health checks for 10 seconds
76
- serverCacheTtl: 60, // Cache server/tool metadata for 60 seconds
77
76
  });
78
77
 
79
78
  // Full type safety and autocomplete
@@ -107,11 +106,114 @@ const client = new McpdClient({
107
106
  apiEndpoint: "http://localhost:8090", // Required
108
107
  apiKey: "optional-key", // Optional: API key for authentication
109
108
  healthCacheTtl: 10, // Optional: TTL in seconds for health cache (default: 10)
110
- serverCacheTtl: 60, // Optional: TTL in seconds for server/tools cache (default: 60)
111
109
  timeout: 30000, // Optional: Request timeout in ms (default: 30000)
112
110
  });
113
111
  ```
114
112
 
113
+ ### Logging
114
+
115
+ The SDK includes optional logging for warnings about unhealthy or non-existent servers that are skipped during operations.
116
+
117
+ **Important:** Logging is disabled by default. Only enable logging in non-MCP-server contexts. MCP servers using stdio transport for JSON-RPC communication should never enable logging, as it will contaminate stdout/stderr and break the protocol.
118
+
119
+ #### Using Environment Variable
120
+
121
+ Set the `MCPD_LOG_LEVEL` environment variable to control logging:
122
+
123
+ ```bash
124
+ # Valid levels: trace, debug, info, warn, error, off (default)
125
+ export MCPD_LOG_LEVEL=warn
126
+ ```
127
+
128
+ **Available Log Levels:**
129
+
130
+ | Level | Description |
131
+ | ------- | --------------------------------------------------------------- |
132
+ | `trace` | Verbose information (includes `debug`, `info`, `warn`, `error`) |
133
+ | `debug` | Debug information (includes `info`, `warn`, `error`) |
134
+ | `info` | General informational messages (includes `warn`, `error`) |
135
+ | `warn` | Warning messages only (includes `error`) |
136
+ | `error` | Error messages only |
137
+ | `off` | (...or unset) Logging disabled (default) |
138
+
139
+ ```typescript
140
+ // Logging is automatically enabled based on MCPD_LOG_LEVEL
141
+ const client = new McpdClient({
142
+ apiEndpoint: "http://localhost:8090",
143
+ });
144
+ ```
145
+
146
+ #### Using Custom Logger
147
+
148
+ For advanced use cases, inject your own logger implementation.
149
+
150
+ **Partial Logger Support:** You can provide only the methods you want to customize. Any omitted methods will fall back to the default logger, which respects `MCPD_LOG_LEVEL`.
151
+
152
+ ```typescript
153
+ import { McpdClient } from "@mozilla-ai/mcpd";
154
+
155
+ // Full custom logger
156
+ const client = new McpdClient({
157
+ apiEndpoint: "http://localhost:8090",
158
+ logger: {
159
+ trace: (...args) => myLogger.trace(args),
160
+ debug: (...args) => myLogger.debug(args),
161
+ info: (...args) => myLogger.info(args),
162
+ warn: (...args) => myLogger.warn(args),
163
+ error: (...args) => myLogger.error(args),
164
+ },
165
+ });
166
+
167
+ // Partial logger: custom warn/error, default (MCPD_LOG_LEVEL-aware) for others
168
+ const client2 = new McpdClient({
169
+ apiEndpoint: "http://localhost:8090",
170
+ logger: {
171
+ warn: (msg) => console.warn(`[mcpd] ${msg}`),
172
+ error: (msg) => console.error(`[mcpd] ${msg}`),
173
+ // trace, debug, info use default logger (respects MCPD_LOG_LEVEL)
174
+ },
175
+ });
176
+ ```
177
+
178
+ #### Disabling Logging
179
+
180
+ To disable logging, simply ensure `MCPD_LOG_LEVEL` is unset or set to `off` (the default):
181
+
182
+ ```typescript
183
+ // Logging is disabled by default (no configuration needed)
184
+ const client = new McpdClient({
185
+ apiEndpoint: "http://localhost:8090",
186
+ });
187
+ ```
188
+
189
+ If you need to disable logging even when `MCPD_LOG_LEVEL` is set (rare case), provide a custom logger with no-op implementations:
190
+
191
+ ```typescript
192
+ // Override MCPD_LOG_LEVEL to force disable
193
+ const client = new McpdClient({
194
+ apiEndpoint: "http://localhost:8090",
195
+ logger: {
196
+ trace: () => {},
197
+ debug: () => {},
198
+ info: () => {},
199
+ warn: () => {},
200
+ error: () => {},
201
+ },
202
+ });
203
+ ```
204
+
205
+ When logging is enabled, warnings are emitted for:
206
+
207
+ - Unhealthy servers that are skipped (e.g., status `timeout`, `unreachable`)
208
+ - Non-existent servers specified in filter options
209
+
210
+ Example warning messages:
211
+
212
+ ```text
213
+ Skipping unhealthy server 'time' with status 'timeout'
214
+ Skipping non-existent server 'unknown'
215
+ ```
216
+
115
217
  ### Core Methods
116
218
 
117
219
  #### `client.listServers()`
@@ -357,12 +459,29 @@ if (await client.isServerHealthy("time")) {
357
459
 
358
460
  #### `client.getAgentTools(options?)`
359
461
 
360
- Generate callable functions that work directly with AI agent frameworks. No conversion layers needed.
462
+ Generate (cached) callable functions that work directly with AI agent frameworks. No conversion layers needed.
463
+
464
+ > [!IMPORTANT]
465
+ > Generated functions are cached for performance. Once cached, subsequent calls return cached functions regardless of filter parameters.
466
+ > To force regeneration, either call `client.clearAgentToolsCache()` first, or use the `refreshCache: true` option.
467
+
468
+ ##### Supports filtering by servers and by tools
469
+
470
+ AI agents perform better with focused tool sets they need to complete the given task.
471
+ Tool filtering enables progressive disclosure - operators can expose a subset of server tools via `mcpd` configuration,
472
+ then agents can further narrow down to only the tools needed for their specific task.
473
+ This prevents overwhelming the model's context window and improves response quality.
474
+
475
+ ##### Examples
361
476
 
362
477
  ```typescript
363
- // Options: { servers?: string[], format?: 'array' | 'object' | 'map' }
364
- // Default format is 'array' (for LangChain)
478
+ // Options: { servers?: string[], tools?: string[], format?: 'array' | 'object' | 'map', refreshCache?: boolean }
479
+ // Default format is 'array' (for LangChain), refreshCache defaults to false
480
+ ```
481
+
482
+ LangChain
365
483
 
484
+ ```typescript
366
485
  // Use with LangChain JS (array format is default)
367
486
  import { ChatOpenAI } from "@langchain/openai";
368
487
 
@@ -380,7 +499,11 @@ const agent = await createOpenAIToolsAgent({
380
499
  tools: langchainTools,
381
500
  prompt,
382
501
  });
502
+ ```
503
+
504
+ Vercel-AI
383
505
 
506
+ ```typescript
384
507
  // Use with Vercel AI SDK (expects object format)
385
508
  import { generateText } from "ai";
386
509
 
@@ -390,12 +513,46 @@ const result = await generateText({
390
513
  tools: vercelTools,
391
514
  prompt: "What time is it in Tokyo?",
392
515
  });
516
+ ```
517
+
518
+ Filtering examples
393
519
 
520
+ ```typescript
394
521
  // Filter to specific servers
395
522
  const timeTools = await client.getAgentTools({
396
523
  servers: ["time"],
397
524
  format: "array",
398
525
  });
526
+ ```
527
+
528
+ ```typescript
529
+ // Filter by tool names (cross-cutting across all servers)
530
+ const mathTools = await client.getAgentTools({
531
+ tools: ["add", "multiply"],
532
+ });
533
+ ```
534
+
535
+ ```typescript
536
+ // Filter by qualified tool names (server-specific)
537
+ const specificTools = await client.getAgentTools({
538
+ tools: ["time__get_current_time", "math__add"],
539
+ });
540
+ ```
541
+
542
+ ```typescript
543
+ // Combine server and tool filtering
544
+ const filteredTools = await client.getAgentTools({
545
+ servers: ["time", "math"],
546
+ tools: ["add", "get_current_time"],
547
+ });
548
+ ```
549
+
550
+ ```typescript
551
+ // Tool filtering works with different formats
552
+ const toolsObject = await client.getAgentTools({
553
+ tools: ["add", "multiply"],
554
+ format: "object",
555
+ });
399
556
 
400
557
  // Use with Map for efficient lookups
401
558
  const toolMap = await client.getAgentTools({ format: "map" });
@@ -404,6 +561,9 @@ if (timeTool) {
404
561
  const result = await timeTool({ timezone: "UTC" });
405
562
  }
406
563
 
564
+ // Force refresh from cache to get latest schemas
565
+ const freshTools = await client.getAgentTools({ refreshCache: true });
566
+
407
567
  // Each function has metadata for both frameworks
408
568
  const tools = await client.getAgentTools();
409
569
  for (const tool of tools) {
@@ -419,7 +579,7 @@ for (const tool of tools) {
419
579
  Clear the cache of generated agent tools functions.
420
580
 
421
581
  ```typescript
422
- // Clear cache to regenerate tools with latest schemas
582
+ // Clear cache to regenerate tools with latest schemas, or latest client side server/tool filters.
423
583
  client.clearAgentToolsCache();
424
584
  const freshTools = await client.getAgentTools();
425
585
  ```
@@ -449,12 +609,20 @@ import {
449
609
  ToolExecutionError, // Tool execution failed
450
610
  ValidationError, // Input validation failed
451
611
  TimeoutError, // Operation timed out
612
+ PipelineError, // Pipeline processing failed
452
613
  } from "@mozilla-ai/mcpd";
453
614
 
454
615
  try {
455
616
  const result = await client.servers.unknown.tools.tool();
456
617
  } catch (error) {
457
- if (error instanceof ToolNotFoundError) {
618
+ if (error instanceof PipelineError) {
619
+ // Pipeline failure - a required plugin failed during processing.
620
+ console.error(`Pipeline ${error.pipelineFlow} failure:`, error.message);
621
+ if (error.pipelineFlow === "response") {
622
+ // Tool was called but results cannot be delivered.
623
+ console.error("A required plugin failed during response processing");
624
+ }
625
+ } else if (error instanceof ToolNotFoundError) {
458
626
  console.error(
459
627
  `Tool not found: ${error.toolName} on server ${error.serverName}`,
460
628
  );
@@ -466,6 +634,20 @@ try {
466
634
  }
467
635
  ```
468
636
 
637
+ ### PipelineError
638
+
639
+ The `PipelineError` is thrown when mcpd's plugin pipeline fails. This indicates a problem with a plugin or an external system that a plugin depends on (e.g., audit service, authentication provider), not a problem with your request or the tool itself.
640
+
641
+ - **Response Pipeline Failure** (`pipelineFlow === 'response'`): The upstream request was processed (the tool was called), but results cannot be returned because a required plugin (like audit logging) failed during response processing. This does not indicate whether the tool itself succeeded or failed.
642
+ - **Request Pipeline Failure** (`pipelineFlow === 'request'`): The request was rejected before reaching the upstream server because a required plugin (like authentication) failed during request processing.
643
+
644
+ Properties:
645
+
646
+ - `message: string` - Descriptive error message
647
+ - `serverName?: string` - The server name (when called through tool execution)
648
+ - `operation?: string` - The operation (e.g., "time.get_current_time")
649
+ - `pipelineFlow?: 'request' | 'response'` - Which pipeline flow failed
650
+
469
651
  ## Development
470
652
 
471
653
  ### Setup
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { McpdClientOptions, ServerHealth } from './types';
1
+ import { McpdClientOptions, ServerHealth, ArrayAgentToolsOptions, ObjectAgentToolsOptions, MapAgentToolsOptions } from './types';
2
2
  import { ServersNamespace } from './dynamicCaller';
3
3
  import { AgentFunction } from './functionBuilder';
4
4
  /**
@@ -20,7 +20,6 @@ import { AgentFunction } from './functionBuilder';
20
20
  * apiEndpoint: 'http://localhost:8090',
21
21
  * apiKey: 'optional-key',
22
22
  * healthCacheTtl: 10,
23
- * serverCacheTtl: 60
24
23
  * });
25
24
  *
26
25
  * // List available servers
@@ -48,6 +47,10 @@ export declare class McpdClient {
48
47
  * Get a list of all configured MCP servers.
49
48
  *
50
49
  * @returns Array of server names
50
+ *
51
+ * @throws {AuthenticationError} If API key was present and authentication fails
52
+ * @throws {ConnectionError} If unable to connect to the mcpd daemon
53
+ * @throws {TimeoutError} If the request times out
51
54
  * @throws {McpdError} If the request fails
52
55
  *
53
56
  * @example
@@ -60,9 +63,13 @@ export declare class McpdClient {
60
63
  /**
61
64
  * Get health information for one or all servers.
62
65
  *
63
- * @param serverName - Optional server name to get health for
66
+ * @param serverName - Server name to get health for, or undefined for all servers
67
+ *
64
68
  * @returns Health information for the specified server or all servers
65
- * @throws {ServerNotFoundError} If the specified server doesn't exist
69
+ *
70
+ * @throws {AuthenticationError} If API key was present and authentication fails
71
+ * @throws {ConnectionError} If unable to connect to the mcpd daemon
72
+ * @throws {TimeoutError} If the request times out
66
73
  * @throws {McpdError} If the request fails
67
74
  *
68
75
  * @example
@@ -82,8 +89,14 @@ export declare class McpdClient {
82
89
  * Check if a specific server is healthy.
83
90
  *
84
91
  * @param serverName - The name of the server to check
92
+ *
85
93
  * @returns True if the server is healthy, false otherwise
86
94
  *
95
+ * @throws {AuthenticationError} If API key was present and authentication fails
96
+ * @throws {ConnectionError} If unable to connect to the mcpd daemon
97
+ * @throws {TimeoutError} If the request times out
98
+ * @throws {McpdError} If the request fails
99
+ *
87
100
  * @example
88
101
  * ```typescript
89
102
  * if (await client.isServerHealthy('time')) {
@@ -102,47 +115,29 @@ export declare class McpdClient {
102
115
  * This forces fresh health checks on the next getServerHealth() or isServerHealthy() call.
103
116
  */
104
117
  clearServerHealthCache(): void;
105
- /**
106
- * Generate callable functions for use with AI agent frameworks (internal).
107
- *
108
- * This method queries servers and creates self-contained, callable functions
109
- * that can be passed to AI agent frameworks. Each function includes its schema
110
- * as metadata and handles the MCP communication internally.
111
- *
112
- * This method automatically filters out unhealthy servers by checking their health
113
- * status before fetching tools. Unhealthy servers are silently skipped to ensure
114
- * the method returns quickly without waiting for timeouts on failed servers.
115
- *
116
- * Tool fetches from multiple servers are executed concurrently for optimal performance.
117
- *
118
- * @param servers - Optional list of server names to include. If not specified, includes all servers.
119
- * @returns Array of callable functions with metadata. Only includes tools from healthy servers.
120
- *
121
- * @throws {ConnectionError} If unable to connect to the mcpd daemon
122
- * @throws {TimeoutError} If requests to the daemon time out
123
- * @throws {AuthenticationError} If API key authentication fails
124
- * @throws {McpdError} If unable to retrieve health status, server list, or generate functions
125
- * @internal
126
- */
127
- agentTools(servers?: string[]): Promise<AgentFunction[]>;
128
118
  /**
129
119
  * Generate callable functions for use with AI agent frameworks.
130
120
  *
131
- * This method queries servers and creates self-contained, callable functions
121
+ * This method queries servers to create and cache self-contained, callable functions
132
122
  * that can be passed to AI agent frameworks. Each function includes its schema
133
123
  * as metadata and handles the MCP communication internally.
134
124
  *
135
- * This method automatically filters out unhealthy servers by checking their health
136
- * status before fetching tools. Unhealthy servers are silently skipped to ensure
137
- * the method returns quickly without waiting for timeouts on failed servers.
125
+ * @remarks
126
+ * This method automatically filters out unhealthy servers by checking their health status before fetching tools.
127
+ * Unhealthy servers are skipped (with optional warnings when logging is enabled) to ensure the
128
+ * method returns quickly without waiting for timeouts on failed servers.
138
129
  *
139
130
  * Tool fetches from multiple servers are executed concurrently for optimal performance.
140
131
  *
141
- * The generated functions are cached for performance. Use clearAgentToolsCache()
142
- * to force regeneration if servers or tools have changed.
132
+ * Generated functions are cached for performance. Once cached, subsequent calls return
133
+ * the cached functions immediately without refetching schemas, regardless of filter parameters.
134
+ * Use {@link clearAgentToolsCache()} to clear the cache, or set refreshCache to true
135
+ * to force regeneration when tool schemas have changed.
136
+ *
137
+ * @param options - Options for output format, server/tool filtering, and cache control
143
138
  *
144
- * @param options - Options for generating agent tools (format and server filtering)
145
- * @returns Functions in the requested format (array, object, or map). Only includes tools from healthy servers.
139
+ * @returns Functions in the requested format (array, object, or map).
140
+ * Only includes tools from healthy servers.
146
141
  *
147
142
  * @throws {ConnectionError} If unable to connect to the mcpd daemon
148
143
  * @throws {TimeoutError} If requests to the daemon time out
@@ -158,6 +153,9 @@ export declare class McpdClient {
158
153
  * // Get tools from specific servers
159
154
  * const tools = await client.getAgentTools({ servers: ['time', 'fetch'] });
160
155
  *
156
+ * // Force refresh from cache
157
+ * const freshTools = await client.getAgentTools({ refreshCache: true });
158
+ *
161
159
  * // Use with LangChain JS (array format)
162
160
  * const langchainTools = await client.getAgentTools({ format: 'array' });
163
161
  * const agent = await createOpenAIToolsAgent({ llm, tools: langchainTools, prompt });
@@ -170,17 +168,8 @@ export declare class McpdClient {
170
168
  * const result = await generateText({ model, tools: vercelTools, prompt });
171
169
  * ```
172
170
  */
173
- getAgentTools(options?: {
174
- format?: "array";
175
- servers?: string[];
176
- }): Promise<AgentFunction[]>;
177
- getAgentTools(options: {
178
- format: "object";
179
- servers?: string[];
180
- }): Promise<Record<string, AgentFunction>>;
181
- getAgentTools(options: {
182
- format: "map";
183
- servers?: string[];
184
- }): Promise<Map<string, AgentFunction>>;
171
+ getAgentTools(options?: ArrayAgentToolsOptions): Promise<AgentFunction[]>;
172
+ getAgentTools(options: ObjectAgentToolsOptions): Promise<Record<string, AgentFunction>>;
173
+ getAgentTools(options: MapAgentToolsOptions): Promise<Map<string, AgentFunction>>;
185
174
  }
186
175
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAYH,OAAO,EAEL,iBAAiB,EACjB,YAAY,EAeb,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,mBAAmB,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aAAa,CACjB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CA+DvC"}
package/dist/errors.d.ts CHANGED
@@ -1,4 +1,16 @@
1
1
  import { ErrorModel } from './types';
2
+ /**
3
+ * Pipeline flow constant for request processing failures.
4
+ */
5
+ export declare const PIPELINE_FLOW_REQUEST: "request";
6
+ /**
7
+ * Pipeline flow constant for response processing failures.
8
+ */
9
+ export declare const PIPELINE_FLOW_RESPONSE: "response";
10
+ /**
11
+ * Pipeline flow indicating where in the pipeline the failure occurred.
12
+ */
13
+ export type PipelineFlow = typeof PIPELINE_FLOW_REQUEST | typeof PIPELINE_FLOW_RESPONSE;
2
14
  /**
3
15
  * Base exception for all mcpd SDK errors.
4
16
  *
@@ -110,4 +122,60 @@ export declare class TimeoutError extends McpdError {
110
122
  readonly timeout: number | undefined;
111
123
  constructor(message: string, operation?: string, timeout?: number, cause?: Error);
112
124
  }
125
+ /**
126
+ * Raised when required pipeline processing fails.
127
+ *
128
+ * This indicates that required processing failed in the mcpd pipeline.
129
+ * The error occurs when a required plugin (such as authentication, validation,
130
+ * audit logging, monitoring, or response transformation) fails during request
131
+ * or response processing.
132
+ *
133
+ * Pipeline Flow Distinction:
134
+ * - **response-pipeline-failure**: The upstream request was processed (the tool
135
+ * was called), but results cannot be returned due to a required response
136
+ * processing step failure. Note: This does not indicate whether the tool
137
+ * itself succeeded or failed - only that the response cannot be delivered.
138
+ *
139
+ * - **request-pipeline-failure**: The request was rejected before reaching the
140
+ * upstream server due to a required request processing step failure (such as
141
+ * authentication, authorization, validation, or rate limiting plugin failure).
142
+ *
143
+ * This typically indicates a problem with a plugin or an external system
144
+ * that a plugin depends on (e.g., audit service, authentication provider).
145
+ * Retrying is unlikely to help as this usually indicates a configuration
146
+ * or dependency problem rather than a transient failure.
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * import { McpdClient, PipelineError } from '@mozilla-ai/mcpd';
151
+ *
152
+ * const client = new McpdClient({ apiEndpoint: 'http://localhost:8090' });
153
+ *
154
+ * try {
155
+ * const result = await client.servers.time.tools.get_current_time();
156
+ * } catch (error) {
157
+ * if (error instanceof PipelineError) {
158
+ * console.log(`Pipeline failure: ${error.message}`);
159
+ * console.log(`Flow: ${error.pipelineFlow}`);
160
+ *
161
+ * if (error.pipelineFlow === 'response') {
162
+ * console.log('Tool was called but results cannot be delivered');
163
+ * } else {
164
+ * console.log('Request was rejected by pipeline');
165
+ * console.log('Check authentication, authorization, or rate limiting');
166
+ * }
167
+ * }
168
+ * }
169
+ * ```
170
+ *
171
+ * @remarks
172
+ * This exception indicates a problem with a plugin or its dependencies, not
173
+ * with your request or the tool itself.
174
+ */
175
+ export declare class PipelineError extends McpdError {
176
+ readonly serverName: string | undefined;
177
+ readonly operation: string | undefined;
178
+ readonly pipelineFlow: PipelineFlow | undefined;
179
+ constructor(message: string, serverName?: string, operation?: string, pipelineFlow?: PipelineFlow, cause?: Error);
180
+ }
113
181
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +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,SA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,qBAAa,aAAc,SAAQ,SAAS;IAC1C,SAAgB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/C,SAAgB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,SAAgB,YAAY,EAAE,YAAY,GAAG,SAAS,CAAC;gBAGrD,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,YAAY,EAC3B,KAAK,CAAC,EAAE,KAAK;CAShB"}
@@ -106,5 +106,11 @@ export declare class FunctionBuilder {
106
106
  * @returns The number of functions currently cached
107
107
  */
108
108
  getCacheSize(): number;
109
+ /**
110
+ * Get all cached functions.
111
+ *
112
+ * @returns Array of all cached agent functions, or empty array if cache is empty
113
+ */
114
+ getCachedFunctions(): AgentFunction[];
109
115
  }
110
116
  //# sourceMappingURL=functionBuilder.d.ts.map
@@ -1 +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;IAIt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AE,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;IAItB;;;;OAIG;IACH,kBAAkB,IAAI,aAAa,EAAE;CAGtC"}
package/dist/index.d.ts CHANGED
@@ -15,6 +15,6 @@
15
15
  * @packageDocumentation
16
16
  */
17
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';
18
+ export { McpdError, AuthenticationError, ConnectionError, PipelineError, PIPELINE_FLOW_REQUEST, PIPELINE_FLOW_RESPONSE, ServerNotFoundError, ServerUnhealthyError, TimeoutError, ToolExecutionError, ToolNotFoundError, ValidationError, type PipelineFlow, } 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 AgentToolsFormat, type BaseAgentToolsOptions, type ArrayAgentToolsOptions, type ObjectAgentToolsOptions, type MapAgentToolsOptions, 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
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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,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