Skip to main content
Glama
midsane

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

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

A
license - permissive license
-
quality - not tested
C
maintenance

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/midsane/mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server