Skip to main content
Glama
MCP Filesystem Server

MCP Filesystem Server

by midsane

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     β”‚β”‚  β”‚
β”‚                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Related MCP server: maic-server-fs-mcp

πŸ“¦ 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

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Provides LLMs with local filesystem operations (read/write files, list directories) and command execution via MCP, enabling file management and task automation within AI clients.
      7
      15 npm
      ISC
    • A
      license
      Not graded
      quality
      D
      maintenance
      Exposes file system operations to AI clients via MCP, enabling secure read, write, and management of files and folders.
      2 npm
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to interact with a sandboxed filesystem via MCP tools for reading, writing, searching, and monitoring files, including batch processing and resource discovery for resume management.
      -

    Appeared in Searches