@mario.andreschak/mcp-filesystem 3.39.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.
- package/dist/index.d.ts +3 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/resources.d.ts +49 -0
- package/dist/resources.js +604 -0
- package/dist/resources.js.map +1 -0
- package/dist/shared.d.ts +24 -0
- package/dist/shared.js +161 -0
- package/dist/shared.js.map +1 -0
- package/dist/tools.d.ts +3 -0
- package/dist/tools.js +1229 -0
- package/dist/tools.js.map +1 -0
- package/package.json +30 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { CallToolRequestSchema, ListResourceTemplatesRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { configureRootsProvider } from './shared.js';
|
|
6
|
+
import { filesystemCallTool, filesystemToolDefinitions } from './tools.js';
|
|
7
|
+
import { filesystemListResources, filesystemReadResource, isFilesystemAppUri, isTouchedFileUri, readTouchedFileResource, } from './resources.js';
|
|
8
|
+
export * from './tools.js';
|
|
9
|
+
export * from './resources.js';
|
|
10
|
+
const server = new Server({ name: '@mario.andreschak/mcp-filesystem', version: '0.1.0' }, { capabilities: { tools: {}, resources: {} } });
|
|
11
|
+
configureRootsProvider(async () => (await server.listRoots()).roots);
|
|
12
|
+
function callerNodeIdOf(meta) {
|
|
13
|
+
if (!meta || typeof meta !== 'object')
|
|
14
|
+
return undefined;
|
|
15
|
+
const flujo = meta.flujo;
|
|
16
|
+
if (!flujo || typeof flujo !== 'object')
|
|
17
|
+
return undefined;
|
|
18
|
+
const callerNodeId = flujo.callerNodeId;
|
|
19
|
+
return typeof callerNodeId === 'string' && callerNodeId.length > 0
|
|
20
|
+
? callerNodeId
|
|
21
|
+
: undefined;
|
|
22
|
+
}
|
|
23
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
24
|
+
tools: filesystemToolDefinitions(),
|
|
25
|
+
}));
|
|
26
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => filesystemCallTool(request.params.name, request.params.arguments ?? {}, callerNodeIdOf(request.params._meta)));
|
|
27
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => filesystemListResources());
|
|
28
|
+
server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => ({ resourceTemplates: [] }));
|
|
29
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
30
|
+
const uri = request.params.uri;
|
|
31
|
+
const result = isFilesystemAppUri(uri)
|
|
32
|
+
? filesystemReadResource(uri)
|
|
33
|
+
: isTouchedFileUri(uri)
|
|
34
|
+
? await readTouchedFileResource(uri)
|
|
35
|
+
: { success: false, error: `Unknown filesystem resource: ${uri}`, statusCode: 404 };
|
|
36
|
+
if (!result.success || !result.data)
|
|
37
|
+
throw new Error(result.error ?? `Could not read ${uri}`);
|
|
38
|
+
return result.data;
|
|
39
|
+
});
|
|
40
|
+
const transport = new StdioServerTransport();
|
|
41
|
+
let closing = false;
|
|
42
|
+
async function shutdown() {
|
|
43
|
+
if (closing)
|
|
44
|
+
return;
|
|
45
|
+
closing = true;
|
|
46
|
+
configureRootsProvider(undefined);
|
|
47
|
+
await server.close().catch(() => undefined);
|
|
48
|
+
}
|
|
49
|
+
process.once('SIGINT', () => void shutdown());
|
|
50
|
+
process.once('SIGTERM', () => void shutdown());
|
|
51
|
+
process.once('SIGHUP', () => void shutdown());
|
|
52
|
+
server.connect(transport).catch((error) => {
|
|
53
|
+
process.stderr.write(`@mario.andreschak/mcp-filesystem failed: ${error instanceof Error ? error.stack ?? error.message : String(error)}\n`);
|
|
54
|
+
process.exitCode = 1;
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type MCPServiceResponse<T> = {
|
|
3
|
+
success: boolean;
|
|
4
|
+
data?: T;
|
|
5
|
+
error?: string;
|
|
6
|
+
statusCode?: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const FILESYSTEM_APP_URI = "ui://filesystem/browser";
|
|
9
|
+
/**
|
|
10
|
+
* #216: the docked "dev canvas" diff app. A `pip`-capable, persistent surface
|
|
11
|
+
* that the mutation tools (`write_file`, `edit_file`) point their `_meta.ui`
|
|
12
|
+
* link at, so every edit feeds the SAME docked tab and updates in place instead
|
|
13
|
+
* of spawning a fresh iframe per write.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEVCANVAS_DIFF_URI = "ui://devcanvas/diff";
|
|
16
|
+
/**
|
|
17
|
+
* #287: expose files the filesystem tools have read/written as MCP resources so
|
|
18
|
+
* a client can track which files a session touched. We keep a lightweight,
|
|
19
|
+
* bounded, newest-first in-memory registry of DESCRIPTORS (path, op, size,
|
|
20
|
+
* timestamp) — NOT copies of file bodies — and read the current content live
|
|
21
|
+
* (re-enforcing path confinement) only when a resource is actually read. That
|
|
22
|
+
* avoids duplicating potentially large/sensitive file contents into any store.
|
|
23
|
+
*/
|
|
24
|
+
export type TouchedFileOp = 'read' | 'write';
|
|
25
|
+
/**
|
|
26
|
+
* Record that a filesystem tool touched `filePath`. Never throws — resource
|
|
27
|
+
* tracking must not be able to break a tool call.
|
|
28
|
+
*/
|
|
29
|
+
export declare function recordTouchedFile(filePath: string, op: TouchedFileOp, size?: number): void;
|
|
30
|
+
/** Test seam: clear the touched-file registry. */
|
|
31
|
+
export declare function _clearTouchedFilesForTests(): void;
|
|
32
|
+
/** True when a URI refers to a tracked (read/written) file resource. */
|
|
33
|
+
export declare function isTouchedFileUri(uri: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* resources/read for a tracked file: read the current content LIVE, re-enforcing
|
|
36
|
+
* the filesystem server's confinement roots (a file recorded earlier could now
|
|
37
|
+
* be outside a narrowed root). Content is capped like `read_file`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function readTouchedFileResource(uri: string): Promise<MCPServiceResponse<MCPReadResourceResult>>;
|
|
40
|
+
/** resources/list for the filesystem server: the browser app + diff canvas + tracked files. */
|
|
41
|
+
export declare function filesystemListResources(): {
|
|
42
|
+
resources: MCPResource[];
|
|
43
|
+
error?: string;
|
|
44
|
+
};
|
|
45
|
+
/** True when a URI is one this module serves. */
|
|
46
|
+
export declare function isFilesystemAppUri(uri: string): boolean;
|
|
47
|
+
/** resources/read for the filesystem server's built-in MCP Apps. */
|
|
48
|
+
export declare function filesystemReadResource(uri: string): MCPServiceResponse<MCPReadResourceResult>;
|
|
49
|
+
export {};
|