LiviuBirjega/files-mcp-ts
If you are the rightful owner of files-mcp-ts and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A lightweight Model Context Protocol (MCP) server implemented in TypeScript for performing basic file operations.
files-mcp-ts
A lightweight Model Context Protocol (MCP) server implemented in TypeScript for performing basic file operations. This server provides secure file system access through the MCP interface, allowing AI assistants and other MCP clients to read, write, and list files in a controlled manner.
Overview
This MCP server implements the Model Context Protocol specification to provide file system operations. The main FilesMcpTs
class in src/index.ts
creates an MCP server that:
- Tools: Exposes three file operation tools (
read_file
,list_files
,write_file
) - Resources: Provides a
file://current-directory
resource for directory listings - Transport: Uses stdio transport for communication with MCP clients
- Architecture: Clean TypeScript implementation with proper error handling and type safety
The server is designed to be spawned by MCP clients and communicates via standard input/output streams.
Project Structure
files-mcp-ts/
βββ src/
β βββ index.ts # Main MCP server implementation
βββ dist/ # Compiled JavaScript output (generated)
βββ node_modules/ # Dependencies (generated)
βββ .gitignore # Git ignore rules
βββ package.json # Package configuration and dependencies
βββ pnpm-lock.yaml # Dependency lock file
βββ tsconfig.json # TypeScript compiler configuration
βββ README.md # This documentation
Features
Tools
read_file
β Read the contents of any text file by providing its pathlist_files
β List all files and directories within a specified directorywrite_file
β Write or overwrite text content to a file (creates directories if needed)
Resources
file://current-directory
β Provides a real-time listing of files in the server's working directory
Technical Features
- Type Safety β Full TypeScript implementation with strict type checking
- Error Handling β Comprehensive error handling with proper MCP error codes
- Async Operations β Non-blocking file operations using Node.js fs/promises
- Input Validation β Parameter validation for all tool calls
Prerequisites
- Node.js 18.x or newer β Required for ES2022 features and MCP SDK compatibility
- pnpm β Recommended package manager (or npm/yarn as alternatives)
- TypeScript knowledge β For development and customization
Installation & Setup
-
Install dependencies:
pnpm install
-
Build the project:
pnpm build
This compiles TypeScript sources from
src/
to JavaScript indist/
. -
Verify installation:
pnpm start
You should see:
Simple Files MCP Server running on stdio
Usage
Development Mode
pnpm dev
Runs the server directly from TypeScript source with hot reloading via tsx
.
Production Mode
pnpm start
# or
npx files-mcp-ts
Runs the compiled JavaScript version from dist/
.
Integration with MCP Clients
The server communicates via stdio and is designed to be spawned by MCP clients. It's not meant to be run interactively but rather integrated into MCP-compatible applications.
MCP Client Integration
Claude Desktop Configuration
Add this server to your Claude Desktop configuration file:
Location: ~/Library/Application Support/Claude/claude_desktop_config.json
(macOS) or %APPDATA%\Claude\claude_desktop_config.json
(Windows)
{
"mcpServers": {
"files-mcp-ts": {
"command": "node",
"args": ["/path/to/files-mcp-ts/dist/index.js"],
"workingDirectory": "/desired/working/directory"
}
}
}
Alternative: Using pnpm
{
"mcpServers": {
"files-mcp-ts": {
"command": "pnpm",
"args": ["exec", "files-mcp-ts"],
"workingDirectory": "/path/to/files-mcp-ts"
}
}
}
Configuration Notes
- The
workingDirectory
determines where thefile://current-directory
resource points - Ensure the path to the compiled
dist/index.js
is correct - Restart Claude Desktop after configuration changes
Windsurf IDE Configuration
Add this server to your Windsurf MCP configuration file:
Location: %APPDATA%\Codeium\Windsurf\mcp_config.json
(Windows) or ~/.codeium/windsurf/mcp_config.json
(macOS/Linux)
{
"mcpServers": {
"files-mcp-ts": {
"command": "node",
"args": [
"/path/to/files-mcp-ts/dist/index.js"
]
}
}
}
Note: Use absolute paths and proper Windows path escaping (double backslashes) for the args
parameter.
Windsurf IDE Integration
Once configured, this MCP server integrates seamlessly with Windsurf IDE. You'll see:
- Server Status Panel - Shows
files-mcp-ts
as enabled with a green status indicator - Available Tools Display - Lists all 3 tools (
read_file
,list_files
,write_file
) with descriptions - Automatic Tool Discovery - Windsurf automatically detects and registers your server's capabilities
- Ready-to-Use Integration - AI assistants in Windsurf can immediately use your file operations
Configuration in Windsurf: The server appears in the MCP configuration panel where you can:
- Toggle the server on/off with the "Enabled" switch
- View all available tools and their descriptions
- Access configuration options via the "Configure" button
- Monitor connection status in real-time
API Reference
Tools
read_file
Reads and returns the contents of a text file.
Parameters:
path
(string, required) β File path to read
Returns: File contents as text
Example:
{
"name": "read_file",
"arguments": {
"path": "./example.txt"
}
}
list_files
Lists all files and directories in the specified directory.
Parameters:
directory
(string, required) β Directory path to list
Returns: Newline-separated list of file/directory names
Example:
{
"name": "list_files",
"arguments": {
"directory": "./src"
}
}
write_file
Writes text content to a file, creating or overwriting as needed.
Parameters:
path
(string, required) β File path to write tocontent
(string, required) β Text content to write
Returns: Success confirmation message
Example:
{
"name": "write_file",
"arguments": {
"path": "./output.txt",
"content": "Hello, World!"
}
}
Resources
Understanding Resources vs Tools
Resources are static or dynamic content that MCP clients can access directly, while Tools are functions that clients can call with parameters.
Aspect | Tools | Resources |
---|---|---|
Usage | Call with parameters | Request by URI |
Flexibility | Can target any file/directory | Fixed to server's working directory |
Parameters | Required | None |
Purpose | Perform actions | Provide information |
Example | list_files("./src") | file://current-directory |
Tool Examples:
// read_file - REQUIRES path parameter
{"name": "read_file", "arguments": {"path": "./example.txt"}}
// list_files - REQUIRES directory parameter
{"name": "list_files", "arguments": {"directory": "./src"}}
// write_file - REQUIRES path AND content parameters
{"name": "write_file", "arguments": {"path": "./new.txt", "content": "Hello!"}}
Resource Example:
URI: "file://current-directory"
Returns: "src\ndist\npackage.json\nREADME.md"
No parameters needed - just request the URI
file://current-directory
Provides a real-time listing of files in the server's working directory.
URI: file://current-directory
MIME Type: text/plain
Content: Newline-separated list of files and directories
How it works:
// In src/index.ts - when a client requests the resource
if (uri === 'file://current-directory') {
const files = await fs.readdir('.'); // Read current directory
return {
contents: [{
uri,
mimeType: 'text/plain',
text: files.join('\n') // Return as newline-separated list
}]
};
}
Example Output:
If the server runs in a directory containing src/
, dist/
, package.json
, README.md
, the resource returns:
src
dist
package.json
README.md
Key Benefits:
- Always current - Reflects real-time directory state
- Efficient - No function call needed, just request the URI
- Cacheable - MCP clients can cache and refresh as needed
- Different from
list_files
tool - This resource shows the server's working directory, while the tool can list any specified directory
How to Access Resources
β Common Misconception:
You cannot access resources by simply typing the URI like file://current-directory
in a chat or browser. Resources are MCP protocol endpoints, not web URLs.
β Correct Usage: Resources must be accessed through MCP clients:
In Windsurf IDE or Claude Desktop:
Ask the AI: "Show me the current directory resource from the MCP server"
The AI assistant will use the MCP interface to fetch the resource for you.
In Your Own MCP Client Code:
// Example client implementation
const response = await mcpClient.readResource({
uri: "file://current-directory"
});
console.log(response.contents[0].text);
Key Concept:
- Resource URI = The "address" of the content (
file://current-directory
) - MCP Client = The "postal service" that fetches it (Windsurf, Claude Desktop, etc.)
- You = The person requesting the content
Think of resources like internal API endpoints that only work through the MCP protocol, not as direct web URLs you can visit in a browser.
Development
Extending the Server
- Adding new tools: Register additional handlers in the
setupToolHandlers()
method - Adding new resources: Register additional handlers in the
setupResourceHandlers()
method - Modifying existing functionality: Edit the respective handler functions in
src/index.ts
Development Workflow
- Make changes to
src/index.ts
- Test with
pnpm dev
for immediate feedback - Build with
pnpm build
for production - Test the built version with
pnpm start
Code Quality
- The project uses TypeScript strict mode for type safety
- All file operations use async/await patterns
- Proper error handling with MCP-specific error codes
- Input validation for all tool parameters
Security Considerations
- File paths are not sanitized by default β consider adding path validation for production use
- The server has access to the entire file system β run in a sandboxed environment if needed
- No authentication or authorization is implemented β suitable for trusted environments only
Security & Access Control
MCP Protocol Isolation
Important: MCP resources are NOT accessible from outside the MCP server ecosystem. This isolation is intentional and provides security benefits.
What MCP Resources Are NOT:
- β Not web URLs - Cannot access via HTTP/HTTPS requests
- β Not REST API endpoints - No direct HTTP access
- β Not file system paths - Cannot browse to them like files
- β Not network services - No TCP/UDP ports exposed
What MCP Resources ARE:
- β Internal protocol endpoints - Only work within MCP ecosystem
- β Client-server communication - Require MCP client to access
- β Stdio-based - Communication over standard input/output
- β Process-to-process - Server spawned by MCP client
Security Architecture:
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Outside β β MCP Client β β MCP Server β
β World βββββΆβ (Windsurf/ βββββΆβ (files-mcp-ts) β
β β β Claude) β β β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β
β
Cannot access Can access Provides
resources directly via MCP protocol resources
Security Benefits:
- No network exposure - Server doesn't listen on network ports
- Controlled access - Only authorized MCP clients can connect
- Process isolation - Server runs as subprocess of client
- No direct file system exposure - Resources mediated through MCP protocol
- Client-level authentication - Access control handled by MCP client
- Sandboxing possible - Client can restrict server capabilities
External Access Considerations:
If external access is needed, you would need to build a separate HTTP bridge service, but this would defeat the security purpose of MCP's isolated design. The file://current-directory
URI only has meaning within the MCP context - it's not a universal resource locator like HTTP URLs.
Contributing
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
Development Setup
- Fork the repository
- Clone your fork:
git clone <your-fork-url>
- Install dependencies:
pnpm install
- Make your changes
- Test thoroughly with
pnpm dev
- Build and verify:
pnpm build && pnpm start
- Submit a pull request