@movesafe/mcp 0.1.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +266 -0
  3. package/package.json +50 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 endrilickollari
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.
package/dist/index.js ADDED
@@ -0,0 +1,266 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { realpathSync } from "fs";
5
+ import { fileURLToPath } from "url";
6
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
7
+
8
+ // src/server.ts
9
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
10
+ import { CORE_VERSION } from "@movesafe/core";
11
+ import { z as z2 } from "zod";
12
+
13
+ // src/apply-move.ts
14
+ import { resolve } from "path";
15
+ import { applyMove, planMove } from "@movesafe/core";
16
+ function hashMismatch(planHash) {
17
+ return {
18
+ ok: false,
19
+ status: "hash-mismatch",
20
+ planHash,
21
+ diagnostics: [
22
+ {
23
+ severity: "error",
24
+ code: "plan-hash-mismatch",
25
+ message: "The plan for this move has changed since it was reviewed. Call plan_move again and review the new plan.",
26
+ path: void 0
27
+ }
28
+ ],
29
+ manualRecoveryPaths: []
30
+ };
31
+ }
32
+ function applyMoveTool(options) {
33
+ const from = resolve(options.cwd, options.from);
34
+ const to = resolve(options.cwd, options.to);
35
+ const plan = planMove({ from, to, cwd: options.cwd });
36
+ if (plan.planHash !== options.planHash) {
37
+ return hashMismatch(options.planHash);
38
+ }
39
+ if (plan.status === "blocked") {
40
+ return {
41
+ ok: false,
42
+ status: "rejected",
43
+ planHash: plan.planHash,
44
+ diagnostics: plan.diagnostics,
45
+ manualRecoveryPaths: []
46
+ };
47
+ }
48
+ const result = applyMove(plan);
49
+ return {
50
+ ok: result.status === "applied",
51
+ status: result.status,
52
+ planHash: plan.planHash,
53
+ diagnostics: [...plan.diagnostics, ...result.diagnostics],
54
+ manualRecoveryPaths: result.manualRecoveryPaths
55
+ };
56
+ }
57
+
58
+ // src/check-imports.ts
59
+ import { resolve as resolve2 } from "path";
60
+ import { checkImports as checkCoreImports } from "@movesafe/core";
61
+ function checkImports(options) {
62
+ const target = resolve2(options.cwd, options.path ?? ".");
63
+ const result = checkCoreImports({ path: target, cwd: options.cwd });
64
+ const findings = [...result.findings, ...result.diagnostics];
65
+ const noConfig = result.diagnostics.find((diagnostic) => diagnostic.code === "no-tsconfig-found");
66
+ const errorCount = findings.filter((finding) => finding.severity === "error").length;
67
+ const warningCount = findings.filter((finding) => finding.severity === "warning").length;
68
+ const infoCount = findings.filter((finding) => finding.severity === "info").length;
69
+ return {
70
+ ok: result.clean,
71
+ error: noConfig?.message,
72
+ findings,
73
+ summary: { errorCount, warningCount, infoCount, total: findings.length }
74
+ };
75
+ }
76
+
77
+ // src/plan-move.ts
78
+ import { resolve as resolve3 } from "path";
79
+ import { planMove as planMove2 } from "@movesafe/core";
80
+ import { computePlanDiff } from "@movesafe/core/advanced";
81
+ var EMPTY_DIFF = { files: [] };
82
+ function planMoveTool(options) {
83
+ const from = resolve3(options.cwd, options.from);
84
+ const to = resolve3(options.cwd, options.to);
85
+ const plan = planMove2({ from, to, cwd: options.cwd });
86
+ return {
87
+ ok: plan.status === "ready",
88
+ status: plan.status,
89
+ operation: plan.operation,
90
+ scope: plan.scope,
91
+ planHash: plan.planHash,
92
+ moves: plan.moves,
93
+ edits: plan.edits,
94
+ diagnostics: plan.diagnostics,
95
+ diff: plan.status === "ready" ? computePlanDiff(plan) : EMPTY_DIFF
96
+ };
97
+ }
98
+
99
+ // src/schemas.ts
100
+ import { z } from "zod";
101
+ var diagnosticSchema = z.object({
102
+ severity: z.enum(["error", "warning", "info"]),
103
+ code: z.string(),
104
+ message: z.string(),
105
+ path: z.string().optional(),
106
+ source: z.enum(["workspace", "tsconfig", "scanner", "resolver"]).optional()
107
+ });
108
+ var editSchema = z.object({
109
+ file: z.string(),
110
+ span: z.object({ start: z.number(), end: z.number() }),
111
+ oldText: z.string(),
112
+ newText: z.string(),
113
+ reason: z.string()
114
+ });
115
+ var moveSchema = z.object({
116
+ fromFilePath: z.string(),
117
+ toFilePath: z.string()
118
+ });
119
+ var diffLineSchema = z.object({
120
+ kind: z.enum(["context", "added", "removed"]),
121
+ text: z.string()
122
+ });
123
+ var diffHunkSchema = z.object({
124
+ oldStart: z.number(),
125
+ oldLines: z.number(),
126
+ newStart: z.number(),
127
+ newLines: z.number(),
128
+ lines: z.array(diffLineSchema)
129
+ });
130
+ var fileDiffSchema = z.object({
131
+ oldPath: z.string(),
132
+ newPath: z.string(),
133
+ hunks: z.array(diffHunkSchema)
134
+ });
135
+ var diffSchema = z.object({
136
+ files: z.array(fileDiffSchema)
137
+ });
138
+ var planMoveOutputSchema = {
139
+ ok: z.boolean(),
140
+ status: z.enum(["ready", "blocked"]),
141
+ operation: z.enum(["file", "directory"]),
142
+ scope: z.enum(["project", "workspace"]),
143
+ planHash: z.string(),
144
+ moves: z.array(moveSchema),
145
+ edits: z.array(editSchema),
146
+ diagnostics: z.array(diagnosticSchema),
147
+ diff: diffSchema
148
+ };
149
+ var applyMoveOutputSchema = {
150
+ ok: z.boolean(),
151
+ status: z.enum(["applied", "rejected", "partial", "hash-mismatch"]),
152
+ planHash: z.string(),
153
+ diagnostics: z.array(diagnosticSchema),
154
+ manualRecoveryPaths: z.array(z.string())
155
+ };
156
+ var checkImportsOutputSchema = {
157
+ ok: z.boolean(),
158
+ error: z.string().optional(),
159
+ findings: z.array(diagnosticSchema),
160
+ summary: z.object({
161
+ errorCount: z.number(),
162
+ warningCount: z.number(),
163
+ infoCount: z.number(),
164
+ total: z.number()
165
+ })
166
+ };
167
+
168
+ // src/server.ts
169
+ function structuredResult(structuredContent, text) {
170
+ return { content: [{ type: "text", text }], structuredContent, isError: false };
171
+ }
172
+ function toolError(error) {
173
+ const message = error instanceof Error ? error.message : String(error);
174
+ return { content: [{ type: "text", text: message }], isError: true };
175
+ }
176
+ function summarizePlan(plan) {
177
+ if (plan.status === "blocked") {
178
+ const errorCount = plan.diagnostics.filter((d) => d.severity === "error").length;
179
+ return `Plan blocked: ${errorCount} error(s).`;
180
+ }
181
+ const fileCount = new Set(plan.diff.files.map((file) => file.newPath)).size;
182
+ return `Plan ready: ${plan.edits.length} edit(s) across ${fileCount} file(s). Hash ${plan.planHash}.`;
183
+ }
184
+ function summarizeApply(result) {
185
+ switch (result.status) {
186
+ case "applied":
187
+ return "Applied.";
188
+ case "hash-mismatch":
189
+ return "Rejected: plan hash mismatch \u2014 call plan_move again and apply the new hash.";
190
+ case "partial":
191
+ return `Partial: ${result.manualRecoveryPaths.length} path(s) need manual recovery.`;
192
+ case "rejected":
193
+ return `Rejected: ${result.diagnostics.find((d) => d.severity === "error")?.message ?? "plan failed validation."}`;
194
+ }
195
+ }
196
+ function createServer() {
197
+ const server = new McpServer({ name: "movesafe", version: CORE_VERSION });
198
+ server.registerTool(
199
+ "plan_move",
200
+ {
201
+ title: "Plan a move",
202
+ description: "Plans moving a TypeScript file, directory, or cross-package file, rewriting every import that references it. Read-only \u2014 never touches disk. Returns a planHash to pass to apply_move.",
203
+ inputSchema: {
204
+ from: z2.string().describe("Path to the file or directory to move"),
205
+ to: z2.string().describe("Destination path")
206
+ },
207
+ outputSchema: planMoveOutputSchema
208
+ },
209
+ ({ from, to }) => {
210
+ try {
211
+ const result = planMoveTool({ from, to, cwd: process.cwd() });
212
+ return structuredResult(result, summarizePlan(result));
213
+ } catch (error) {
214
+ return toolError(error);
215
+ }
216
+ }
217
+ );
218
+ server.registerTool(
219
+ "apply_move",
220
+ {
221
+ title: "Apply a planned move",
222
+ description: "Applies the move planned by plan_move. Recomputes the plan from current disk state and refuses (hash-mismatch) if it no longer matches the supplied planHash \u2014 never applies a plan different from the one reviewed.",
223
+ inputSchema: {
224
+ from: z2.string().describe("Path to the file or directory to move"),
225
+ to: z2.string().describe("Destination path"),
226
+ planHash: z2.string().describe("The planHash returned by plan_move for this exact move")
227
+ },
228
+ outputSchema: applyMoveOutputSchema
229
+ },
230
+ ({ from, to, planHash }) => {
231
+ try {
232
+ const result = applyMoveTool({ from, to, planHash, cwd: process.cwd() });
233
+ return structuredResult(result, summarizeApply(result));
234
+ } catch (error) {
235
+ return toolError(error);
236
+ }
237
+ }
238
+ );
239
+ server.registerTool(
240
+ "check_imports",
241
+ {
242
+ title: "Check imports",
243
+ description: "Scans a project for unresolvable imports, orphaned barrel exports, and case-sensitivity mismatches.",
244
+ inputSchema: {
245
+ path: z2.string().optional().describe("Directory to check (defaults to the current directory)")
246
+ },
247
+ outputSchema: checkImportsOutputSchema
248
+ },
249
+ ({ path }) => {
250
+ try {
251
+ const result = checkImports({ path, cwd: process.cwd() });
252
+ const text = result.ok ? "Clean." : `${result.summary.errorCount} error(s), ${result.summary.warningCount} warning(s).`;
253
+ return structuredResult(result, text);
254
+ } catch (error) {
255
+ return toolError(error);
256
+ }
257
+ }
258
+ );
259
+ return server;
260
+ }
261
+
262
+ // src/index.ts
263
+ var isMainModule = process.argv[1] !== void 0 && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url);
264
+ if (isMainModule) {
265
+ await createServer().connect(new StdioServerTransport());
266
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@movesafe/mcp",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for planning and applying safe TypeScript file moves.",
5
+ "license": "MIT",
6
+ "author": "Endri Liçkollari",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/endrilickollari/movesafe.git",
10
+ "directory": "packages/mcp"
11
+ },
12
+ "homepage": "https://github.com/endrilickollari/movesafe#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/endrilickollari/movesafe/issues"
15
+ },
16
+ "keywords": [
17
+ "typescript",
18
+ "refactoring",
19
+ "mcp"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "engines": {
25
+ "node": ">=22.13"
26
+ },
27
+ "type": "module",
28
+ "bin": {
29
+ "movesafe-mcp": "./dist/index.js"
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "dependencies": {
35
+ "@modelcontextprotocol/sdk": "^1.30.0",
36
+ "zod": "^3.25.76",
37
+ "@movesafe/core": "0.1.0"
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "^26.1.1",
41
+ "tsup": "^8.5.1",
42
+ "typescript": "^5.9.3",
43
+ "vitest": "^4.1.10"
44
+ },
45
+ "scripts": {
46
+ "build": "tsup",
47
+ "lint": "eslint .",
48
+ "test": "vitest run"
49
+ }
50
+ }