Skip to content

Commit f211529

Browse files
committed
refactor(server): move schema-derivation helper out of src to test-only
specToToolDefinition was no longer on the live path (McpServer derives each tool's advertised JSON Schema from its Zod inputShape), surviving only to let unit tests assert that advertised schema. Move it to a test helper (packages/server/test/tool-schema.ts as toToolDefinition) and drop the 80 per-tool xToolDefinition exports it fed. spec.ts is now just the ToolSpec / ToolKind types. Per-tool tests re-derive their definition through the helper, so their assertions (required fields, property types a client sees) are unchanged. No production code path changes — live tool registration still runs off the Zod specs in ALL_TOOL_SPECS. 504 tests green, typecheck/lint/build clean; knip's unused-export count drops from 94 to 46.
1 parent e590564 commit f211529

89 files changed

Lines changed: 213 additions & 346 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/server/src/tools/add-page.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22

3-
import { specToToolDefinition, type ToolSpec } from './spec.js';
3+
import type { ToolSpec } from './spec.js';
44

55
export const ADD_PAGE_TOOL_NAME = 'add_page';
66

@@ -12,5 +12,3 @@ export const addPageTool: ToolSpec = {
1212
},
1313
kind: 'write',
1414
};
15-
16-
export const addPageToolDefinition = specToToolDefinition(addPageTool);

packages/server/src/tools/add-variable-mode.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22

3-
import { specToToolDefinition, type ToolSpec } from './spec.js';
3+
import type { ToolSpec } from './spec.js';
44

55
export const ADD_VARIABLE_MODE_TOOL_NAME = 'add_variable_mode';
66

@@ -13,5 +13,3 @@ export const addVariableModeTool: ToolSpec = {
1313
},
1414
kind: 'write',
1515
};
16-
17-
export const addVariableModeToolDefinition = specToToolDefinition(addVariableModeTool);

packages/server/src/tools/analyze-project.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { z } from 'zod';
22

33
import { analyzeProject, type ProjectProfile } from '../profile/profile.js';
4-
import { specToToolDefinition, type ToolSpec } from './spec.js';
4+
import type { ToolSpec } from './spec.js';
55

66
export const ANALYZE_PROJECT_TOOL_NAME = 'analyze_project';
77

@@ -21,9 +21,6 @@ export const analyzeProjectTool: ToolSpec = {
2121
inputShape,
2222
kind: 'local',
2323
};
24-
25-
export const analyzeProjectToolDefinition = specToToolDefinition(analyzeProjectTool);
26-
2724
export const handleAnalyzeProject = async (rawArgs: unknown): Promise<ProjectProfile> => {
2825
const args = z.object(inputShape).parse(rawArgs);
2926
return analyzeProject(args.rootDir ?? process.cwd());

packages/server/src/tools/apply-style-to-node.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22

3-
import { specToToolDefinition, type ToolSpec } from './spec.js';
3+
import type { ToolSpec } from './spec.js';
44

55
export const APPLY_STYLE_TO_NODE_TOOL_NAME = 'apply_style_to_node';
66

@@ -16,5 +16,3 @@ export const applyStyleToNodeTool: ToolSpec = {
1616
},
1717
kind: 'write',
1818
};
19-
20-
export const applyStyleToNodeToolDefinition = specToToolDefinition(applyStyleToNodeTool);

packages/server/src/tools/batch-rename-nodes.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22

3-
import { specToToolDefinition, type ToolSpec } from './spec.js';
3+
import type { ToolSpec } from './spec.js';
44

55
export const BATCH_RENAME_NODES_TOOL_NAME = 'batch_rename_nodes';
66

@@ -16,5 +16,3 @@ export const batchRenameNodesTool: ToolSpec = {
1616
},
1717
kind: 'write',
1818
};
19-
20-
export const batchRenameNodesToolDefinition = specToToolDefinition(batchRenameNodesTool);

packages/server/src/tools/batch.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22

3-
import { specToToolDefinition, type ToolSpec } from './spec.js';
3+
import type { ToolSpec } from './spec.js';
44

55
export const BATCH_TOOL_NAME = 'batch';
66

@@ -32,5 +32,3 @@ export const batchTool: ToolSpec = {
3232
},
3333
kind: 'write',
3434
};
35-
36-
export const batchToolDefinition = specToToolDefinition(batchTool);

packages/server/src/tools/bind-variable-to-node.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22

3-
import { specToToolDefinition, type ToolSpec } from './spec.js';
3+
import type { ToolSpec } from './spec.js';
44

55
export const BIND_VARIABLE_TO_NODE_TOOL_NAME = 'bind_variable_to_node';
66

@@ -16,5 +16,3 @@ export const bindVariableToNodeTool: ToolSpec = {
1616
},
1717
kind: 'write',
1818
};
19-
20-
export const bindVariableToNodeToolDefinition = specToToolDefinition(bindVariableToNodeTool);

packages/server/src/tools/clone-node.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22

3-
import { specToToolDefinition, type ToolSpec } from './spec.js';
3+
import type { ToolSpec } from './spec.js';
44

55
export const CLONE_NODE_TOOL_NAME = 'clone_node';
66

@@ -13,5 +13,3 @@ export const cloneNodeTool: ToolSpec = {
1313
},
1414
kind: 'write',
1515
};
16-
17-
export const cloneNodeToolDefinition = specToToolDefinition(cloneNodeTool);

packages/server/src/tools/component-map.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { analyzeProject, type ProjectProfile } from '../profile/profile.js';
1919
import { scanComponents } from '../scan/scan.js';
2020
import { GET_DESIGN_CONTEXT_TOOL_NAME } from './get-design-context.js';
2121
import { GET_LOCAL_COMPONENTS_TOOL_NAME } from './get-local-components.js';
22-
import { specToToolDefinition, type ToolSpec } from './spec.js';
22+
import type { ToolSpec } from './spec.js';
2323

2424
export const COMPONENT_MAP_TOOL_NAME = 'component_map';
2525

@@ -58,9 +58,6 @@ export const componentMapTool: ToolSpec = {
5858
inputShape,
5959
kind: 'local',
6060
};
61-
62-
export const componentMapToolDefinition = specToToolDefinition(componentMapTool);
63-
6461
export type ToolDispatcher = (toolName: string, args: unknown) => Promise<unknown>;
6562

6663
const readOverrides = async (rootDir: string): Promise<ReturnType<typeof parseMapFile>> => {

packages/server/src/tools/create-component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22

3-
import { specToToolDefinition, type ToolSpec } from './spec.js';
3+
import type { ToolSpec } from './spec.js';
44

55
export const CREATE_COMPONENT_TOOL_NAME = 'create_component';
66

@@ -19,5 +19,3 @@ export const createComponentTool: ToolSpec = {
1919
},
2020
kind: 'write',
2121
};
22-
23-
export const createComponentToolDefinition = specToToolDefinition(createComponentTool);

0 commit comments

Comments
 (0)