mcp-local-files

mcp-local-files

Enables ChatGPT/Codex to read, search, and edit files in a single allowed folder on Windows through OpenAI Secure MCP Tunnel.

Category
访问服务器

README

Local Files MCP

English | 日本語

A small local MCP server that lets ChatGPT/Codex read, search, and edit a single allowed folder on this Windows machine through OpenAI Secure MCP Tunnel.

This project is intentionally simple and local-first. The server runs over stdio, and tunnel-client.exe forwards ChatGPT MCP requests to it. The exposed folder is controlled by root-dir.txt, not hardcoded in server.js.

Current folder

This repository lives at:

%USERPROFILE%\mcp-local-files

The folder currently exposed to ChatGPT/Codex is stored in:

%USERPROFILE%\mcp-local-files\root-dir.txt

To see or change it manually:

type %USERPROFILE%\mcp-local-files\root-dir.txt
notepad %USERPROFILE%\mcp-local-files\root-dir.txt

Files

server.js          MCP stdio server implementation
cli.js             npm CLI wrapper and tunnel-client downloader
package.json       Node.js dependencies and npm scripts
run-mcp.cmd        Starts the MCP server using ROOT_DIR from root-dir.txt
mcp-here.cmd       Writes the current terminal directory into root-dir.txt
root-dir.txt       Current allowed folder for Local Files MCP
AGENTS.md          Instructions for Codex/agents working on this folder

Install

From PowerShell:

cd %USERPROFILE%\mcp-local-files
npm install

When installed as an npm package, the CLI command is:

mcp-local-files --help

First-time tunnel setup

The CLI can guide the first tunnel profile setup:

mcp-local-files setup

It will:

download OpenAI tunnel-client if needed
open the OpenAI Tunnels page
open the OpenAI Runtime API keys page
ask for a tunnel_id and Runtime API key
create the default tunnel-client profile
save the Runtime API key outside this project folder

OpenAI setup pages:

https://platform.openai.com/settings/organization/tunnels
https://platform.openai.com/settings/organization/api-keys

The default profile name shown by setup is:

local-files

The Runtime API key is stored in the user's private config file:

%USERPROFILE%\.mcp-local-files\secrets.json

Do not commit this file. It is intentionally outside the npm package folder.

After setup, the profile you just created is saved as the CLI default. That means mcp-local-files --tunnel-here will use that profile automatically unless you pass --profile. If you already ran setup with an older CLI, the command also falls back to the only saved profile when exactly one profile exists.

Non-interactive values can be passed like this:

mcp-local-files setup --profile local-files --tunnel-id tunnel_xxx --no-open

The Runtime API key is still requested interactively so it does not appear in shell history.

On Windows, the default MCP command saved by setup is:

cmd /d /s /c "%USERPROFILE%/mcp-local-files/run-mcp.cmd"

This keeps the existing run-mcp.cmd / root-dir.txt flow intact.

run-mcp.cmd reads ROOT_DIR from root-dir.txt, then exports it to the child node process using the endlocal & set trick so the env var survives across cmd's local scope. server.js resolves ROOT_DIR from, in order:

  1. process.env.ROOT_DIR
  2. process.argv[2]
  3. %USERPROFILE%\mcp-local-files\root-dir.txt

This lets the same run-mcp.cmd work both as the tunnel target and as a local smoke test without changing directory first.

Change the exposed folder quickly

Open Windows Terminal, cd into the folder you want ChatGPT/Codex to access, then run:

%USERPROFILE%\mcp-local-files\mcp-here.cmd

Example:

cd C:\path\to\your-project
%USERPROFILE%\mcp-local-files\mcp-here.cmd

After changing the folder, restart the tunnel client so the new ROOT_DIR is applied.

With the npm CLI, this can be done in one step:

cd C:\path\to\your-project
mcp-local-files --tunnel-here

--tunnel-here writes the current folder to the root file, downloads OpenAI tunnel-client on first use if needed, verifies its SHA256 checksum, and starts the last profile created by mcp-local-files setup.

Use a different profile when needed:

mcp-local-files --tunnel-here --profile local-files

Start the local MCP server directly

For a local smoke test:

cmd /d /s /c "%USERPROFILE%/mcp-local-files/run-mcp.cmd"

The process should keep running. Stop it with Ctrl+C.

The npm CLI can also start the stdio server directly:

mcp-local-files --root C:\path\to\folder

Run through OpenAI Tunnel

The profile already created is:

local-files

Normal run command:

cd C:\path\to\tunnel-client-folder
.\tunnel-client.exe run --profile local-files

The npm CLI can download and run OpenAI tunnel-client automatically:

mcp-local-files tunnel run --profile local-files

If mcp-local-files setup saved a Runtime API key for that profile, the CLI passes it to tunnel-client as CONTROL_PLANE_API_KEY only for the child process.

