dsh-skill-pool 0.3.7 → 0.4.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/src/inventory.js CHANGED
@@ -17,7 +17,7 @@
17
17
  import { join } from 'node:path'
18
18
 
19
19
  import { listLibrarySkills } from './library.js'
20
- import { MCP_TOOL_PREFIX, effectiveEnabled, effectiveScope, groupKeyOfSource, mcpServerOf } from './rules.js'
20
+ import { isAmbiguousMcpToolName, MCP_TOOL_PREFIX, effectiveEnabled, effectiveScope, groupKeyOfSource, mcpServerOf } from './rules.js'
21
21
  import { mcpEntryId } from './uploads.js'
22
22
 
23
23
  /** Provider name the library provider registers under (must match §3). */
@@ -220,6 +220,9 @@ export function collectMcpServers(ctx) {
220
220
  for (const schema of tools.schemas()) {
221
221
  const name = schema?.name
222
222
  if (typeof name !== 'string' || !name.startsWith(MCP_TOOL_PREFIX)) continue
223
+ // An ambiguous public name cannot be attributed to a server safely; the
224
+ // activation layer denies it, so showing it under a prefix would mislead.
225
+ if (isAmbiguousMcpToolName(name)) continue
223
226
  const server = mcpServerOf(name)
224
227
  if (server.length === 0) continue
225
228
  ensure(server).tools.push(name)
@@ -289,6 +292,8 @@ function mcpRows(ctx, state) {
289
292
  const live = byName.get(server)
290
293
  rows.push({
291
294
  server,
295
+ // The connection definition (URL/command/headers/env) never enters the
296
+ // inventory.
292
297
  tools: Array.isArray(live?.tools) ? [...live.tools] : [],
293
298
  managed: live?.managed === true,
294
299
  entryId: live?.entryId !== undefined && live.entryId.length > 0 ? live.entryId : mcpEntryId(server),
package/src/mount.js CHANGED
@@ -9,7 +9,8 @@
9
9
  * @module dsh-skill-pool/mount
10
10
  */
11
11
 
12
- import { serverToolPrefix, upsertMcpServer } from './uploads.js'
12
+ import { isAmbiguousMcpToolName, mcpServerOf } from './rules.js'
13
+ import { upsertMcpServer } from './uploads.js'
13
14
 
14
15
  /** Default readiness window for one MCP mount (§6: 20s). */
15
16
  export const DEFAULT_PROBE_TIMEOUT_MS = 20_000
@@ -26,10 +27,14 @@ export const DEFAULT_PROBE_INTERVAL_MS = 500
26
27
  export function hasServerTools(ctx, serverName) {
27
28
  const tools = ctx.get('tools')
28
29
  if (tools === undefined || typeof tools.schemas !== 'function') return false
29
- const prefix = serverToolPrefix(serverName)
30
- if (prefix.length === 0) return false
31
30
  try {
32
- return tools.schemas().some((schema) => typeof schema?.name === 'string' && schema.name.startsWith(prefix))
31
+ return tools.schemas().some((schema) => {
32
+ const name = schema?.name
33
+ if (typeof name !== 'string' || !name.startsWith('mcp__')) return false
34
+ // A name that cannot be attributed to exactly one server must not make
35
+ // another server look ready (e.g. `mcp__a___b` from server `a_`).
36
+ return !isAmbiguousMcpToolName(name) && mcpServerOf(name) === serverName
37
+ })
33
38
  } catch {
34
39
  return false
35
40
  }
package/src/rules.js CHANGED
@@ -229,6 +229,35 @@ export function resolvePool(state, { mode, cwd, allModes, allWorkspaces } = {})
229
229
  }
230
230
  }
231
231
 
232
+ /**
233
+ * Whether an MCP public tool name has more than one plausible server split.
234
+ *
235
+ * The public name is `mcp__<server>__<raw>`, and neither `server` nor `raw` is
236
+ * prevented from containing `__`. Parsing at the first separator can therefore
237
+ * attribute an external `alpha__a` tool to an allowed `alpha` server. Callers
238
+ * use this predicate to deny an ambiguous name instead of allowing it by
239
+ * prefix. This is deliberately conservative: a legitimate raw name containing
240
+ * `__` is hidden too.
241
+ *
242
+ * @param {unknown} toolName - model-facing tool name.
243
+ * @returns {boolean} whether the server boundary is ambiguous (or malformed).
244
+ */
245
+ export function isAmbiguousMcpToolName(toolName) {
246
+ if (typeof toolName !== 'string' || !toolName.startsWith(MCP_TOOL_PREFIX)) return false
247
+ // A 12-hex suffix is the host's lossy-normalization/truncation marker. Such a
248
+ // name may have lost a server separator, so it cannot be prefix-allowed.
249
+ if (/_[0-9a-f]{12}$/.test(toolName)) return true
250
+ const rest = toolName.slice(MCP_TOOL_PREFIX.length)
251
+ // Every position that can split rest into non-empty server + non-empty raw.
252
+ // Overlapping separators matter: `a___b` can split as (`a`, `_b`) or
253
+ // (`a_`, `b`), so `indexOf('__', first + 2)` is not enough.
254
+ const splits = []
255
+ for (let index = 1; index + 2 < rest.length; index += 1) {
256
+ if (rest[index] === '_' && rest[index + 1] === '_') splits.push(index)
257
+ }
258
+ return splits.length !== 1
259
+ }
260
+
232
261
  /**
233
262
  * Parse the MCP Server name out of one public tool name.
234
263
  * @param {unknown} toolName - model-facing tool name such as `mcp__qcc__search`.