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
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.