agent-swarm-kit 1.1.9 → 1.1.11

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/build/index.cjs CHANGED
@@ -3951,6 +3951,10 @@ class ClientAgent {
3951
3951
  });
3952
3952
  this.params.onInit && this.params.onInit(params.clientId, params.agentName);
3953
3953
  }
3954
+ /**
3955
+ * Resolves and combines tools from the agent's parameters and MCP tool list, ensuring no duplicate tool names.
3956
+ * @returns A promise resolving to an array of unique IAgentTool objects.
3957
+ */
3954
3958
  async _resolveTools() {
3955
3959
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
3956
3960
  this.params.logger.debug(`ClientAgent agentName=${this.params.agentName} clientId=${this.params.clientId} _resolveTools`);
@@ -4648,12 +4652,25 @@ class ClientOperator {
4648
4652
  }
4649
4653
  }
4650
4654
 
4655
+ /**
4656
+ * A no-operation implementation of the IMCP interface.
4657
+ * This class provides empty or error-throwing implementations of MCP methods.
4658
+ */
4651
4659
  class NoopMCP {
4660
+ /**
4661
+ * Creates an instance of NoopMCP.
4662
+ * @param agentName - The name of the agent associated with this MCP.
4663
+ */
4652
4664
  constructor(agentName) {
4653
4665
  this.agentName = agentName;
4654
4666
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4655
4667
  swarm$1.loggerService.debug(`NoopMCP CTOR agentName=${agentName}`);
4656
4668
  }
4669
+ /**
4670
+ * Lists available tools for a given client.
4671
+ * @param clientId - The ID of the client requesting the tool list.
4672
+ * @returns A promise resolving to an empty array of tools.
4673
+ */
4657
4674
  async listTools(clientId) {
4658
4675
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4659
4676
  swarm$1.loggerService.debug(`NoopMCP listTools agentName=${this.agentName}`, {
@@ -4661,6 +4678,12 @@ class NoopMCP {
4661
4678
  });
4662
4679
  return [];
4663
4680
  }
4681
+ /**
4682
+ * Checks if a specific tool exists for a given client.
4683
+ * @param toolName - The name of the tool to check.
4684
+ * @param clientId - The ID of the client.
4685
+ * @returns A promise resolving to false, indicating no tools are available.
4686
+ */
4664
4687
  hasTool(toolName, clientId) {
4665
4688
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4666
4689
  swarm$1.loggerService.debug(`NoopMCP hasTool agentName=${this.agentName}`, {
@@ -4669,6 +4692,12 @@ class NoopMCP {
4669
4692
  });
4670
4693
  return Promise.resolve(false);
4671
4694
  }
4695
+ /**
4696
+ * Attempts to call a tool, always throwing an error in this implementation.
4697
+ * @param toolName - The name of the tool to call.
4698
+ * @param dto - The data transfer object containing tool call parameters.
4699
+ * @throws Error indicating that NoopMCP cannot call tools.
4700
+ */
4672
4701
  async callTool(toolName, dto) {
4673
4702
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4674
4703
  swarm$1.loggerService.debug(`NoopMCP callTool agentName=${this.agentName}`, {
@@ -4678,7 +4707,16 @@ class NoopMCP {
4678
4707
  throw new Error(`NoopPolicy callTool should not be called agentName=${this.agentName} toolName=${toolName}`);
4679
4708
  }
4680
4709
  }
4710
+ /**
4711
+ * A composite implementation of the IMCP interface that merges multiple MCPs.
4712
+ * This class delegates tool-related operations to a list of MCPs.
4713
+ */
4681
4714
  class MergeMCP {
4715
+ /**
4716
+ * Creates an instance of MergeMCP.
4717
+ * @param mcpList - An array of IMCP instances to merge.
4718
+ * @param agentName - The name of the agent associated with this MCP.
4719
+ */
4682
4720
  constructor(mcpList, agentName) {
4683
4721
  this.mcpList = mcpList;
4684
4722
  this.agentName = agentName;
@@ -4687,6 +4725,11 @@ class MergeMCP {
4687
4725
  mcpList,
4688
4726
  });
4689
4727
  }
4728
+ /**
4729
+ * Lists all tools available from the merged MCPs for a given client.
4730
+ * @param clientId - The ID of the client requesting the tool list.
4731
+ * @returns A promise resolving to a flattened array of tools from all MCPs.
4732
+ */
4690
4733
  async listTools(clientId) {
4691
4734
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4692
4735
  swarm$1.loggerService.debug(`MergeMCP listTools agentName=${this.agentName}`, {
@@ -4698,6 +4741,12 @@ class MergeMCP {
4698
4741
  }
4699
4742
  return toolList.flatMap((tools) => tools);
4700
4743
  }
4744
+ /**
4745
+ * Checks if a specific tool exists in any of the merged MCPs for a given client.
4746
+ * @param toolName - The name of the tool to check.
4747
+ * @param clientId - The ID of the client.
4748
+ * @returns A promise resolving to true if the tool exists in any MCP, false otherwise.
4749
+ */
4701
4750
  async hasTool(toolName, clientId) {
4702
4751
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4703
4752
  swarm$1.loggerService.debug(`MergeMCP hasTool agentName=${this.agentName}`, {
@@ -4711,6 +4760,12 @@ class MergeMCP {
4711
4760
  }
4712
4761
  return false;
4713
4762
  }
4763
+ /**
4764
+ * Calls a tool from one of the merged MCPs if it exists.
4765
+ * @param toolName - The name of the tool to call.
4766
+ * @param dto - The data transfer object containing tool call parameters.
4767
+ * @throws Error if the tool is not found in any of the merged MCPs.
4768
+ */
4714
4769
  async callTool(toolName, dto) {
4715
4770
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
4716
4771
  swarm$1.loggerService.debug(`MergeMCP callTool agentName=${this.agentName}`, {
@@ -8676,6 +8731,23 @@ class AgentValidationService {
8676
8731
  }
8677
8732
  return this._agentMap.get(agentName).states || [];
8678
8733
  };
8734
+ /**
8735
+ * Retrieves the list of mcp names associated with a given agent.
8736
+ * Logs the operation and validates agent existence, supporting ClientMCP integration.
8737
+ * @param {AgentName} agentName - The name of the agent to query, sourced from Agent.interface.
8738
+ * @returns {MCPName[]} An array of mcp names from the agent’s schema.
8739
+ * @throws {Error} If the agent is not found in _agentMap.
8740
+ */
8741
+ this.getMCPList = (agentName) => {
8742
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
8743
+ this.loggerService.info("agentValidationService getMCPList", {
8744
+ agentName,
8745
+ });
8746
+ if (!this._agentMap.has(agentName)) {
8747
+ throw new Error(`agent-swarm agent ${agentName} not exist (getMCPList)`);
8748
+ }
8749
+ return this._agentMap.get(agentName).mcp || [];
8750
+ };
8679
8751
  /**
8680
8752
  * Registers a new agent with its schema in the validation service.
8681
8753
  * Logs the operation and updates _agentMap and _agentDepsMap, supporting AgentSchemaService’s agent registration.
@@ -11851,6 +11923,13 @@ class DocService {
11851
11923
  * @private
11852
11924
  */
11853
11925
  this.agentSchemaService = inject(TYPES.agentSchemaService);
11926
+ /**
11927
+ * Model context protocol service instance, injected via DI.
11928
+ * Retrieves IMCPSchema objects for writeAgentDoc and agent descriptions in writeSwarmDoc, providing details like tools and prompts.
11929
+ * @type {MCPSchemaService}
11930
+ * @private
11931
+ */
11932
+ this.mcpSchemaService = inject(TYPES.mcpSchemaService);
11854
11933
  /**
11855
11934
  * Policy schema service instance, injected via DI.
11856
11935
  * Supplies policy descriptions for writeSwarmDoc, documenting banhammer policies associated with swarms.
@@ -12087,6 +12166,22 @@ class DocService {
12087
12166
  result.push("");
12088
12167
  }
12089
12168
  }
12169
+ if (agentSchema.mcp) {
12170
+ result.push(`## Model Context Protocol`);
12171
+ result.push("");
12172
+ for (let i = 0; i !== agentSchema.mcp.length; i++) {
12173
+ if (!agentSchema.mcp[i]) {
12174
+ continue;
12175
+ }
12176
+ result.push(`${i + 1}. ${agentSchema.mcp[i]}`);
12177
+ const { docDescription } = this.mcpSchemaService.get(agentSchema.mcp[i]);
12178
+ if (docDescription) {
12179
+ result.push("");
12180
+ result.push(docDescription);
12181
+ }
12182
+ result.push("");
12183
+ }
12184
+ }
12090
12185
  if (agentSchema.tools) {
12091
12186
  result.push(`## Used tools`);
12092
12187
  result.push("");
@@ -14645,9 +14740,21 @@ class WikiValidationService {
14645
14740
  }
14646
14741
  }
14647
14742
 
14743
+ /**
14744
+ * A client-side implementation of the IMCP interface for managing tools and their operations.
14745
+ */
14648
14746
  class ClientMCP {
14747
+ /**
14748
+ * Creates an instance of ClientMCP.
14749
+ * @param params - The parameters for configuring the MCP, including callbacks and tool management functions.
14750
+ */
14649
14751
  constructor(params) {
14650
14752
  this.params = params;
14753
+ /**
14754
+ * Memoized function to fetch and cache tools for a given client ID.
14755
+ * @param clientId - The ID of the client requesting the tools.
14756
+ * @returns A promise resolving to a Map of tool names to IMCPTool objects.
14757
+ */
14651
14758
  this.fetchTools = functoolsKit.memoize(([clientId]) => `${clientId}`, async (clientId) => {
14652
14759
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
14653
14760
  this.params.logger.debug(`ClientMCP mcpName=${this.params.mcpName} fetchTools`, {
@@ -14664,6 +14771,11 @@ class ClientMCP {
14664
14771
  this.params.callbacks.onInit();
14665
14772
  }
14666
14773
  }
14774
+ /**
14775
+ * Lists all available tools for a given client.
14776
+ * @param clientId - The ID of the client requesting the tool list.
14777
+ * @returns A promise resolving to an array of IMCPTool objects.
14778
+ */
14667
14779
  async listTools(clientId) {
14668
14780
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
14669
14781
  this.params.logger.debug(`ClientMCP mcpName=${this.params.mcpName} listTools`, {
@@ -14675,6 +14787,12 @@ class ClientMCP {
14675
14787
  const toolMap = await this.fetchTools(clientId);
14676
14788
  return Array.from(toolMap.values());
14677
14789
  }
14790
+ /**
14791
+ * Checks if a specific tool exists for a given client.
14792
+ * @param toolName - The name of the tool to check.
14793
+ * @param clientId - The ID of the client.
14794
+ * @returns A promise resolving to true if the tool exists, false otherwise.
14795
+ */
14678
14796
  async hasTool(toolName, clientId) {
14679
14797
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
14680
14798
  this.params.logger.debug(`ClientMCP mcpName=${this.params.mcpName} hasTool`, {
@@ -14684,6 +14802,12 @@ class ClientMCP {
14684
14802
  const toolMap = await this.fetchTools(clientId);
14685
14803
  return toolMap.has(toolName);
14686
14804
  }
14805
+ /**
14806
+ * Calls a specific tool with the provided parameters.
14807
+ * @param toolName - The name of the tool to call.
14808
+ * @param dto - The data transfer object containing tool call parameters.
14809
+ * @returns A promise resolving when the tool call is complete.
14810
+ */
14687
14811
  async callTool(toolName, dto) {
14688
14812
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
14689
14813
  this.params.logger.debug(`ClientMCP mcpName=${this.params.mcpName} callTool`, {
@@ -14695,6 +14819,10 @@ class ClientMCP {
14695
14819
  }
14696
14820
  return await this.params.callTool(toolName, dto);
14697
14821
  }
14822
+ /**
14823
+ * Disposes of resources associated with a client, clearing cached tools and invoking the dispose callback.
14824
+ * @param clientId - The ID of the client whose resources are to be disposed.
14825
+ */
14698
14826
  dispose(clientId) {
14699
14827
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_DEBUG &&
14700
14828
  this.params.logger.debug(`ClientMCP mcpName=${this.params.mcpName} dispose`, {
@@ -14707,12 +14835,25 @@ class ClientMCP {
14707
14835
  }
14708
14836
  }
14709
14837
 
14838
+ /**
14839
+ * Service class for managing MCP (Model Context Protocol) connections and operations.
14840
+ * Implements the IMCP interface to handle tool listing, checking, calling, and disposal.
14841
+ */
14710
14842
  class MCPConnectionService {
14711
14843
  constructor() {
14844
+ /** Injected LoggerService for logging operations. */
14712
14845
  this.loggerService = inject(TYPES.loggerService);
14846
+ /** Injected BusService for communication or event handling. */
14713
14847
  this.busService = inject(TYPES.busService);
14848
+ /** Injected MethodContextService for accessing method context information. */
14714
14849
  this.methodContextService = inject(TYPES.methodContextService);
14850
+ /** Injected MCPSchemaService for managing MCP schemas. */
14715
14851
  this.mcpSchemaService = inject(TYPES.mcpSchemaService);
14852
+ /**
14853
+ * Memoized function to retrieve or create an MCP instance for a given MCP name.
14854
+ * @param mcpName - The name of the MCP to retrieve or create.
14855
+ * @returns A ClientMCP instance configured with the specified schema and dependencies.
14856
+ */
14716
14857
  this.getMCP = functoolsKit.memoize(([mcpName]) => `${mcpName}`, (mcpName) => {
14717
14858
  const schema = this.mcpSchemaService.get(mcpName);
14718
14859
  return new ClientMCP({
@@ -14722,7 +14863,27 @@ class MCPConnectionService {
14722
14863
  ...schema,
14723
14864
  });
14724
14865
  });
14866
+ /**
14867
+ * Disposes of resources associated with a client, clearing cached MCP instances.
14868
+ * @param clientId - The ID of the client whose resources are to be disposed.
14869
+ * @returns A promise resolving when the disposal is complete.
14870
+ */
14871
+ this.dispose = async (clientId) => {
14872
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14873
+ this.loggerService.info(`mcpConnectionService dispose`, { clientId });
14874
+ const key = `${this.methodContextService.context.clientId}-${this.methodContextService.context.agentName}`;
14875
+ if (!this.getMCP.has(key)) {
14876
+ return;
14877
+ }
14878
+ await this.getMCP(this.methodContextService.context.mcpName).dispose(clientId);
14879
+ this.getMCP.clear(clientId);
14880
+ };
14725
14881
  }
14882
+ /**
14883
+ * Lists available tools for a given client.
14884
+ * @param clientId - The ID of the client requesting the tool list.
14885
+ * @returns A promise resolving to an array of IMCPTool objects.
14886
+ */
14726
14887
  async listTools(clientId) {
14727
14888
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14728
14889
  this.loggerService.info(`mcpConnectionService listTools`, {
@@ -14730,6 +14891,12 @@ class MCPConnectionService {
14730
14891
  });
14731
14892
  return await this.getMCP(this.methodContextService.context.mcpName).listTools(clientId);
14732
14893
  }
14894
+ /**
14895
+ * Checks if a specific tool exists for a given client.
14896
+ * @param toolName - The name of the tool to check.
14897
+ * @param clientId - The ID of the client.
14898
+ * @returns A promise resolving to true if the tool exists, false otherwise.
14899
+ */
14733
14900
  async hasTool(toolName, clientId) {
14734
14901
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14735
14902
  this.loggerService.info(`mcpConnectionService hasTool`, {
@@ -14738,6 +14905,12 @@ class MCPConnectionService {
14738
14905
  });
14739
14906
  return await this.getMCP(this.methodContextService.context.mcpName).hasTool(toolName, clientId);
14740
14907
  }
14908
+ /**
14909
+ * Calls a specific tool with the provided parameters.
14910
+ * @param toolName - The name of the tool to call.
14911
+ * @param dto - The data transfer object containing tool call parameters.
14912
+ * @returns A promise resolving when the tool call is complete.
14913
+ */
14741
14914
  async callTool(toolName, dto) {
14742
14915
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14743
14916
  this.loggerService.info(`mcpConnectionService hasTool`, {
@@ -14748,10 +14921,21 @@ class MCPConnectionService {
14748
14921
  }
14749
14922
  }
14750
14923
 
14924
+ /**
14925
+ * Service class for managing MCP (Model Context Protocol) schemas.
14926
+ * Provides methods to register, override, and retrieve MCP schemas.
14927
+ */
14751
14928
  class MCPSchemaService {
14752
14929
  constructor() {
14930
+ /** Injected LoggerService for logging operations. */
14753
14931
  this.loggerService = inject(TYPES.loggerService);
14932
+ /** Registry for storing MCP schemas, keyed by MCP name. */
14754
14933
  this.registry = new functoolsKit.ToolRegistry("mcpSchemaService");
14934
+ /**
14935
+ * Validates the basic structure of an MCP schema.
14936
+ * @param mcpSchema - The MCP schema to validate.
14937
+ * @throws Error if the schema is missing required fields or has invalid types.
14938
+ */
14755
14939
  this.validateShallow = (mcpSchema) => {
14756
14940
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14757
14941
  this.loggerService.info(`mcpSchemaService validateShallow`, {
@@ -14767,18 +14951,34 @@ class MCPSchemaService {
14767
14951
  throw new Error(`agent-swarm mcp schema validation failed: listTools must be provided mcpName=${mcpSchema.mcpName}`);
14768
14952
  }
14769
14953
  };
14954
+ /**
14955
+ * Registers a new MCP schema in the registry.
14956
+ * @param key - The name of the MCP to register.
14957
+ * @param value - The MCP schema to register.
14958
+ */
14770
14959
  this.register = (key, value) => {
14771
14960
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14772
14961
  this.loggerService.info(`mcpSchemaService register`, { key });
14773
14962
  this.validateShallow(value);
14774
14963
  this.registry = this.registry.register(key, value);
14775
14964
  };
14965
+ /**
14966
+ * Overrides an existing MCP schema with new or partial values.
14967
+ * @param key - The name of the MCP to override.
14968
+ * @param value - The partial MCP schema to apply.
14969
+ * @returns The updated MCP schema.
14970
+ */
14776
14971
  this.override = (key, value) => {
14777
14972
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14778
14973
  this.loggerService.info(`mcpSchemaService override`, { key });
14779
14974
  this.registry = this.registry.override(key, value);
14780
14975
  return this.registry.get(key);
14781
14976
  };
14977
+ /**
14978
+ * Retrieves an MCP schema by its name.
14979
+ * @param key - The name of the MCP to retrieve.
14980
+ * @returns The MCP schema associated with the given name.
14981
+ */
14782
14982
  this.get = (key) => {
14783
14983
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14784
14984
  this.loggerService.info(`mcpSchemaService get`, { key });
@@ -14787,11 +14987,48 @@ class MCPSchemaService {
14787
14987
  }
14788
14988
  }
14789
14989
 
14990
+ /**
14991
+ * Public service class for interacting with MCP (Model Context Protocol) operations.
14992
+ * Provides methods to list tools, check tool existence, call tools, and dispose resources,
14993
+ * executing operations within a specified context.
14994
+ */
14790
14995
  class MCPPublicService {
14791
14996
  constructor() {
14997
+ /** Injected LoggerService for logging operations. */
14792
14998
  this.loggerService = inject(TYPES.loggerService);
14999
+ /** Injected MCPConnectionService for handling MCP operations. */
14793
15000
  this.mcpConnectionService = inject(TYPES.mcpConnectionService);
15001
+ /**
15002
+ * Disposes of resources associated with a client within a specified context.
15003
+ * @param methodName - The name of the method for context tracking.
15004
+ * @param clientId - The ID of the client whose resources are to be disposed.
15005
+ * @param mcpName - The name of the MCP to query.
15006
+ * @returns A promise resolving when the disposal is complete.
15007
+ */
15008
+ this.dispose = async (methodName, clientId, mcpName) => {
15009
+ GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
15010
+ this.loggerService.info(`mcpPublicService dispose`, { clientId });
15011
+ return await MethodContextService.runInContext(async () => {
15012
+ return await this.mcpConnectionService.dispose(clientId);
15013
+ }, {
15014
+ methodName,
15015
+ clientId,
15016
+ mcpName,
15017
+ agentName: "",
15018
+ swarmName: "",
15019
+ storageName: "",
15020
+ stateName: "",
15021
+ policyName: "",
15022
+ });
15023
+ };
14794
15024
  }
15025
+ /**
15026
+ * Lists available tools for a given client within a specified context.
15027
+ * @param methodName - The name of the method for context tracking.
15028
+ * @param clientId - The ID of the client requesting the tool list.
15029
+ * @param mcpName - The name of the MCP to query.
15030
+ * @returns A promise resolving to an array of IMCPTool objects.
15031
+ */
14795
15032
  async listTools(methodName, clientId, mcpName) {
14796
15033
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14797
15034
  this.loggerService.info(`mcpPublicService listTools`, {
@@ -14810,6 +15047,14 @@ class MCPPublicService {
14810
15047
  policyName: "",
14811
15048
  });
14812
15049
  }
15050
+ /**
15051
+ * Checks if a specific tool exists for a given client within a specified context.
15052
+ * @param methodName - The name of the method for context tracking.
15053
+ * @param clientId - The ID of the client.
15054
+ * @param mcpName - The name of the MCP to query.
15055
+ * @param toolName - The name of the tool to check.
15056
+ * @returns A promise resolving to true if the tool exists, false otherwise.
15057
+ */
14813
15058
  async hasTool(methodName, clientId, mcpName, toolName) {
14814
15059
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14815
15060
  this.loggerService.info(`mcpPublicService hasTool`, {
@@ -14829,6 +15074,15 @@ class MCPPublicService {
14829
15074
  policyName: "",
14830
15075
  });
14831
15076
  }
15077
+ /**
15078
+ * Calls a specific tool with the provided parameters within a specified context.
15079
+ * @param methodName - The name of the method for context tracking.
15080
+ * @param clientId - The ID of the client.
15081
+ * @param mcpName - The name of the MCP to query.
15082
+ * @param toolName - The name of the tool to call.
15083
+ * @param dto - The data transfer object containing tool call parameters.
15084
+ * @returns A promise resolving when the tool call is complete.
15085
+ */
14832
15086
  async callTool(methodName, clientId, mcpName, toolName, dto) {
14833
15087
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14834
15088
  this.loggerService.info(`mcpPublicService callTool`, {
@@ -14850,10 +15104,22 @@ class MCPPublicService {
14850
15104
  }
14851
15105
  }
14852
15106
 
15107
+ /**
15108
+ * Service class for validating and managing MCP (Model Context Protocol) schemas.
15109
+ * Maintains a map of MCP schemas and provides methods to add and validate them.
15110
+ */
14853
15111
  class MCPValidationService {
14854
15112
  constructor() {
15113
+ /** Injected LoggerService for logging operations. */
14855
15114
  this.loggerService = inject(TYPES.loggerService);
15115
+ /** Internal map storing MCP schemas, keyed by MCP name. */
14856
15116
  this._mcpMap = new Map();
15117
+ /**
15118
+ * Adds a new MCP schema to the map.
15119
+ * @param mcpName - The name of the MCP to add.
15120
+ * @param mcpSchema - The MCP schema to store.
15121
+ * @throws Error if an MCP with the same name already exists.
15122
+ */
14857
15123
  this.addMCP = (mcpName, mcpSchema) => {
14858
15124
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14859
15125
  this.loggerService.info("mcpValidationService addMCP", {
@@ -14865,6 +15131,12 @@ class MCPValidationService {
14865
15131
  }
14866
15132
  this._mcpMap.set(mcpName, mcpSchema);
14867
15133
  };
15134
+ /**
15135
+ * Validates the existence of an MCP schema by its name.
15136
+ * @param mcpName - The name of the MCP to validate.
15137
+ * @param source - The source context or identifier for the validation request.
15138
+ * @throws Error if the MCP does not exist in the map.
15139
+ */
14868
15140
  this.validate = functoolsKit.memoize(([mcpName]) => mcpName, (mcpName, source) => {
14869
15141
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_INFO &&
14870
15142
  this.loggerService.info("mcpValidationService validate", {
@@ -15955,6 +16227,11 @@ const addTool = beginContext((toolSchema) => {
15955
16227
  });
15956
16228
 
15957
16229
  const METHOD_NAME$T = "function.setup.addMCP";
16230
+ /**
16231
+ * Registers a new MCP (Model Context Protocol) schema in the system.
16232
+ * @param mcpSchema - The MCP schema to register.
16233
+ * @returns The name of the registered MCP.
16234
+ */
15958
16235
  const addMCP = beginContext((mcpSchema) => {
15959
16236
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
15960
16237
  swarm$1.loggerService.log(METHOD_NAME$T, {
@@ -16344,6 +16621,11 @@ const overrideTool = beginContext((toolSchema) => {
16344
16621
  });
16345
16622
 
16346
16623
  const METHOD_NAME$G = "function.test.overrideMCP";
16624
+ /**
16625
+ * Overrides an existing MCP (Model Context Protocol) schema with a new or partial schema.
16626
+ * @param mcpSchema - The MCP schema containing the name and optional properties to override.
16627
+ * @returns The result of the override operation from the MCP schema service.
16628
+ */
16347
16629
  const overrideMCP = beginContext((mcpSchema) => {
16348
16630
  GLOBAL_CONFIG.CC_LOGGER_ENABLE_LOG &&
16349
16631
  swarm$1.loggerService.log(METHOD_NAME$G, {
@@ -17097,6 +17379,21 @@ const disposeConnection = beginContext(async (clientId, swarmName, methodName =
17097
17379
  await swarm$1.statePublicService.dispose(methodName, clientId, stateName);
17098
17380
  }));
17099
17381
  }
17382
+ // Dispose of mcp resources associated with agents
17383
+ {
17384
+ const mcpDisposeSet = new Set();
17385
+ await Promise.all(swarm$1.swarmValidationService
17386
+ .getAgentList(swarmName)
17387
+ .flatMap((agentName) => swarm$1.agentValidationService.getMCPList(agentName))
17388
+ .filter((mcpName) => !!mcpName)
17389
+ .map(async (mcpName) => {
17390
+ if (mcpDisposeSet.has(mcpName)) {
17391
+ return;
17392
+ }
17393
+ mcpDisposeSet.add(mcpName);
17394
+ await swarm$1.mcpPublicService.dispose(methodName, clientId, mcpName);
17395
+ }));
17396
+ }
17100
17397
  // Dispose of auxiliary services and remove the session
17101
17398
  await HistoryAdapter.dispose(clientId, null);
17102
17399
  await LoggerAdapter.dispose(clientId);