filesystem-mcp 1.0.0 → 1.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.
@@ -38,6 +38,7 @@ const zod_1 = require("zod");
38
38
  const fs = __importStar(require("node:fs/promises"));
39
39
  const path = __importStar(require("node:path"));
40
40
  const response_js_1 = require("../utils/response.js");
41
+ const paths_js_1 = require("../utils/paths.js");
41
42
  const description = `Create or overwrite a file with the specified content.
42
43
 
43
44
  - Creates parent directories if they don't exist
@@ -49,15 +50,15 @@ function registerCreate(server) {
49
50
  description,
50
51
  inputSchema: {
51
52
  path: zod_1.z.string().describe('Absolute path where file will be created'),
52
- file_text: zod_1.z.string().describe('Content to write to the file'),
53
+ content: zod_1.z.string().describe('Content to write to the file'),
53
54
  },
54
55
  annotations: {
55
56
  readOnlyHint: false,
56
57
  destructiveHint: true,
57
58
  },
58
59
  }, async (args) => {
59
- const targetPath = args.path;
60
- const content = args.file_text;
60
+ const targetPath = (0, paths_js_1.expandPath)(args.path);
61
+ const { content } = args;
61
62
  // Create parent directories if needed
62
63
  const dir = path.dirname(targetPath);
63
64
  await fs.mkdir(dir, { recursive: true });
@@ -37,10 +37,12 @@ exports.registerInsert = registerInsert;
37
37
  const zod_1 = require("zod");
38
38
  const fs = __importStar(require("node:fs/promises"));
39
39
  const response_js_1 = require("../utils/response.js");
40
+ const paths_js_1 = require("../utils/paths.js");
40
41
  const description = `Insert text at a specific line in a file.
41
42
 
42
43
  - insert_line = 0: Insert at the beginning
43
44
  - insert_line = N: Insert after line N
45
+ - insert_line = -1: Insert at the end
44
46
  - insert_text should typically end with a newline
45
47
  - Use absolute paths`;
46
48
  function registerInsert(server) {
@@ -49,7 +51,7 @@ function registerInsert(server) {
49
51
  description,
50
52
  inputSchema: {
51
53
  path: zod_1.z.string().describe('Absolute path to file'),
52
- insert_line: zod_1.z.number().int().min(0).describe('Line number to insert after (0 = beginning)'),
54
+ insert_line: zod_1.z.number().int().min(-1).describe('Line number to insert after (0 = beginning, -1 = end)'),
53
55
  insert_text: zod_1.z.string().describe('Text to insert (should end with newline)'),
54
56
  },
55
57
  annotations: {
@@ -57,14 +59,17 @@ function registerInsert(server) {
57
59
  destructiveHint: true,
58
60
  },
59
61
  }, async (args) => {
60
- const targetPath = args.path;
61
- const insertLine = args.insert_line;
62
+ const targetPath = (0, paths_js_1.expandPath)(args.path);
62
63
  const insertText = args.insert_text;
63
64
  const content = await fs.readFile(targetPath, 'utf-8');
64
65
  const lines = content.split('\n');
66
+ // Handle -1 as "end of file"
67
+ // If file ends with newline, insert before the trailing empty element
68
+ const endPosition = content.endsWith('\n') ? lines.length - 1 : lines.length;
69
+ const insertLine = args.insert_line === -1 ? endPosition : args.insert_line;
65
70
  // Validate line number
66
71
  if (insertLine > lines.length) {
67
- throw new Error(`insert_line ${insertLine} is beyond file length (${lines.length} lines)`);
72
+ throw new Error(`insert_line ${args.insert_line} is beyond file length (${lines.length} lines)`);
68
73
  }
69
74
  // Warn if insert_text doesn't end with newline
70
75
  let warning;
@@ -37,6 +37,7 @@ exports.registerStrReplace = registerStrReplace;
37
37
  const zod_1 = require("zod");
38
38
  const fs = __importStar(require("node:fs/promises"));
39
39
  const response_js_1 = require("../utils/response.js");
40
+ const paths_js_1 = require("../utils/paths.js");
40
41
  const description = `Replace an exact string in a file.
41
42
 
42
43
  - old_str must match exactly and be unique in the file
@@ -57,7 +58,7 @@ function registerStrReplace(server) {
57
58
  destructiveHint: true,
58
59
  },
59
60
  }, async (args) => {
60
- const targetPath = args.path;
61
+ const targetPath = (0, paths_js_1.expandPath)(args.path);
61
62
  const oldStr = args.old_str;
62
63
  const newStr = args.new_str ?? '';
63
64
  const content = await fs.readFile(targetPath, 'utf-8');
@@ -38,6 +38,7 @@ const zod_1 = require("zod");
38
38
  const fs = __importStar(require("node:fs/promises"));
39
39
  const path = __importStar(require("node:path"));
40
40
  const response_js_1 = require("../utils/response.js");
41
+ const paths_js_1 = require("../utils/paths.js");
41
42
  const description = `View file contents or list directory.
42
43
 
43
44
  For files:
@@ -61,7 +62,7 @@ function registerView(server) {
61
62
  readOnlyHint: true,
62
63
  },
63
64
  }, async (args) => {
64
- const targetPath = args.path;
65
+ const targetPath = (0, paths_js_1.expandPath)(args.path);
65
66
  const stat = await fs.stat(targetPath);
66
67
  if (stat.isDirectory()) {
67
68
  const entries = await listDirectory(targetPath, 2);
@@ -0,0 +1 @@
1
+ export declare function expandPath(p: string): string;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.expandPath = expandPath;
37
+ const os = __importStar(require("node:os"));
38
+ function expandPath(p) {
39
+ if (p.startsWith('~/')) {
40
+ return p.replace('~', os.homedir());
41
+ }
42
+ if (p === '~') {
43
+ return os.homedir();
44
+ }
45
+ return p;
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "filesystem-mcp",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "MCP server for filesystem operations (view, create, edit files)",
5
5
  "license": "MIT",
6
6
  "author": "Adam Jones (domdomegg)",