ylcnfrht/file-mcp-server
If you are the rightful owner of file-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
A tiny Model Context Protocol (MCP) server that exposes basic file system operations, built with TypeScript and Zod.
File MCP Server
A tiny Model Context Protocol (MCP) server that exposes basic file system operations. Built with TypeScript and Zod. Easy to extend.
Quick Start
npm install
npm run build && npm start
Server runs over stdio and operates on files within the current working directory (or FILE_BASE_DIR environment variable).
Development
npm run dev
Inspector
Interactive testing with MCP Inspector:
npm run build
npm run inspector
This starts the server under the inspector so you can list tools and call them.
Tools
- listFiles: lists all files in a directory
- readFile: reads the content of a file
- writeFile: writes content to a file (creates or overwrites)
- deleteFile: deletes a file from the filesystem
List tools request (MCP):
{
"method": "tools/list",
"params": {}
}
Call example:
{
"method": "tools/call",
"params": {
"name": "writeFile",
"arguments": { "filePath": "example.txt", "content": "Hello, World!" }
}
}
Response example:
{
"content": [{ "type": "text", "text": "File \"example.txt\" written successfully." }]
}
Validation & Schemas
- Input validation is done with Zod directly in
src/index.ts. inputSchemareturned bytools/listis a JSON Schema object that MCP clients can use.
File path input schema (Zod):
const readInput = z.object({ filePath: z.string().describe('Path to the file to read') });
File path and content input schema (Zod):
const writeInput = z.object({
filePath: z.string().describe('Path to the file to write'),
content: z.string().describe('Content to write'),
});
JSON Schema (for MCP):
const inputFilePathAndContentJsonSchema = {
type: 'object',
properties: {
filePath: { type: 'string', description: 'filePath' },
content: { type: 'string', description: 'content' },
},
required: ['filePath', 'content'],
} as const;
Project Structure
src/
index.ts # server setup, tool definitions, validation, and handlers
dist/
index.js # build output
Extending (add a new tool)
All tools are defined in src/index.ts under the tools map. To add one:
- Add or reuse a Zod schema and corresponding JSON Schema.
- Implement an
executefunction. - Register the tool in the
toolsmap withdescription,inputSchema,validate,execute, andformat.
Scripts
From package.json:
build: compile TypeScript todist/start: runnode dist/index.jsdev:tsc && node dist/index.jsinspector:npx @modelcontextprotocol/inspector node dist/index.js
Troubleshooting
- "Cannot find module …/x.js": ensure ESM paths include
.jsextensions (tsconfig uses NodeNext). - "File not found":
readFilethrows when file doesn't exist. - "Invalid arguments …": Zod validation failed; ensure valid
filePathandcontentstrings. - "Permission denied": ensure the server has read/write permissions for the target directory.
License
MIT