file-share-mcp 1.0.15 → 1.0.16
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 +5 -0
- package/dist/mcp-server.js +34 -1
- package/dist/utils/file-manager.js +30 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,6 +11,11 @@ The agent can list, read, and notify about files. The user can upload, download,
|
|
|
11
11
|
- `list_shared_files` — List all files available in the shared folder
|
|
12
12
|
- `share_file` — Notify the user that a file is ready to download
|
|
13
13
|
- `preview_file` — Read the content of a `.txt` or `.md` file (max 1 MB)
|
|
14
|
+
- `write_file` — Write text content to a new file in the shared folder
|
|
15
|
+
- `copy_file` — Copy a file from the agent workspace into the shared folder
|
|
16
|
+
- `download_file` — Copy a file from the shared folder to the agent machine (any file type, binary included)
|
|
17
|
+
- `create_directory` / `delete_directory` — Manage subdirectories
|
|
18
|
+
- `move_file` — Move or rename a file inside the shared folder
|
|
14
19
|
- **Web GUI** — Upload, download, preview, and delete files from a browser
|
|
15
20
|
- **Zero config** — works out of the box with sensible defaults (`~/.file-share-mcp`)
|
|
16
21
|
- **Proxy-ready** — optional integration with the [file-share-mcp proxy](https://github.com/...)
|
package/dist/mcp-server.js
CHANGED
|
@@ -8,7 +8,7 @@ import { fileURLToPath } from 'url';
|
|
|
8
8
|
import fs from 'fs';
|
|
9
9
|
import { GuiLauncher, setupLogging, createLogger, reconnectGuiToolDefinition } from '@imenam/mcp-gui-interface';
|
|
10
10
|
import { getConfig } from './utils/config-manager.js';
|
|
11
|
-
import { getSharedFiles, validateSafePath, writeSharedFile, copyToSharedFolder, createDirectory, deleteDirectory, moveFile, } from './utils/file-manager.js';
|
|
11
|
+
import { getSharedFiles, validateSafePath, writeSharedFile, copyToSharedFolder, copyFromSharedFolder, createDirectory, deleteDirectory, moveFile, } from './utils/file-manager.js';
|
|
12
12
|
import { VERSION } from './version.js';
|
|
13
13
|
const __filename = fileURLToPath(import.meta.url);
|
|
14
14
|
const __dirname = path.dirname(__filename);
|
|
@@ -135,6 +135,28 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
135
135
|
required: ['source_path'],
|
|
136
136
|
},
|
|
137
137
|
},
|
|
138
|
+
{
|
|
139
|
+
name: 'download_file',
|
|
140
|
+
description: 'Download a file from the shared folder to the agent workspace (the reverse of copy_file). Works for any file type, including binary ones.',
|
|
141
|
+
inputSchema: {
|
|
142
|
+
type: 'object',
|
|
143
|
+
properties: {
|
|
144
|
+
path: {
|
|
145
|
+
type: 'string',
|
|
146
|
+
description: 'Relative path of the file in the shared folder (e.g. "exports/report.pdf").',
|
|
147
|
+
},
|
|
148
|
+
destination_path: {
|
|
149
|
+
type: 'string',
|
|
150
|
+
description: 'ABSOLUTE destination path on the agent machine: either an existing directory (the file keeps its name) or the full target file path. Missing parent directories are created.',
|
|
151
|
+
},
|
|
152
|
+
overwrite: {
|
|
153
|
+
type: 'boolean',
|
|
154
|
+
description: 'Replace the destination file if it already exists. Defaults to false.',
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
required: ['path', 'destination_path'],
|
|
158
|
+
},
|
|
159
|
+
},
|
|
138
160
|
{
|
|
139
161
|
name: 'create_directory',
|
|
140
162
|
description: 'Create a new subdirectory inside the shared folder.',
|
|
@@ -268,6 +290,17 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
268
290
|
content: [{ type: 'text', text: `File "${copiedName}" copied to shared folder.` }],
|
|
269
291
|
};
|
|
270
292
|
}
|
|
293
|
+
case 'download_file': {
|
|
294
|
+
const { path: relativePath, destination_path, overwrite } = z.object({
|
|
295
|
+
path: z.string(),
|
|
296
|
+
destination_path: z.string(),
|
|
297
|
+
overwrite: z.boolean().optional(),
|
|
298
|
+
}).parse(args);
|
|
299
|
+
const written = copyFromSharedFolder(relativePath, destination_path, overwrite ?? false);
|
|
300
|
+
return {
|
|
301
|
+
content: [{ type: 'text', text: `File "${relativePath}" downloaded to "${written}".` }],
|
|
302
|
+
};
|
|
303
|
+
}
|
|
271
304
|
case 'create_directory': {
|
|
272
305
|
const { path: dirPath } = z.object({ path: z.string() }).parse(args);
|
|
273
306
|
createDirectory(dirPath);
|
|
@@ -101,6 +101,36 @@ export function copyToSharedFolder(sourcePath, filename, relativePath = '') {
|
|
|
101
101
|
fs.copyFileSync(sourcePath, path.join(dir, targetFilename));
|
|
102
102
|
return relativePath ? `${relativePath}/${targetFilename}` : targetFilename;
|
|
103
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Copy a file out of the shared folder onto the agent machine.
|
|
106
|
+
*
|
|
107
|
+
* `destination` is either a directory (existing, or written with a trailing
|
|
108
|
+
* separator) — the file then keeps its name — or the full target file path.
|
|
109
|
+
*/
|
|
110
|
+
export function copyFromSharedFolder(relativePath, destination, overwrite = false) {
|
|
111
|
+
const sourcePath = validateSafePath(relativePath);
|
|
112
|
+
if (!fs.existsSync(sourcePath)) {
|
|
113
|
+
throw new Error(`File not found in shared folder: ${relativePath}`);
|
|
114
|
+
}
|
|
115
|
+
if (!fs.statSync(sourcePath).isFile()) {
|
|
116
|
+
throw new Error(`Path is not a file: ${relativePath}`);
|
|
117
|
+
}
|
|
118
|
+
if (!path.isAbsolute(destination)) {
|
|
119
|
+
throw new Error(`Destination must be an absolute path: ${destination}`);
|
|
120
|
+
}
|
|
121
|
+
const looksLikeDir = destination.endsWith('/') ||
|
|
122
|
+
destination.endsWith(path.sep) ||
|
|
123
|
+
(fs.existsSync(destination) && fs.statSync(destination).isDirectory());
|
|
124
|
+
const destPath = looksLikeDir
|
|
125
|
+
? path.join(destination, path.basename(sourcePath))
|
|
126
|
+
: destination;
|
|
127
|
+
if (!overwrite && fs.existsSync(destPath)) {
|
|
128
|
+
throw new Error(`Destination already exists: ${destPath}. Pass overwrite=true to replace it.`);
|
|
129
|
+
}
|
|
130
|
+
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
131
|
+
fs.copyFileSync(sourcePath, destPath);
|
|
132
|
+
return destPath;
|
|
133
|
+
}
|
|
104
134
|
export function createDirectory(relativePath) {
|
|
105
135
|
const fullPath = validateSafePath(relativePath);
|
|
106
136
|
fs.mkdirSync(fullPath, { recursive: true });
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '1.0.
|
|
1
|
+
export const VERSION = '1.0.16';
|