Apply suggestions from code review comments on docs and logging
Co-authored-by: Ola Hungerford <olahungerford@gmail.com>
This commit is contained in:
parent
f8dd74576b
commit
f3891aaf69
2 changed files with 8 additions and 8 deletions
|
|
@ -9,11 +9,11 @@ Node.js server implementing Model Context Protocol (MCP) for filesystem operatio
|
||||||
- Move files/directories
|
- Move files/directories
|
||||||
- Search files
|
- Search files
|
||||||
- Get file metadata
|
- Get file metadata
|
||||||
- Dynamic directory access control via MCP roots protocol
|
- Dynamic directory access control via [Roots](https://modelcontextprotocol.io/docs/concepts/roots)
|
||||||
|
|
||||||
## Directory Access Control
|
## Directory Access Control
|
||||||
|
|
||||||
The server uses a flexible directory access control system. Directories can be specified via command-line arguments or dynamically via the MCP roots protocol.
|
The server uses a flexible directory access control system. Directories can be specified via command-line arguments or dynamically via [Roots](https://modelcontextprotocol.io/docs/concepts/roots).
|
||||||
|
|
||||||
### Method 1: Command-line Arguments
|
### Method 1: Command-line Arguments
|
||||||
Specify Allowed directories when starting the server:
|
Specify Allowed directories when starting the server:
|
||||||
|
|
@ -21,14 +21,14 @@ Specify Allowed directories when starting the server:
|
||||||
mcp-server-filesystem /path/to/dir1 /path/to/dir2
|
mcp-server-filesystem /path/to/dir1 /path/to/dir2
|
||||||
```
|
```
|
||||||
|
|
||||||
### Method 2: MCP Roots Protocol (Recommended)
|
### Method 2: MCP Roots (Recommended)
|
||||||
MCP clients that support the roots protocol can dynamically update the Allowed directories.
|
MCP clients that support [Roots](https://modelcontextprotocol.io/docs/concepts/roots) can dynamically update the Allowed directories.
|
||||||
|
|
||||||
Roots notified by Client to Server, completely replace any server-side Allowed directories when provided.
|
Roots notified by Client to Server, completely replace any server-side Allowed directories when provided.
|
||||||
|
|
||||||
**Important**: If server starts without command-line arguments AND client doesn't support roots protocol (or provides empty roots), the server will throw an error during initialization.
|
**Important**: If server starts without command-line arguments AND client doesn't support roots protocol (or provides empty roots), the server will throw an error during initialization.
|
||||||
|
|
||||||
This is the recommended method, as MCP roots protocol for dynamic directory management. This enables runtime directory updates via `roots/list_changed` notifications without server restart, providing a more flexible and modern integration experience.
|
This is the recommended method, as this enables runtime directory updates via `roots/list_changed` notifications without server restart, providing a more flexible and modern integration experience.
|
||||||
|
|
||||||
### How It Works
|
### How It Works
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -927,14 +927,14 @@ server.oninitialized = async () => {
|
||||||
if (response && 'roots' in response) {
|
if (response && 'roots' in response) {
|
||||||
await updateAllowedDirectoriesFromRoots(response.roots);
|
await updateAllowedDirectoriesFromRoots(response.roots);
|
||||||
} else {
|
} else {
|
||||||
console.log("Client returned no roots set, keeping current settings");
|
console.error("Client returned no roots set, keeping current settings");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to request initial roots from client:", error instanceof Error ? error.message : String(error));
|
console.error("Failed to request initial roots from client:", error instanceof Error ? error.message : String(error));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (allowedDirectories.length > 0) {
|
if (allowedDirectories.length > 0) {
|
||||||
console.log("Client does not support MCP Roots, using allowed directories set from server args:", allowedDirectories);
|
console.error("Client does not support MCP Roots, using allowed directories set from server args:", allowedDirectories);
|
||||||
}else{
|
}else{
|
||||||
throw new Error(`Server cannot operate: No allowed directories available. Server was started without command-line directories and client either does not support MCP roots protocol or provided empty roots. Please either: 1) Start server with directory arguments, or 2) Use a client that supports MCP roots protocol and provides valid root directories.`);
|
throw new Error(`Server cannot operate: No allowed directories available. Server was started without command-line directories and client either does not support MCP roots protocol or provided empty roots. Please either: 1) Start server with directory arguments, or 2) Use a client that supports MCP roots protocol and provides valid root directories.`);
|
||||||
}
|
}
|
||||||
|
|
@ -947,7 +947,7 @@ async function runServer() {
|
||||||
await server.connect(transport);
|
await server.connect(transport);
|
||||||
console.error("Secure MCP Filesystem Server running on stdio");
|
console.error("Secure MCP Filesystem Server running on stdio");
|
||||||
if (allowedDirectories.length === 0) {
|
if (allowedDirectories.length === 0) {
|
||||||
console.log("Started without allowed directories - waiting for client to provide roots via MCP protocol");
|
console.error("Started without allowed directories - waiting for client to provide roots via MCP protocol");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue