@mastra/mcp 0.4.1-alpha.3 → 0.4.1-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -10,6 +10,7 @@ var streamableHttp_js = require('@modelcontextprotocol/sdk/client/streamableHttp
10
10
  var protocol_js = require('@modelcontextprotocol/sdk/shared/protocol.js');
11
11
  var types_js = require('@modelcontextprotocol/sdk/types.js');
12
12
  var exitHook = require('exit-hook');
13
+ var equal = require('fast-deep-equal');
13
14
  var uuid = require('uuid');
14
15
  var core = require('@mastra/core');
15
16
  var index_js$1 = require('@modelcontextprotocol/sdk/server/index.js');
@@ -19,6 +20,8 @@ var fs = require('fs');
19
20
  var os = require('os');
20
21
  var path = require('path');
21
22
 
23
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
24
+
22
25
  function _interopNamespace(e) {
23
26
  if (e && e.__esModule) return e;
24
27
  var n = Object.create(null);
@@ -37,6 +40,7 @@ function _interopNamespace(e) {
37
40
  return Object.freeze(n);
38
41
  }
39
42
 
43
+ var equal__default = /*#__PURE__*/_interopDefault(equal);
40
44
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
41
45
  var os__namespace = /*#__PURE__*/_interopNamespace(os);
42
46
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
@@ -4118,12 +4122,13 @@ function convertLogLevelToLoggerMethod(level) {
4118
4122
  return "info";
4119
4123
  }
4120
4124
  }
4121
- var MastraMCPClient = class extends base.MastraBase {
4125
+ var InternalMastraMCPClient = class _InternalMastraMCPClient extends base.MastraBase {
4122
4126
  name;
4123
4127
  client;
4124
4128
  timeout;
4125
4129
  logHandler;
4126
4130
  enableServerLogs;
4131
+ static hasWarned = false;
4127
4132
  serverConfig;
4128
4133
  transport;
4129
4134
  constructor({
@@ -4134,6 +4139,12 @@ var MastraMCPClient = class extends base.MastraBase {
4134
4139
  timeout = protocol_js.DEFAULT_REQUEST_TIMEOUT_MSEC
4135
4140
  }) {
4136
4141
  super({ name: "MastraMCPClient" });
4142
+ if (!_InternalMastraMCPClient.hasWarned) {
4143
+ console.warn(
4144
+ "[DEPRECATION] MastraMCPClient is deprecated and will be removed in a future release. Please use MCPClient instead."
4145
+ );
4146
+ _InternalMastraMCPClient.hasWarned = true;
4147
+ }
4137
4148
  this.name = name;
4138
4149
  this.timeout = timeout;
4139
4150
  this.logHandler = server.logger;
@@ -4350,48 +4361,74 @@ var MastraMCPClient = class extends base.MastraBase {
4350
4361
  return toolsRes;
4351
4362
  }
4352
4363
  };
4353
- var mastraMCPConfigurationInstances = /* @__PURE__ */ new Map();
4354
- var MCPConfiguration = class extends base.MastraBase {
4364
+ var MastraMCPClient = InternalMastraMCPClient;
4365
+ var mcpClientInstances = /* @__PURE__ */ new Map();
4366
+ var MCPClient = class extends base.MastraBase {
4355
4367
  serverConfigs = {};
4356
4368
  id;
4357
4369
  defaultTimeout;
4370
+ mcpClientsById = /* @__PURE__ */ new Map();
4371
+ disconnectPromise = null;
4358
4372
  constructor(args) {
4359
- super({ name: "MCPConfiguration" });
4373
+ super({ name: "MCPClient" });
4360
4374
  this.defaultTimeout = args.timeout ?? protocol_js.DEFAULT_REQUEST_TIMEOUT_MSEC;
4361
4375
  this.serverConfigs = args.servers;
4362
4376
  this.id = args.id ?? this.makeId();
4363
- const existingInstance = mastraMCPConfigurationInstances.get(this.id);
4377
+ if (args.id) {
4378
+ this.id = args.id;
4379
+ const cached = mcpClientInstances.get(this.id);
4380
+ if (cached && !equal__default.default(cached.serverConfigs, args.servers)) {
4381
+ const existingInstance2 = mcpClientInstances.get(this.id);
4382
+ if (existingInstance2) {
4383
+ void existingInstance2.disconnect();
4384
+ }
4385
+ }
4386
+ } else {
4387
+ this.id = this.makeId();
4388
+ }
4389
+ const existingInstance = mcpClientInstances.get(this.id);
4364
4390
  if (existingInstance) {
4365
4391
  if (!args.id) {
4366
- throw new Error(`MCPConfiguration was initialized multiple times with the same configuration options.
4392
+ throw new Error(`MCPClient was initialized multiple times with the same configuration options.
4367
4393
 
4368
4394
  This error is intended to prevent memory leaks.
4369
4395
 
4370
4396
  To fix this you have three different options:
4371
- 1. If you need multiple MCPConfiguration class instances with identical server configurations, set an id when configuring: new MCPConfiguration({ id: "my-unique-id" })
4372
- 2. Call "await configuration.disconnect()" after you're done using the configuration and before you recreate another instance with the same options. If the identical MCPConfiguration instance is already closed at the time of re-creating it, you will not see this error.
4373
- 3. If you only need one instance of MCPConfiguration in your app, refactor your code so it's only created one time (ex. move it out of a loop into a higher scope code block)
4397
+ 1. If you need multiple MCPClient class instances with identical server configurations, set an id when configuring: new MCPClient({ id: "my-unique-id" })
4398
+ 2. Call "await client.disconnect()" after you're done using the client and before you recreate another instance with the same options. If the identical MCPClient instance is already closed at the time of re-creating it, you will not see this error.
4399
+ 3. If you only need one instance of MCPClient in your app, refactor your code so it's only created one time (ex. move it out of a loop into a higher scope code block)
4374
4400
  `);
4375
4401
  }
4376
4402
  return existingInstance;
4377
4403
  }
4404
+ mcpClientInstances.set(this.id, this);
4378
4405
  this.addToInstanceCache();
4379
4406
  return this;
4380
4407
  }
4381
4408
  addToInstanceCache() {
4382
- if (!mastraMCPConfigurationInstances.has(this.id)) {
4383
- mastraMCPConfigurationInstances.set(this.id, this);
4409
+ if (!mcpClientInstances.has(this.id)) {
4410
+ mcpClientInstances.set(this.id, this);
4384
4411
  }
4385
4412
  }
4386
4413
  makeId() {
4387
4414
  const text = JSON.stringify(this.serverConfigs).normalize("NFKC");
4388
- const idNamespace = uuid.v5(`MCPConfiguration`, uuid.v5.DNS);
4415
+ const idNamespace = uuid.v5(`MCPClient`, uuid.v5.DNS);
4389
4416
  return uuid.v5(text, idNamespace);
4390
4417
  }
4391
4418
  async disconnect() {
4392
- mastraMCPConfigurationInstances.delete(this.id);
4393
- await Promise.all(Array.from(this.mcpClientsById.values()).map((client) => client.disconnect()));
4394
- this.mcpClientsById.clear();
4419
+ if (this.disconnectPromise) {
4420
+ return this.disconnectPromise;
4421
+ }
4422
+ this.disconnectPromise = (async () => {
4423
+ try {
4424
+ mcpClientInstances.delete(this.id);
4425
+ await Promise.all(Array.from(this.mcpClientsById.values()).map((client) => client.disconnect()));
4426
+ this.mcpClientsById.clear();
4427
+ } finally {
4428
+ this.disconnectPromise = null;
4429
+ }
4430
+ })();
4431
+ return this.disconnectPromise;
4395
4432
  }
4396
4433
  async getTools() {
4397
4434
  this.addToInstanceCache();
@@ -4426,16 +4463,21 @@ To fix this you have three different options:
4426
4463
  }
4427
4464
  return sessionIds;
4428
4465
  }
4429
- mcpClientsById = /* @__PURE__ */ new Map();
4430
4466
  async getConnectedClient(name, config) {
4467
+ if (this.disconnectPromise) {
4468
+ await this.disconnectPromise;
4469
+ }
4431
4470
  const exists = this.mcpClientsById.has(name);
4471
+ const existingClient = this.mcpClientsById.get(name);
4432
4472
  if (exists) {
4433
- const mcpClient2 = this.mcpClientsById.get(name);
4434
- await mcpClient2.connect();
4435
- return mcpClient2;
4473
+ if (!existingClient) {
4474
+ throw new Error(`Client ${name} exists but is undefined`);
4475
+ }
4476
+ await existingClient.connect();
4477
+ return existingClient;
4436
4478
  }
4437
4479
  this.logger.debug(`Connecting to ${name} MCP server`);
4438
- const mcpClient = new MastraMCPClient({
4480
+ const mcpClient = new InternalMastraMCPClient({
4439
4481
  name,
4440
4482
  server: config,
4441
4483
  timeout: config.timeout ?? this.defaultTimeout
@@ -4445,7 +4487,7 @@ To fix this you have three different options:
4445
4487
  await mcpClient.connect();
4446
4488
  } catch (e) {
4447
4489
  this.mcpClientsById.delete(name);
4448
- this.logger.error(`MCPConfiguration errored connecting to MCP server ${name}`, {
4490
+ this.logger.error(`MCPClient errored connecting to MCP server ${name}`, {
4449
4491
  error: e instanceof Error ? e.message : String(e)
4450
4492
  });
4451
4493
  throw new Error(
@@ -4465,6 +4507,14 @@ To fix this you have three different options:
4465
4507
  );
4466
4508
  }
4467
4509
  };
4510
+ var MCPConfiguration = class extends MCPClient {
4511
+ constructor(args) {
4512
+ super(args);
4513
+ this.logger.warn(
4514
+ `MCPConfiguration has been renamed to MCPClient and MCPConfiguration is deprecated. The API is identical but the MCPConfiguration export will be removed in the future. Update your imports now to prevent future errors.`
4515
+ );
4516
+ }
4517
+ };
4468
4518
 
4469
4519
  // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseAnyOf.js
4470
4520
  var parseAnyOf = (schema, refs) => {
@@ -6585,6 +6635,7 @@ var MCPServer = class {
6585
6635
  }
6586
6636
  };
6587
6637
 
6638
+ exports.MCPClient = MCPClient;
6588
6639
  exports.MCPConfiguration = MCPConfiguration;
6589
6640
  exports.MCPServer = MCPServer;
6590
6641
  exports.MastraMCPClient = MastraMCPClient;
package/dist/index.d.cts CHANGED
@@ -3,6 +3,8 @@ export { LogMessage_alias_1 as LogMessage } from './_tsup-dts-rollup.cjs';
3
3
  export { LogHandler_alias_1 as LogHandler } from './_tsup-dts-rollup.cjs';
4
4
  export { MastraMCPServerDefinition_alias_1 as MastraMCPServerDefinition } from './_tsup-dts-rollup.cjs';
5
5
  export { MastraMCPClient_alias_1 as MastraMCPClient } from './_tsup-dts-rollup.cjs';
6
+ export { MCPClientOptions_alias_1 as MCPClientOptions } from './_tsup-dts-rollup.cjs';
7
+ export { MCPClient_alias_1 as MCPClient } from './_tsup-dts-rollup.cjs';
6
8
  export { MCPConfigurationOptions_alias_1 as MCPConfigurationOptions } from './_tsup-dts-rollup.cjs';
7
9
  export { MCPConfiguration_alias_1 as MCPConfiguration } from './_tsup-dts-rollup.cjs';
8
10
  export { MCPServer } from './_tsup-dts-rollup.cjs';
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export { LogMessage_alias_1 as LogMessage } from './_tsup-dts-rollup.js';
3
3
  export { LogHandler_alias_1 as LogHandler } from './_tsup-dts-rollup.js';
4
4
  export { MastraMCPServerDefinition_alias_1 as MastraMCPServerDefinition } from './_tsup-dts-rollup.js';
5
5
  export { MastraMCPClient_alias_1 as MastraMCPClient } from './_tsup-dts-rollup.js';
6
+ export { MCPClientOptions_alias_1 as MCPClientOptions } from './_tsup-dts-rollup.js';
7
+ export { MCPClient_alias_1 as MCPClient } from './_tsup-dts-rollup.js';
6
8
  export { MCPConfigurationOptions_alias_1 as MCPConfigurationOptions } from './_tsup-dts-rollup.js';
7
9
  export { MCPConfiguration_alias_1 as MCPConfiguration } from './_tsup-dts-rollup.js';
8
10
  export { MCPServer } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/
8
8
  import { DEFAULT_REQUEST_TIMEOUT_MSEC } from '@modelcontextprotocol/sdk/shared/protocol.js';
9
9
  import { ListResourcesResultSchema, CallToolResultSchema, ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
10
10
  import { asyncExitHook, gracefulExit } from 'exit-hook';
11
+ import equal from 'fast-deep-equal';
11
12
  import { v5 } from 'uuid';
12
13
  import { isVercelTool, isZodType, resolveSerializedZodOutput } from '@mastra/core';
13
14
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
@@ -4094,12 +4095,13 @@ function convertLogLevelToLoggerMethod(level) {
4094
4095
  return "info";
4095
4096
  }
4096
4097
  }
4097
- var MastraMCPClient = class extends MastraBase {
4098
+ var InternalMastraMCPClient = class _InternalMastraMCPClient extends MastraBase {
4098
4099
  name;
4099
4100
  client;
4100
4101
  timeout;
4101
4102
  logHandler;
4102
4103
  enableServerLogs;
4104
+ static hasWarned = false;
4103
4105
  serverConfig;
4104
4106
  transport;
4105
4107
  constructor({
@@ -4110,6 +4112,12 @@ var MastraMCPClient = class extends MastraBase {
4110
4112
  timeout = DEFAULT_REQUEST_TIMEOUT_MSEC
4111
4113
  }) {
4112
4114
  super({ name: "MastraMCPClient" });
4115
+ if (!_InternalMastraMCPClient.hasWarned) {
4116
+ console.warn(
4117
+ "[DEPRECATION] MastraMCPClient is deprecated and will be removed in a future release. Please use MCPClient instead."
4118
+ );
4119
+ _InternalMastraMCPClient.hasWarned = true;
4120
+ }
4113
4121
  this.name = name;
4114
4122
  this.timeout = timeout;
4115
4123
  this.logHandler = server.logger;
@@ -4326,48 +4334,74 @@ var MastraMCPClient = class extends MastraBase {
4326
4334
  return toolsRes;
4327
4335
  }
4328
4336
  };
4329
- var mastraMCPConfigurationInstances = /* @__PURE__ */ new Map();
4330
- var MCPConfiguration = class extends MastraBase {
4337
+ var MastraMCPClient = InternalMastraMCPClient;
4338
+ var mcpClientInstances = /* @__PURE__ */ new Map();
4339
+ var MCPClient = class extends MastraBase {
4331
4340
  serverConfigs = {};
4332
4341
  id;
4333
4342
  defaultTimeout;
4343
+ mcpClientsById = /* @__PURE__ */ new Map();
4344
+ disconnectPromise = null;
4334
4345
  constructor(args) {
4335
- super({ name: "MCPConfiguration" });
4346
+ super({ name: "MCPClient" });
4336
4347
  this.defaultTimeout = args.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
4337
4348
  this.serverConfigs = args.servers;
4338
4349
  this.id = args.id ?? this.makeId();
4339
- const existingInstance = mastraMCPConfigurationInstances.get(this.id);
4350
+ if (args.id) {
4351
+ this.id = args.id;
4352
+ const cached = mcpClientInstances.get(this.id);
4353
+ if (cached && !equal(cached.serverConfigs, args.servers)) {
4354
+ const existingInstance2 = mcpClientInstances.get(this.id);
4355
+ if (existingInstance2) {
4356
+ void existingInstance2.disconnect();
4357
+ }
4358
+ }
4359
+ } else {
4360
+ this.id = this.makeId();
4361
+ }
4362
+ const existingInstance = mcpClientInstances.get(this.id);
4340
4363
  if (existingInstance) {
4341
4364
  if (!args.id) {
4342
- throw new Error(`MCPConfiguration was initialized multiple times with the same configuration options.
4365
+ throw new Error(`MCPClient was initialized multiple times with the same configuration options.
4343
4366
 
4344
4367
  This error is intended to prevent memory leaks.
4345
4368
 
4346
4369
  To fix this you have three different options:
4347
- 1. If you need multiple MCPConfiguration class instances with identical server configurations, set an id when configuring: new MCPConfiguration({ id: "my-unique-id" })
4348
- 2. Call "await configuration.disconnect()" after you're done using the configuration and before you recreate another instance with the same options. If the identical MCPConfiguration instance is already closed at the time of re-creating it, you will not see this error.
4349
- 3. If you only need one instance of MCPConfiguration in your app, refactor your code so it's only created one time (ex. move it out of a loop into a higher scope code block)
4370
+ 1. If you need multiple MCPClient class instances with identical server configurations, set an id when configuring: new MCPClient({ id: "my-unique-id" })
4371
+ 2. Call "await client.disconnect()" after you're done using the client and before you recreate another instance with the same options. If the identical MCPClient instance is already closed at the time of re-creating it, you will not see this error.
4372
+ 3. If you only need one instance of MCPClient in your app, refactor your code so it's only created one time (ex. move it out of a loop into a higher scope code block)
4350
4373
  `);
4351
4374
  }
4352
4375
  return existingInstance;
4353
4376
  }
4377
+ mcpClientInstances.set(this.id, this);
4354
4378
  this.addToInstanceCache();
4355
4379
  return this;
4356
4380
  }
4357
4381
  addToInstanceCache() {
4358
- if (!mastraMCPConfigurationInstances.has(this.id)) {
4359
- mastraMCPConfigurationInstances.set(this.id, this);
4382
+ if (!mcpClientInstances.has(this.id)) {
4383
+ mcpClientInstances.set(this.id, this);
4360
4384
  }
4361
4385
  }
4362
4386
  makeId() {
4363
4387
  const text = JSON.stringify(this.serverConfigs).normalize("NFKC");
4364
- const idNamespace = v5(`MCPConfiguration`, v5.DNS);
4388
+ const idNamespace = v5(`MCPClient`, v5.DNS);
4365
4389
  return v5(text, idNamespace);
4366
4390
  }
4367
4391
  async disconnect() {
4368
- mastraMCPConfigurationInstances.delete(this.id);
4369
- await Promise.all(Array.from(this.mcpClientsById.values()).map((client) => client.disconnect()));
4370
- this.mcpClientsById.clear();
4392
+ if (this.disconnectPromise) {
4393
+ return this.disconnectPromise;
4394
+ }
4395
+ this.disconnectPromise = (async () => {
4396
+ try {
4397
+ mcpClientInstances.delete(this.id);
4398
+ await Promise.all(Array.from(this.mcpClientsById.values()).map((client) => client.disconnect()));
4399
+ this.mcpClientsById.clear();
4400
+ } finally {
4401
+ this.disconnectPromise = null;
4402
+ }
4403
+ })();
4404
+ return this.disconnectPromise;
4371
4405
  }
4372
4406
  async getTools() {
4373
4407
  this.addToInstanceCache();
@@ -4402,16 +4436,21 @@ To fix this you have three different options:
4402
4436
  }
4403
4437
  return sessionIds;
4404
4438
  }
4405
- mcpClientsById = /* @__PURE__ */ new Map();
4406
4439
  async getConnectedClient(name, config) {
4440
+ if (this.disconnectPromise) {
4441
+ await this.disconnectPromise;
4442
+ }
4407
4443
  const exists = this.mcpClientsById.has(name);
4444
+ const existingClient = this.mcpClientsById.get(name);
4408
4445
  if (exists) {
4409
- const mcpClient2 = this.mcpClientsById.get(name);
4410
- await mcpClient2.connect();
4411
- return mcpClient2;
4446
+ if (!existingClient) {
4447
+ throw new Error(`Client ${name} exists but is undefined`);
4448
+ }
4449
+ await existingClient.connect();
4450
+ return existingClient;
4412
4451
  }
4413
4452
  this.logger.debug(`Connecting to ${name} MCP server`);
4414
- const mcpClient = new MastraMCPClient({
4453
+ const mcpClient = new InternalMastraMCPClient({
4415
4454
  name,
4416
4455
  server: config,
4417
4456
  timeout: config.timeout ?? this.defaultTimeout
@@ -4421,7 +4460,7 @@ To fix this you have three different options:
4421
4460
  await mcpClient.connect();
4422
4461
  } catch (e) {
4423
4462
  this.mcpClientsById.delete(name);
4424
- this.logger.error(`MCPConfiguration errored connecting to MCP server ${name}`, {
4463
+ this.logger.error(`MCPClient errored connecting to MCP server ${name}`, {
4425
4464
  error: e instanceof Error ? e.message : String(e)
4426
4465
  });
4427
4466
  throw new Error(
@@ -4441,6 +4480,14 @@ To fix this you have three different options:
4441
4480
  );
4442
4481
  }
4443
4482
  };
4483
+ var MCPConfiguration = class extends MCPClient {
4484
+ constructor(args) {
4485
+ super(args);
4486
+ this.logger.warn(
4487
+ `MCPConfiguration has been renamed to MCPClient and MCPConfiguration is deprecated. The API is identical but the MCPConfiguration export will be removed in the future. Update your imports now to prevent future errors.`
4488
+ );
4489
+ }
4490
+ };
4444
4491
 
4445
4492
  // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseAnyOf.js
4446
4493
  var parseAnyOf = (schema, refs) => {
@@ -6561,4 +6608,4 @@ var MCPServer = class {
6561
6608
  }
6562
6609
  };
6563
6610
 
6564
- export { MCPConfiguration, MCPServer, MastraMCPClient };
6611
+ export { MCPClient, MCPConfiguration, MCPServer, MastraMCPClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp",
3
- "version": "0.4.1-alpha.3",
3
+ "version": "0.4.1-alpha.5",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -25,19 +25,20 @@
25
25
  "@modelcontextprotocol/sdk": "^1.10.2",
26
26
  "date-fns": "^4.1.0",
27
27
  "exit-hook": "^4.0.0",
28
+ "fast-deep-equal": "^3.1.3",
28
29
  "uuid": "^11.1.0",
29
- "@mastra/core": "^0.9.1-alpha.3"
30
+ "@mastra/core": "^0.9.1-alpha.4"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@ai-sdk/anthropic": "^1.1.15",
33
- "@microsoft/api-extractor": "^7.52.1",
34
+ "@microsoft/api-extractor": "^7.52.5",
34
35
  "@types/node": "^20.17.27",
35
36
  "eslint": "^9.23.0",
36
37
  "json-schema-to-zod": "^2.6.0",
37
38
  "tsup": "^8.4.0",
38
39
  "tsx": "^4.19.3",
39
40
  "typescript": "^5.8.2",
40
- "vitest": "^3.0.9",
41
+ "vitest": "^3.1.2",
41
42
  "zod": "^3.24.2",
42
43
  "zod-to-json-schema": "^3.22.4",
43
44
  "@internal/lint": "0.0.2"
package/src/client.ts CHANGED
@@ -89,12 +89,13 @@ function convertLogLevelToLoggerMethod(level: LoggingLevel): 'debug' | 'info' |
89
89
  }
90
90
  }
91
91
 
92
- export class MastraMCPClient extends MastraBase {
92
+ export class InternalMastraMCPClient extends MastraBase {
93
93
  name: string;
94
94
  private client: Client;
95
95
  private readonly timeout: number;
96
96
  private logHandler?: LogHandler;
97
97
  private enableServerLogs?: boolean;
98
+ private static hasWarned = false;
98
99
  private serverConfig: MastraMCPServerDefinition;
99
100
  private transport?: Transport;
100
101
 
@@ -112,6 +113,13 @@ export class MastraMCPClient extends MastraBase {
112
113
  timeout?: number;
113
114
  }) {
114
115
  super({ name: 'MastraMCPClient' });
116
+ if (!InternalMastraMCPClient.hasWarned) {
117
+ // eslint-disable-next-line no-console
118
+ console.warn(
119
+ '[DEPRECATION] MastraMCPClient is deprecated and will be removed in a future release. Please use MCPClient instead.',
120
+ );
121
+ InternalMastraMCPClient.hasWarned = true;
122
+ }
115
123
  this.name = name;
116
124
  this.timeout = timeout;
117
125
  this.logHandler = server.logger;
@@ -362,3 +370,8 @@ export class MastraMCPClient extends MastraBase {
362
370
  return toolsRes;
363
371
  }
364
372
  }
373
+
374
+ /**
375
+ * @deprecated MastraMCPClient is deprecated and will be removed in a future release. Please use MCPClient instead.
376
+ */
377
+ export const MastraMCPClient = InternalMastraMCPClient;
@@ -1,12 +1,12 @@
1
1
  import { spawn } from 'child_process';
2
2
  import path from 'path';
3
3
  import { describe, it, expect, beforeEach, afterEach, afterAll, beforeAll, vi } from 'vitest';
4
- import { MCPConfiguration } from './configuration';
4
+ import { MCPClient } from './configuration';
5
5
 
6
6
  vi.setConfig({ testTimeout: 80000, hookTimeout: 80000 });
7
7
 
8
- describe('MCPConfiguration', () => {
9
- let mcp: MCPConfiguration;
8
+ describe('MCPClient', () => {
9
+ let mcp: MCPClient;
10
10
  let weatherProcess: ReturnType<typeof spawn>;
11
11
 
12
12
  beforeAll(async () => {
@@ -36,7 +36,7 @@ describe('MCPConfiguration', () => {
36
36
  });
37
37
 
38
38
  beforeEach(async () => {
39
- mcp = new MCPConfiguration({
39
+ mcp = new MCPClient({
40
40
  servers: {
41
41
  stockPrice: {
42
42
  command: 'npx',
@@ -95,7 +95,7 @@ describe('MCPConfiguration', () => {
95
95
  });
96
96
 
97
97
  it('should handle connection errors gracefully', async () => {
98
- const badConfig = new MCPConfiguration({
98
+ const badConfig = new MCPClient({
99
99
  servers: {
100
100
  badServer: {
101
101
  command: 'nonexistent-command',
@@ -110,7 +110,7 @@ describe('MCPConfiguration', () => {
110
110
 
111
111
  describe('Instance Management', () => {
112
112
  it('should allow multiple instances with different IDs', async () => {
113
- const config2 = new MCPConfiguration({
113
+ const config2 = new MCPClient({
114
114
  id: 'custom-id',
115
115
  servers: {
116
116
  stockPrice: {
@@ -130,7 +130,7 @@ describe('MCPConfiguration', () => {
130
130
  it('should allow reuse of configuration after closing', async () => {
131
131
  await mcp.disconnect();
132
132
 
133
- const config2 = new MCPConfiguration({
133
+ const config2 = new MCPClient({
134
134
  servers: {
135
135
  stockPrice: {
136
136
  command: 'npx',
@@ -150,7 +150,7 @@ describe('MCPConfiguration', () => {
150
150
  });
151
151
 
152
152
  it('should throw error when creating duplicate instance without ID', async () => {
153
- const existingConfig = new MCPConfiguration({
153
+ const existingConfig = new MCPClient({
154
154
  servers: {
155
155
  stockPrice: {
156
156
  command: 'npx',
@@ -164,7 +164,7 @@ describe('MCPConfiguration', () => {
164
164
 
165
165
  expect(
166
166
  () =>
167
- new MCPConfiguration({
167
+ new MCPClient({
168
168
  servers: {
169
169
  stockPrice: {
170
170
  command: 'npx',
@@ -175,14 +175,14 @@ describe('MCPConfiguration', () => {
175
175
  },
176
176
  },
177
177
  }),
178
- ).toThrow(/MCPConfiguration was initialized multiple times/);
178
+ ).toThrow(/MCPClient was initialized multiple times/);
179
179
 
180
180
  await existingConfig.disconnect();
181
181
  });
182
182
  });
183
- describe('MCPConfiguration Operation Timeouts', () => {
183
+ describe('MCPClient Operation Timeouts', () => {
184
184
  it('should respect custom timeout in configuration', async () => {
185
- const config = new MCPConfiguration({
185
+ const config = new MCPClient({
186
186
  id: 'test-timeout-config',
187
187
  timeout: 3000, // 3 second timeout
188
188
  servers: {
@@ -208,7 +208,7 @@ describe('MCPConfiguration', () => {
208
208
  });
209
209
 
210
210
  it('should respect per-server timeout override', async () => {
211
- const config = new MCPConfiguration({
211
+ const config = new MCPClient({
212
212
  id: 'test-server-timeout-config',
213
213
  timeout: 500, // Global timeout of 500ms
214
214
  servers: {
@@ -236,9 +236,9 @@ describe('MCPConfiguration', () => {
236
236
  });
237
237
  });
238
238
 
239
- describe('MCPConfiguration Connection Timeout', () => {
239
+ describe('MCPClient Connection Timeout', () => {
240
240
  it('should throw timeout error for slow starting server', async () => {
241
- const slowConfig = new MCPConfiguration({
241
+ const slowConfig = new MCPClient({
242
242
  id: 'test-slow-server',
243
243
  servers: {
244
244
  slowServer: {
@@ -254,7 +254,7 @@ describe('MCPConfiguration', () => {
254
254
  });
255
255
 
256
256
  it('timeout should be longer than configured timeout', async () => {
257
- const slowConfig = new MCPConfiguration({
257
+ const slowConfig = new MCPClient({
258
258
  id: 'test-slow-server',
259
259
  timeout: 2000,
260
260
  servers: {
@@ -272,7 +272,7 @@ describe('MCPConfiguration', () => {
272
272
  });
273
273
 
274
274
  it('should respect per-server timeout configuration', async () => {
275
- const mixedConfig = new MCPConfiguration({
275
+ const mixedConfig = new MCPClient({
276
276
  id: 'test-mixed-timeout',
277
277
  timeout: 1000, // Short global timeout
278
278
  servers: {