local-env-mcp

local-env-mcp

Exposes your local machine's filesystem, git, shell, network, databases, and system to any MCP-compatible LLM client over HTTP.

Category
访问服务器

README

local-env-mcp

A stateless, Dockerized Model Context Protocol (MCP) server built with TypeScript. It exposes your local machine — filesystem, git, shell, network, databases, and system — to any MCP-compatible LLM client over HTTP.

Built natively in TypeScript on the @modelcontextprotocol/sdk utilizing Express, Zod schemas, and a fully decoupled, layered architecture.


Quick Start

# 1. Clone and install
git clone <repo-url>
cd local-mcp
npm install

# 2. Build the TypeScript source
npm run build

# 3. Start the server (runs on port 3000 by default)
npm start

# OR Start with Docker (multi-stage build)
docker compose up -d --build

# 4. Expose via ngrok (in a separate terminal)
ngrok http 3001

# 5. Copy the ngrok URL and add to Claude.ai
# Settings → Integrations → Add MCP Server
# URL: https://your-ngrok-url.ngrok-free.app/mcp

Table of Contents


Architecture

LLM Client (Claude / Cursor / API)
        │  HTTPS POST /mcp
        ▼
   Express Routing Layer (src/app.ts)
        │
        ├── GET  /health → System Checks
        ├── POST /mcp    → Create Server Session
        ├── GET  /mcp    → Resume Session
        └── DELETE /mcp  → Purge Session
               │
               ▼
   Layered Tool Registry (src/tools/registry.ts)
               │
 ┌─────────┬───┴─────┬─────────┬─────────┬─────────┐
 ▼         ▼         ▼         ▼         ▼         ▼
 FS       Git      Network   Shell     System    Postgres
(9)      (11)       (8)       (9)       (8)       (3)

Stateless Mode: Each POST request spins up a fresh McpServer instance dynamically managed by a singleton Session Manager.


Project Structure

Migrated from legacy monolithic JS, the project now follows a strictly typed layered framework:

local-mcp/
├── src/
│   ├── server.ts               # Listener & bootstrap
│   ├── app.ts                  # Express routing & middleware wiring
│   ├── config.ts               # Zod-validated env loader (.env handled via dotenv)
│   ├── logger.ts               # Winston configuration
│   ├── routes/                 # Separated Controllers (health.ts, mcp.ts)
│   ├── services/               # Core Logic (processManager, sessionManager)
│   ├── types/                  # Shared TS definitions
│   └── tools/                  # All 48 MCP Tools separated by domain
│       ├── filesystem/         
│       ├── git/                
│       ├── network/            
│       ├── postgres/           # Dynamic Database capabilities
│       ├── shell/              
│       ├── system/             
│       └── registry.ts         # Injects toolsets into active MCP Sessions

Transport & Session Model

Uses the Streamable HTTP transport.

Route Purpose
POST /mcp Initiates tool requests (tools/list, tools/call) — hooks into new or cached session.
GET /mcp Streams Server-Sent Events (SSE) for continuous clients.
DELETE /mcp Gracefully terminate an active server.

Tool Reference

Currently bundling 48 Native Tools mapped through specific modules.

📁 Filesystem

(All paths resolved relative to FS_ROOT protecting against directory traversal)

  • read_file, write_file, list_dir, make_dir, delete_path, copy_path, move_path, search_files, file_info

🌿 Git

(Powered by simple-git, targets directories relative to FS_ROOT)

  • git_status, git_diff, git_log, git_branch, git_add, git_commit, git_push, git_pull, git_clone, git_stash, git_show

🌐 Network

  • http_request, ping, dns_lookup, port_scan, whois, traceroute, download_file, check_connectivity

💻 Shell

(Managed by the injected ProcessManager service isolating spawn logs in memory)

  • run_command, spawn_process, list_processes, get_process_logs, kill_process, system_info, get_env, which, ps

🖥️ System

  • cron_list, disk_usage, open, notify, clipboard_write, clipboard_read, screenshot, list_installed

🐘 Postgres

(Connects dynamically on-the-fly rather than hardcoded global connections)

  • pg_query: Execute parameterized raw SQL queries directly.
  • pg_list_tables: Enumerate all active tables ignoring system schemas.
  • pg_describe_table: Interrogate type formats, nullability, and default requirements for a target schema table.

Note: The Postgres tools require you to provide a connectionString argument directly through the LLM interface, keeping your server completely credential-less by design.


Environment Variables

Handled seamlessly using dotenv.

Variable Required Default Description
PORT No 3000 HTTP port the Express server binds to.
FS_ROOT No /host-home Root directory for File operations. Path constraints enforce this border.
MCP_AUTH_TOKEN Yes (prod) (none) Bearer auth token for X-MCP-Token. Omitting heavily warns during dev mode.
NODE_ENV No development Setting to production enforces Token Auth checks.

Extending with New Tools

Adding tools is significantly easier with the Modular Architecture:

  1. Create a strictly-typed configuration inside your target domain layer (e.g. src/tools/custom/myTool.ts):
import { z } from "zod";
import type { ToolDefinition } from "../../types/index.js";
import { ok } from "../../utils/response.js";

export const myCustomTool: ToolDefinition = {
  name: "custom_tool",
  description: "Does something specific",
  schema: {
    target: z.string().describe("What to target"),
  },
  handler: async ({ target }) => {
    return ok(`Executed logic on ${target}`);
  }
};
  1. Import and append your tool array to registerAllTools in src/tools/registry.ts.

Security Model

Concern Mitigation
Path traversal safePath() heavily anchors against FS_ROOT bounds.
Secret leakage get_env redacts items masking standard keys (secrets/passwords/apis).
Docker Isolation Runs natively as unescalated mcpuser relying on safe Mount Points.
DB Access Handled dynamically avoiding persistent env leaks in logs.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选