MCP Filesystem Server

MCP Filesystem Server

Provides file system operations (list, read, write, search) via MCP, enabling an AI agent to manage files through natural language.

Category
Visit Server

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:free via 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

  1. Clone the repository

    git clone <repo-url>
    cd mcp
    
  2. Install dependencies

    npm install
    
  3. Configure environment variables

    cp sample-env .env
    # Edit .env and add your OpenRouter API key:
    # OPENROUTER_API_KEY=your_key_here
    
  4. Start the MCP Server (optional β€” orchestrator spawns it automatically)

    npm run dev
    
  5. Run the Orchestrator

    npm run orchestrator
    
  6. 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 exit to 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:free via OpenRouter. This can be changed in src/orchestrator.ts by modifying the model field in the chat.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

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Exa Search

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.

Official
Featured