@sparkelf/dsh-patch-ptc-mcp-schema-types 0.1.0-rc.12

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SparkElf
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ # Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
2
+ # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
+ # after editing either side, bring the other along and re-record with:
4
+ # pnpm run verify-translation-pairing --write patches/npm/ptc-mcp-schema-types/README.md
5
+ README.md: 92bf8729e1881f4bdecb6c27c56e277a47901c75
6
+ README.zh.md: 66601620ed68a7995a076f9d6605f64c9b9c0a8a
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # @sparkelf/dsh-patch-ptc-mcp-schema-types
2
+
3
+ English | [中文](README.zh.md)
4
+
5
+ This data-only package keeps TypeScript PTC declarations precise when MCP tools advertise JSON Schema draft markers, string length or pattern constraints, and array item-count constraints. The projection omits only those validation keywords while retaining object, array, property, required, and scalar types. Unsupported structural keywords still render as `unknown`.
6
+
7
+ The ToolRuntime enforced Schema subset remains unchanged, and the MCP server continues to validate the complete original Schema. The target is exact official source revision `0a53fb55bea101816fa226bb964ae2bed71c343b`.
8
+
9
+ Retire this package when official DSH projects the same validation-only MCP keywords into PTC declarations without weakening runtime Schema enforcement.
package/README.zh.md ADDED
@@ -0,0 +1,9 @@
1
+ # @sparkelf/dsh-patch-ptc-mcp-schema-types
2
+
3
+ [English](README.md) | 中文
4
+
5
+ 该 data-only package 让 MCP 工具带有 JSON Schema draft 标记、字符串长度或正则约束、数组元素数量约束时,TypeScript PTC 声明仍保留精确类型。投影只省略这些校验关键字,对象、数组、属性、必填项与标量类型均保留;不受支持的结构性关键字仍渲染为 `unknown`。
6
+
7
+ ToolRuntime 强制执行的 Schema 子集保持不变,MCP server 继续校验完整原始 Schema。目标为 exact official source revision `0a53fb55bea101816fa226bb964ae2bed71c343b`。
8
+
9
+ 当 official DSH 能以相同行为把纯校验 MCP 关键字投影为 PTC 声明,且不放松运行时 Schema 校验时,退役该 package。
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "description": "Data-only exact official-source patch preserving MCP parameter types in the TypeScript PTC SDK",
3
+ "dshPatch": {
4
+ "formatVersion": 1,
5
+ "variants": [
6
+ {
7
+ "dsh": ">=0.1.2-alpha.2",
8
+ "file": "./patches/ptc-mcp-schema-types.patch",
9
+ "id": "ptc-mcp-validation-schema-types",
10
+ "target": {
11
+ "baseRevision": "0a53fb55bea101816fa226bb964ae2bed71c343b",
12
+ "kind": "dsh-source",
13
+ "paths": [
14
+ "packages/core/tools/"
15
+ ]
16
+ }
17
+ }
18
+ ]
19
+ },
20
+ "files": [
21
+ "patches/*.patch"
22
+ ],
23
+ "license": "MIT",
24
+ "name": "@sparkelf/dsh-patch-ptc-mcp-schema-types",
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "repository": {
29
+ "directory": "patches/npm/ptc-mcp-schema-types",
30
+ "type": "git",
31
+ "url": "git+https://github.com/SparkElf/deepseek-harness-plus.git"
32
+ },
33
+ "type": "module",
34
+ "version": "0.1.0-rc.12"
35
+ }
@@ -0,0 +1,185 @@
1
+ diff --git a/packages/core/tools/README.i18n.yaml b/packages/core/tools/README.i18n.yaml
2
+ index feacbdc2e4..e86e7ea531 100644
3
+ --- a/packages/core/tools/README.i18n.yaml
4
+ +++ b/packages/core/tools/README.i18n.yaml
5
+ @@ -2,5 +2,5 @@
6
+ # side as of the last confirmed-consistent state. Both languages carry equal authority;
7
+ # after editing either side, bring the other along and re-record with:
8
+ # pnpm run verify-translation-pairing --write packages/core/tools/README.md
9
+ -README.md: f586b926ec9a8e426f48b62e4d03b1661201a76a
10
+ -README.zh.md: 5f422dd848ee9a6e8e0afe96d3dd03238ecc3857
11
+ +README.md: c4d6ad64f2cc36b295f696262a74ed99ba151859
12
+ +README.zh.md: 7f810c335505ff0a34c8f7b4d133880c13a85862
13
+ diff --git a/packages/core/tools/README.md b/packages/core/tools/README.md
14
+ index f586b926ec..c4d6ad64f2 100644
15
+ --- a/packages/core/tools/README.md
16
+ +++ b/packages/core/tools/README.md
17
+ @@ -168,7 +168,7 @@ Prefix-stable while visible definitions and their order are unchanged. Registrat
18
+
19
+ #### What the model sees
20
+
21
+ -PTC mode exposes the generated [`run_code` schema](../../../docs/tool-catalog.md#deepseek-aidsh-tools), the SDK instructions below, and the generated exact SDK block for the loaded runtime's language. The TypeScript instructions identify generated declarations as program-only bindings. When the current `bash` parameter schema accepts the example arguments, they also show a complete `run_code` call around `tools.bash(...)`. The `tools:sdk` section uses first-party order 5000. `both` exposes normal schemas and this PTC mode API; under `ptc` the prompt also carries the `tools:ptc-only` rule earlier in the first-party order, so the model reads which tools it may call before it reads what each one is for.
22
+ +PTC mode exposes the generated [`run_code` schema](../../../docs/tool-catalog.md#deepseek-aidsh-tools), the SDK instructions below, and the generated exact SDK block for the loaded runtime's language. The TypeScript instructions identify generated declarations as program-only bindings. JSON Schema draft markers plus string length, string pattern, and array item-count constraints remain owned by the tool validator and are omitted only from TypeScript declarations, so an MCP schema retains its object, array, property, required, and scalar types; unsupported structural keywords still render as `unknown`. When the current `bash` parameter schema accepts the example arguments, the instructions also show a complete `run_code` call around `tools.bash(...)`. The `tools:sdk` section uses first-party order 5000. `both` exposes normal schemas and this PTC mode API; under `ptc` the prompt also carries the `tools:ptc-only` rule earlier in the first-party order, so the model reads which tools it may call before it reads what each one is for.
23
+
24
+ ##### TypeScript PTC mode SDK instructions with bash
25
+
26
+ diff --git a/packages/core/tools/README.zh.md b/packages/core/tools/README.zh.md
27
+ index 5f422dd848..7f810c3355 100644
28
+ --- a/packages/core/tools/README.zh.md
29
+ +++ b/packages/core/tools/README.zh.md
30
+ @@ -168,7 +168,7 @@ ctx.tools.register(defineTool({
31
+
32
+ #### 模型看到什么
33
+
34
+ -PTC mode 会公开生成的 [`run_code` schema](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tools)、下方 SDK 说明,以及按所加载运行时语言生成的精确 SDK 块。TypeScript 说明会把生成声明明确标为只能在程序内使用的绑定。当当前 `bash` 参数 schema 接受示例参数时,说明还会给出以 `run_code` 包住 `tools.bash(...)` 的完整调用。`tools:sdk` 段使用 first-party 顺序 5000。`both` 会同时公开普通 schema 与此 PTC mode API;在 `ptc` 下,提示词还会带上处于更早 first-party 顺序的 `tools:ptc-only` 规则,让模型先读到「可以调用哪些工具」再读「每个工具做什么」。
35
+ +PTC mode 会公开生成的 [`run_code` schema](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tools)、下方 SDK 说明,以及按所加载运行时语言生成的精确 SDK 块。TypeScript 说明会把生成声明明确标为只能在程序内使用的绑定。JSON Schema draft 标记、字符串长度与正则约束、数组元素数量约束仍由工具 validator 持有,只在 TypeScript 声明中省略,因此 MCP schema 会保留对象、数组、属性、必填项与标量类型;不受支持的结构性关键字仍渲染为 `unknown`。当当前 `bash` 参数 schema 接受示例参数时,说明还会给出以 `run_code` 包住 `tools.bash(...)` 的完整调用。`tools:sdk` 段使用 first-party 顺序 5000。`both` 会同时公开普通 schema 与此 PTC mode API;在 `ptc` 下,提示词还会带上处于更早 first-party 顺序的 `tools:ptc-only` 规则,让模型先读到「可以调用哪些工具」再读「每个工具做什么」。
36
+
37
+ ##### 带 bash 的 TypeScript PTC mode SDK 说明
38
+
39
+ diff --git a/packages/core/tools/src/json-schema.ts b/packages/core/tools/src/json-schema.ts
40
+ index c064fb294c..573cdd69c0 100644
41
+ --- a/packages/core/tools/src/json-schema.ts
42
+ +++ b/packages/core/tools/src/json-schema.ts
43
+ @@ -84,6 +84,14 @@ const CONSTRAINT_KEYWORDS = new Set([
44
+ 'const',
45
+ ])
46
+ const ANNOTATION_KEYWORDS = new Set(['description', 'title', 'default', 'examples'])
47
+ +const TYPE_PROJECTION_IGNORED_KEYWORDS = new Set([
48
+ + '$schema',
49
+ + 'minLength',
50
+ + 'maxLength',
51
+ + 'pattern',
52
+ + 'minItems',
53
+ + 'maxItems',
54
+ +])
55
+ const SCHEMA_TYPES: readonly JsonSchemaType[] = ['object', 'array', 'string', 'number', 'integer', 'boolean', 'null']
56
+
57
+ /* jscpd:ignore-start -- this realm boundary mirrors the session-owned lossless-JSON intrinsic test */
58
+ @@ -224,7 +232,13 @@ function checkObjectSchemaTail(
59
+ }
60
+
61
+ /** Collect every violation for one raw schema tree without using the JavaScript call stack. */
62
+ -function checkSchemaNode(root: unknown, rootPath: string, violations: string[], seen: Set<object>): void {
63
+ +function checkSchemaNode(
64
+ + root: unknown,
65
+ + rootPath: string,
66
+ + violations: string[],
67
+ + seen: Set<object>,
68
+ + ignoredKeywords?: ReadonlySet<string>,
69
+ +): void {
70
+ const tasks: SchemaWalkTask[] = [{ kind: 'enter', node: root, path: rootPath }]
71
+ for (let task = tasks.pop(); task !== undefined; task = tasks.pop()) {
72
+ if (task.kind === 'leave') {
73
+ @@ -256,6 +270,7 @@ function checkSchemaNode(root: unknown, rootPath: string, violations: string[],
74
+
75
+ for (const key of Object.keys(node)) {
76
+ if (CONSTRAINT_KEYWORDS.has(key)) continue
77
+ + if (ignoredKeywords?.has(key)) continue
78
+ if (ANNOTATION_KEYWORDS.has(key)) {
79
+ try {
80
+ if (!isJsonValue(node[key])) violations.push(`${path}.${key} annotation must be lossless JSON data`)
81
+ @@ -388,6 +403,22 @@ export function assertSupportedJsonSchema(schema: unknown): asserts schema is Js
82
+ if (violations.length > 0) throw new JsonSchemaError(violations)
83
+ }
84
+
85
+ +/**
86
+ + * Assert the JSON Schema structure that a generated TypeScript declaration can represent.
87
+ + *
88
+ + * Validation-only string and array constraints remain outside the enforced ToolRuntime
89
+ + * subset. The PTC declaration omits those constraints while retaining their object,
90
+ + * array, property, required, and scalar types. Structural keywords outside the shared
91
+ + * vocabulary still reject the projection.
92
+ + * @param schema - untrusted raw JSON Schema from a registered tool.
93
+ + * @returns Assertion that the schema structure is safe to render as TypeScript.
94
+ + */
95
+ +export function assertTypeProjectableJsonSchema(schema: unknown): asserts schema is JsonSchemaNode {
96
+ + const violations: string[] = []
97
+ + checkSchemaNode(schema, 'schema', violations, new Set(), TYPE_PROJECTION_IGNORED_KEYWORDS)
98
+ + if (violations.length > 0) throw new JsonSchemaError(violations)
99
+ +}
100
+ +
101
+ /**
102
+ * Assert the enforced subset plus the object-root constraint retained by
103
+ * subagent and workflow structured outputs.
104
+ diff --git a/packages/core/tools/src/ts-types.ts b/packages/core/tools/src/ts-types.ts
105
+ index d92c987817..a2d6fa7132 100644
106
+ --- a/packages/core/tools/src/ts-types.ts
107
+ +++ b/packages/core/tools/src/ts-types.ts
108
+ @@ -7,7 +7,7 @@
109
+ */
110
+
111
+ import type { ToolSchema } from '@deepseek-ai/dsh-llm'
112
+ -import { assertSupportedJsonSchema } from './json-schema.ts'
113
+ +import { assertTypeProjectableJsonSchema } from './json-schema.ts'
114
+ import type { JsonSchemaNode, JsonSchemaScalar } from './json-schema.ts'
115
+ /** Internal PTC mode projection: the model-facing schema plus the canonical output schema. */
116
+ export interface ToolSdkSchema extends ToolSchema {
117
+ @@ -239,7 +239,7 @@ function renderSupportedSchema(schema: JsonSchemaNode, indent: number): TypeDocu
118
+ */
119
+ export function jsonSchemaToTs(schema: unknown, indent = 0): string {
120
+ try {
121
+ - assertSupportedJsonSchema(schema)
122
+ + assertTypeProjectableJsonSchema(schema)
123
+ return flattenTypeDocument(renderSupportedSchema(schema, indent))
124
+ } catch {
125
+ return 'unknown'
126
+ diff --git a/packages/core/tools/tests/ts-types.spec.ts b/packages/core/tools/tests/ts-types.spec.ts
127
+ index 5a3f0edca5..eacda7635a 100644
128
+ --- a/packages/core/tools/tests/ts-types.spec.ts
129
+ +++ b/packages/core/tools/tests/ts-types.spec.ts
130
+ @@ -1,6 +1,7 @@
131
+ import { describe, expect, it } from 'vitest'
132
+ import { jsonSchemaToTs, renderToolsSdk } from '@deepseek-ai/dsh-tools/src/ts-types.ts'
133
+ import type { ToolSdkSchema } from '@deepseek-ai/dsh-tools/src/ts-types.ts'
134
+ +import { assertSupportedJsonSchema } from '@deepseek-ai/dsh-tools/src/json-schema.ts'
135
+ import type { JsonSchemaNode } from '@deepseek-ai/dsh-tools/src/json-schema.ts'
136
+ import { parameterSchemaSpecToJsonSchema } from '@deepseek-ai/dsh-tools'
137
+
138
+ @@ -61,6 +62,47 @@ describe('jsonSchemaToTs', () => {
139
+ ].join('\n'))
140
+ })
141
+
142
+ + it('projects MCP validation keywords without admitting them to runtime schema enforcement', () => {
143
+ + const schema = {
144
+ + $schema: 'http://json-schema.org/draft-07/schema#',
145
+ + type: 'object',
146
+ + properties: {
147
+ + sources: {
148
+ + type: 'array',
149
+ + minItems: 1,
150
+ + maxItems: 12,
151
+ + items: {
152
+ + type: 'object',
153
+ + properties: {
154
+ + resourceRef: { type: 'string', minLength: 1, maxLength: 1000 },
155
+ + alias: { type: 'string', pattern: '^[A-Za-z_][A-Za-z0-9_]{0,63}$' },
156
+ + },
157
+ + required: ['resourceRef', 'alias'],
158
+ + },
159
+ + },
160
+ + sql: { type: 'string', minLength: 1, maxLength: 20000 },
161
+ + },
162
+ + required: ['sources', 'sql'],
163
+ + }
164
+ +
165
+ + expect(() => { assertSupportedJsonSchema(schema) }).toThrow(/not a supported keyword/)
166
+ + const rendered = jsonSchemaToTs(schema)
167
+ + expect(rendered).toContain('sources:')
168
+ + expect(rendered).toContain('resourceRef: string;')
169
+ + expect(rendered).toContain('alias: string;')
170
+ + expect(rendered).toContain('sql: string;')
171
+ + expect(rendered).not.toBe('unknown')
172
+ + const sdk = renderToolsSdk([{
173
+ + name: 'mcp__dataops__execute_sql',
174
+ + description: 'Execute SQL.',
175
+ + parameters: schema,
176
+ + output: {},
177
+ + }])
178
+ + expect(sdk).toContain('mcp__dataops__execute_sql: {')
179
+ + expect(sdk).not.toContain('mcp__dataops__execute_sql: unknown;')
180
+ + expect(jsonSchemaToTs({ type: 'object', allOf: [{ type: 'object' }] })).toBe('unknown')
181
+ + })
182
+ +
183
+ it('is total: unsupported or hostile constructs degrade to unknown, never throw', () => {
184
+ const cases: unknown[] = [
185
+ undefined,