Configure and use the Model Context Protocol filesystem server for AI-powered file and directory operations with secure access controls.
Configure and use the Model Context Protocol (MCP) filesystem server to enable AI assistants to perform secure file and directory operations on your system.
This skill helps you set up and use the `@agent-infra/mcp-server-filesystem` package, which provides AI agents with controlled access to filesystem operations through the Model Context Protocol. It supports multiple deployment modes and AI development environments.
1. **Identify your MCP client's configuration file location:**
- VS Code/Cursor: `.vscode/mcp.json` or global settings
- Windsurf: Follow their MCP documentation
- Claude Desktop: `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or equivalent on other platforms
2. **Add the filesystem server configuration:**
```json
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"@agent-infra/mcp-server-filesystem@latest"
]
}
}
}
```
3. **Configure allowed directories (recommended for security):**
Add the `--allowed-directories` flag to restrict access to specific paths:
```json
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"@agent-infra/mcp-server-filesystem@latest",
"--allowed-directories",
"/path/to/project1",
"/path/to/project2"
]
}
}
}
```
4. **Restart your MCP client** to load the new configuration.
Run this command in your terminal:
```bash
code --add-mcp '{"name":"filesystem","command":"npx","args":["@agent-infra/mcp-server-filesystem@latest"]}'
```
1. **Start the MCP server on a specific port:**
```bash
npx @agent-infra/mcp-server-filesystem --port 8089 --allowed-directories /path/to/allowed/dir
```
2. **Configure your MCP client with the remote endpoint:**
For SSE:
```json
{
"mcpServers": {
"filesystem": {
"url": "http://127.0.0.1:8089/sse"
}
}
}
```
For Streamable HTTP (recommended):
```json
{
"mcpServers": {
"filesystem": {
"type": "streamable-http",
"url": "http://127.0.0.1:8089/mcp"
}
}
}
```
If building a custom MCP client:
```javascript
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
import { createServer } from '@agent-infra/mcp-server-filesystem';
const client = new Client(
{
name: 'filesystem-client',
version: '1.0',
},
{
capabilities: {},
},
);
const server = createServer();
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
await Promise.all([
client.connect(clientTransport),
server.connect(serverTransport),
]);
// List available tools
const tools = await client.listTools();
// Call a tool
const result = await client.callTool({
name: 'list_directory',
arguments: {
path: '/your/path'
},
});
```
Once configured, the AI assistant will have access to filesystem tools such as:
1. **Always use `--allowed-directories`** to restrict filesystem access to specific paths
2. **Avoid granting access to:**
- System directories (`/etc`, `/System`, `/Windows`)
- User home directory root (unless specifically needed)
- Directories containing sensitive credentials
3. **Use separate configurations** for different projects with appropriate directory restrictions
4. **Review the AI's file operations** before confirming destructive actions
After setup, you can ask your AI assistant:
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/mcp-filesystem-server/raw