@mastra/mcp 0.0.1-alpha.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,489 @@
1
+ import { jsonSchemaToModel, createTool } from '@mastra/core';
2
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
3
+ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
4
+ import { ListResourcesResultSchema } from '@modelcontextprotocol/sdk/types.js';
5
+
6
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
7
+ try {
8
+ var i = n[a](c),
9
+ u = i.value;
10
+ } catch (n) {
11
+ return void e(n);
12
+ }
13
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
14
+ }
15
+ function _asyncToGenerator(n) {
16
+ return function () {
17
+ var t = this,
18
+ e = arguments;
19
+ return new Promise(function (r, o) {
20
+ var a = n.apply(t, e);
21
+ function _next(n) {
22
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
23
+ }
24
+ function _throw(n) {
25
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
26
+ }
27
+ _next(void 0);
28
+ });
29
+ };
30
+ }
31
+ function _regeneratorRuntime() {
32
+ _regeneratorRuntime = function () {
33
+ return e;
34
+ };
35
+ var t,
36
+ e = {},
37
+ r = Object.prototype,
38
+ n = r.hasOwnProperty,
39
+ o = Object.defineProperty || function (t, e, r) {
40
+ t[e] = r.value;
41
+ },
42
+ i = "function" == typeof Symbol ? Symbol : {},
43
+ a = i.iterator || "@@iterator",
44
+ c = i.asyncIterator || "@@asyncIterator",
45
+ u = i.toStringTag || "@@toStringTag";
46
+ function define(t, e, r) {
47
+ return Object.defineProperty(t, e, {
48
+ value: r,
49
+ enumerable: !0,
50
+ configurable: !0,
51
+ writable: !0
52
+ }), t[e];
53
+ }
54
+ try {
55
+ define({}, "");
56
+ } catch (t) {
57
+ define = function (t, e, r) {
58
+ return t[e] = r;
59
+ };
60
+ }
61
+ function wrap(t, e, r, n) {
62
+ var i = e && e.prototype instanceof Generator ? e : Generator,
63
+ a = Object.create(i.prototype),
64
+ c = new Context(n || []);
65
+ return o(a, "_invoke", {
66
+ value: makeInvokeMethod(t, r, c)
67
+ }), a;
68
+ }
69
+ function tryCatch(t, e, r) {
70
+ try {
71
+ return {
72
+ type: "normal",
73
+ arg: t.call(e, r)
74
+ };
75
+ } catch (t) {
76
+ return {
77
+ type: "throw",
78
+ arg: t
79
+ };
80
+ }
81
+ }
82
+ e.wrap = wrap;
83
+ var h = "suspendedStart",
84
+ l = "suspendedYield",
85
+ f = "executing",
86
+ s = "completed",
87
+ y = {};
88
+ function Generator() {}
89
+ function GeneratorFunction() {}
90
+ function GeneratorFunctionPrototype() {}
91
+ var p = {};
92
+ define(p, a, function () {
93
+ return this;
94
+ });
95
+ var d = Object.getPrototypeOf,
96
+ v = d && d(d(values([])));
97
+ v && v !== r && n.call(v, a) && (p = v);
98
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
99
+ function defineIteratorMethods(t) {
100
+ ["next", "throw", "return"].forEach(function (e) {
101
+ define(t, e, function (t) {
102
+ return this._invoke(e, t);
103
+ });
104
+ });
105
+ }
106
+ function AsyncIterator(t, e) {
107
+ function invoke(r, o, i, a) {
108
+ var c = tryCatch(t[r], t, o);
109
+ if ("throw" !== c.type) {
110
+ var u = c.arg,
111
+ h = u.value;
112
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
113
+ invoke("next", t, i, a);
114
+ }, function (t) {
115
+ invoke("throw", t, i, a);
116
+ }) : e.resolve(h).then(function (t) {
117
+ u.value = t, i(u);
118
+ }, function (t) {
119
+ return invoke("throw", t, i, a);
120
+ });
121
+ }
122
+ a(c.arg);
123
+ }
124
+ var r;
125
+ o(this, "_invoke", {
126
+ value: function (t, n) {
127
+ function callInvokeWithMethodAndArg() {
128
+ return new e(function (e, r) {
129
+ invoke(t, n, e, r);
130
+ });
131
+ }
132
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
133
+ }
134
+ });
135
+ }
136
+ function makeInvokeMethod(e, r, n) {
137
+ var o = h;
138
+ return function (i, a) {
139
+ if (o === f) throw Error("Generator is already running");
140
+ if (o === s) {
141
+ if ("throw" === i) throw a;
142
+ return {
143
+ value: t,
144
+ done: !0
145
+ };
146
+ }
147
+ for (n.method = i, n.arg = a;;) {
148
+ var c = n.delegate;
149
+ if (c) {
150
+ var u = maybeInvokeDelegate(c, n);
151
+ if (u) {
152
+ if (u === y) continue;
153
+ return u;
154
+ }
155
+ }
156
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
157
+ if (o === h) throw o = s, n.arg;
158
+ n.dispatchException(n.arg);
159
+ } else "return" === n.method && n.abrupt("return", n.arg);
160
+ o = f;
161
+ var p = tryCatch(e, r, n);
162
+ if ("normal" === p.type) {
163
+ if (o = n.done ? s : l, p.arg === y) continue;
164
+ return {
165
+ value: p.arg,
166
+ done: n.done
167
+ };
168
+ }
169
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
170
+ }
171
+ };
172
+ }
173
+ function maybeInvokeDelegate(e, r) {
174
+ var n = r.method,
175
+ o = e.iterator[n];
176
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
177
+ var i = tryCatch(o, e.iterator, r.arg);
178
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
179
+ var a = i.arg;
180
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
181
+ }
182
+ function pushTryEntry(t) {
183
+ var e = {
184
+ tryLoc: t[0]
185
+ };
186
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
187
+ }
188
+ function resetTryEntry(t) {
189
+ var e = t.completion || {};
190
+ e.type = "normal", delete e.arg, t.completion = e;
191
+ }
192
+ function Context(t) {
193
+ this.tryEntries = [{
194
+ tryLoc: "root"
195
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
196
+ }
197
+ function values(e) {
198
+ if (e || "" === e) {
199
+ var r = e[a];
200
+ if (r) return r.call(e);
201
+ if ("function" == typeof e.next) return e;
202
+ if (!isNaN(e.length)) {
203
+ var o = -1,
204
+ i = function next() {
205
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
206
+ return next.value = t, next.done = !0, next;
207
+ };
208
+ return i.next = i;
209
+ }
210
+ }
211
+ throw new TypeError(typeof e + " is not iterable");
212
+ }
213
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
214
+ value: GeneratorFunctionPrototype,
215
+ configurable: !0
216
+ }), o(GeneratorFunctionPrototype, "constructor", {
217
+ value: GeneratorFunction,
218
+ configurable: !0
219
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
220
+ var e = "function" == typeof t && t.constructor;
221
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
222
+ }, e.mark = function (t) {
223
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
224
+ }, e.awrap = function (t) {
225
+ return {
226
+ __await: t
227
+ };
228
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
229
+ return this;
230
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
231
+ void 0 === i && (i = Promise);
232
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
233
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
234
+ return t.done ? t.value : a.next();
235
+ });
236
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
237
+ return this;
238
+ }), define(g, "toString", function () {
239
+ return "[object Generator]";
240
+ }), e.keys = function (t) {
241
+ var e = Object(t),
242
+ r = [];
243
+ for (var n in e) r.push(n);
244
+ return r.reverse(), function next() {
245
+ for (; r.length;) {
246
+ var t = r.pop();
247
+ if (t in e) return next.value = t, next.done = !1, next;
248
+ }
249
+ return next.done = !0, next;
250
+ };
251
+ }, e.values = values, Context.prototype = {
252
+ constructor: Context,
253
+ reset: function (e) {
254
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
255
+ },
256
+ stop: function () {
257
+ this.done = !0;
258
+ var t = this.tryEntries[0].completion;
259
+ if ("throw" === t.type) throw t.arg;
260
+ return this.rval;
261
+ },
262
+ dispatchException: function (e) {
263
+ if (this.done) throw e;
264
+ var r = this;
265
+ function handle(n, o) {
266
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
267
+ }
268
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
269
+ var i = this.tryEntries[o],
270
+ a = i.completion;
271
+ if ("root" === i.tryLoc) return handle("end");
272
+ if (i.tryLoc <= this.prev) {
273
+ var c = n.call(i, "catchLoc"),
274
+ u = n.call(i, "finallyLoc");
275
+ if (c && u) {
276
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
277
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
278
+ } else if (c) {
279
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
280
+ } else {
281
+ if (!u) throw Error("try statement without catch or finally");
282
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
283
+ }
284
+ }
285
+ }
286
+ },
287
+ abrupt: function (t, e) {
288
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
289
+ var o = this.tryEntries[r];
290
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
291
+ var i = o;
292
+ break;
293
+ }
294
+ }
295
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
296
+ var a = i ? i.completion : {};
297
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
298
+ },
299
+ complete: function (t, e) {
300
+ if ("throw" === t.type) throw t.arg;
301
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
302
+ },
303
+ finish: function (t) {
304
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
305
+ var r = this.tryEntries[e];
306
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
307
+ }
308
+ },
309
+ catch: function (t) {
310
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
311
+ var r = this.tryEntries[e];
312
+ if (r.tryLoc === t) {
313
+ var n = r.completion;
314
+ if ("throw" === n.type) {
315
+ var o = n.arg;
316
+ resetTryEntry(r);
317
+ }
318
+ return o;
319
+ }
320
+ }
321
+ throw Error("illegal catch attempt");
322
+ },
323
+ delegateYield: function (e, r, n) {
324
+ return this.delegate = {
325
+ iterator: values(e),
326
+ resultName: r,
327
+ nextLoc: n
328
+ }, "next" === this.method && (this.arg = t), y;
329
+ }
330
+ }, e;
331
+ }
332
+
333
+ var MastraMCPClient = /*#__PURE__*/function () {
334
+ function MastraMCPClient(_ref) {
335
+ var name = _ref.name,
336
+ _ref$version = _ref.version,
337
+ version = _ref$version === void 0 ? '1.0.0' : _ref$version,
338
+ server = _ref.server,
339
+ _ref$capabilities = _ref.capabilities,
340
+ capabilities = _ref$capabilities === void 0 ? {} : _ref$capabilities;
341
+ this.name = void 0;
342
+ this.transport = void 0;
343
+ this.client = void 0;
344
+ this.name = name;
345
+ this.transport = new StdioClientTransport(server);
346
+ this.client = new Client({
347
+ name: name,
348
+ version: version
349
+ }, {
350
+ capabilities: capabilities
351
+ });
352
+ }
353
+ var _proto = MastraMCPClient.prototype;
354
+ _proto.connect = /*#__PURE__*/function () {
355
+ var _connect = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
356
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
357
+ while (1) switch (_context.prev = _context.next) {
358
+ case 0:
359
+ _context.next = 2;
360
+ return this.client.connect(this.transport);
361
+ case 2:
362
+ return _context.abrupt("return", _context.sent);
363
+ case 3:
364
+ case "end":
365
+ return _context.stop();
366
+ }
367
+ }, _callee, this);
368
+ }));
369
+ function connect() {
370
+ return _connect.apply(this, arguments);
371
+ }
372
+ return connect;
373
+ }();
374
+ _proto.disconnect = /*#__PURE__*/function () {
375
+ var _disconnect = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
376
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
377
+ while (1) switch (_context2.prev = _context2.next) {
378
+ case 0:
379
+ _context2.next = 2;
380
+ return this.client.close();
381
+ case 2:
382
+ return _context2.abrupt("return", _context2.sent);
383
+ case 3:
384
+ case "end":
385
+ return _context2.stop();
386
+ }
387
+ }, _callee2, this);
388
+ }));
389
+ function disconnect() {
390
+ return _disconnect.apply(this, arguments);
391
+ }
392
+ return disconnect;
393
+ }();
394
+ _proto.resources = /*#__PURE__*/function () {
395
+ var _resources = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
396
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
397
+ while (1) switch (_context3.prev = _context3.next) {
398
+ case 0:
399
+ _context3.next = 2;
400
+ return this.client.request({
401
+ method: 'resources/list'
402
+ }, ListResourcesResultSchema);
403
+ case 2:
404
+ return _context3.abrupt("return", _context3.sent);
405
+ case 3:
406
+ case "end":
407
+ return _context3.stop();
408
+ }
409
+ }, _callee3, this);
410
+ }));
411
+ function resources() {
412
+ return _resources.apply(this, arguments);
413
+ }
414
+ return resources;
415
+ }();
416
+ _proto.tools = /*#__PURE__*/function () {
417
+ var _tools = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
418
+ var _this = this;
419
+ var _yield$this$client$li, tools, toolsRes;
420
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
421
+ while (1) switch (_context5.prev = _context5.next) {
422
+ case 0:
423
+ _context5.next = 2;
424
+ return this.client.listTools();
425
+ case 2:
426
+ _yield$this$client$li = _context5.sent;
427
+ tools = _yield$this$client$li.tools;
428
+ toolsRes = {};
429
+ tools.forEach(function (tool) {
430
+ var s = jsonSchemaToModel(tool.inputSchema);
431
+ var mastraTool = createTool({
432
+ id: _this.name + "_" + tool.name,
433
+ description: tool.description,
434
+ inputSchema: s,
435
+ execute: function () {
436
+ var _execute = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref2) {
437
+ var context, res;
438
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
439
+ while (1) switch (_context4.prev = _context4.next) {
440
+ case 0:
441
+ context = _ref2.context;
442
+ _context4.prev = 1;
443
+ _context4.next = 4;
444
+ return _this.client.callTool({
445
+ name: tool.name,
446
+ arguments: context
447
+ });
448
+ case 4:
449
+ res = _context4.sent;
450
+ return _context4.abrupt("return", res);
451
+ case 8:
452
+ _context4.prev = 8;
453
+ _context4.t0 = _context4["catch"](1);
454
+ console.log('Error calling tool', tool.name);
455
+ console.error(_context4.t0);
456
+ throw _context4.t0;
457
+ case 13:
458
+ case "end":
459
+ return _context4.stop();
460
+ }
461
+ }, _callee4, null, [[1, 8]]);
462
+ }));
463
+ function execute(_x) {
464
+ return _execute.apply(this, arguments);
465
+ }
466
+ return execute;
467
+ }()
468
+ });
469
+ if (tool.name) {
470
+ toolsRes[tool.name] = mastraTool;
471
+ }
472
+ });
473
+ return _context5.abrupt("return", toolsRes);
474
+ case 7:
475
+ case "end":
476
+ return _context5.stop();
477
+ }
478
+ }, _callee5, this);
479
+ }));
480
+ function tools() {
481
+ return _tools.apply(this, arguments);
482
+ }
483
+ return tools;
484
+ }();
485
+ return MastraMCPClient;
486
+ }();
487
+
488
+ export { MastraMCPClient };
489
+ //# sourceMappingURL=mcp.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.esm.js","sources":["../src/client.ts"],"sourcesContent":["import { createTool, jsonSchemaToModel } from '@mastra/core';\nimport { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { StdioClientTransport, StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';\nimport { ClientCapabilities, ListResourcesResultSchema } from '@modelcontextprotocol/sdk/types.js';\n\nexport class MastraMCPClient {\n name: string;\n private transport: StdioClientTransport;\n private client: Client;\n constructor({\n name,\n version = '1.0.0',\n server,\n capabilities = {},\n }: {\n name: string;\n server: StdioServerParameters;\n capabilities?: ClientCapabilities;\n version?: string;\n }) {\n this.name = name;\n this.transport = new StdioClientTransport(server);\n\n this.client = new Client(\n {\n name,\n version,\n },\n {\n capabilities,\n },\n );\n }\n\n async connect() {\n return await this.client.connect(this.transport);\n }\n\n async disconnect() {\n return await this.client.close();\n }\n\n async resources() {\n return await this.client.request({ method: 'resources/list' }, ListResourcesResultSchema);\n }\n\n async tools() {\n const { tools } = await this.client.listTools();\n const toolsRes: Record<string, any> = {};\n tools.forEach(tool => {\n const s = jsonSchemaToModel(tool.inputSchema);\n const mastraTool = createTool({\n id: `${this.name}_${tool.name}`,\n description: tool.description,\n inputSchema: s,\n execute: async ({ context }) => {\n try {\n const res = await this.client.callTool({\n name: tool.name,\n arguments: context\n });\n\n return res;\n } catch (e) {\n console.log('Error calling tool', tool.name);\n console.error(e);\n throw e;\n }\n },\n });\n\n if (tool.name) {\n toolsRes[tool.name] = mastraTool;\n }\n });\n\n return toolsRes;\n }\n}\n"],"names":["MastraMCPClient","_ref","name","_ref$version","version","server","_ref$capabilities","capabilities","transport","client","StdioClientTransport","Client","_proto","prototype","connect","_connect","_asyncToGenerator","_regeneratorRuntime","mark","_callee","wrap","_callee$","_context","prev","next","abrupt","sent","stop","apply","arguments","disconnect","_disconnect","_callee2","_callee2$","_context2","close","resources","_resources","_callee3","_callee3$","_context3","request","method","ListResourcesResultSchema","tools","_tools","_callee5","_this","_yield$this$client$li","toolsRes","_callee5$","_context5","listTools","forEach","tool","s","jsonSchemaToModel","inputSchema","mastraTool","createTool","id","description","execute","_execute","_callee4","_ref2","context","res","_callee4$","_context4","callTool","t0","console","log","error","_x"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAaA,eAAe,gBAAA,YAAA;EAIxB,SAAAA,eAAAA,CAAAC,IAAA,EAUC;AAAA,IAAA,IATGC,IAAI,GAAAD,IAAA,CAAJC,IAAI;MAAAC,YAAA,GAAAF,IAAA,CACJG,OAAO;AAAPA,MAAAA,OAAO,GAAAD,YAAA,KAAG,KAAA,CAAA,GAAA,OAAO,GAAAA,YAAA;MACjBE,MAAM,GAAAJ,IAAA,CAANI,MAAM;MAAAC,iBAAA,GAAAL,IA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AA,iBAAA,EAAA;AAcV,eAAA,CAAC,CAAA;cAEF,IAAIR,IAAI,CAACpD,IAAI,EAAE;AACX+C,gBAAAA,QAAQ,CAACK,IAAI,CAACpD,IAAI,CAAC,GAAGwD,UAAU,CAAA;AACpC,eAAA;AACJ,aAAC,CAAC,CAAA;AAAC,YAAA,OAAAP,SAAA,CAAA1B,MAAA,CAAA,QAAA,EAEIwB,QAAQ,CAAA,CAAA;AAAA,UAAA,KAAA,CAAA,CAAA;AAAA,UAAA,KAAA,KAAA;YAAA,OAAAE,SAAA,CAAAxB,IAAA,EAAA,CAAA;AAAA,SAAA;AAAA,OAAA,EAAAmB,QAAA,EAAA,IAAA,CAAA,CAAA;KAClB,CAAA,CAAA,CAAA;AAAA,IAAA,SA/BKF,KAAKA,GAAA;AAAA,MAAA,OAAAC,MAAA,CAAAjB,KAAA,CAAA,IAAA,EAAAC,SAAA,CAAA,CAAA;AAAA,KAAA;AAAA,IAAA,OAALe,KAAK,CAAA;AAAA,GAAA,EAAA,CAAA;AAAA,EAAA,OAAA5C,eAAA,CAAA;AAAA,CAAA;;;;"}
package/jest.config.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { config } from 'dotenv';
2
+
3
+ config();
4
+
5
+ export default {
6
+ preset: 'ts-jest',
7
+ extensionsToTreatAsEsm: ['.ts'],
8
+ moduleNameMapper: {
9
+ '^(\\.{1,2}/.*)\\.js$': '$1',
10
+ },
11
+ transform: {
12
+ '^.+\\.tsx?$': [
13
+ 'ts-jest',
14
+ {
15
+ useESM: true,
16
+ },
17
+ ],
18
+ },
19
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@mastra/mcp",
3
+ "version": "0.0.1-alpha.1",
4
+ "description": "",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/mcp.esm.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/mcp.esm.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "keywords": [],
23
+ "author": "",
24
+ "license": "ISC",
25
+ "dependencies": {
26
+ "@modelcontextprotocol/sdk": "^1.1.1",
27
+ "date-fns": "^4.1.0",
28
+ "dotenv": "^16.3.1",
29
+ "zod": "^3.24.1",
30
+ "@mastra/core": "0.1.27-alpha.61"
31
+ },
32
+ "devDependencies": {
33
+ "@babel/preset-env": "^7.26.0",
34
+ "@babel/preset-typescript": "^7.26.0",
35
+ "@tsconfig/recommended": "^1.0.7",
36
+ "@types/jsdom": "^21.1.7",
37
+ "@types/node": "^22.9.0",
38
+ "@types/pg": "^8.11.10",
39
+ "dts-cli": "^2.0.5",
40
+ "jest": "^29.7.0",
41
+ "ts-jest": "^29.2.5"
42
+ },
43
+ "scripts": {
44
+ "build": "dts build",
45
+ "build:dev": "dts watch",
46
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
47
+ }
48
+ }
@@ -0,0 +1,53 @@
1
+ import { Agent } from '@mastra/core';
2
+
3
+ import { MastraMCPClient } from './client.js';
4
+
5
+ const everArtClient = new MastraMCPClient({
6
+ name: 'everart',
7
+ server: {
8
+ command: '/usr/local/bin/docker',
9
+ args: ['run', '-i', '--rm', '--network=host', '-e', 'EVERART_API_KEY', 'mcp/everart'],
10
+ env: {
11
+ EVERART_API_KEY: process.env.EVERART_API_KEY!,
12
+ },
13
+ },
14
+ });
15
+
16
+ const agent = new Agent({
17
+ name: 'everart',
18
+ instructions: 'You are my artist. Include the url in your response.',
19
+ model: {
20
+ provider: 'ANTHROPIC',
21
+ name: 'claude-3-5-sonnet-20241022',
22
+ toolChoice: 'auto',
23
+ },
24
+ });
25
+
26
+ describe.skip('MastraMCPClient', () => {
27
+ beforeAll(async () => {
28
+ await everArtClient.connect();
29
+ });
30
+
31
+ afterAll(async () => {
32
+ await everArtClient.disconnect();
33
+ });
34
+
35
+ it('Converting tools into Mastra', async () => {
36
+ const list = await everArtClient.resources();
37
+
38
+ expect(list.resources.length).toBeGreaterThan(0);
39
+
40
+ // The MCP server tools are now available to your Mastra Agents
41
+ const tools = await everArtClient.tools();
42
+
43
+ const response = await agent.generate('Can you make me a picture of a dog?', {
44
+ toolsets: {
45
+ everart: tools,
46
+ },
47
+ });
48
+
49
+ console.log(response.text);
50
+
51
+ expect(Object.keys(tools).length).toBeGreaterThan(0);
52
+ }, 50000);
53
+ });