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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-project-mcp",
|
|
3
3
|
"description": "Per-project MCP servers for DeepSeek Harness: mounts the MCP servers a project declares into the sessions working in it",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -86,10 +86,10 @@
|
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
|
-
"@deepseek-ai/cordis": "4.0
|
|
90
|
-
"@deepseek-ai/dsh-mcp-client": "0.2.2-
|
|
91
|
-
"@deepseek-ai/dsh-scope": "0.2.
|
|
92
|
-
"@deepseek-ai/dsh-tools": "0.2.
|
|
89
|
+
"@deepseek-ai/cordis": "4.1.0",
|
|
90
|
+
"@deepseek-ai/dsh-mcp-client": "0.2.2-rc.4",
|
|
91
|
+
"@deepseek-ai/dsh-scope": "0.2.2-rc.4",
|
|
92
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.4",
|
|
93
93
|
"@types/node": "^22.20.4",
|
|
94
94
|
"@types/react": "^18.3.31",
|
|
95
95
|
"@vitest/coverage-v8": "^5.0.2",
|
package/src/guidance.ts
CHANGED
|
@@ -200,8 +200,42 @@ export interface GuidanceSectionLike {
|
|
|
200
200
|
readonly order: number
|
|
201
201
|
/** `false` preserves literal text; this section carries no variables. */
|
|
202
202
|
readonly interpolate?: boolean
|
|
203
|
-
/** Text, or a provider evaluated at each assembly. */
|
|
204
|
-
readonly text: string | (() => string)
|
|
203
|
+
/** Text, or a provider evaluated at each assembly with that assembly's context. */
|
|
204
|
+
readonly text: string | ((assembly?: GuidanceAssemblyLike) => string)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* The assembly-context slice this wiring reads: the step's frozen tool
|
|
209
|
+
* admission.
|
|
210
|
+
*
|
|
211
|
+
* `systemPrompt.assemble()` hands sections the same context the step was
|
|
212
|
+
* prepared with, including the `toolSet` that `ctx.tools.resolve()` produced —
|
|
213
|
+
* the definitions admitted for *this* step. Naming a tool in the guidance text
|
|
214
|
+
* while it is absent from that snapshot is the one way the section can promise
|
|
215
|
+
* a call that answers `unknown tool`, so the text is filtered against it.
|
|
216
|
+
* Declared structurally, like every other harness type in this module.
|
|
217
|
+
*/
|
|
218
|
+
export interface GuidanceAssemblyLike {
|
|
219
|
+
/** Scope whose providers participate; `toolSet.view()` admits only this exact key. */
|
|
220
|
+
readonly scope?: unknown
|
|
221
|
+
/** Step-owned admission; absent on an older host or a bare test stub. */
|
|
222
|
+
readonly toolSet?: { view(scope: unknown): ReadonlyMap<string, unknown> }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The public tool names this step's admission actually carries.
|
|
227
|
+
*
|
|
228
|
+
* @param assembly - the section's assembly context, when the host hands one.
|
|
229
|
+
* @returns the admitted names, or `undefined` when there is no snapshot to
|
|
230
|
+
* judge by — then nothing is filtered and the text is built from live state.
|
|
231
|
+
*/
|
|
232
|
+
export function admittedNames(assembly?: GuidanceAssemblyLike): ReadonlySet<string> | undefined {
|
|
233
|
+
const set = assembly?.toolSet
|
|
234
|
+
const scope = assembly?.scope
|
|
235
|
+
// `ResolvedToolSet.view()` admits only the exact requesting agent, so an
|
|
236
|
+
// assembly without its own scope has no admission this text may compare to.
|
|
237
|
+
if (set === undefined || scope === undefined) return undefined
|
|
238
|
+
return new Set(set.view(scope).keys())
|
|
205
239
|
}
|
|
206
240
|
|
|
207
241
|
/** The `systemPrompt` slice the wiring reads (structural view). */
|
|
@@ -245,8 +279,12 @@ export interface GuidanceContextLike {
|
|
|
245
279
|
export interface GuidanceWiringOptions {
|
|
246
280
|
/** Agent-scoped context; the section lives here. */
|
|
247
281
|
readonly ctx: GuidanceContextLike
|
|
248
|
-
/**
|
|
249
|
-
|
|
282
|
+
/**
|
|
283
|
+
* Live section text; called at every assembly, so it may read changing state.
|
|
284
|
+
* The assembly context is passed through, so the text can judge its promises
|
|
285
|
+
* against that step's admission ({@link admittedNames}).
|
|
286
|
+
*/
|
|
287
|
+
readonly text: (assembly?: GuidanceAssemblyLike) => string
|
|
250
288
|
/** Section name override; defaults to {@link GUIDANCE_SECTION_NAME}. */
|
|
251
289
|
readonly name?: string
|
|
252
290
|
/** Sink for a contained failure of this plugin's own work. */
|
package/src/parse.ts
CHANGED
|
@@ -38,6 +38,9 @@ const INPUT_PREFIX = 'input:'
|
|
|
38
38
|
/** Maximum length of a generated `serverName`. */
|
|
39
39
|
const MAX_SERVER_NAME_LENGTH = 32
|
|
40
40
|
|
|
41
|
+
/** `closeTimeoutMs` of a resolved mcp-client config; the client's own schema default, never overridden here. */
|
|
42
|
+
const MCP_CLOSE_TIMEOUT_MS = 5000
|
|
43
|
+
|
|
41
44
|
/** Severity of a parse diagnostic. */
|
|
42
45
|
export type IssueLevel = 'error' | 'warning'
|
|
43
46
|
|
|
@@ -436,6 +439,10 @@ function buildStdioEntry(
|
|
|
436
439
|
env: expandedEnv.value,
|
|
437
440
|
cwd: expandedCwd.value,
|
|
438
441
|
toolCallTimeoutMs: ctx.toolCallTimeoutMs,
|
|
442
|
+
closeTimeoutMs: MCP_CLOSE_TIMEOUT_MS,
|
|
443
|
+
// This parser expands `${input:…}` itself and hands literals to the
|
|
444
|
+
// client, so the client's own `${credential:…}` templates stay off.
|
|
445
|
+
expandTemplates: false,
|
|
439
446
|
failOnStartupError: ctx.failOnStartupError,
|
|
440
447
|
},
|
|
441
448
|
}
|
|
@@ -471,6 +478,8 @@ function buildHttpEntry(
|
|
|
471
478
|
url: expandedUrl.value,
|
|
472
479
|
headers: expandedHeaders.value,
|
|
473
480
|
toolCallTimeoutMs: ctx.toolCallTimeoutMs,
|
|
481
|
+
closeTimeoutMs: MCP_CLOSE_TIMEOUT_MS,
|
|
482
|
+
expandTemplates: false,
|
|
474
483
|
failOnStartupError: ctx.failOnStartupError,
|
|
475
484
|
},
|
|
476
485
|
}
|
package/src/runtime.ts
CHANGED
|
@@ -64,11 +64,12 @@ import {
|
|
|
64
64
|
} from './discovery.ts'
|
|
65
65
|
import {
|
|
66
66
|
DEFAULT_GUIDANCE_ENABLED,
|
|
67
|
+
admittedNames,
|
|
67
68
|
buildGuidance,
|
|
68
69
|
installGuidance,
|
|
69
70
|
projectLabel,
|
|
70
71
|
} from './guidance.ts'
|
|
71
|
-
import type { GuidanceContextLike, GuidanceServer } from './guidance.ts'
|
|
72
|
+
import type { GuidanceAssemblyLike, GuidanceContextLike, GuidanceServer } from './guidance.ts'
|
|
72
73
|
// The volatile key list lives at the entry (`src/index.ts`) because the schema
|
|
73
74
|
// declares it; the import cycles back here, but it is read only inside
|
|
74
75
|
// `applyLiveConfig`, long after both modules finished evaluating.
|
|
@@ -3256,7 +3257,7 @@ export class ProjectMcpRuntime {
|
|
|
3256
3257
|
try {
|
|
3257
3258
|
state.guidanceDispose = installGuidance({
|
|
3258
3259
|
ctx: scope.ctx as unknown as GuidanceContextLike,
|
|
3259
|
-
text: () => this.guidanceText(agent, state),
|
|
3260
|
+
text: (assembly) => this.guidanceText(agent, state, assembly),
|
|
3260
3261
|
onError: (error) => {
|
|
3261
3262
|
this.ctx.logger.warn(
|
|
3262
3263
|
`project-mcp: guidance section failed for session ${agent.id}: ${errorText(error)}`,
|
|
@@ -3477,14 +3478,25 @@ export class ProjectMcpRuntime {
|
|
|
3477
3478
|
*
|
|
3478
3479
|
* It reads the mount records and the registry at every assembly, so a rescan
|
|
3479
3480
|
* that mounted or dropped a server — and a search that activated a tool — are
|
|
3480
|
-
* reflected without re-registering the section.
|
|
3481
|
-
*
|
|
3482
|
-
*
|
|
3481
|
+
* reflected without re-registering the section. The assembly's own admission
|
|
3482
|
+
* snapshot is authoritative when it is present: a tool registered after the
|
|
3483
|
+
* step was prepared is already named by the registry but cannot be called in
|
|
3484
|
+
* that step, so the text does not promise it ({@link admittedNames}). Total:
|
|
3485
|
+
* any failure returns the empty string, because a section that throws would
|
|
3486
|
+
* fail the model request that asked for the assembly.
|
|
3487
|
+
*
|
|
3488
|
+
* @param agent - session whose scope the section belongs to.
|
|
3489
|
+
* @param state - the session's live state.
|
|
3490
|
+
* @param assembly - the assembly context, when the host hands one.
|
|
3491
|
+
* @returns the section text, or `''` when there is nothing true to say.
|
|
3483
3492
|
*/
|
|
3484
|
-
private guidanceText(agent: AgentLike, state: AgentState): string {
|
|
3493
|
+
private guidanceText(agent: AgentLike, state: AgentState, assembly?: GuidanceAssemblyLike): string {
|
|
3485
3494
|
try {
|
|
3486
3495
|
const projectRoot = state.projectRoot
|
|
3487
3496
|
if (projectRoot === undefined || this.mountsOf(state).size === 0) return ''
|
|
3497
|
+
// The step's frozen admission, when the host carries one: everything named
|
|
3498
|
+
// below is a callability promise, and only an admitted name can keep it.
|
|
3499
|
+
const admitted = admittedNames(assembly)
|
|
3488
3500
|
const activationEnabled = this.config.activationEnabled ?? DEFAULT_ACTIVATION_ENABLED
|
|
3489
3501
|
// With activation on, the presented set is the session's counter baseline
|
|
3490
3502
|
// plus its activations; with it off, the registry lists every tool.
|
|
@@ -3497,6 +3509,7 @@ export class ProjectMcpRuntime {
|
|
|
3497
3509
|
const offered: string[] = []
|
|
3498
3510
|
const deferred: string[] = []
|
|
3499
3511
|
for (const schema of this.mountedSchemas(state)) {
|
|
3512
|
+
if (admitted !== undefined && !admitted.has(schema.name)) continue
|
|
3500
3513
|
const server = matchServer(schema.name, mounted)
|
|
3501
3514
|
if (server === undefined) continue
|
|
3502
3515
|
const name = schema.name.slice(`mcp__${server}__`.length)
|
|
@@ -3518,6 +3531,7 @@ export class ProjectMcpRuntime {
|
|
|
3518
3531
|
const mostUsed: string[] = []
|
|
3519
3532
|
if (activationEnabled) {
|
|
3520
3533
|
for (const fullName of this.seedActivation(state).baseline) {
|
|
3534
|
+
if (admitted !== undefined && !admitted.has(fullName)) continue
|
|
3521
3535
|
const server = matchServer(fullName, mounted)
|
|
3522
3536
|
if (server !== undefined) mostUsed.push(fullName.slice(`mcp__${server}__`.length))
|
|
3523
3537
|
}
|