On first use, it downloads the matching platform zip from the official openai/tunnel-client GitHub release, downloads SHA256SUMS.txt, verifies the archive, extracts the binary into the user cache, and runs it from there.

Default cache locations:

Windows: %USERPROFILE%\.cache\mcp-local-files\tunnel-client
macOS/Linux: ~/.cache/mcp-local-files/tunnel-client

To use an existing binary instead of auto-download:

mcp-local-files --tunnel-client C:\path\to\tunnel-client.exe tunnel run --profile local-files

Useful diagnostic command:

cd C:\path\to\tunnel-client-folder
.\tunnel-client.exe doctor --profile local-files --explain

If the profile must be recreated, prefer forward slashes in the MCP command to avoid Windows escaping problems:

.\tunnel-client.exe init --sample sample_mcp_stdio_local --profile local-files --tunnel-id tunnel_xxx --mcp-command 'cmd /d /s /c "%USERPROFILE%/mcp-local-files/run-mcp.cmd"'

Do not commit or paste Runtime API keys into this project. Set them only in the terminal environment when needed.

The tunnel-client binary is not bundled in this package. It is fetched from OpenAI's public release artifacts when the CLI needs it. Keep the Apache-2.0 LICENSE and OpenAI NOTICE terms in mind if redistributing downloaded artifacts yourself.

Exposed MCP tools

The server registers these tools:

list_files       List files and folders inside ROOT_DIR
read_file        Read UTF-8 text files inside ROOT_DIR
search_files     Search text files inside ROOT_DIR
stat_file        Return metadata for a file or folder inside ROOT_DIR
copy_file        Copy one file inside ROOT_DIR without deleting the source
copy_files       Copy multiple files inside ROOT_DIR without deleting sources
write_file       Create or overwrite UTF-8 text files inside ROOT_DIR
replace_in_file  Replace exact text inside a UTF-8 text file inside ROOT_DIR
read_binary_file_base64  Read a binary file inside ROOT_DIR and return base64
write_base64_file        Decode base64 and write a binary file inside ROOT_DIR

Copy / transfer tools

Use these when you want TransferFiles-style local movement inside the exposed folder. They only copy files inside ROOT_DIR; they do not delete source files and they still block absolute paths or .. escapes.

stat_file input:

{
  "path": "dist/app.zip"
}

copy_file input:

{
  "sourcePath": "dist/app.zip",
  "destinationPath": "incoming/app.zip",
  "overwrite": false
}

copy_files input:

{
  "files": [
    {
      "sourcePath": "dist/app.zip",
      "destinationPath": "incoming/app.zip"
    }
  ],
  "overwrite": false
}

Batch copies are checked before copying starts. Existing destination files are protected unless overwrite is explicitly set to true. Single copied files are capped at 100 MB, and one batch can contain up to 100 files.

Binary file tools

Use these only for files that must be transferred as bytes, such as PNG, JPEG, WebP, GIF, ZIP, or PDF files.

read_binary_file_base64 input:

{
  "path": "images/example.png",
  "maxBytes": 10000000
}

It returns path, size, base64, encoding: "base64", and a simple mimeType guess. If the file is larger than maxBytes, the server returns an error instead of truncating the data.

write_base64_file input:

{
  "path": "images/example.png",
  "base64": "iVBORw0KGgo...",
  "overwrite": false
}

It creates parent folders when needed. Existing files are protected unless overwrite is explicitly set to true. Decoded binary writes are capped at 25 MB.

Safety model

The server is scoped to one folder only. All paths passed to tools must be relative to ROOT_DIR.

The server blocks:

absolute paths
.. path traversal outside ROOT_DIR
text reads for non-allowlisted file types
large text search over files bigger than 2 MB
binary reads above the requested maxBytes limit
binary writes above the server write-size limit
copying files larger than 100 MB
batch copy requests above 100 files

The directory walker skips:

node_modules
.git
.venv

This is intentional. Do not expose C:\, the full user profile, or folders containing secrets unless the user explicitly requests it and understands the risk.

Troubleshooting

If ChatGPT says connector creation failed and the tunnel log shows file already closed, usually the local MCP process exited immediately. Run this first:

cmd /d /s /c "%USERPROFILE%/mcp-local-files/run-mcp.cmd"

If the log says the command is not recognized, check the profile command path. Prefer this form:

cmd /d /s /c "%USERPROFILE%/mcp-local-files/run-mcp.cmd"

If ROOT_DIR is required appears, check run-mcp.cmd and root-dir.txt.

If Node cannot find packages, run:

cd %USERPROFILE%\mcp-local-files
npm install

Notes

Keep the MCP server stdio-clean. Do not print normal logs to stdout from server.js, because stdout is used by the MCP protocol. Use stderr only for critical startup errors.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选