@browserstack/mcp-server 1.5.0-beta.2 → 1.5.0-beta.20
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/capability/loadtesting.capability-index.json +135 -29
- package/capability/tm.capability-index.json +42368 -12057
- package/dist/tools/capability-registry/bind.js +201 -6
- package/dist/tools/capability-registry/egress.js +52 -6
- package/dist/tools/capability-registry/index-loader.d.ts +15 -1
- package/dist/tools/capability-registry/index-loader.js +92 -2
- package/dist/tools/capability-registry/register.d.ts +14 -0
- package/dist/tools/capability-registry/register.js +367 -117
- package/dist/tools/capability-registry/search.d.ts +108 -3
- package/dist/tools/capability-registry/search.js +381 -14
- package/dist/tools/capability-registry/types.d.ts +80 -6
- package/package.json +7 -2
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The tool surface: four discovery tools plus ONE invoke tool.
|
|
3
3
|
*
|
|
4
|
+
* Discovery is deliberately two steps. `searchCapability` returns a shortlist — enough to
|
|
5
|
+
* CHOOSE — and `describeCapability` returns the contract for the one chosen. Parameters and
|
|
6
|
+
* response shapes are 86% of a full record and are needed once, not eight times: measured
|
|
7
|
+
* over eight queries, ~8.6k tokens a search becomes ~1.1k, and even describing every result
|
|
8
|
+
* still costs less than the single fat call did.
|
|
9
|
+
*
|
|
4
10
|
* ONE invoke tool means one set of MCP annotations, so they describe the whole surface
|
|
5
11
|
* honestly: it can write (not read-only) and it can never delete, because destructive
|
|
6
12
|
* endpoints are refused before binding. Write consent therefore rests on `user_permission`
|
|
@@ -14,8 +20,16 @@ import { indexPaths, isEnabled, resolveBaseUrl } from "./config.js";
|
|
|
14
20
|
import { fetchTransport } from "./egress.js";
|
|
15
21
|
import { CapabilityRegistry, InvocationError, resolveResponses, } from "./index-loader.js";
|
|
16
22
|
import { invoke } from "./resolve.js";
|
|
17
|
-
import { searchCapabilities } from "./search.js";
|
|
23
|
+
import { ambiguousProducts, isBrowseQuery, searchCapabilities, singular, terms, vocabularyOf, } from "./search.js";
|
|
18
24
|
export const PERMISSION_VALUES = ["not_asked", "granted", "denied"];
|
|
25
|
+
/**
|
|
26
|
+
* The search-side twin of `user_permission`: did a human choose the product, or did you?
|
|
27
|
+
*
|
|
28
|
+
* No `denied`. A refused write is a thing the caller must not do; a refused product choice
|
|
29
|
+
* is not a state — the user either named one, in which case you search it, or has not been
|
|
30
|
+
* asked, in which case there is nothing to search yet.
|
|
31
|
+
*/
|
|
32
|
+
export const PRODUCT_CHOICE_VALUES = ["not_asked", "user_confirmed"];
|
|
19
33
|
/**
|
|
20
34
|
* The tool-adder the server factory calls.
|
|
21
35
|
*
|
|
@@ -67,10 +81,13 @@ export function addCapabilityRegistryToolsFromConfig(server, config) {
|
|
|
67
81
|
function ok(payload) {
|
|
68
82
|
return { content: [{ type: "text", text: JSON.stringify(payload) }] };
|
|
69
83
|
}
|
|
70
|
-
function failed(message) {
|
|
84
|
+
function failed(message, extra) {
|
|
71
85
|
return {
|
|
72
86
|
content: [
|
|
73
|
-
{
|
|
87
|
+
{
|
|
88
|
+
type: "text",
|
|
89
|
+
text: JSON.stringify({ ok: false, error: message, ...extra }),
|
|
90
|
+
},
|
|
74
91
|
],
|
|
75
92
|
isError: true,
|
|
76
93
|
};
|
|
@@ -91,29 +108,12 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
91
108
|
: z.string();
|
|
92
109
|
/** "tm, loadtesting" — for prose that has to name them. */
|
|
93
110
|
const productList = productNames.join(", ") || "none loaded";
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
* trip they save. Everywhere else the names alone are what a caller needs.
|
|
101
|
-
*
|
|
102
|
-
* Each summary is cut to its first sentence and capped, and the whole catalog is
|
|
103
|
-
* budgeted: past the budget the names still route, which is the part that matters.
|
|
104
|
-
*/
|
|
105
|
-
const productCatalog = (() => {
|
|
106
|
-
const lines = productNames.map((name) => {
|
|
107
|
-
const summary = registry.index.products[name].summary.trim();
|
|
108
|
-
const firstSentence = summary.split(/(?<=\.)\s/)[0] ?? summary;
|
|
109
|
-
const trimmed = firstSentence.length > 130
|
|
110
|
-
? `${firstSentence.slice(0, 127).trimEnd()}…`
|
|
111
|
-
: firstSentence;
|
|
112
|
-
return `${name} — ${trimmed.replace(/\.$/, "")}`;
|
|
113
|
-
});
|
|
114
|
-
const joined = lines.join("; ");
|
|
115
|
-
return joined.length <= 500 ? joined : productList;
|
|
116
|
-
})();
|
|
111
|
+
// NO PRODUCT CATALOG IN ANY DESCRIPTION. listProducts used to restate every product's
|
|
112
|
+
// trimmed summary in its own description — duplicating, as static context on every
|
|
113
|
+
// single request, the exact thing the tool returns when called. Authored summaries are
|
|
114
|
+
// also unbounded (loadtesting's runs to 470 characters) and change with the artifact,
|
|
115
|
+
// so the prose went stale on its own. The names still travel in the `product` enum,
|
|
116
|
+
// which is where a client can actually validate them.
|
|
117
117
|
const transport = deps.transport || fetchTransport();
|
|
118
118
|
const tools = {};
|
|
119
119
|
/** Instrumentation in the house style, and never fatal to the call it wraps. */
|
|
@@ -125,9 +125,10 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
125
125
|
// Telemetry must not decide whether a tool call succeeds.
|
|
126
126
|
}
|
|
127
127
|
};
|
|
128
|
-
tools.listProducts = server.tool("listProducts", "List the BrowserStack products this surface can reach
|
|
129
|
-
"
|
|
130
|
-
|
|
128
|
+
tools.listProducts = server.tool("listProducts", "List the BrowserStack products this surface can reach: what each one does, the " +
|
|
129
|
+
"entities it models, and a line saying what each entity is. START HERE — " +
|
|
130
|
+
"searchCapability needs a product, and this is what tells you which one. If two " +
|
|
131
|
+
"products could both fit the task, ask the user rather than choosing for them.", {}, {
|
|
131
132
|
title: "List Capability Products",
|
|
132
133
|
readOnlyHint: true,
|
|
133
134
|
destructiveHint: false,
|
|
@@ -135,40 +136,53 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
135
136
|
openWorldHint: false,
|
|
136
137
|
}, async () => {
|
|
137
138
|
track("listProducts");
|
|
138
|
-
const info = registry.buildInfo();
|
|
139
139
|
return ok({
|
|
140
|
-
build_id: registry.buildId,
|
|
141
140
|
products: registry.productNames().map((name) => ({
|
|
142
141
|
name,
|
|
143
142
|
summary: registry.index.products[name].summary,
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
// THE ENTITIES AND WHAT EACH ONE IS. Routing is this tool's whole job, and a
|
|
144
|
+
// product summary alone does not do it: "add a tag to xyz test" reads as
|
|
145
|
+
// either product until you can see that `tag` exists in one and not the other.
|
|
146
|
+
// The one-line description is what makes each name mean something — `version`
|
|
147
|
+
// alone does not say whether it versions a test case or a project — so an
|
|
148
|
+
// agent can choose here instead of calling describeEntity once per entity to
|
|
149
|
+
// find out, which for tm is 19 calls at ~1.4KB apiece.
|
|
150
|
+
//
|
|
151
|
+
// NAME AND DESCRIPTION ONLY. The aliases used to travel here too, and they are
|
|
152
|
+
// the wrong half for this job: they answer "what else is this called", which
|
|
153
|
+
// matters when a search has already failed on vocabulary, not when choosing a
|
|
154
|
+
// product. They still reach the caller at exactly that moment, in
|
|
155
|
+
// searchCapability's weak-match block, where the full vocabulary is the answer
|
|
156
|
+
// rather than 2.5KB of speculative context on every routing call.
|
|
157
|
+
entities: (vocabularyOf(registry.index.products, name)[name] ?? []).map(({ entity, description }) => ({
|
|
158
|
+
entity,
|
|
159
|
+
...(description ? { description } : {}),
|
|
160
|
+
})),
|
|
161
|
+
// NO build_id OR version. They are provenance — for our logs and for cache
|
|
162
|
+
// busting — and capability resolution must never depend on them, which means
|
|
163
|
+
// no caller has anything to do with them. They rode on the one call an agent
|
|
164
|
+
// makes before it knows anything, costing context to say nothing actionable.
|
|
165
|
+
// Still on searchCapability's response, where a support question about which
|
|
166
|
+
// index answered can actually be traced to a result.
|
|
148
167
|
})),
|
|
149
168
|
});
|
|
150
169
|
});
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const bundle = registry.index.products[product];
|
|
163
|
-
if (!bundle)
|
|
164
|
-
return failed(`unknown product '${product}'`);
|
|
165
|
-
return ok({ product, entities: Object.keys(bundle.entities).sort() });
|
|
166
|
-
});
|
|
170
|
+
// listEntities WAS HERE, and is gone. It answered `{product, entities: [names]}` — a
|
|
171
|
+
// strict subset of what listProducts now returns for every product, and with the
|
|
172
|
+
// aliases missing. Keeping it would have meant two tools for one question, and a tool
|
|
173
|
+
// definition costs context on every request whether or not it is called, which is the
|
|
174
|
+
// entire reason this surface is five generic tools instead of 173 specific ones.
|
|
175
|
+
//
|
|
176
|
+
// One consequence to watch: listProducts now carries every product's vocabulary rather
|
|
177
|
+
// than one product's on request, so it grows with the number of products — roughly 1KB
|
|
178
|
+
// each. That is the right trade while routing is the problem it solves (you cannot
|
|
179
|
+
// choose between products by looking at one of them), but past a dozen products it may
|
|
180
|
+
// need a names-only default with aliases on request.
|
|
167
181
|
tools.describeEntity = server.tool("describeEntity", "Describe one entity: what it is, what identifies it, what it relates to, and the " +
|
|
168
182
|
"vocabulary the product uses for it. Read this before filtering or writing, because " +
|
|
169
183
|
"ids and field values usually have to be resolved first.", {
|
|
170
184
|
product: productArg().describe(`Which product the entity belongs to: ${productList}.`),
|
|
171
|
-
entity: z.string().describe("Entity name
|
|
185
|
+
entity: z.string().describe("Entity name, as listProducts returns it."),
|
|
172
186
|
}, {
|
|
173
187
|
title: "Describe Entity",
|
|
174
188
|
readOnlyHint: true,
|
|
@@ -186,93 +200,319 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
186
200
|
}
|
|
187
201
|
return ok({ product, entity, ...doc });
|
|
188
202
|
});
|
|
189
|
-
tools.searchCapability = server.tool("searchCapability", "Find endpoints this surface can call, by plain language,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
"
|
|
193
|
-
"
|
|
194
|
-
"
|
|
195
|
-
"
|
|
196
|
-
"
|
|
197
|
-
"
|
|
198
|
-
"
|
|
199
|
-
"
|
|
200
|
-
"
|
|
201
|
-
"
|
|
203
|
+
tools.searchCapability = server.tool("searchCapability", "Find endpoints this surface can call, by plain language, within ONE product. " +
|
|
204
|
+
`You must say which: ${productList}. If the task does not name it unambiguously, ` +
|
|
205
|
+
"call listProducts first — it returns what each product does, the entities each " +
|
|
206
|
+
"models, and what every entity means, which is what settles the choice. Where two " +
|
|
207
|
+
"products use the same word for different things, ask the user rather than picking. " +
|
|
208
|
+
"Search matches the product's OWN words, not synonyms. When your words are not the " +
|
|
209
|
+
"product's, the response says so: `weak_match: true` with a `suggested_vocabulary` " +
|
|
210
|
+
"map of the product's entities and their aliases. Results are still returned, but " +
|
|
211
|
+
"treat them as unconfirmed — pick the closest entity from that map and search again " +
|
|
212
|
+
"using its vocabulary, or call describeEntity on it for the fuller picture. That one " +
|
|
213
|
+
"extra round trip is far cheaper than invoking the wrong capability. " +
|
|
214
|
+
"Narrowing further with `entity` sharpens results. " +
|
|
215
|
+
"THIS IS A SHORTLIST, NOT A CONTRACT. Each result carries only what you need to " +
|
|
216
|
+
"CHOOSE: `name` (the handle), `product`, `mode` (whether it writes), `intent` and " +
|
|
217
|
+
"`guidance` (what it does and what goes wrong), and `method`/`path` for products " +
|
|
218
|
+
"that publish no name yet. " +
|
|
219
|
+
"It does NOT carry parameters or response shapes. Once you have picked one, call " +
|
|
220
|
+
"describeCapability for its full contract, then invokeCapability. Fetching the " +
|
|
221
|
+
"contract only for the one you chose is the difference between ~1k and ~8.6k tokens " +
|
|
222
|
+
"a search. Results are ranked and capped. " +
|
|
223
|
+
"TO SEE EVERYTHING rather than search, pass query='*' — that lists the product " +
|
|
224
|
+
"(honouring `entity` and `mode`) in a stable order instead of ranking it, which is " +
|
|
225
|
+
"what you want when the task is 'what can this product do' rather than a lookup. " +
|
|
226
|
+
"TO PAGE, send `offset`: every response carries `offset` and, when more matched, " +
|
|
227
|
+
"`next_offset` — resend the SAME query with that value. `next_offset` is absent on " +
|
|
228
|
+
"the last page, so walk until it stops rather than comparing counts.", {
|
|
202
229
|
query: z
|
|
203
230
|
.string()
|
|
204
|
-
.describe("What you are trying to do, in plain language."
|
|
231
|
+
.describe("What you are trying to do, in plain language. Pass '*' (or 'all') to BROWSE " +
|
|
232
|
+
"instead of search: every capability in the product, in a stable order, " +
|
|
233
|
+
"paginated — use it when you want to see the surface rather than find one thing."),
|
|
205
234
|
entity: z
|
|
206
235
|
.string()
|
|
207
236
|
.optional()
|
|
208
|
-
.describe("Restrict to one entity (
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
237
|
+
.describe("Restrict to one entity (listProducts names them)."),
|
|
238
|
+
// REQUIRED, and the reason is the tool that is NOT being called. listProducts
|
|
239
|
+
// carries the routing data — each product's purpose, its entities, and what every
|
|
240
|
+
// entity means — but nothing obliged an agent to read it: a search that worked
|
|
241
|
+
// without naming a product meant the routing step could always be skipped, and an
|
|
242
|
+
// optional step in front of a working one is a step that does not happen. Requiring
|
|
243
|
+
// the argument makes the ordering structural instead of advisory.
|
|
244
|
+
//
|
|
245
|
+
// It costs one listProducts call on queries that were already unambiguous — 139 of
|
|
246
|
+
// 147 vocabulary terms resolve to a single product — and buys the eight that are
|
|
247
|
+
// not (run, project, report, result, folder, workspace, execution, history), where
|
|
248
|
+
// the old behaviour was to silently pick whichever product ranked higher. A wasted
|
|
249
|
+
// round trip against a silent wrong-product answer is not a close trade.
|
|
250
|
+
product: productArg().describe(`Which product to search: ${productList}. Call listProducts if the task does ` +
|
|
251
|
+
`not make it obvious, and ask the user when two products could both fit.`),
|
|
252
|
+
// REQUIRED, and self-reported, exactly like `user_permission` on a write. The
|
|
253
|
+
// server cannot see whether you asked anyone; what it can do is refuse to answer a
|
|
254
|
+
// question only the user can settle, and make claiming otherwise an explicit act
|
|
255
|
+
// rather than an omission.
|
|
256
|
+
product_choice: z
|
|
257
|
+
.enum(PRODUCT_CHOICE_VALUES)
|
|
258
|
+
.describe("'user_confirmed' only when the user named the product, or the task names it " +
|
|
259
|
+
"unmistakably. 'not_asked' otherwise — then a query that could mean either " +
|
|
260
|
+
"product is refused and told what to ask, instead of being answered for the " +
|
|
261
|
+
"wrong one. Never search each product in turn and merge the results: that is " +
|
|
262
|
+
"the guess this argument exists to prevent."),
|
|
212
263
|
mode: z
|
|
213
264
|
.enum(["read", "write", "destructive"])
|
|
214
265
|
.optional()
|
|
215
266
|
.describe("Restrict to reads or writes. Omit to let the query decide."),
|
|
216
267
|
limit: z.number().optional().describe("Max results (default 8)."),
|
|
217
|
-
|
|
218
|
-
.
|
|
268
|
+
offset: z
|
|
269
|
+
.number()
|
|
219
270
|
.optional()
|
|
220
|
-
.describe("
|
|
221
|
-
"
|
|
222
|
-
"endpoints), or 'none'."),
|
|
271
|
+
.describe("Skip this many results — send the `next_offset` from the previous response " +
|
|
272
|
+
"with the SAME query to get the next page. Omit for the first page."),
|
|
223
273
|
}, {
|
|
224
274
|
title: "Search Capabilities",
|
|
225
275
|
readOnlyHint: true,
|
|
226
276
|
destructiveHint: false,
|
|
227
277
|
idempotentHint: true,
|
|
228
278
|
openWorldHint: false,
|
|
229
|
-
}, async ({ query, entity, product, mode, limit,
|
|
279
|
+
}, async ({ query, entity, product, product_choice, mode, limit, offset }) => {
|
|
230
280
|
track("searchCapability");
|
|
231
|
-
|
|
232
|
-
|
|
281
|
+
// THE GATE. Nothing here can tell whether a human was asked — same as the write
|
|
282
|
+
// gate, which also takes the caller's word. What it can do is refuse to answer a
|
|
283
|
+
// question that is genuinely the user's, so that answering it anyway takes a
|
|
284
|
+
// deliberate claim instead of silence.
|
|
285
|
+
//
|
|
286
|
+
// Only when the query itself cannot settle the choice: every recognised word is one
|
|
287
|
+
// both products claim. 27 of the 198 eval queries, against 135 if constituent words
|
|
288
|
+
// counted. `entity` is an explicit narrowing, so a caller that named one has already
|
|
289
|
+
// been specific enough and is not asked again.
|
|
290
|
+
// The ambiguity gate asks the USER which product a word belongs to. A browse query
|
|
291
|
+
// contains no word to be ambiguous about — `*` names nothing — so there is nothing
|
|
292
|
+
// to ask, and asking anyway would block the one query whose whole purpose is to
|
|
293
|
+
// show what a product contains.
|
|
294
|
+
if (product_choice !== "user_confirmed" &&
|
|
295
|
+
!entity &&
|
|
296
|
+
!isBrowseQuery(query)) {
|
|
297
|
+
const ambiguity = ambiguousProducts(registry.index.products, query);
|
|
298
|
+
if (ambiguity.products.length > 1) {
|
|
299
|
+
// EVERYTHING NEEDED TO ASK, IN THE REFUSAL. Telling the agent to go and call
|
|
300
|
+
// listProducts costs a round trip and still leaves it composing a question out
|
|
301
|
+
// of nothing — so it tends to guess instead, which is the behaviour being
|
|
302
|
+
// stopped. What makes the choice answerable is what each product calls the
|
|
303
|
+
// shared word and what it means THERE: tm's project owns folders and test
|
|
304
|
+
// cases, Load Testing's does not.
|
|
305
|
+
const options = ambiguity.products.map((name) => {
|
|
306
|
+
const entities = registry.index.products[name]?.entities ?? {};
|
|
307
|
+
const senses = ambiguity.terms
|
|
308
|
+
.map((term) => {
|
|
309
|
+
const key = Object.keys(entities).find((candidate) => [
|
|
310
|
+
candidate,
|
|
311
|
+
...(entities[candidate].aliases ?? []),
|
|
312
|
+
].some((word) => terms(word).map(singular).join(" ") === term));
|
|
313
|
+
const doc = key ? entities[key] : undefined;
|
|
314
|
+
return doc
|
|
315
|
+
? { term, entity: key, means: doc.description }
|
|
316
|
+
: undefined;
|
|
317
|
+
})
|
|
318
|
+
.filter(Boolean);
|
|
319
|
+
return {
|
|
320
|
+
product: name,
|
|
321
|
+
summary: registry.index.products[name]?.summary,
|
|
322
|
+
...(senses.length ? { shared_terms: senses } : {}),
|
|
323
|
+
};
|
|
324
|
+
});
|
|
325
|
+
return failed(`'${query}' could mean ${ambiguity.products.join(" or ")} — ` +
|
|
326
|
+
`${ambiguity.terms.map((t) => `'${t}'`).join(", ")} ` +
|
|
327
|
+
`${ambiguity.terms.length === 1 ? "belongs" : "belong"} to both. ` +
|
|
328
|
+
"Put the choice in `clarify` to the USER in their own terms, wait for an " +
|
|
329
|
+
"answer, then resend with product_choice='user_confirmed'. Do NOT search " +
|
|
330
|
+
"each product in turn and merge the results — that answers the question " +
|
|
331
|
+
"instead of asking it.", {
|
|
332
|
+
clarify: {
|
|
333
|
+
question: `Which product do you mean — ${ambiguity.products.join(" or ")}?`,
|
|
334
|
+
shared: ambiguity.terms,
|
|
335
|
+
options,
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
const { hits, weak, top_matched, ...rest } = searchCapabilities(registry.index.products, query, {
|
|
233
341
|
entity,
|
|
234
342
|
product,
|
|
235
343
|
mode: mode,
|
|
236
344
|
limit,
|
|
345
|
+
offset,
|
|
237
346
|
});
|
|
238
347
|
return ok({
|
|
239
|
-
build_id
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
348
|
+
// NO build_id. It is provenance — for our logs and for cache busting — and
|
|
349
|
+
// resolution must never depend on it, which is exactly why no caller has anything
|
|
350
|
+
// to do with it. It was also the WHOLE registry's id, so a search scoped to one
|
|
351
|
+
// product still announced every other product's build: metadata about builds the
|
|
352
|
+
// caller did not ask about and cannot act on. The startup log already records
|
|
353
|
+
// what loaded, which is where a question about a stale index gets answered.
|
|
354
|
+
//
|
|
355
|
+
// A SHORTLIST: only what choosing requires. Parameters and response shapes are 86%
|
|
356
|
+
// of a full record and are needed for exactly ONE of the eight — the one the caller
|
|
357
|
+
// picks — so they move to describeCapability. Measured over eight queries: 8.6k
|
|
358
|
+
// tokens a search becomes ~1k, and even describing all eight results still costs
|
|
359
|
+
// slightly less than today.
|
|
360
|
+
//
|
|
361
|
+
// NO ROUTE, AND NO PRODUCT. Both were justified and both justifications expired.
|
|
362
|
+
//
|
|
363
|
+
// `method`/`path` were unconditional because Load Testing published no names, so
|
|
364
|
+
// its rows would otherwise have been unaddressable. It now names all 20, as tm
|
|
365
|
+
// names all 173 — every row on this surface is reachable by name. Publishing the
|
|
366
|
+
// route anyway contradicts the premise the whole registry rests on: an agent
|
|
367
|
+
// addresses a capability by a handle that outlives the route. They remain as a
|
|
368
|
+
// fallback for a product that ships unnamed capabilities, emitted only for the
|
|
369
|
+
// rows that actually need them, which today is none.
|
|
370
|
+
//
|
|
371
|
+
// `product` was here because results could span products. They cannot: `product`
|
|
372
|
+
// is a required argument, so every row is the product the caller named.
|
|
373
|
+
capabilities: hits.map(({ capability }) => ({
|
|
374
|
+
...(capability.name
|
|
375
|
+
? { name: capability.name }
|
|
376
|
+
: { method: capability.method, path: capability.path }),
|
|
377
|
+
mode: capability.mode,
|
|
378
|
+
entity: capability.entity,
|
|
379
|
+
...(capability.intent ? { intent: capability.intent } : {}),
|
|
380
|
+
...(capability.guidance?.length
|
|
381
|
+
? { guidance: capability.guidance }
|
|
382
|
+
: {}),
|
|
383
|
+
})),
|
|
257
384
|
...rest,
|
|
385
|
+
// WHEN THE MATCH IS WEAK, HAND OVER THE VOCABULARY.
|
|
386
|
+
//
|
|
387
|
+
// A vocabulary miss returns a full page of confident-looking hits — nothing in the
|
|
388
|
+
// shape of the response says the caller's word does not exist in this product. This
|
|
389
|
+
// is that signal, plus the fix in the same round trip: the caller is a model, and it
|
|
390
|
+
// maps "bucket" to "folder" instantly once it can see the entity list.
|
|
391
|
+
//
|
|
392
|
+
// Additive, never a replacement — the results are still there, and the caller is
|
|
393
|
+
// told to re-search rather than to trust this. That is what makes a generous
|
|
394
|
+
// threshold safe.
|
|
395
|
+
...(weak
|
|
396
|
+
? {
|
|
397
|
+
weak_match: true,
|
|
398
|
+
suggested_vocabulary: vocabularyOf(registry.index.products, product),
|
|
399
|
+
hint: "Nothing matched the product's own words strongly (best term score " +
|
|
400
|
+
`${top_matched.toFixed(1)}). The results below may not answer the ` +
|
|
401
|
+
"question. Re-search using a term from suggested_vocabulary, or call " +
|
|
402
|
+
"describeEntity on the closest entity for its full vocabulary.",
|
|
403
|
+
}
|
|
404
|
+
: {}),
|
|
258
405
|
});
|
|
259
406
|
});
|
|
260
|
-
tools.
|
|
261
|
-
"
|
|
262
|
-
"
|
|
263
|
-
"
|
|
264
|
-
"
|
|
265
|
-
"
|
|
266
|
-
"
|
|
267
|
-
"
|
|
268
|
-
"
|
|
269
|
-
"
|
|
407
|
+
tools.describeCapability = server.tool("describeCapability", "The full contract for ONE capability you picked from searchCapability: its " +
|
|
408
|
+
"parameters grouped into path_params / query / body under the spec's own names, " +
|
|
409
|
+
"what it returns, and its declared response shapes fully expanded. Call this after " +
|
|
410
|
+
"search and before invokeCapability — search deliberately omits all of it, because " +
|
|
411
|
+
"it is only needed for the one capability you actually call. " +
|
|
412
|
+
"Identify it by `name`, exactly as search returned it; only when a result carries " +
|
|
413
|
+
"no `name` (some products publish none yet) pass `method` and `path` instead. " +
|
|
414
|
+
"Every parameter lists its type, whether it is required, its allowed values where " +
|
|
415
|
+
"the set is closed, and any limits the product declares — obey those before calling " +
|
|
416
|
+
"rather than discovering them from a rejected request.", {
|
|
417
|
+
name: z
|
|
418
|
+
.string()
|
|
419
|
+
.optional()
|
|
420
|
+
.describe("The capability's published name, exactly as searchCapability returned it."),
|
|
421
|
+
method: z
|
|
422
|
+
.string()
|
|
423
|
+
.optional()
|
|
424
|
+
.describe("HTTP method — only for capabilities returned without a `name`."),
|
|
425
|
+
path: z
|
|
426
|
+
.string()
|
|
427
|
+
.optional()
|
|
428
|
+
.describe("Path with {placeholders} intact — only for capabilities returned without a `name`."),
|
|
429
|
+
product: productArg()
|
|
430
|
+
.optional()
|
|
431
|
+
.describe(`Which product owns it (${productList}). searchCapability returns it on every ` +
|
|
432
|
+
"result; required only when two products share a name or a path."),
|
|
433
|
+
include_responses: z
|
|
434
|
+
.enum(["success", "all", "none"])
|
|
435
|
+
.optional()
|
|
436
|
+
.describe("Which declared responses to expand: 'success' (default, the 2xx shape), 'all' " +
|
|
437
|
+
"(adds the error shapes — several times larger, and near-identical across " +
|
|
438
|
+
"endpoints), or 'none'."),
|
|
439
|
+
}, {
|
|
440
|
+
title: "Describe Capability",
|
|
441
|
+
readOnlyHint: true,
|
|
442
|
+
destructiveHint: false,
|
|
443
|
+
idempotentHint: true,
|
|
444
|
+
openWorldHint: false,
|
|
445
|
+
}, async (input) => {
|
|
446
|
+
track("describeCapability");
|
|
447
|
+
try {
|
|
448
|
+
// The same two handles as invokeCapability, resolved the same way, so a name that
|
|
449
|
+
// describes is a name that invokes. Divergence here would be its own bug class.
|
|
450
|
+
if (!input.name && !(input.method && input.path)) {
|
|
451
|
+
return failed("pass `name` — or, for a capability returned without one, both `method` and " +
|
|
452
|
+
"`path`, exactly as searchCapability returned them");
|
|
453
|
+
}
|
|
454
|
+
const { product: owner, capability } = input.name
|
|
455
|
+
? registry.byNameLookup(input.name, input.product)
|
|
456
|
+
: registry.byEndpointLookup(input.method, input.path, input.product);
|
|
457
|
+
const selection = (input.include_responses ||
|
|
458
|
+
"success");
|
|
459
|
+
const responses = resolveResponses(registry.index.products[owner], capability, selection);
|
|
460
|
+
// Dropped rather than overwritten: the raw field holds `{"$response": …}` pointers,
|
|
461
|
+
// and spreading the capability would leak them through whenever the resolved value
|
|
462
|
+
// is absent.
|
|
463
|
+
const { responses: unresolved, method, path, ...contract } = capability;
|
|
464
|
+
void unresolved;
|
|
465
|
+
return ok({
|
|
466
|
+
// No build_id here either, same reason. `product` stays: describeCapability
|
|
467
|
+
// resolves by NAME and its product argument is optional, so the answer has to
|
|
468
|
+
// say whose contract came back.
|
|
469
|
+
product: owner,
|
|
470
|
+
// NO ROUTE, for the same reason the shortlist has none. A named capability is
|
|
471
|
+
// invoked by its name; the route is how WE reach the product, not something
|
|
472
|
+
// the caller acts on, and a contract that shows both invites the caller to
|
|
473
|
+
// hold the half that breaks when `/edit` becomes `/edit-v2`. The parameters
|
|
474
|
+
// below still carry `path_params`, so the caller knows what to supply — it
|
|
475
|
+
// just never sees the template they are substituted into.
|
|
476
|
+
//
|
|
477
|
+
// Emitted only when there is no name to use instead, which is what
|
|
478
|
+
// invokeCapability falls back to for a product that publishes none. No shipped
|
|
479
|
+
// product is in that state today.
|
|
480
|
+
...(capability.name ? {} : { method, path }),
|
|
481
|
+
...contract,
|
|
482
|
+
...(responses ? { responses } : {}),
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
catch (error) {
|
|
486
|
+
if (error instanceof InvocationError)
|
|
487
|
+
return failed(error.message);
|
|
488
|
+
logger.error("describeCapability failed: %s", error instanceof Error ? error.message : String(error));
|
|
489
|
+
return failed("that capability could not be described");
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
tools.invokeCapability = server.tool("invokeCapability", "Call a capability whose contract you have from describeCapability. Pass `name` exactly " +
|
|
493
|
+
"as given — that is the handle. Only when a result carries no `name` (some products " +
|
|
494
|
+
"do not publish them yet) pass `method` and `path` instead, exactly as returned. " +
|
|
495
|
+
"Arguments go in path_params / query / body under the spec's own names. One call " +
|
|
496
|
+
"makes exactly one request and returns the product's own response untouched; when " +
|
|
497
|
+
"`completed` is false there is another page, which you fetch by sending the " +
|
|
498
|
+
"capability's own page parameter. If the mode is 'write' you MUST ask the user " +
|
|
499
|
+
"first, then resend with user_permission='granted' and a change_summary; both are " +
|
|
500
|
+
"recorded. Capabilities whose mode is 'destructive' (deletes) are refused outright — " +
|
|
501
|
+
"archiving, closing and merging are ordinary writes and DO run, so read the mode and " +
|
|
502
|
+
"intent before confirming with the user.", {
|
|
503
|
+
name: z
|
|
504
|
+
.string()
|
|
505
|
+
.optional()
|
|
506
|
+
.describe("The capability's published name, exactly as returned (e.g. 'create_test_run_v1'). " +
|
|
507
|
+
"Preferred over method/path."),
|
|
270
508
|
method: z
|
|
271
509
|
.string()
|
|
272
|
-
.
|
|
510
|
+
.optional()
|
|
511
|
+
.describe("HTTP method — only for capabilities returned without a `name`."),
|
|
273
512
|
path: z
|
|
274
513
|
.string()
|
|
275
|
-
.
|
|
514
|
+
.optional()
|
|
515
|
+
.describe("Path with {placeholders} intact — only for capabilities returned without a `name`."),
|
|
276
516
|
path_params: z
|
|
277
517
|
.record(z.string(), z.any())
|
|
278
518
|
.optional()
|
|
@@ -287,8 +527,8 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
287
527
|
.describe("Body fields, under the spec's names."),
|
|
288
528
|
product: productArg()
|
|
289
529
|
.optional()
|
|
290
|
-
.describe(`Which product owns the
|
|
291
|
-
"on every result; required only when two products share a path."),
|
|
530
|
+
.describe(`Which product owns the capability (${productList}). searchCapability returns it ` +
|
|
531
|
+
"on every result; required only when two products share a name or a path."),
|
|
292
532
|
user_permission: z
|
|
293
533
|
.enum(PERMISSION_VALUES)
|
|
294
534
|
.optional()
|
|
@@ -298,7 +538,7 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
298
538
|
.optional()
|
|
299
539
|
.describe("What will change. Required for writes."),
|
|
300
540
|
}, {
|
|
301
|
-
title: "Invoke
|
|
541
|
+
title: "Invoke Capability",
|
|
302
542
|
// Not read-only: this is the one tool that writes. Never destructive, because
|
|
303
543
|
// destructive endpoints are refused before binding — the refusal is enforced here,
|
|
304
544
|
// not merely hinted at. Not idempotent: it creates, clones and starts runs. Closed
|
|
@@ -308,9 +548,20 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
308
548
|
idempotentHint: false,
|
|
309
549
|
openWorldHint: false,
|
|
310
550
|
}, async (input) => {
|
|
311
|
-
track("
|
|
551
|
+
track("invokeCapability");
|
|
312
552
|
try {
|
|
313
|
-
|
|
553
|
+
// Either handle resolves to the same capability. `name` wins when both are sent,
|
|
554
|
+
// rather than cross-checking them: a caller pasting a stale path alongside a good
|
|
555
|
+
// name should still reach the right operation, which is the point of naming.
|
|
556
|
+
if (!input.name && !(input.method && input.path)) {
|
|
557
|
+
return failed("pass `name` — or, for a capability returned without one, both `method` and " +
|
|
558
|
+
"`path`, exactly as searchCapability returned them");
|
|
559
|
+
}
|
|
560
|
+
const { product, capability } = input.name
|
|
561
|
+
? registry.byNameLookup(input.name, input.product)
|
|
562
|
+
: registry.byEndpointLookup(input.method, input.path, input.product);
|
|
563
|
+
/** What to call it in errors — the handle the caller actually used. */
|
|
564
|
+
const handle = capability.name || `${capability.method} ${capability.path}`;
|
|
314
565
|
const args = {
|
|
315
566
|
path_params: input.path_params,
|
|
316
567
|
query: input.query,
|
|
@@ -318,8 +569,7 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
318
569
|
};
|
|
319
570
|
if (capability.mode === "destructive") {
|
|
320
571
|
// Refused before binding, so consent is never sought for something that cannot run.
|
|
321
|
-
return failed(`${
|
|
322
|
-
`through this surface`);
|
|
572
|
+
return failed(`${handle} is a destructive operation and is not available through this surface`);
|
|
323
573
|
}
|
|
324
574
|
if (capability.mode === "write") {
|
|
325
575
|
const permission = input.user_permission || "not_asked";
|
|
@@ -345,8 +595,8 @@ export function addCapabilityRegistryTools(server, deps, config) {
|
|
|
345
595
|
catch (error) {
|
|
346
596
|
if (error instanceof InvocationError)
|
|
347
597
|
return failed(error.message);
|
|
348
|
-
logger.error("
|
|
349
|
-
return failed("that
|
|
598
|
+
logger.error("invokeCapability failed: %s", error instanceof Error ? error.message : String(error));
|
|
599
|
+
return failed("that capability could not be invoked");
|
|
350
600
|
}
|
|
351
601
|
});
|
|
352
602
|
return tools;
|