@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.
- package/CHANGELOG.md +14 -0
- package/dist/client.d.ts +39 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/mcp.cjs.development.js +493 -0
- package/dist/mcp.cjs.development.js.map +1 -0
- package/dist/mcp.cjs.production.min.js +2 -0
- package/dist/mcp.cjs.production.min.js.map +1 -0
- package/dist/mcp.esm.js +489 -0
- package/dist/mcp.esm.js.map +1 -0
- package/jest.config.ts +19 -0
- package/package.json +48 -0
- package/src/client.test.ts +53 -0
- package/src/client.ts +79 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +10 -0
package/CHANGELOG.md
ADDED
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
2
|
+
import { ClientCapabilities } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
export declare class MastraMCPClient {
|
|
4
|
+
name: string;
|
|
5
|
+
private transport;
|
|
6
|
+
private client;
|
|
7
|
+
constructor({ name, version, server, capabilities, }: {
|
|
8
|
+
name: string;
|
|
9
|
+
server: StdioServerParameters;
|
|
10
|
+
capabilities?: ClientCapabilities;
|
|
11
|
+
version?: string;
|
|
12
|
+
});
|
|
13
|
+
connect(): Promise<void>;
|
|
14
|
+
disconnect(): Promise<void>;
|
|
15
|
+
resources(): Promise<import("zod").objectOutputType<import("zod").objectUtil.extendShape<import("zod").objectUtil.extendShape<{
|
|
16
|
+
_meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
|
|
17
|
+
}, {
|
|
18
|
+
nextCursor: import("zod").ZodOptional<import("zod").ZodString>;
|
|
19
|
+
}>, {
|
|
20
|
+
resources: import("zod").ZodArray<import("zod").ZodObject<{
|
|
21
|
+
uri: import("zod").ZodString;
|
|
22
|
+
name: import("zod").ZodString;
|
|
23
|
+
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
24
|
+
mimeType: import("zod").ZodOptional<import("zod").ZodString>;
|
|
25
|
+
}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{
|
|
26
|
+
uri: import("zod").ZodString;
|
|
27
|
+
name: import("zod").ZodString;
|
|
28
|
+
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
29
|
+
mimeType: import("zod").ZodOptional<import("zod").ZodString>;
|
|
30
|
+
}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{
|
|
31
|
+
uri: import("zod").ZodString;
|
|
32
|
+
name: import("zod").ZodString;
|
|
33
|
+
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
34
|
+
mimeType: import("zod").ZodOptional<import("zod").ZodString>;
|
|
35
|
+
}, import("zod").ZodTypeAny, "passthrough">>, "many">;
|
|
36
|
+
}>, import("zod").ZodTypeAny, "passthrough">>;
|
|
37
|
+
tools(): Promise<Record<string, any>>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AACxG,OAAO,EAAE,kBAAkB,EAA6B,MAAM,oCAAoC,CAAC;AAEnG,qBAAa,eAAe;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,MAAM,CAAS;gBACX,EACR,IAAI,EACJ,OAAiB,EACjB,MAAM,EACN,YAAiB,GACpB,EAAE;QACC,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,qBAAqB,CAAC;QAC9B,YAAY,CAAC,EAAE,kBAAkB,CAAC;QAClC,OAAO,CAAC,EAAE,MAAM,CAAC;KACpB;IAeK,OAAO;IAIP,UAAU;IAIV,SAAS;;;;;;;;;;;;;;;;;;;;;;IAIT,KAAK;CAgCd"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@mastra/core');
|
|
6
|
+
var index_js = require('@modelcontextprotocol/sdk/client/index.js');
|
|
7
|
+
var stdio_js = require('@modelcontextprotocol/sdk/client/stdio.js');
|
|
8
|
+
var types_js = require('@modelcontextprotocol/sdk/types.js');
|
|
9
|
+
|
|
10
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
11
|
+
try {
|
|
12
|
+
var i = n[a](c),
|
|
13
|
+
u = i.value;
|
|
14
|
+
} catch (n) {
|
|
15
|
+
return void e(n);
|
|
16
|
+
}
|
|
17
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
18
|
+
}
|
|
19
|
+
function _asyncToGenerator(n) {
|
|
20
|
+
return function () {
|
|
21
|
+
var t = this,
|
|
22
|
+
e = arguments;
|
|
23
|
+
return new Promise(function (r, o) {
|
|
24
|
+
var a = n.apply(t, e);
|
|
25
|
+
function _next(n) {
|
|
26
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
27
|
+
}
|
|
28
|
+
function _throw(n) {
|
|
29
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
30
|
+
}
|
|
31
|
+
_next(void 0);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function _regeneratorRuntime() {
|
|
36
|
+
_regeneratorRuntime = function () {
|
|
37
|
+
return e;
|
|
38
|
+
};
|
|
39
|
+
var t,
|
|
40
|
+
e = {},
|
|
41
|
+
r = Object.prototype,
|
|
42
|
+
n = r.hasOwnProperty,
|
|
43
|
+
o = Object.defineProperty || function (t, e, r) {
|
|
44
|
+
t[e] = r.value;
|
|
45
|
+
},
|
|
46
|
+
i = "function" == typeof Symbol ? Symbol : {},
|
|
47
|
+
a = i.iterator || "@@iterator",
|
|
48
|
+
c = i.asyncIterator || "@@asyncIterator",
|
|
49
|
+
u = i.toStringTag || "@@toStringTag";
|
|
50
|
+
function define(t, e, r) {
|
|
51
|
+
return Object.defineProperty(t, e, {
|
|
52
|
+
value: r,
|
|
53
|
+
enumerable: !0,
|
|
54
|
+
configurable: !0,
|
|
55
|
+
writable: !0
|
|
56
|
+
}), t[e];
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
define({}, "");
|
|
60
|
+
} catch (t) {
|
|
61
|
+
define = function (t, e, r) {
|
|
62
|
+
return t[e] = r;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function wrap(t, e, r, n) {
|
|
66
|
+
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
67
|
+
a = Object.create(i.prototype),
|
|
68
|
+
c = new Context(n || []);
|
|
69
|
+
return o(a, "_invoke", {
|
|
70
|
+
value: makeInvokeMethod(t, r, c)
|
|
71
|
+
}), a;
|
|
72
|
+
}
|
|
73
|
+
function tryCatch(t, e, r) {
|
|
74
|
+
try {
|
|
75
|
+
return {
|
|
76
|
+
type: "normal",
|
|
77
|
+
arg: t.call(e, r)
|
|
78
|
+
};
|
|
79
|
+
} catch (t) {
|
|
80
|
+
return {
|
|
81
|
+
type: "throw",
|
|
82
|
+
arg: t
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
e.wrap = wrap;
|
|
87
|
+
var h = "suspendedStart",
|
|
88
|
+
l = "suspendedYield",
|
|
89
|
+
f = "executing",
|
|
90
|
+
s = "completed",
|
|
91
|
+
y = {};
|
|
92
|
+
function Generator() {}
|
|
93
|
+
function GeneratorFunction() {}
|
|
94
|
+
function GeneratorFunctionPrototype() {}
|
|
95
|
+
var p = {};
|
|
96
|
+
define(p, a, function () {
|
|
97
|
+
return this;
|
|
98
|
+
});
|
|
99
|
+
var d = Object.getPrototypeOf,
|
|
100
|
+
v = d && d(d(values([])));
|
|
101
|
+
v && v !== r && n.call(v, a) && (p = v);
|
|
102
|
+
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
103
|
+
function defineIteratorMethods(t) {
|
|
104
|
+
["next", "throw", "return"].forEach(function (e) {
|
|
105
|
+
define(t, e, function (t) {
|
|
106
|
+
return this._invoke(e, t);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function AsyncIterator(t, e) {
|
|
111
|
+
function invoke(r, o, i, a) {
|
|
112
|
+
var c = tryCatch(t[r], t, o);
|
|
113
|
+
if ("throw" !== c.type) {
|
|
114
|
+
var u = c.arg,
|
|
115
|
+
h = u.value;
|
|
116
|
+
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
117
|
+
invoke("next", t, i, a);
|
|
118
|
+
}, function (t) {
|
|
119
|
+
invoke("throw", t, i, a);
|
|
120
|
+
}) : e.resolve(h).then(function (t) {
|
|
121
|
+
u.value = t, i(u);
|
|
122
|
+
}, function (t) {
|
|
123
|
+
return invoke("throw", t, i, a);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
a(c.arg);
|
|
127
|
+
}
|
|
128
|
+
var r;
|
|
129
|
+
o(this, "_invoke", {
|
|
130
|
+
value: function (t, n) {
|
|
131
|
+
function callInvokeWithMethodAndArg() {
|
|
132
|
+
return new e(function (e, r) {
|
|
133
|
+
invoke(t, n, e, r);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function makeInvokeMethod(e, r, n) {
|
|
141
|
+
var o = h;
|
|
142
|
+
return function (i, a) {
|
|
143
|
+
if (o === f) throw Error("Generator is already running");
|
|
144
|
+
if (o === s) {
|
|
145
|
+
if ("throw" === i) throw a;
|
|
146
|
+
return {
|
|
147
|
+
value: t,
|
|
148
|
+
done: !0
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
for (n.method = i, n.arg = a;;) {
|
|
152
|
+
var c = n.delegate;
|
|
153
|
+
if (c) {
|
|
154
|
+
var u = maybeInvokeDelegate(c, n);
|
|
155
|
+
if (u) {
|
|
156
|
+
if (u === y) continue;
|
|
157
|
+
return u;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
161
|
+
if (o === h) throw o = s, n.arg;
|
|
162
|
+
n.dispatchException(n.arg);
|
|
163
|
+
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
164
|
+
o = f;
|
|
165
|
+
var p = tryCatch(e, r, n);
|
|
166
|
+
if ("normal" === p.type) {
|
|
167
|
+
if (o = n.done ? s : l, p.arg === y) continue;
|
|
168
|
+
return {
|
|
169
|
+
value: p.arg,
|
|
170
|
+
done: n.done
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function maybeInvokeDelegate(e, r) {
|
|
178
|
+
var n = r.method,
|
|
179
|
+
o = e.iterator[n];
|
|
180
|
+
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;
|
|
181
|
+
var i = tryCatch(o, e.iterator, r.arg);
|
|
182
|
+
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
183
|
+
var a = i.arg;
|
|
184
|
+
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);
|
|
185
|
+
}
|
|
186
|
+
function pushTryEntry(t) {
|
|
187
|
+
var e = {
|
|
188
|
+
tryLoc: t[0]
|
|
189
|
+
};
|
|
190
|
+
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
191
|
+
}
|
|
192
|
+
function resetTryEntry(t) {
|
|
193
|
+
var e = t.completion || {};
|
|
194
|
+
e.type = "normal", delete e.arg, t.completion = e;
|
|
195
|
+
}
|
|
196
|
+
function Context(t) {
|
|
197
|
+
this.tryEntries = [{
|
|
198
|
+
tryLoc: "root"
|
|
199
|
+
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
200
|
+
}
|
|
201
|
+
function values(e) {
|
|
202
|
+
if (e || "" === e) {
|
|
203
|
+
var r = e[a];
|
|
204
|
+
if (r) return r.call(e);
|
|
205
|
+
if ("function" == typeof e.next) return e;
|
|
206
|
+
if (!isNaN(e.length)) {
|
|
207
|
+
var o = -1,
|
|
208
|
+
i = function next() {
|
|
209
|
+
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
210
|
+
return next.value = t, next.done = !0, next;
|
|
211
|
+
};
|
|
212
|
+
return i.next = i;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
216
|
+
}
|
|
217
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
218
|
+
value: GeneratorFunctionPrototype,
|
|
219
|
+
configurable: !0
|
|
220
|
+
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
221
|
+
value: GeneratorFunction,
|
|
222
|
+
configurable: !0
|
|
223
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
224
|
+
var e = "function" == typeof t && t.constructor;
|
|
225
|
+
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
226
|
+
}, e.mark = function (t) {
|
|
227
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
228
|
+
}, e.awrap = function (t) {
|
|
229
|
+
return {
|
|
230
|
+
__await: t
|
|
231
|
+
};
|
|
232
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
233
|
+
return this;
|
|
234
|
+
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
235
|
+
void 0 === i && (i = Promise);
|
|
236
|
+
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
237
|
+
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
238
|
+
return t.done ? t.value : a.next();
|
|
239
|
+
});
|
|
240
|
+
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
241
|
+
return this;
|
|
242
|
+
}), define(g, "toString", function () {
|
|
243
|
+
return "[object Generator]";
|
|
244
|
+
}), e.keys = function (t) {
|
|
245
|
+
var e = Object(t),
|
|
246
|
+
r = [];
|
|
247
|
+
for (var n in e) r.push(n);
|
|
248
|
+
return r.reverse(), function next() {
|
|
249
|
+
for (; r.length;) {
|
|
250
|
+
var t = r.pop();
|
|
251
|
+
if (t in e) return next.value = t, next.done = !1, next;
|
|
252
|
+
}
|
|
253
|
+
return next.done = !0, next;
|
|
254
|
+
};
|
|
255
|
+
}, e.values = values, Context.prototype = {
|
|
256
|
+
constructor: Context,
|
|
257
|
+
reset: function (e) {
|
|
258
|
+
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);
|
|
259
|
+
},
|
|
260
|
+
stop: function () {
|
|
261
|
+
this.done = !0;
|
|
262
|
+
var t = this.tryEntries[0].completion;
|
|
263
|
+
if ("throw" === t.type) throw t.arg;
|
|
264
|
+
return this.rval;
|
|
265
|
+
},
|
|
266
|
+
dispatchException: function (e) {
|
|
267
|
+
if (this.done) throw e;
|
|
268
|
+
var r = this;
|
|
269
|
+
function handle(n, o) {
|
|
270
|
+
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
271
|
+
}
|
|
272
|
+
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
273
|
+
var i = this.tryEntries[o],
|
|
274
|
+
a = i.completion;
|
|
275
|
+
if ("root" === i.tryLoc) return handle("end");
|
|
276
|
+
if (i.tryLoc <= this.prev) {
|
|
277
|
+
var c = n.call(i, "catchLoc"),
|
|
278
|
+
u = n.call(i, "finallyLoc");
|
|
279
|
+
if (c && u) {
|
|
280
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
281
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
282
|
+
} else if (c) {
|
|
283
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
284
|
+
} else {
|
|
285
|
+
if (!u) throw Error("try statement without catch or finally");
|
|
286
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
abrupt: function (t, e) {
|
|
292
|
+
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
293
|
+
var o = this.tryEntries[r];
|
|
294
|
+
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
295
|
+
var i = o;
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
300
|
+
var a = i ? i.completion : {};
|
|
301
|
+
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
302
|
+
},
|
|
303
|
+
complete: function (t, e) {
|
|
304
|
+
if ("throw" === t.type) throw t.arg;
|
|
305
|
+
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;
|
|
306
|
+
},
|
|
307
|
+
finish: function (t) {
|
|
308
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
309
|
+
var r = this.tryEntries[e];
|
|
310
|
+
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
catch: function (t) {
|
|
314
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
315
|
+
var r = this.tryEntries[e];
|
|
316
|
+
if (r.tryLoc === t) {
|
|
317
|
+
var n = r.completion;
|
|
318
|
+
if ("throw" === n.type) {
|
|
319
|
+
var o = n.arg;
|
|
320
|
+
resetTryEntry(r);
|
|
321
|
+
}
|
|
322
|
+
return o;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
throw Error("illegal catch attempt");
|
|
326
|
+
},
|
|
327
|
+
delegateYield: function (e, r, n) {
|
|
328
|
+
return this.delegate = {
|
|
329
|
+
iterator: values(e),
|
|
330
|
+
resultName: r,
|
|
331
|
+
nextLoc: n
|
|
332
|
+
}, "next" === this.method && (this.arg = t), y;
|
|
333
|
+
}
|
|
334
|
+
}, e;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
var MastraMCPClient = /*#__PURE__*/function () {
|
|
338
|
+
function MastraMCPClient(_ref) {
|
|
339
|
+
var name = _ref.name,
|
|
340
|
+
_ref$version = _ref.version,
|
|
341
|
+
version = _ref$version === void 0 ? '1.0.0' : _ref$version,
|
|
342
|
+
server = _ref.server,
|
|
343
|
+
_ref$capabilities = _ref.capabilities,
|
|
344
|
+
capabilities = _ref$capabilities === void 0 ? {} : _ref$capabilities;
|
|
345
|
+
this.name = void 0;
|
|
346
|
+
this.transport = void 0;
|
|
347
|
+
this.client = void 0;
|
|
348
|
+
this.name = name;
|
|
349
|
+
this.transport = new stdio_js.StdioClientTransport(server);
|
|
350
|
+
this.client = new index_js.Client({
|
|
351
|
+
name: name,
|
|
352
|
+
version: version
|
|
353
|
+
}, {
|
|
354
|
+
capabilities: capabilities
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
var _proto = MastraMCPClient.prototype;
|
|
358
|
+
_proto.connect = /*#__PURE__*/function () {
|
|
359
|
+
var _connect = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
360
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
361
|
+
while (1) switch (_context.prev = _context.next) {
|
|
362
|
+
case 0:
|
|
363
|
+
_context.next = 2;
|
|
364
|
+
return this.client.connect(this.transport);
|
|
365
|
+
case 2:
|
|
366
|
+
return _context.abrupt("return", _context.sent);
|
|
367
|
+
case 3:
|
|
368
|
+
case "end":
|
|
369
|
+
return _context.stop();
|
|
370
|
+
}
|
|
371
|
+
}, _callee, this);
|
|
372
|
+
}));
|
|
373
|
+
function connect() {
|
|
374
|
+
return _connect.apply(this, arguments);
|
|
375
|
+
}
|
|
376
|
+
return connect;
|
|
377
|
+
}();
|
|
378
|
+
_proto.disconnect = /*#__PURE__*/function () {
|
|
379
|
+
var _disconnect = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
380
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
381
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
382
|
+
case 0:
|
|
383
|
+
_context2.next = 2;
|
|
384
|
+
return this.client.close();
|
|
385
|
+
case 2:
|
|
386
|
+
return _context2.abrupt("return", _context2.sent);
|
|
387
|
+
case 3:
|
|
388
|
+
case "end":
|
|
389
|
+
return _context2.stop();
|
|
390
|
+
}
|
|
391
|
+
}, _callee2, this);
|
|
392
|
+
}));
|
|
393
|
+
function disconnect() {
|
|
394
|
+
return _disconnect.apply(this, arguments);
|
|
395
|
+
}
|
|
396
|
+
return disconnect;
|
|
397
|
+
}();
|
|
398
|
+
_proto.resources = /*#__PURE__*/function () {
|
|
399
|
+
var _resources = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
400
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
401
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
402
|
+
case 0:
|
|
403
|
+
_context3.next = 2;
|
|
404
|
+
return this.client.request({
|
|
405
|
+
method: 'resources/list'
|
|
406
|
+
}, types_js.ListResourcesResultSchema);
|
|
407
|
+
case 2:
|
|
408
|
+
return _context3.abrupt("return", _context3.sent);
|
|
409
|
+
case 3:
|
|
410
|
+
case "end":
|
|
411
|
+
return _context3.stop();
|
|
412
|
+
}
|
|
413
|
+
}, _callee3, this);
|
|
414
|
+
}));
|
|
415
|
+
function resources() {
|
|
416
|
+
return _resources.apply(this, arguments);
|
|
417
|
+
}
|
|
418
|
+
return resources;
|
|
419
|
+
}();
|
|
420
|
+
_proto.tools = /*#__PURE__*/function () {
|
|
421
|
+
var _tools = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
422
|
+
var _this = this;
|
|
423
|
+
var _yield$this$client$li, tools, toolsRes;
|
|
424
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
425
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
426
|
+
case 0:
|
|
427
|
+
_context5.next = 2;
|
|
428
|
+
return this.client.listTools();
|
|
429
|
+
case 2:
|
|
430
|
+
_yield$this$client$li = _context5.sent;
|
|
431
|
+
tools = _yield$this$client$li.tools;
|
|
432
|
+
toolsRes = {};
|
|
433
|
+
tools.forEach(function (tool) {
|
|
434
|
+
var s = core.jsonSchemaToModel(tool.inputSchema);
|
|
435
|
+
var mastraTool = core.createTool({
|
|
436
|
+
id: _this.name + "_" + tool.name,
|
|
437
|
+
description: tool.description,
|
|
438
|
+
inputSchema: s,
|
|
439
|
+
execute: function () {
|
|
440
|
+
var _execute = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref2) {
|
|
441
|
+
var context, res;
|
|
442
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
443
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
444
|
+
case 0:
|
|
445
|
+
context = _ref2.context;
|
|
446
|
+
_context4.prev = 1;
|
|
447
|
+
_context4.next = 4;
|
|
448
|
+
return _this.client.callTool({
|
|
449
|
+
name: tool.name,
|
|
450
|
+
arguments: context
|
|
451
|
+
});
|
|
452
|
+
case 4:
|
|
453
|
+
res = _context4.sent;
|
|
454
|
+
return _context4.abrupt("return", res);
|
|
455
|
+
case 8:
|
|
456
|
+
_context4.prev = 8;
|
|
457
|
+
_context4.t0 = _context4["catch"](1);
|
|
458
|
+
console.log('Error calling tool', tool.name);
|
|
459
|
+
console.error(_context4.t0);
|
|
460
|
+
throw _context4.t0;
|
|
461
|
+
case 13:
|
|
462
|
+
case "end":
|
|
463
|
+
return _context4.stop();
|
|
464
|
+
}
|
|
465
|
+
}, _callee4, null, [[1, 8]]);
|
|
466
|
+
}));
|
|
467
|
+
function execute(_x) {
|
|
468
|
+
return _execute.apply(this, arguments);
|
|
469
|
+
}
|
|
470
|
+
return execute;
|
|
471
|
+
}()
|
|
472
|
+
});
|
|
473
|
+
if (tool.name) {
|
|
474
|
+
toolsRes[tool.name] = mastraTool;
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
return _context5.abrupt("return", toolsRes);
|
|
478
|
+
case 7:
|
|
479
|
+
case "end":
|
|
480
|
+
return _context5.stop();
|
|
481
|
+
}
|
|
482
|
+
}, _callee5, this);
|
|
483
|
+
}));
|
|
484
|
+
function tools() {
|
|
485
|
+
return _tools.apply(this, arguments);
|
|
486
|
+
}
|
|
487
|
+
return tools;
|
|
488
|
+
}();
|
|
489
|
+
return MastraMCPClient;
|
|
490
|
+
}();
|
|
491
|
+
|
|
492
|
+
exports.MastraMCPClient = MastraMCPClient;
|
|
493
|
+
//# sourceMappingURL=mcp.cjs.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.cjs.development.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,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AA,CAAA,CAAA;mBAGxB,CAAA,CAAA,CAAA;kBAAA,SAbDF,OAAOA,CAAAa,EAAA,EAAA;AAAA,oBAAA,OAAAZ,QAAA,CAAAnC,KAAA,CAAA,IAAA,EAAAC,SAAA,CAAA,CAAA;AAAA,mBAAA;AAAA,kBAAA,OAAPiC,OAAO,CAAA;AAAA,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;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@mastra/core"),r=require("@modelcontextprotocol/sdk/client/index.js"),e=require("@modelcontextprotocol/sdk/client/stdio.js"),n=require("@modelcontextprotocol/sdk/types.js");function o(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function i(t){return function(){var r=this,e=arguments;return new Promise((function(n,i){var a=t.apply(r,e);function c(t){o(a,n,i,c,u,"next",t)}function u(t){o(a,n,i,c,u,"throw",t)}c(void 0)}))}}function a(){a=function(){return r};var t,r={},e=Object.prototype,n=e.hasOwnProperty,o=Object.defineProperty||function(t,r,e){t[r]=e.value},i="function"==typeof Symbol?Symbol:{},c=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function h(t,r,e,n){var i=Object.create((r&&r.prototype instanceof g?r:g).prototype),a=new G(n||[]);return o(i,"_invoke",{value:O(t,e,a)}),i}function f(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=h;var p="suspendedStart",v="suspendedYield",y="executing",d="completed",m={};function g(){}function w(){}function x(){}var b={};l(b,c,(function(){return this}));var L=Object.getPrototypeOf,E=L&&L(L(N([])));E&&E!==e&&n.call(E,c)&&(b=E);var j=x.prototype=g.prototype=Object.create(b);function _(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function k(t,r){function e(o,i,a,c){var u=f(t[o],t,i);if("throw"!==u.type){var s=u.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,c)}),(function(t){e("throw",t,a,c)})):r.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return e("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new r((function(r,o){e(t,n,r,o)}))}return i=i?i.then(o,o):o()}})}function O(r,e,n){var o=p;return function(i,a){if(o===y)throw Error("Generator is already running");if(o===d){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=P(c,n);if(u){if(u===m)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var s=f(r,e,n);if("normal"===s.type){if(o=n.done?d:v,s.arg===m)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=d,n.method="throw",n.arg=s.arg)}}}function P(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,P(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var i=f(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,m;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,m):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,m)}function S(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function T(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function G(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(S,this),this.reset(!0)}function N(r){if(r||""===r){var e=r[c];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var o=-1,i=function e(){for(;++o<r.length;)if(n.call(r,o))return e.value=r[o],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return w.prototype=x,o(j,"constructor",{value:x,configurable:!0}),o(x,"constructor",{value:w,configurable:!0}),w.displayName=l(x,s,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===w||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,l(t,s,"GeneratorFunction")),t.prototype=Object.create(j),t},r.awrap=function(t){return{__await:t}},_(k.prototype),l(k.prototype,u,(function(){return this})),r.AsyncIterator=k,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new k(h(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},_(j),l(j,s,"Generator"),l(j,c,(function(){return this})),l(j,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=N,G.prototype={constructor:G,reset:function(r){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(T),!r)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function o(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,m):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;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&&r&&(this.next=r),m},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),T(e),m}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;T(e)}return o}}throw Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:N(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),m}},r}exports.MastraMCPClient=function(){function o(t){var n=t.name,o=t.version,i=void 0===o?"1.0.0":o,a=t.server,c=t.capabilities,u=void 0===c?{}:c;this.name=void 0,this.transport=void 0,this.client=void 0,this.name=n,this.transport=new e.StdioClientTransport(a),this.client=new r.Client({name:n,version:i},{capabilities:u})}var c=o.prototype;return c.connect=function(){var t=i(a().mark((function t(){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.client.connect(this.transport);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),c.disconnect=function(){var t=i(a().mark((function t(){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.client.close();case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),c.resources=function(){var t=i(a().mark((function t(){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.client.request({method:"resources/list"},n.ListResourcesResultSchema);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),c.tools=function(){var r=i(a().mark((function r(){var e,n=this;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.client.listTools();case 2:return e={},r.sent.tools.forEach((function(r){var o,c=t.jsonSchemaToModel(r.inputSchema),u=t.createTool({id:n.name+"_"+r.name,description:r.description,inputSchema:c,execute:(o=i(a().mark((function t(e){var o;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=e.context,t.prev=1,t.next=4,n.client.callTool({name:r.name,arguments:o});case 4:return t.abrupt("return",t.sent);case 8:throw t.prev=8,t.t0=t.catch(1),console.log("Error calling tool",r.name),console.error(t.t0),t.t0;case 13:case"end":return t.stop()}}),t,null,[[1,8]])}))),function(t){return o.apply(this,arguments)})});r.name&&(e[r.name]=u)})),r.abrupt("return",e);case 7:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),o}();
|
|
2
|
+
//# sourceMappingURL=mcp.cjs.production.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.cjs.production.min.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","this","transport","client","StdioClientTransport","Client","_proto","prototype","connect","_connect","_asyncToGenerator","_regeneratorRuntime","mark","_callee","wrap","_context","prev","next","abrupt","sent","stop","apply","arguments","disconnect","_disconnect","_callee2","_context2","close","resources","_resources","_callee3","_context3","request","method","ListResourcesResultSchema","tools","_tools","_callee5","toolsRes","_this","_context5","listTools","forEach","tool","_execute","s","jsonSchemaToModel","inputSchema","mastraTool","createTool","id","description","execute","_callee4","_ref2","context","_context4","callTool","t0","console","log","error","_x"],"mappings":"w7NAK4B,WAIxB,SAAAA,EAAAC,GAUC,IATGC,EAAID,EAAJC,KAAIC,EAAAF,EACJG,QAAAA,OAAU,IAAHD,EAAG,QAAOA,EACjBE,EAAMJ,EAANI,OAAMC,EAAAL,EACNM,aAAAA,OAAY,IAAAD,EAAG,CAAA,EAAEA,EAAAE,KAPrBN,UAAI,EAAAM,KACIC,eAAS,EAAAD,KACTE,YAAM,EAYVF,KAAKN,KAAOA,EACZM,KAAKC,UAAY,IAAIE,EAAoBA,qBAACN,GAE1CG,KAAKE,OAAS,IAAIE,SACd,CACIV,KAAAA,EACAE,QAAAA,GAEJ,CACIG,aAAAA,GAGZ,CAAC,IAAAM,EAAAb,EAAAc,UAcU,OAdVD,EAEKE,QAAO,WAAA,IAAAC,EAAAC,EAAAC,IAAAC,MAAb,SAAAC,IAAA,OAAAF,IAAAG,MAAA,SAAAC,GAAA,cAAAA,EAAAC,KAAAD,EAAAE,MAAA,KAAA,EAAA,OAAAF,EAAAE,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