MCP Filesystem Server
Provides file system operations (list, read, write, search) via MCP, enabling an AI agent to manage files through natural language.
README
MCP Filesystem Server & AI Orchestrator
A TypeScript-based Model Context Protocol (MCP) project featuring a lightweight filesystem server and an interactive AI agent that can read, write, search, and list files through natural language conversation.
🏗️ Architecture
This project consists of two main components communicating via the MCP protocol:
┌─────────────────────────────────────────────────────┐
│ AI Orchestrator │
│ (src/orchestrator.ts) │
│ │
│ ┌──────────┐ ┌──────────┐ ┌─────────────────┐ │
│ │ User │──▶│ OpenAI │──▶│ MCP Client │ │
│ │ Input │ │ (LLM) │ │ (Stdio) │ │
│ └──────────┘ └────┬─────┘ └────────┬────────┘ │
│ ▲ │ │ │
│ │ tool calls tool results │
│ │ & responses │ │
│ ┌────┴────┐ │ │
│ │ Output │ ▼ │
│ └─────────┘ ┌──────────────┐ │
│ │ │ │
│ ┌─────────────────────┐│ │
│ │ MCP Filesystem ││ │
│ │ Server ││ │
│ │ (src/index.ts) ││ │
│ │ ││ │
│ │ • list_files ││ │
│ │ • read_file ││ │
│ │ • write_file ││ │
│ │ • search_files ││ │
│ └─────────────────────┘│ │
└─────────────────────────────────────────────────────┘
📦 Tech Stack
| Technology | Purpose |
|---|---|
| TypeScript | Language |
| tsx | Run TypeScript directly (no build step) |
| Node.js | Runtime |
| @modelcontextprotocol/sdk | MCP protocol implementation |
| OpenAI SDK | LLM communication via OpenRouter |
| zod | Runtime validation |
| dotenv | Environment variable management |
🔧 Components
1. MCP Server — src/index.ts
A filesystem tool server that exposes 4 tools over MCP via stdio transport:
| Tool | Description | Parameters |
|---|---|---|
list_files |
List files in a directory | dir (string) — required |
read_file |
Read contents of a file | filePath (string) — required |
write_file |
Write content to a file | filePath (string), content (string) — both required |
search_files |
Search files containing specific text | dir (string), query (string) — both required |
2. Orchestrator / AI Agent — src/orchestrator.ts
An interactive AI agent that:
- Connects to the MCP server (spawns it as a child process)
- Dynamically fetches available tools from the server
- Accepts natural language user input via a REPL interface
- Sends prompts to the OpenAI-compatible LLM (
inclusionai/ring-2.6-1t:freevia OpenRouter) - Detects tool call requests in the model's response
- Executes the corresponding MCP tools on the server
- Feeds tool results back to the model for continued reasoning
- Outputs the final natural language answer
🔄 Interaction Flow
User Input
│
▼
┌──────────────┐
│ OpenAI LLM │ (via OpenRouter)
│ (Reasoning) │
└──────┬───────┘
│
┌───┴────────┐
│ Tool Call? │
└───┬────────┘
Yes │ No
▼ ▼
┌────────────┐ ┌──────────────┐
│ MCP Server │ │ Final Answer│
│ (File Ops) │ │ → User │
└─────┬──────┘ └──────────────┘
│
▼
Tool Result
│
▼
Feed back to LLM → Continue reasoning or finalize
⚡ Quick Start
Prerequisites
- Node.js (v18+ recommended)
- npm
- An OpenRouter API key (get one at openrouter.ai)
Setup
-
Clone the repository
git clone <repo-url> cd mcp -
Install dependencies
npm install -
Configure environment variables
cp sample-env .env # Edit .env and add your OpenRouter API key: # OPENROUTER_API_KEY=your_key_here -
Start the MCP Server (optional — orchestrator spawns it automatically)
npm run dev -
Run the Orchestrator
npm run orchestrator -
Interact with the agent — Type natural language commands like:
- "List all files in the src directory"
- "Read the contents of package.json"
- "Write a hello world message to a new file"
- "Search for 'import' in the src folder"
- Type
exitto quit
📁 Project Structure
.
├── .env # OpenRouter API key (not committed)
├── .gitignore # Git ignore rules
├── package.json # Node.js project configuration
├── package-lock.json # Dependency lock file
├── sample-env # Environment variable template
├── tsconfig.json # TypeScript compiler options
├── README.md # This file
└── src/
├── index.ts # MCP Server — filesystem tools
└── orchestrator.ts # AI Agent — MCP client & prompt loop
📝 Notes
- Model: The orchestrator uses
inclusionai/ring-2.6-1t:freevia OpenRouter. This can be changed insrc/orchestrator.tsby modifying themodelfield in thechat.completions.create()call. - Transport: Both server and client communicate over stdio (
StdioServerTransport/StdioClientTransport), which is the simplest MCP transport method. - Security: This is a demo project. In production, you'd want proper error handling, input validation, security boundaries on file access, and potentially a different transport method (e.g., SSE or HTTP).
📚 References
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。