@mcp-z/client 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +159 -0
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/cjs/auth/capability-discovery.d.cts +25 -0
- package/dist/cjs/auth/capability-discovery.d.ts +25 -0
- package/dist/cjs/auth/capability-discovery.js +280 -0
- package/dist/cjs/auth/capability-discovery.js.map +1 -0
- package/dist/cjs/auth/index.d.cts +9 -0
- package/dist/cjs/auth/index.d.ts +9 -0
- package/dist/cjs/auth/index.js +28 -0
- package/dist/cjs/auth/index.js.map +1 -0
- package/dist/cjs/auth/interactive-oauth-flow.d.cts +58 -0
- package/dist/cjs/auth/interactive-oauth-flow.d.ts +58 -0
- package/dist/cjs/auth/interactive-oauth-flow.js +537 -0
- package/dist/cjs/auth/interactive-oauth-flow.js.map +1 -0
- package/dist/cjs/auth/oauth-callback-listener.d.cts +56 -0
- package/dist/cjs/auth/oauth-callback-listener.d.ts +56 -0
- package/dist/cjs/auth/oauth-callback-listener.js +333 -0
- package/dist/cjs/auth/oauth-callback-listener.js.map +1 -0
- package/dist/cjs/auth/pkce.d.cts +17 -0
- package/dist/cjs/auth/pkce.d.ts +17 -0
- package/dist/cjs/auth/pkce.js +192 -0
- package/dist/cjs/auth/pkce.js.map +1 -0
- package/dist/cjs/auth/rfc9728-discovery.d.cts +34 -0
- package/dist/cjs/auth/rfc9728-discovery.d.ts +34 -0
- package/dist/cjs/auth/rfc9728-discovery.js +436 -0
- package/dist/cjs/auth/rfc9728-discovery.js.map +1 -0
- package/dist/cjs/auth/types.d.cts +137 -0
- package/dist/cjs/auth/types.d.ts +137 -0
- package/dist/cjs/auth/types.js +9 -0
- package/dist/cjs/auth/types.js.map +1 -0
- package/dist/cjs/client-helpers.d.cts +55 -0
- package/dist/cjs/client-helpers.d.ts +55 -0
- package/dist/cjs/client-helpers.js +128 -0
- package/dist/cjs/client-helpers.js.map +1 -0
- package/dist/cjs/config/server-loader.d.cts +27 -0
- package/dist/cjs/config/server-loader.d.ts +27 -0
- package/dist/cjs/config/server-loader.js +111 -0
- package/dist/cjs/config/server-loader.js.map +1 -0
- package/dist/cjs/config/validate-config.d.cts +15 -0
- package/dist/cjs/config/validate-config.d.ts +15 -0
- package/dist/cjs/config/validate-config.js +128 -0
- package/dist/cjs/config/validate-config.js.map +1 -0
- package/dist/cjs/connection/connect-client.d.cts +59 -0
- package/dist/cjs/connection/connect-client.d.ts +59 -0
- package/dist/cjs/connection/connect-client.js +536 -0
- package/dist/cjs/connection/connect-client.js.map +1 -0
- package/dist/cjs/connection/existing-process-transport.d.cts +40 -0
- package/dist/cjs/connection/existing-process-transport.d.ts +40 -0
- package/dist/cjs/connection/existing-process-transport.js +274 -0
- package/dist/cjs/connection/existing-process-transport.js.map +1 -0
- package/dist/cjs/connection/types.d.cts +61 -0
- package/dist/cjs/connection/types.d.ts +61 -0
- package/dist/cjs/connection/types.js +53 -0
- package/dist/cjs/connection/types.js.map +1 -0
- package/dist/cjs/connection/wait-for-http-ready.d.cts +15 -0
- package/dist/cjs/connection/wait-for-http-ready.d.ts +15 -0
- package/dist/cjs/connection/wait-for-http-ready.js +232 -0
- package/dist/cjs/connection/wait-for-http-ready.js.map +1 -0
- package/dist/cjs/dcr/dcr-authenticator.d.cts +73 -0
- package/dist/cjs/dcr/dcr-authenticator.d.ts +73 -0
- package/dist/cjs/dcr/dcr-authenticator.js +655 -0
- package/dist/cjs/dcr/dcr-authenticator.js.map +1 -0
- package/dist/cjs/dcr/dynamic-client-registrar.d.cts +28 -0
- package/dist/cjs/dcr/dynamic-client-registrar.d.ts +28 -0
- package/dist/cjs/dcr/dynamic-client-registrar.js +245 -0
- package/dist/cjs/dcr/dynamic-client-registrar.js.map +1 -0
- package/dist/cjs/dcr/index.d.cts +8 -0
- package/dist/cjs/dcr/index.d.ts +8 -0
- package/dist/cjs/dcr/index.js +24 -0
- package/dist/cjs/dcr/index.js.map +1 -0
- package/dist/cjs/index.d.cts +21 -0
- package/dist/cjs/index.d.ts +21 -0
- package/dist/cjs/index.js +94 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/monkey-patches.d.cts +6 -0
- package/dist/cjs/monkey-patches.d.ts +6 -0
- package/dist/cjs/monkey-patches.js +236 -0
- package/dist/cjs/monkey-patches.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/response-wrappers.d.cts +41 -0
- package/dist/cjs/response-wrappers.d.ts +41 -0
- package/dist/cjs/response-wrappers.js +443 -0
- package/dist/cjs/response-wrappers.js.map +1 -0
- package/dist/cjs/search/index.d.cts +6 -0
- package/dist/cjs/search/index.d.ts +6 -0
- package/dist/cjs/search/index.js +25 -0
- package/dist/cjs/search/index.js.map +1 -0
- package/dist/cjs/search/search.d.cts +22 -0
- package/dist/cjs/search/search.d.ts +22 -0
- package/dist/cjs/search/search.js +630 -0
- package/dist/cjs/search/search.js.map +1 -0
- package/dist/cjs/search/types.d.cts +122 -0
- package/dist/cjs/search/types.d.ts +122 -0
- package/dist/cjs/search/types.js +10 -0
- package/dist/cjs/search/types.js.map +1 -0
- package/dist/cjs/spawn/spawn-server.d.cts +83 -0
- package/dist/cjs/spawn/spawn-server.d.ts +83 -0
- package/dist/cjs/spawn/spawn-server.js +410 -0
- package/dist/cjs/spawn/spawn-server.js.map +1 -0
- package/dist/cjs/spawn/spawn-servers.d.cts +151 -0
- package/dist/cjs/spawn/spawn-servers.d.ts +151 -0
- package/dist/cjs/spawn/spawn-servers.js +911 -0
- package/dist/cjs/spawn/spawn-servers.js.map +1 -0
- package/dist/cjs/types.d.cts +11 -0
- package/dist/cjs/types.d.ts +11 -0
- package/dist/cjs/types.js +10 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils/logger.d.cts +24 -0
- package/dist/cjs/utils/logger.d.ts +24 -0
- package/dist/cjs/utils/logger.js +80 -0
- package/dist/cjs/utils/logger.js.map +1 -0
- package/dist/cjs/utils/path-utils.d.cts +45 -0
- package/dist/cjs/utils/path-utils.d.ts +45 -0
- package/dist/cjs/utils/path-utils.js +158 -0
- package/dist/cjs/utils/path-utils.js.map +1 -0
- package/dist/cjs/utils/sanitizer.d.cts +30 -0
- package/dist/cjs/utils/sanitizer.d.ts +30 -0
- package/dist/cjs/utils/sanitizer.js +124 -0
- package/dist/cjs/utils/sanitizer.js.map +1 -0
- package/dist/esm/auth/capability-discovery.d.ts +25 -0
- package/dist/esm/auth/capability-discovery.js +110 -0
- package/dist/esm/auth/capability-discovery.js.map +1 -0
- package/dist/esm/auth/index.d.ts +9 -0
- package/dist/esm/auth/index.js +6 -0
- package/dist/esm/auth/index.js.map +1 -0
- package/dist/esm/auth/interactive-oauth-flow.d.ts +58 -0
- package/dist/esm/auth/interactive-oauth-flow.js +217 -0
- package/dist/esm/auth/interactive-oauth-flow.js.map +1 -0
- package/dist/esm/auth/oauth-callback-listener.d.ts +56 -0
- package/dist/esm/auth/oauth-callback-listener.js +166 -0
- package/dist/esm/auth/oauth-callback-listener.js.map +1 -0
- package/dist/esm/auth/pkce.d.ts +17 -0
- package/dist/esm/auth/pkce.js +41 -0
- package/dist/esm/auth/pkce.js.map +1 -0
- package/dist/esm/auth/rfc9728-discovery.d.ts +34 -0
- package/dist/esm/auth/rfc9728-discovery.js +157 -0
- package/dist/esm/auth/rfc9728-discovery.js.map +1 -0
- package/dist/esm/auth/types.d.ts +137 -0
- package/dist/esm/auth/types.js +7 -0
- package/dist/esm/auth/types.js.map +1 -0
- package/dist/esm/client-helpers.d.ts +55 -0
- package/dist/esm/client-helpers.js +81 -0
- package/dist/esm/client-helpers.js.map +1 -0
- package/dist/esm/config/server-loader.d.ts +27 -0
- package/dist/esm/config/server-loader.js +49 -0
- package/dist/esm/config/server-loader.js.map +1 -0
- package/dist/esm/config/validate-config.d.ts +15 -0
- package/dist/esm/config/validate-config.js +76 -0
- package/dist/esm/config/validate-config.js.map +1 -0
- package/dist/esm/connection/connect-client.d.ts +59 -0
- package/dist/esm/connection/connect-client.js +272 -0
- package/dist/esm/connection/connect-client.js.map +1 -0
- package/dist/esm/connection/existing-process-transport.d.ts +40 -0
- package/dist/esm/connection/existing-process-transport.js +103 -0
- package/dist/esm/connection/existing-process-transport.js.map +1 -0
- package/dist/esm/connection/types.d.ts +61 -0
- package/dist/esm/connection/types.js +34 -0
- package/dist/esm/connection/types.js.map +1 -0
- package/dist/esm/connection/wait-for-http-ready.d.ts +15 -0
- package/dist/esm/connection/wait-for-http-ready.js +43 -0
- package/dist/esm/connection/wait-for-http-ready.js.map +1 -0
- package/dist/esm/dcr/dcr-authenticator.d.ts +73 -0
- package/dist/esm/dcr/dcr-authenticator.js +235 -0
- package/dist/esm/dcr/dcr-authenticator.js.map +1 -0
- package/dist/esm/dcr/dynamic-client-registrar.d.ts +28 -0
- package/dist/esm/dcr/dynamic-client-registrar.js +66 -0
- package/dist/esm/dcr/dynamic-client-registrar.js.map +1 -0
- package/dist/esm/dcr/index.d.ts +8 -0
- package/dist/esm/dcr/index.js +5 -0
- package/dist/esm/dcr/index.js.map +1 -0
- package/dist/esm/index.d.ts +21 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/monkey-patches.d.ts +6 -0
- package/dist/esm/monkey-patches.js +32 -0
- package/dist/esm/monkey-patches.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/response-wrappers.d.ts +41 -0
- package/dist/esm/response-wrappers.js +201 -0
- package/dist/esm/response-wrappers.js.map +1 -0
- package/dist/esm/search/index.d.ts +6 -0
- package/dist/esm/search/index.js +3 -0
- package/dist/esm/search/index.js.map +1 -0
- package/dist/esm/search/search.d.ts +22 -0
- package/dist/esm/search/search.js +236 -0
- package/dist/esm/search/search.js.map +1 -0
- package/dist/esm/search/types.d.ts +122 -0
- package/dist/esm/search/types.js +8 -0
- package/dist/esm/search/types.js.map +1 -0
- package/dist/esm/spawn/spawn-server.d.ts +83 -0
- package/dist/esm/spawn/spawn-server.js +145 -0
- package/dist/esm/spawn/spawn-server.js.map +1 -0
- package/dist/esm/spawn/spawn-servers.d.ts +151 -0
- package/dist/esm/spawn/spawn-servers.js +406 -0
- package/dist/esm/spawn/spawn-servers.js.map +1 -0
- package/dist/esm/types.d.ts +11 -0
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/logger.d.ts +24 -0
- package/dist/esm/utils/logger.js +59 -0
- package/dist/esm/utils/logger.js.map +1 -0
- package/dist/esm/utils/path-utils.d.ts +45 -0
- package/dist/esm/utils/path-utils.js +89 -0
- package/dist/esm/utils/path-utils.js.map +1 -0
- package/dist/esm/utils/sanitizer.d.ts +30 -0
- package/dist/esm/utils/sanitizer.js +43 -0
- package/dist/esm/utils/sanitizer.js.map +1 -0
- package/package.json +92 -0
- package/schemas/servers.d.ts +90 -0
- package/schemas/servers.schema.json +104 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search implementation for MCP capability discovery
|
|
3
|
+
*
|
|
4
|
+
* Provides text-based search across tools, prompts, and resources
|
|
5
|
+
* from connected MCP servers.
|
|
6
|
+
*/ "use strict";
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
function _export(target, all) {
|
|
11
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
_export(exports, {
|
|
17
|
+
get buildCapabilityIndex () {
|
|
18
|
+
return buildCapabilityIndex;
|
|
19
|
+
},
|
|
20
|
+
get search () {
|
|
21
|
+
return search;
|
|
22
|
+
},
|
|
23
|
+
get searchCapabilities () {
|
|
24
|
+
return searchCapabilities;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
function _array_like_to_array(arr, len) {
|
|
28
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
29
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
30
|
+
return arr2;
|
|
31
|
+
}
|
|
32
|
+
function _array_with_holes(arr) {
|
|
33
|
+
if (Array.isArray(arr)) return arr;
|
|
34
|
+
}
|
|
35
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
36
|
+
try {
|
|
37
|
+
var info = gen[key](arg);
|
|
38
|
+
var value = info.value;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
reject(error);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (info.done) {
|
|
44
|
+
resolve(value);
|
|
45
|
+
} else {
|
|
46
|
+
Promise.resolve(value).then(_next, _throw);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function _async_to_generator(fn) {
|
|
50
|
+
return function() {
|
|
51
|
+
var self = this, args = arguments;
|
|
52
|
+
return new Promise(function(resolve, reject) {
|
|
53
|
+
var gen = fn.apply(self, args);
|
|
54
|
+
function _next(value) {
|
|
55
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
56
|
+
}
|
|
57
|
+
function _throw(err) {
|
|
58
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
59
|
+
}
|
|
60
|
+
_next(undefined);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function _iterable_to_array_limit(arr, i) {
|
|
65
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
66
|
+
if (_i == null) return;
|
|
67
|
+
var _arr = [];
|
|
68
|
+
var _n = true;
|
|
69
|
+
var _d = false;
|
|
70
|
+
var _s, _e;
|
|
71
|
+
try {
|
|
72
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
73
|
+
_arr.push(_s.value);
|
|
74
|
+
if (i && _arr.length === i) break;
|
|
75
|
+
}
|
|
76
|
+
} catch (err) {
|
|
77
|
+
_d = true;
|
|
78
|
+
_e = err;
|
|
79
|
+
} finally{
|
|
80
|
+
try {
|
|
81
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
82
|
+
} finally{
|
|
83
|
+
if (_d) throw _e;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return _arr;
|
|
87
|
+
}
|
|
88
|
+
function _non_iterable_rest() {
|
|
89
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
90
|
+
}
|
|
91
|
+
function _sliced_to_array(arr, i) {
|
|
92
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
93
|
+
}
|
|
94
|
+
function _type_of(obj) {
|
|
95
|
+
"@swc/helpers - typeof";
|
|
96
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
97
|
+
}
|
|
98
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
99
|
+
if (!o) return;
|
|
100
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
101
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
102
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
103
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
104
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
105
|
+
}
|
|
106
|
+
function _ts_generator(thisArg, body) {
|
|
107
|
+
var f, y, t, _ = {
|
|
108
|
+
label: 0,
|
|
109
|
+
sent: function() {
|
|
110
|
+
if (t[0] & 1) throw t[1];
|
|
111
|
+
return t[1];
|
|
112
|
+
},
|
|
113
|
+
trys: [],
|
|
114
|
+
ops: []
|
|
115
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
116
|
+
return d(g, "next", {
|
|
117
|
+
value: verb(0)
|
|
118
|
+
}), d(g, "throw", {
|
|
119
|
+
value: verb(1)
|
|
120
|
+
}), d(g, "return", {
|
|
121
|
+
value: verb(2)
|
|
122
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
123
|
+
value: function() {
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
}), g;
|
|
127
|
+
function verb(n) {
|
|
128
|
+
return function(v) {
|
|
129
|
+
return step([
|
|
130
|
+
n,
|
|
131
|
+
v
|
|
132
|
+
]);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function step(op) {
|
|
136
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
137
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
138
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
139
|
+
if (y = 0, t) op = [
|
|
140
|
+
op[0] & 2,
|
|
141
|
+
t.value
|
|
142
|
+
];
|
|
143
|
+
switch(op[0]){
|
|
144
|
+
case 0:
|
|
145
|
+
case 1:
|
|
146
|
+
t = op;
|
|
147
|
+
break;
|
|
148
|
+
case 4:
|
|
149
|
+
_.label++;
|
|
150
|
+
return {
|
|
151
|
+
value: op[1],
|
|
152
|
+
done: false
|
|
153
|
+
};
|
|
154
|
+
case 5:
|
|
155
|
+
_.label++;
|
|
156
|
+
y = op[1];
|
|
157
|
+
op = [
|
|
158
|
+
0
|
|
159
|
+
];
|
|
160
|
+
continue;
|
|
161
|
+
case 7:
|
|
162
|
+
op = _.ops.pop();
|
|
163
|
+
_.trys.pop();
|
|
164
|
+
continue;
|
|
165
|
+
default:
|
|
166
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
167
|
+
_ = 0;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
171
|
+
_.label = op[1];
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
175
|
+
_.label = t[1];
|
|
176
|
+
t = op;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
if (t && _.label < t[2]) {
|
|
180
|
+
_.label = t[2];
|
|
181
|
+
_.ops.push(op);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
if (t[2]) _.ops.pop();
|
|
185
|
+
_.trys.pop();
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
op = body.call(thisArg, _);
|
|
189
|
+
} catch (e) {
|
|
190
|
+
op = [
|
|
191
|
+
6,
|
|
192
|
+
e
|
|
193
|
+
];
|
|
194
|
+
y = 0;
|
|
195
|
+
} finally{
|
|
196
|
+
f = t = 0;
|
|
197
|
+
}
|
|
198
|
+
if (op[0] & 5) throw op[1];
|
|
199
|
+
return {
|
|
200
|
+
value: op[0] ? op[1] : void 0,
|
|
201
|
+
done: true
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
var DEFAULT_LIMIT = 20;
|
|
206
|
+
var DEFAULT_THRESHOLD = 0;
|
|
207
|
+
var DEFAULT_TYPES = [
|
|
208
|
+
'tool',
|
|
209
|
+
'prompt',
|
|
210
|
+
'resource'
|
|
211
|
+
];
|
|
212
|
+
var DEFAULT_SEARCH_FIELDS = [
|
|
213
|
+
'name',
|
|
214
|
+
'description',
|
|
215
|
+
'schema'
|
|
216
|
+
];
|
|
217
|
+
/**
|
|
218
|
+
* Extract searchable text from a JSON Schema's property descriptions
|
|
219
|
+
*/ function extractSchemaText(inputSchema) {
|
|
220
|
+
if (!inputSchema || (typeof inputSchema === "undefined" ? "undefined" : _type_of(inputSchema)) !== 'object') {
|
|
221
|
+
return '';
|
|
222
|
+
}
|
|
223
|
+
var schema = inputSchema;
|
|
224
|
+
var parts = [];
|
|
225
|
+
// Add schema-level description if present
|
|
226
|
+
if (schema.description) {
|
|
227
|
+
parts.push(schema.description);
|
|
228
|
+
}
|
|
229
|
+
// Add property names and descriptions
|
|
230
|
+
if (schema.properties) {
|
|
231
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
232
|
+
try {
|
|
233
|
+
for(var _iterator = Object.entries(schema.properties)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
234
|
+
var _step_value = _sliced_to_array(_step.value, 2), propName = _step_value[0], prop = _step_value[1];
|
|
235
|
+
parts.push(propName);
|
|
236
|
+
if (prop && (typeof prop === "undefined" ? "undefined" : _type_of(prop)) === 'object' && prop.description) {
|
|
237
|
+
parts.push(prop.description);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
} catch (err) {
|
|
241
|
+
_didIteratorError = true;
|
|
242
|
+
_iteratorError = err;
|
|
243
|
+
} finally{
|
|
244
|
+
try {
|
|
245
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
246
|
+
_iterator.return();
|
|
247
|
+
}
|
|
248
|
+
} finally{
|
|
249
|
+
if (_didIteratorError) {
|
|
250
|
+
throw _iteratorError;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return parts.join(' ');
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Extract searchable text from prompt arguments
|
|
259
|
+
*/ function extractArgumentsText(args) {
|
|
260
|
+
if (!args || !Array.isArray(args)) {
|
|
261
|
+
return '';
|
|
262
|
+
}
|
|
263
|
+
return args.map(function(arg) {
|
|
264
|
+
var parts = [
|
|
265
|
+
arg.name
|
|
266
|
+
];
|
|
267
|
+
if (arg.description) {
|
|
268
|
+
parts.push(arg.description);
|
|
269
|
+
}
|
|
270
|
+
return parts.join(' ');
|
|
271
|
+
}).join(' ');
|
|
272
|
+
}
|
|
273
|
+
function buildCapabilityIndex(clients) {
|
|
274
|
+
return _async_to_generator(function() {
|
|
275
|
+
var capabilities, servers, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, serverName, client, _ref, toolsResult, promptsResult, resourcesResult, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tool, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, prompt, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, resource, err;
|
|
276
|
+
return _ts_generator(this, function(_state) {
|
|
277
|
+
switch(_state.label){
|
|
278
|
+
case 0:
|
|
279
|
+
capabilities = [];
|
|
280
|
+
servers = [];
|
|
281
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
282
|
+
_state.label = 1;
|
|
283
|
+
case 1:
|
|
284
|
+
_state.trys.push([
|
|
285
|
+
1,
|
|
286
|
+
6,
|
|
287
|
+
7,
|
|
288
|
+
8
|
|
289
|
+
]);
|
|
290
|
+
_iterator = clients[Symbol.iterator]();
|
|
291
|
+
_state.label = 2;
|
|
292
|
+
case 2:
|
|
293
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
294
|
+
3,
|
|
295
|
+
5
|
|
296
|
+
];
|
|
297
|
+
_step_value = _sliced_to_array(_step.value, 2), serverName = _step_value[0], client = _step_value[1];
|
|
298
|
+
servers.push(serverName);
|
|
299
|
+
return [
|
|
300
|
+
4,
|
|
301
|
+
Promise.all([
|
|
302
|
+
client.listTools().catch(function() {
|
|
303
|
+
return null;
|
|
304
|
+
}),
|
|
305
|
+
client.listPrompts().catch(function() {
|
|
306
|
+
return null;
|
|
307
|
+
}),
|
|
308
|
+
client.listResources().catch(function() {
|
|
309
|
+
return null;
|
|
310
|
+
})
|
|
311
|
+
])
|
|
312
|
+
];
|
|
313
|
+
case 3:
|
|
314
|
+
_ref = _sliced_to_array.apply(void 0, [
|
|
315
|
+
_state.sent(),
|
|
316
|
+
3
|
|
317
|
+
]), toolsResult = _ref[0], promptsResult = _ref[1], resourcesResult = _ref[2];
|
|
318
|
+
// Index tools
|
|
319
|
+
if (toolsResult === null || toolsResult === void 0 ? void 0 : toolsResult.tools) {
|
|
320
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
321
|
+
try {
|
|
322
|
+
for(_iterator1 = toolsResult.tools[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
323
|
+
tool = _step1.value;
|
|
324
|
+
capabilities.push({
|
|
325
|
+
type: 'tool',
|
|
326
|
+
server: serverName,
|
|
327
|
+
name: tool.name,
|
|
328
|
+
description: tool.description,
|
|
329
|
+
schemaText: extractSchemaText(tool.inputSchema)
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
} catch (err) {
|
|
333
|
+
_didIteratorError1 = true;
|
|
334
|
+
_iteratorError1 = err;
|
|
335
|
+
} finally{
|
|
336
|
+
try {
|
|
337
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
338
|
+
_iterator1.return();
|
|
339
|
+
}
|
|
340
|
+
} finally{
|
|
341
|
+
if (_didIteratorError1) {
|
|
342
|
+
throw _iteratorError1;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
// Index prompts
|
|
348
|
+
if (promptsResult === null || promptsResult === void 0 ? void 0 : promptsResult.prompts) {
|
|
349
|
+
_iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
|
|
350
|
+
try {
|
|
351
|
+
for(_iterator2 = promptsResult.prompts[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
|
|
352
|
+
prompt = _step2.value;
|
|
353
|
+
capabilities.push({
|
|
354
|
+
type: 'prompt',
|
|
355
|
+
server: serverName,
|
|
356
|
+
name: prompt.name,
|
|
357
|
+
description: prompt.description,
|
|
358
|
+
argumentsText: extractArgumentsText(prompt.arguments),
|
|
359
|
+
arguments: prompt.arguments
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
} catch (err) {
|
|
363
|
+
_didIteratorError2 = true;
|
|
364
|
+
_iteratorError2 = err;
|
|
365
|
+
} finally{
|
|
366
|
+
try {
|
|
367
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
368
|
+
_iterator2.return();
|
|
369
|
+
}
|
|
370
|
+
} finally{
|
|
371
|
+
if (_didIteratorError2) {
|
|
372
|
+
throw _iteratorError2;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
// Index resources
|
|
378
|
+
if (resourcesResult === null || resourcesResult === void 0 ? void 0 : resourcesResult.resources) {
|
|
379
|
+
_iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = undefined;
|
|
380
|
+
try {
|
|
381
|
+
for(_iterator3 = resourcesResult.resources[Symbol.iterator](); !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true){
|
|
382
|
+
resource = _step3.value;
|
|
383
|
+
capabilities.push({
|
|
384
|
+
type: 'resource',
|
|
385
|
+
server: serverName,
|
|
386
|
+
name: resource.name,
|
|
387
|
+
description: resource.description,
|
|
388
|
+
uri: resource.uri,
|
|
389
|
+
mimeType: resource.mimeType
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
} catch (err) {
|
|
393
|
+
_didIteratorError3 = true;
|
|
394
|
+
_iteratorError3 = err;
|
|
395
|
+
} finally{
|
|
396
|
+
try {
|
|
397
|
+
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
398
|
+
_iterator3.return();
|
|
399
|
+
}
|
|
400
|
+
} finally{
|
|
401
|
+
if (_didIteratorError3) {
|
|
402
|
+
throw _iteratorError3;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
_state.label = 4;
|
|
408
|
+
case 4:
|
|
409
|
+
_iteratorNormalCompletion = true;
|
|
410
|
+
return [
|
|
411
|
+
3,
|
|
412
|
+
2
|
|
413
|
+
];
|
|
414
|
+
case 5:
|
|
415
|
+
return [
|
|
416
|
+
3,
|
|
417
|
+
8
|
|
418
|
+
];
|
|
419
|
+
case 6:
|
|
420
|
+
err = _state.sent();
|
|
421
|
+
_didIteratorError = true;
|
|
422
|
+
_iteratorError = err;
|
|
423
|
+
return [
|
|
424
|
+
3,
|
|
425
|
+
8
|
|
426
|
+
];
|
|
427
|
+
case 7:
|
|
428
|
+
try {
|
|
429
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
430
|
+
_iterator.return();
|
|
431
|
+
}
|
|
432
|
+
} finally{
|
|
433
|
+
if (_didIteratorError) {
|
|
434
|
+
throw _iteratorError;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return [
|
|
438
|
+
7
|
|
439
|
+
];
|
|
440
|
+
case 8:
|
|
441
|
+
return [
|
|
442
|
+
2,
|
|
443
|
+
{
|
|
444
|
+
capabilities: capabilities,
|
|
445
|
+
servers: servers,
|
|
446
|
+
indexedAt: new Date()
|
|
447
|
+
}
|
|
448
|
+
];
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
})();
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Calculate relevance score and matched fields for a capability against a query
|
|
455
|
+
*/ function scoreCapability(capability, queryTerms, searchFields) {
|
|
456
|
+
var matchedOn = [];
|
|
457
|
+
var totalScore = 0;
|
|
458
|
+
// Weights for different match types
|
|
459
|
+
var EXACT_NAME_WEIGHT = 1.0;
|
|
460
|
+
var PARTIAL_NAME_WEIGHT = 0.8;
|
|
461
|
+
var DESCRIPTION_WEIGHT = 0.6;
|
|
462
|
+
var SCHEMA_WEIGHT = 0.4;
|
|
463
|
+
var SERVER_WEIGHT = 0.3;
|
|
464
|
+
var nameLower = capability.name.toLowerCase();
|
|
465
|
+
var descLower = (capability.description || '').toLowerCase();
|
|
466
|
+
var serverLower = capability.server.toLowerCase();
|
|
467
|
+
// Get schema/arguments text based on type
|
|
468
|
+
var schemaTextLower = '';
|
|
469
|
+
if (capability.type === 'tool') {
|
|
470
|
+
schemaTextLower = capability.schemaText.toLowerCase();
|
|
471
|
+
} else if (capability.type === 'prompt') {
|
|
472
|
+
schemaTextLower = capability.argumentsText.toLowerCase();
|
|
473
|
+
} else if (capability.type === 'resource') {
|
|
474
|
+
// For resources, include URI and mimeType in searchable text
|
|
475
|
+
schemaTextLower = "".concat(capability.uri, " ").concat(capability.mimeType || '').toLowerCase();
|
|
476
|
+
}
|
|
477
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
478
|
+
try {
|
|
479
|
+
for(var _iterator = queryTerms[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
480
|
+
var term = _step.value;
|
|
481
|
+
var termLower = term.toLowerCase();
|
|
482
|
+
// Check name matches
|
|
483
|
+
if (searchFields.includes('name')) {
|
|
484
|
+
if (nameLower === termLower) {
|
|
485
|
+
totalScore += EXACT_NAME_WEIGHT;
|
|
486
|
+
if (!matchedOn.includes('name')) matchedOn.push('name');
|
|
487
|
+
} else if (nameLower.includes(termLower)) {
|
|
488
|
+
totalScore += PARTIAL_NAME_WEIGHT;
|
|
489
|
+
if (!matchedOn.includes('name')) matchedOn.push('name');
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
// Check description matches
|
|
493
|
+
if (searchFields.includes('description') && descLower.includes(termLower)) {
|
|
494
|
+
totalScore += DESCRIPTION_WEIGHT;
|
|
495
|
+
if (!matchedOn.includes('description')) matchedOn.push('description');
|
|
496
|
+
}
|
|
497
|
+
// Check schema/arguments matches
|
|
498
|
+
if (searchFields.includes('schema') && schemaTextLower.includes(termLower)) {
|
|
499
|
+
totalScore += SCHEMA_WEIGHT;
|
|
500
|
+
var fieldName = capability.type === 'tool' ? 'inputSchema' : capability.type === 'prompt' ? 'arguments' : 'uri';
|
|
501
|
+
if (!matchedOn.includes(fieldName)) matchedOn.push(fieldName);
|
|
502
|
+
}
|
|
503
|
+
// Check server name matches
|
|
504
|
+
if (searchFields.includes('server') && serverLower.includes(termLower)) {
|
|
505
|
+
totalScore += SERVER_WEIGHT;
|
|
506
|
+
if (!matchedOn.includes('server')) matchedOn.push('server');
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
} catch (err) {
|
|
510
|
+
_didIteratorError = true;
|
|
511
|
+
_iteratorError = err;
|
|
512
|
+
} finally{
|
|
513
|
+
try {
|
|
514
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
515
|
+
_iterator.return();
|
|
516
|
+
}
|
|
517
|
+
} finally{
|
|
518
|
+
if (_didIteratorError) {
|
|
519
|
+
throw _iteratorError;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
// Normalize score to 0-1 range based on number of terms
|
|
524
|
+
var normalizedScore = queryTerms.length > 0 ? Math.min(1, totalScore / queryTerms.length) : 0;
|
|
525
|
+
return {
|
|
526
|
+
score: normalizedScore,
|
|
527
|
+
matchedOn: matchedOn
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function searchCapabilities(index, query) {
|
|
531
|
+
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
532
|
+
var _options_types = options.types, types = _options_types === void 0 ? DEFAULT_TYPES : _options_types, servers = options.servers, _options_searchFields = options.searchFields, searchFields = _options_searchFields === void 0 ? DEFAULT_SEARCH_FIELDS : _options_searchFields, _options_limit = options.limit, limit = _options_limit === void 0 ? DEFAULT_LIMIT : _options_limit, _options_threshold = options.threshold, threshold = _options_threshold === void 0 ? DEFAULT_THRESHOLD : _options_threshold;
|
|
533
|
+
// Tokenize query into search terms
|
|
534
|
+
var queryTerms = query.toLowerCase().split(/\s+/).filter(function(term) {
|
|
535
|
+
return term.length > 0;
|
|
536
|
+
});
|
|
537
|
+
// If empty query, return empty results
|
|
538
|
+
if (queryTerms.length === 0) {
|
|
539
|
+
return {
|
|
540
|
+
query: query,
|
|
541
|
+
results: [],
|
|
542
|
+
total: 0
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
// Filter and score capabilities
|
|
546
|
+
var scoredResults = [];
|
|
547
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
548
|
+
try {
|
|
549
|
+
for(var _iterator = index.capabilities[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
550
|
+
var capability = _step.value;
|
|
551
|
+
// Filter by type
|
|
552
|
+
if (!types.includes(capability.type)) {
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
// Filter by server
|
|
556
|
+
if (servers && servers.length > 0 && !servers.includes(capability.server)) {
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
// Score the capability
|
|
560
|
+
var _scoreCapability = scoreCapability(capability, queryTerms, searchFields), score = _scoreCapability.score, matchedOn = _scoreCapability.matchedOn;
|
|
561
|
+
// Apply threshold filter
|
|
562
|
+
if (score >= threshold && matchedOn.length > 0) {
|
|
563
|
+
scoredResults.push({
|
|
564
|
+
capability: capability,
|
|
565
|
+
score: score,
|
|
566
|
+
matchedOn: matchedOn
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
} catch (err) {
|
|
571
|
+
_didIteratorError = true;
|
|
572
|
+
_iteratorError = err;
|
|
573
|
+
} finally{
|
|
574
|
+
try {
|
|
575
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
576
|
+
_iterator.return();
|
|
577
|
+
}
|
|
578
|
+
} finally{
|
|
579
|
+
if (_didIteratorError) {
|
|
580
|
+
throw _iteratorError;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
// Sort by score descending
|
|
585
|
+
scoredResults.sort(function(a, b) {
|
|
586
|
+
return b.score - a.score;
|
|
587
|
+
});
|
|
588
|
+
// Get total before limiting
|
|
589
|
+
var total = scoredResults.length;
|
|
590
|
+
// Apply limit and transform to SearchResult
|
|
591
|
+
var results = scoredResults.slice(0, limit).map(function(param) {
|
|
592
|
+
var capability = param.capability, score = param.score, matchedOn = param.matchedOn;
|
|
593
|
+
return {
|
|
594
|
+
type: capability.type,
|
|
595
|
+
server: capability.server,
|
|
596
|
+
name: capability.name,
|
|
597
|
+
description: capability.description,
|
|
598
|
+
matchedOn: matchedOn,
|
|
599
|
+
score: score
|
|
600
|
+
};
|
|
601
|
+
});
|
|
602
|
+
return {
|
|
603
|
+
query: query,
|
|
604
|
+
results: results,
|
|
605
|
+
total: total
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function search(_0, _1) {
|
|
609
|
+
return _async_to_generator(function(clients, query) {
|
|
610
|
+
var options, index;
|
|
611
|
+
var _arguments = arguments;
|
|
612
|
+
return _ts_generator(this, function(_state) {
|
|
613
|
+
switch(_state.label){
|
|
614
|
+
case 0:
|
|
615
|
+
options = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
|
|
616
|
+
return [
|
|
617
|
+
4,
|
|
618
|
+
buildCapabilityIndex(clients)
|
|
619
|
+
];
|
|
620
|
+
case 1:
|
|
621
|
+
index = _state.sent();
|
|
622
|
+
return [
|
|
623
|
+
2,
|
|
624
|
+
searchCapabilities(index, query, options)
|
|
625
|
+
];
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
}).apply(this, arguments);
|
|
629
|
+
}
|
|
630
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/libs/client/src/search/search.ts"],"sourcesContent":["/**\n * Search implementation for MCP capability discovery\n *\n * Provides text-based search across tools, prompts, and resources\n * from connected MCP servers.\n */\n\nimport type { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport type { PromptArgument } from '../connection/types.ts';\nimport type { CapabilityIndex, CapabilityType, IndexedCapability, IndexedPrompt, IndexedResource, IndexedTool, SearchField, SearchOptions, SearchResponse, SearchResult } from './types.ts';\n\nexport type CapabilityClient = Pick<Client, 'listTools' | 'listPrompts' | 'listResources'>;\n\nconst DEFAULT_LIMIT = 20;\nconst DEFAULT_THRESHOLD = 0;\nconst DEFAULT_TYPES: CapabilityType[] = ['tool', 'prompt', 'resource'];\nconst DEFAULT_SEARCH_FIELDS: SearchField[] = ['name', 'description', 'schema'];\n\n/**\n * Extract searchable text from a JSON Schema's property descriptions\n */\nfunction extractSchemaText(inputSchema: unknown): string {\n if (!inputSchema || typeof inputSchema !== 'object') {\n return '';\n }\n\n const schema = inputSchema as {\n properties?: Record<string, { description?: string; name?: string }>;\n description?: string;\n };\n\n const parts: string[] = [];\n\n // Add schema-level description if present\n if (schema.description) {\n parts.push(schema.description);\n }\n\n // Add property names and descriptions\n if (schema.properties) {\n for (const [propName, prop] of Object.entries(schema.properties)) {\n parts.push(propName);\n if (prop && typeof prop === 'object' && prop.description) {\n parts.push(prop.description);\n }\n }\n }\n\n return parts.join(' ');\n}\n\n/**\n * Extract searchable text from prompt arguments\n */\nfunction extractArgumentsText(args: PromptArgument[] | undefined): string {\n if (!args || !Array.isArray(args)) {\n return '';\n }\n\n return args\n .map((arg) => {\n const parts = [arg.name];\n if (arg.description) {\n parts.push(arg.description);\n }\n return parts.join(' ');\n })\n .join(' ');\n}\n\n/**\n * Build an index of capabilities from connected MCP clients\n */\nexport async function buildCapabilityIndex(clients: Map<string, CapabilityClient>): Promise<CapabilityIndex> {\n const capabilities: IndexedCapability[] = [];\n const servers: string[] = [];\n\n for (const [serverName, client] of clients) {\n servers.push(serverName);\n\n // Fetch all capabilities in parallel, handling errors gracefully\n const [toolsResult, promptsResult, resourcesResult] = await Promise.all([client.listTools().catch(() => null), client.listPrompts().catch(() => null), client.listResources().catch(() => null)]);\n\n // Index tools\n if (toolsResult?.tools) {\n for (const tool of toolsResult.tools) {\n capabilities.push({\n type: 'tool',\n server: serverName,\n name: tool.name,\n description: tool.description,\n schemaText: extractSchemaText(tool.inputSchema),\n } satisfies IndexedTool);\n }\n }\n\n // Index prompts\n if (promptsResult?.prompts) {\n for (const prompt of promptsResult.prompts) {\n capabilities.push({\n type: 'prompt',\n server: serverName,\n name: prompt.name,\n description: prompt.description,\n argumentsText: extractArgumentsText(prompt.arguments as PromptArgument[] | undefined),\n arguments: prompt.arguments as PromptArgument[] | undefined,\n } satisfies IndexedPrompt);\n }\n }\n\n // Index resources\n if (resourcesResult?.resources) {\n for (const resource of resourcesResult.resources) {\n capabilities.push({\n type: 'resource',\n server: serverName,\n name: resource.name,\n description: resource.description,\n uri: resource.uri,\n mimeType: resource.mimeType,\n } satisfies IndexedResource);\n }\n }\n }\n\n return {\n capabilities,\n servers,\n indexedAt: new Date(),\n };\n}\n\n/**\n * Calculate relevance score and matched fields for a capability against a query\n */\nfunction scoreCapability(capability: IndexedCapability, queryTerms: string[], searchFields: SearchField[]): { score: number; matchedOn: string[] } {\n const matchedOn: string[] = [];\n let totalScore = 0;\n\n // Weights for different match types\n const EXACT_NAME_WEIGHT = 1.0;\n const PARTIAL_NAME_WEIGHT = 0.8;\n const DESCRIPTION_WEIGHT = 0.6;\n const SCHEMA_WEIGHT = 0.4;\n const SERVER_WEIGHT = 0.3;\n\n const nameLower = capability.name.toLowerCase();\n const descLower = (capability.description || '').toLowerCase();\n const serverLower = capability.server.toLowerCase();\n\n // Get schema/arguments text based on type\n let schemaTextLower = '';\n if (capability.type === 'tool') {\n schemaTextLower = capability.schemaText.toLowerCase();\n } else if (capability.type === 'prompt') {\n schemaTextLower = capability.argumentsText.toLowerCase();\n } else if (capability.type === 'resource') {\n // For resources, include URI and mimeType in searchable text\n schemaTextLower = `${capability.uri} ${capability.mimeType || ''}`.toLowerCase();\n }\n\n for (const term of queryTerms) {\n const termLower = term.toLowerCase();\n\n // Check name matches\n if (searchFields.includes('name')) {\n if (nameLower === termLower) {\n totalScore += EXACT_NAME_WEIGHT;\n if (!matchedOn.includes('name')) matchedOn.push('name');\n } else if (nameLower.includes(termLower)) {\n totalScore += PARTIAL_NAME_WEIGHT;\n if (!matchedOn.includes('name')) matchedOn.push('name');\n }\n }\n\n // Check description matches\n if (searchFields.includes('description') && descLower.includes(termLower)) {\n totalScore += DESCRIPTION_WEIGHT;\n if (!matchedOn.includes('description')) matchedOn.push('description');\n }\n\n // Check schema/arguments matches\n if (searchFields.includes('schema') && schemaTextLower.includes(termLower)) {\n totalScore += SCHEMA_WEIGHT;\n const fieldName = capability.type === 'tool' ? 'inputSchema' : capability.type === 'prompt' ? 'arguments' : 'uri';\n if (!matchedOn.includes(fieldName)) matchedOn.push(fieldName);\n }\n\n // Check server name matches\n if (searchFields.includes('server') && serverLower.includes(termLower)) {\n totalScore += SERVER_WEIGHT;\n if (!matchedOn.includes('server')) matchedOn.push('server');\n }\n }\n\n // Normalize score to 0-1 range based on number of terms\n const normalizedScore = queryTerms.length > 0 ? Math.min(1, totalScore / queryTerms.length) : 0;\n\n return { score: normalizedScore, matchedOn };\n}\n\n/**\n * Search for capabilities matching a query string\n */\nexport function searchCapabilities(index: CapabilityIndex, query: string, options: SearchOptions = {}): SearchResponse {\n const { types = DEFAULT_TYPES, servers, searchFields = DEFAULT_SEARCH_FIELDS, limit = DEFAULT_LIMIT, threshold = DEFAULT_THRESHOLD } = options;\n\n // Tokenize query into search terms\n const queryTerms = query\n .toLowerCase()\n .split(/\\s+/)\n .filter((term) => term.length > 0);\n\n // If empty query, return empty results\n if (queryTerms.length === 0) {\n return { query, results: [], total: 0 };\n }\n\n // Filter and score capabilities\n const scoredResults: Array<{ capability: IndexedCapability; score: number; matchedOn: string[] }> = [];\n\n for (const capability of index.capabilities) {\n // Filter by type\n if (!types.includes(capability.type)) {\n continue;\n }\n\n // Filter by server\n if (servers && servers.length > 0 && !servers.includes(capability.server)) {\n continue;\n }\n\n // Score the capability\n const { score, matchedOn } = scoreCapability(capability, queryTerms, searchFields);\n\n // Apply threshold filter\n if (score >= threshold && matchedOn.length > 0) {\n scoredResults.push({ capability, score, matchedOn });\n }\n }\n\n // Sort by score descending\n scoredResults.sort((a, b) => b.score - a.score);\n\n // Get total before limiting\n const total = scoredResults.length;\n\n // Apply limit and transform to SearchResult\n const results: SearchResult[] = scoredResults.slice(0, limit).map(({ capability, score, matchedOn }) => ({\n type: capability.type,\n server: capability.server,\n name: capability.name,\n description: capability.description,\n matchedOn,\n score,\n }));\n\n return { query, results, total };\n}\n\n/**\n * Convenience function to search directly from connected clients\n * Builds index and performs search in one call\n */\nexport async function search(clients: Map<string, CapabilityClient>, query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n const index = await buildCapabilityIndex(clients);\n return searchCapabilities(index, query, options);\n}\n"],"names":["buildCapabilityIndex","search","searchCapabilities","DEFAULT_LIMIT","DEFAULT_THRESHOLD","DEFAULT_TYPES","DEFAULT_SEARCH_FIELDS","extractSchemaText","inputSchema","schema","parts","description","push","properties","Object","entries","propName","prop","join","extractArgumentsText","args","Array","isArray","map","arg","name","clients","capabilities","servers","serverName","client","toolsResult","promptsResult","resourcesResult","tool","prompt","resource","Promise","all","listTools","catch","listPrompts","listResources","tools","type","server","schemaText","prompts","argumentsText","arguments","resources","uri","mimeType","indexedAt","Date","scoreCapability","capability","queryTerms","searchFields","matchedOn","totalScore","EXACT_NAME_WEIGHT","PARTIAL_NAME_WEIGHT","DESCRIPTION_WEIGHT","SCHEMA_WEIGHT","SERVER_WEIGHT","nameLower","toLowerCase","descLower","serverLower","schemaTextLower","term","termLower","includes","fieldName","normalizedScore","length","Math","min","score","index","query","options","types","limit","threshold","split","filter","results","total","scoredResults","sort","a","b","slice"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;QAoEqBA;eAAAA;;QA+LAC;eAAAA;;QA5DNC;eAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA/LhB,IAAMC,gBAAgB;AACtB,IAAMC,oBAAoB;AAC1B,IAAMC,gBAAkC;IAAC;IAAQ;IAAU;CAAW;AACtE,IAAMC,wBAAuC;IAAC;IAAQ;IAAe;CAAS;AAE9E;;CAEC,GACD,SAASC,kBAAkBC,WAAoB;IAC7C,IAAI,CAACA,eAAe,CAAA,OAAOA,4CAAP,SAAOA,YAAU,MAAM,UAAU;QACnD,OAAO;IACT;IAEA,IAAMC,SAASD;IAKf,IAAME,QAAkB,EAAE;IAE1B,0CAA0C;IAC1C,IAAID,OAAOE,WAAW,EAAE;QACtBD,MAAME,IAAI,CAACH,OAAOE,WAAW;IAC/B;IAEA,sCAAsC;IACtC,IAAIF,OAAOI,UAAU,EAAE;YAChB,kCAAA,2BAAA;;YAAL,QAAK,YAA0BC,OAAOC,OAAO,CAACN,OAAOI,UAAU,sBAA1D,SAAA,6BAAA,QAAA,yBAAA,iCAA6D;gBAA7D,mCAAA,iBAAOG,2BAAUC;gBACpBP,MAAME,IAAI,CAACI;gBACX,IAAIC,QAAQ,CAAA,OAAOA,qCAAP,SAAOA,KAAG,MAAM,YAAYA,KAAKN,WAAW,EAAE;oBACxDD,MAAME,IAAI,CAACK,KAAKN,WAAW;gBAC7B;YACF;;YALK;YAAA;;;qBAAA,6BAAA;oBAAA;;;oBAAA;0BAAA;;;;IAMP;IAEA,OAAOD,MAAMQ,IAAI,CAAC;A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