dsh-project-mcp 0.4.3 → 0.5.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/README.md +9 -1
- package/lib/index.d.ts +38 -7
- package/lib/index.js +35 -5
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
- package/src/guidance.ts +42 -4
- package/src/parse.ts +9 -0
- package/src/runtime.ts +20 -6
package/README.md
CHANGED
|
@@ -460,6 +460,12 @@ the offered names**, the rest are not registered at all, and `mcp_search_tools`
|
|
|
460
460
|
is what makes one callable from the next step. The guidance says so in the same
|
|
461
461
|
words — its names line promises an exact-name call only where the tool is still
|
|
462
462
|
registered — and the per-session panel keeps reporting both tiers either way.
|
|
463
|
+
Both lines are also judged against the step's own admission: `systemPrompt`
|
|
464
|
+
hands a section the context its step was prepared with, including the `toolSet`
|
|
465
|
+
`ctx.tools.resolve()` froze, and a tool registered between that snapshot and the
|
|
466
|
+
prompt assembly (a server that just connected) is named by the registry but not
|
|
467
|
+
callable in that step — so the section leaves it out rather than promising a
|
|
468
|
+
call that would answer `unknown tool`.
|
|
463
469
|
The first request of a session is always the wide one: the route is learned on
|
|
464
470
|
the first step, and the pass that follows trims the layer.
|
|
465
471
|
|
|
@@ -526,7 +532,9 @@ description and parameters.
|
|
|
526
532
|
probing blindly. The line also states the direct-call contract — deferral
|
|
527
533
|
trims the assembled request list, it never unregisters the tool, so a call by
|
|
528
534
|
the exact full name `mcp__<server>__<tool>` still executes; searching first
|
|
529
|
-
is how the model sees the description and parameters, not a gate.
|
|
535
|
+
is how the model sees the description and parameters, not a gate. A name the
|
|
536
|
+
step did not admit is not listed at all, so the line never promises more than
|
|
537
|
+
the step's own tool set can answer.
|
|
530
538
|
- **A most-used line from the durable counters.** When the seeded baseline is
|
|
531
539
|
non-empty, the section names the project's hot tools (most-called first, up
|
|
532
540
|
to four names with `+N more`) and says they are offered from the first step
|
package/lib/index.d.ts
CHANGED
|
@@ -2917,9 +2917,17 @@ export declare class ProjectMcpRuntime {
|
|
|
2917
2917
|
*
|
|
2918
2918
|
* It reads the mount records and the registry at every assembly, so a rescan
|
|
2919
2919
|
* that mounted or dropped a server — and a search that activated a tool — are
|
|
2920
|
-
* reflected without re-registering the section.
|
|
2921
|
-
*
|
|
2922
|
-
*
|
|
2920
|
+
* reflected without re-registering the section. The assembly's own admission
|
|
2921
|
+
* snapshot is authoritative when it is present: a tool registered after the
|
|
2922
|
+
* step was prepared is already named by the registry but cannot be called in
|
|
2923
|
+
* that step, so the text does not promise it ({@link admittedNames}). Total:
|
|
2924
|
+
* any failure returns the empty string, because a section that throws would
|
|
2925
|
+
* fail the model request that asked for the assembly.
|
|
2926
|
+
*
|
|
2927
|
+
* @param agent - session whose scope the section belongs to.
|
|
2928
|
+
* @param state - the session's live state.
|
|
2929
|
+
* @param assembly - the assembly context, when the host hands one.
|
|
2930
|
+
* @returns the section text, or `''` when there is nothing true to say.
|
|
2923
2931
|
*/
|
|
2924
2932
|
private guidanceText;
|
|
2925
2933
|
/**
|
|
@@ -3446,8 +3454,27 @@ interface GuidanceSectionLike {
|
|
|
3446
3454
|
readonly order: number;
|
|
3447
3455
|
/** `false` preserves literal text; this section carries no variables. */
|
|
3448
3456
|
readonly interpolate?: boolean;
|
|
3449
|
-
/** Text, or a provider evaluated at each assembly. */
|
|
3450
|
-
readonly text: string | (() => string);
|
|
3457
|
+
/** Text, or a provider evaluated at each assembly with that assembly's context. */
|
|
3458
|
+
readonly text: string | ((assembly?: GuidanceAssemblyLike) => string);
|
|
3459
|
+
}
|
|
3460
|
+
/**
|
|
3461
|
+
* The assembly-context slice this wiring reads: the step's frozen tool
|
|
3462
|
+
* admission.
|
|
3463
|
+
*
|
|
3464
|
+
* `systemPrompt.assemble()` hands sections the same context the step was
|
|
3465
|
+
* prepared with, including the `toolSet` that `ctx.tools.resolve()` produced —
|
|
3466
|
+
* the definitions admitted for *this* step. Naming a tool in the guidance text
|
|
3467
|
+
* while it is absent from that snapshot is the one way the section can promise
|
|
3468
|
+
* a call that answers `unknown tool`, so the text is filtered against it.
|
|
3469
|
+
* Declared structurally, like every other harness type in this module.
|
|
3470
|
+
*/
|
|
3471
|
+
interface GuidanceAssemblyLike {
|
|
3472
|
+
/** Scope whose providers participate; `toolSet.view()` admits only this exact key. */
|
|
3473
|
+
readonly scope?: unknown;
|
|
3474
|
+
/** Step-owned admission; absent on an older host or a bare test stub. */
|
|
3475
|
+
readonly toolSet?: {
|
|
3476
|
+
view(scope: unknown): ReadonlyMap<string, unknown>;
|
|
3477
|
+
};
|
|
3451
3478
|
}
|
|
3452
3479
|
/** The `systemPrompt` slice the wiring reads (structural view). */
|
|
3453
3480
|
interface GuidancePromptLike {
|
|
@@ -3487,8 +3514,12 @@ interface GuidanceContextLike {
|
|
|
3487
3514
|
interface GuidanceWiringOptions {
|
|
3488
3515
|
/** Agent-scoped context; the section lives here. */
|
|
3489
3516
|
readonly ctx: GuidanceContextLike;
|
|
3490
|
-
/**
|
|
3491
|
-
|
|
3517
|
+
/**
|
|
3518
|
+
* Live section text; called at every assembly, so it may read changing state.
|
|
3519
|
+
* The assembly context is passed through, so the text can judge its promises
|
|
3520
|
+
* against that step's admission ({@link admittedNames}).
|
|
3521
|
+
*/
|
|
3522
|
+
readonly text: (assembly?: GuidanceAssemblyLike) => string;
|
|
3492
3523
|
/** Section name override; defaults to {@link GUIDANCE_SECTION_NAME}. */
|
|
3493
3524
|
readonly name?: string;
|
|
3494
3525
|
/** Sink for a contained failure of this plugin's own work. */
|
package/lib/index.js
CHANGED
|
@@ -1167,6 +1167,8 @@ const REFERENCE_PATTERN = /\$\{([^}]+)\}/g;
|
|
|
1167
1167
|
const INPUT_PREFIX = "input:";
|
|
1168
1168
|
/** Maximum length of a generated `serverName`. */
|
|
1169
1169
|
const MAX_SERVER_NAME_LENGTH$1 = 32;
|
|
1170
|
+
/** `closeTimeoutMs` of a resolved mcp-client config; the client's own schema default, never overridden here. */
|
|
1171
|
+
const MCP_CLOSE_TIMEOUT_MS = 5e3;
|
|
1170
1172
|
/** Expand every `${...}` reference inside `value`. */
|
|
1171
1173
|
function expandValue(value, ctx) {
|
|
1172
1174
|
const whole = WHOLE_REF_PATTERN.exec(value);
|
|
@@ -1449,6 +1451,8 @@ function buildStdioEntry(name, record, source, ctx, issues, enabled) {
|
|
|
1449
1451
|
env: expandedEnv.value,
|
|
1450
1452
|
cwd: expandedCwd.value,
|
|
1451
1453
|
toolCallTimeoutMs: ctx.toolCallTimeoutMs,
|
|
1454
|
+
closeTimeoutMs: MCP_CLOSE_TIMEOUT_MS,
|
|
1455
|
+
expandTemplates: false,
|
|
1452
1456
|
failOnStartupError: ctx.failOnStartupError
|
|
1453
1457
|
}
|
|
1454
1458
|
};
|
|
@@ -1472,6 +1476,8 @@ function buildHttpEntry(name, record, source, ctx, issues, enabled) {
|
|
|
1472
1476
|
url: expandedUrl.value,
|
|
1473
1477
|
headers: expandedHeaders.value,
|
|
1474
1478
|
toolCallTimeoutMs: ctx.toolCallTimeoutMs,
|
|
1479
|
+
closeTimeoutMs: MCP_CLOSE_TIMEOUT_MS,
|
|
1480
|
+
expandTemplates: false,
|
|
1475
1481
|
failOnStartupError: ctx.failOnStartupError
|
|
1476
1482
|
}
|
|
1477
1483
|
};
|
|
@@ -1915,6 +1921,19 @@ function projectLabel(projectRoot, home) {
|
|
|
1915
1921
|
return index === -1 ? root : root.slice(index + 1);
|
|
1916
1922
|
}
|
|
1917
1923
|
/**
|
|
1924
|
+
* The public tool names this step's admission actually carries.
|
|
1925
|
+
*
|
|
1926
|
+
* @param assembly - the section's assembly context, when the host hands one.
|
|
1927
|
+
* @returns the admitted names, or `undefined` when there is no snapshot to
|
|
1928
|
+
* judge by — then nothing is filtered and the text is built from live state.
|
|
1929
|
+
*/
|
|
1930
|
+
function admittedNames(assembly) {
|
|
1931
|
+
const set = assembly?.toolSet;
|
|
1932
|
+
const scope = assembly?.scope;
|
|
1933
|
+
if (set === void 0 || scope === void 0) return void 0;
|
|
1934
|
+
return new Set(set.view(scope).keys());
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1918
1937
|
* Register the guidance section on one agent scope.
|
|
1919
1938
|
*
|
|
1920
1939
|
* The section goes in through `ctx.inject(['systemPrompt'], …)`, so the scope
|
|
@@ -5826,7 +5845,7 @@ var ProjectMcpRuntime = class {
|
|
|
5826
5845
|
if (this.config.guidanceEnabled ?? true) try {
|
|
5827
5846
|
state.guidanceDispose = installGuidance({
|
|
5828
5847
|
ctx: scope.ctx,
|
|
5829
|
-
text: () => this.guidanceText(agent, state),
|
|
5848
|
+
text: (assembly) => this.guidanceText(agent, state, assembly),
|
|
5830
5849
|
onError: (error) => {
|
|
5831
5850
|
this.ctx.logger.warn(`project-mcp: guidance section failed for session ${agent.id}: ${errorText(error)}`);
|
|
5832
5851
|
}
|
|
@@ -5996,14 +6015,23 @@ var ProjectMcpRuntime = class {
|
|
|
5996
6015
|
*
|
|
5997
6016
|
* It reads the mount records and the registry at every assembly, so a rescan
|
|
5998
6017
|
* that mounted or dropped a server — and a search that activated a tool — are
|
|
5999
|
-
* reflected without re-registering the section.
|
|
6000
|
-
*
|
|
6001
|
-
*
|
|
6018
|
+
* reflected without re-registering the section. The assembly's own admission
|
|
6019
|
+
* snapshot is authoritative when it is present: a tool registered after the
|
|
6020
|
+
* step was prepared is already named by the registry but cannot be called in
|
|
6021
|
+
* that step, so the text does not promise it ({@link admittedNames}). Total:
|
|
6022
|
+
* any failure returns the empty string, because a section that throws would
|
|
6023
|
+
* fail the model request that asked for the assembly.
|
|
6024
|
+
*
|
|
6025
|
+
* @param agent - session whose scope the section belongs to.
|
|
6026
|
+
* @param state - the session's live state.
|
|
6027
|
+
* @param assembly - the assembly context, when the host hands one.
|
|
6028
|
+
* @returns the section text, or `''` when there is nothing true to say.
|
|
6002
6029
|
*/
|
|
6003
|
-
guidanceText(agent, state) {
|
|
6030
|
+
guidanceText(agent, state, assembly) {
|
|
6004
6031
|
try {
|
|
6005
6032
|
const projectRoot = state.projectRoot;
|
|
6006
6033
|
if (projectRoot === void 0 || this.mountsOf(state).size === 0) return "";
|
|
6034
|
+
const admitted = admittedNames(assembly);
|
|
6007
6035
|
const activationEnabled = this.config.activationEnabled ?? true;
|
|
6008
6036
|
const presented = activationEnabled ? presentedNames(this.seedActivation(state)) : void 0;
|
|
6009
6037
|
const mounted = new Set([...this.mountsOf(state).values()].map((mount) => mount.runtimeName));
|
|
@@ -6011,6 +6039,7 @@ var ProjectMcpRuntime = class {
|
|
|
6011
6039
|
const offered = [];
|
|
6012
6040
|
const deferred = [];
|
|
6013
6041
|
for (const schema of this.mountedSchemas(state)) {
|
|
6042
|
+
if (admitted !== void 0 && !admitted.has(schema.name)) continue;
|
|
6014
6043
|
const server = matchServer(schema.name, mounted);
|
|
6015
6044
|
if (server === void 0) continue;
|
|
6016
6045
|
const name = schema.name.slice(`mcp__${server}__`.length);
|
|
@@ -6028,6 +6057,7 @@ var ProjectMcpRuntime = class {
|
|
|
6028
6057
|
}));
|
|
6029
6058
|
const mostUsed = [];
|
|
6030
6059
|
if (activationEnabled) for (const fullName of this.seedActivation(state).baseline) {
|
|
6060
|
+
if (admitted !== void 0 && !admitted.has(fullName)) continue;
|
|
6031
6061
|
const server = matchServer(fullName, mounted);
|
|
6032
6062
|
if (server !== void 0) mostUsed.push(fullName.slice(`mcp__${server}__`.length));
|
|
6033
6063
|
}
|