Notion Terminal MCP
Enables AI agents to remotely execute terminal commands and perform filesystem operations on the host machine, with secure authentication and optional ngrok tunneling for integration with Notion and other clients.
README
Notion Terminal MCP
An authenticated, production-ready remote Model Context Protocol (MCP) server providing Terminal Execution and Filesystem Tools to Notion Custom Agents, Claude, Cursor, and autonomous AI agents over Streamable HTTP.
Includes built-in zero-config public tunneling via the official Ngrok Node.js SDK (@ngrok/ngrok).
Features
- ⚡ Streamable HTTP Transport: Modern MCP server implementation running on Express.
- 🌐 Built-in Ngrok Tunnel: Expose your local MCP server to Notion with a single command (
npm run startornpm run dev) using@ngrok/ngrok. - 💻 Terminal Execution: Execute PowerShell or cmd commands with configurable timeouts, working directories, and recursive process tree termination.
- 📁 Filesystem Operations: Full set of tools for reading, writing, moving, listing, statting, and deleting files and directories.
- 🔒 Security & Sandboxing:
- Sandboxed Mode (
FULL_ACCESS=false): Strict path containment inside a configuredFILES_ROOTwith path traversal defense. - Full Host Mode (
FULL_ACCESS=true): Unrestricted access when you need full host automation. - Timing-Safe Auth: Constant-time comparison (
crypto.timingSafeEqual) for Bearer tokens and API keys. - Host Header Validation: Prevents DNS rebinding and unauthorized host header spoofing.
- Sandboxed Mode (
- 🤖 Agent-First Design: Detailed specifications and JSON schemas optimized for AI models (AGENT_SPEC.md).
Quick Start
1. Installation
Clone the repository and install dependencies:
git clone https://github.com/Speedstu/notion-terminal-mcp.git
cd notion-terminal-mcp
npm install
2. Environment Setup
Copy .env.example to .env or run the setup script:
# Automated setup (generates a secure 32+ character API key)
.\setup.ps1
Or manually:
Copy-Item .env.example .env
# Generate a secure token:
npm run token
Edit your .env file:
# Required: Secure API Key for Notion
MCP_API_KEY=your_generated_32_char_api_key
PORT=3000
HOST=127.0.0.1
# Ngrok Public Tunnel (Optional but recommended for Notion)
NGROK_ENABLED=true
NGROK_AUTHTOKEN=your_ngrok_authtoken_here
NGROK_DOMAIN=your-static-name.ngrok-free.app
# Security & Sandboxing
FULL_ACCESS=false
FILES_ROOT=./workspace
ALLOWED_HOSTS=localhost:3000;127.0.0.1:3000;*.ngrok-free.app;*.ngrok.app;*.ngrok-free.dev
3. Build & Run
# Build TypeScript
npm run build
# Start production server
npm run start
For development with hot reload:
npm run dev
When started with NGROK_ENABLED=true, the server will output connection details ready to paste into Notion:
============================================================
NOTION MCP AGENT CONNECTION READY
============================================================
URL to paste into Notion: https://your-domain.ngrok-free.app/mcp
Authentication Header:
Header Name: Authorization
Header Value: Bearer <your_token>
============================================================
Connecting to Notion Custom Agents
- In Notion, open Settings & members → Connections (or open your Notion Agent configuration).
- Add a new Custom MCP Connection.
- Set Server URL to:
https://your-domain.ngrok-free.app/mcp - Set Authentication:
- Header Name:
Authorization - Header Value:
Bearer <YOUR_MCP_API_KEY>
- Header Name:
- Test the connection. Notion will automatically discover all 7 tools (
terminal_execute,file_read,file_write,file_list,file_stat,file_mkdir,file_move,file_delete).
Available MCP Tools
See AGENT_SPEC.md for full JSON schemas, parameters, and return types.
| Tool | Description |
|---|---|
terminal_execute |
Execute PowerShell or cmd commands with UTF-8 encoding and timeout options. |
file_search |
Search files by name glob (*.ts) and/or search for text/regex inside files (Grep). |
file_replace |
Safely replace an exact block of code or text in a file without rewriting it completely. |
file_read |
Read file contents (UTF-8 or Base64) with offset pagination for large files. |
file_write |
Create, overwrite, or append content to files (creates missing directories). |
file_list |
List directory contents recursively or flat with file sizes. |
file_stat |
Inspect file/directory metadata (size, created/modified timestamps, mode). |
file_mkdir |
Create directories recursively. |
file_move |
Move or rename files and directories. |
file_delete |
Safely delete files or directories (recursive: true required for directories). |
Configuration Reference (.env)
| Variable | Default | Description |
|---|---|---|
MCP_API_KEY |
required | Secret key for authentication (min 32 characters). |
PORT |
3000 |
Port for the HTTP server. |
HOST |
127.0.0.1 |
Host address to bind to. |
NGROK_ENABLED |
false |
Enable/disable automatic ngrok tunnel creation on start. |
NGROK_AUTHTOKEN |
"" |
Ngrok authtoken (optional if configured globally via ngrok CLI). |
NGROK_DOMAIN |
"" |
Static/custom ngrok domain (e.g. xyz.ngrok-free.app). |
ALLOWED_HOSTS |
localhost:3000;... |
Semicolon-separated list of allowed Host headers. |
FULL_ACCESS |
false |
When false, restricts file operations and terminal cwd to FILES_ROOT. |
FILES_ROOT |
./workspace |
Base directory for the sandbox when FULL_ACCESS=false. |
COMMAND_TIMEOUT_MS |
120000 |
Default timeout for terminal commands (2 minutes). |
MAX_OUTPUT_BYTES |
1048576 |
Max stdout/stderr capture size (1 MB). |
MAX_FILE_BYTES |
10485760 |
Max file size read/write limit per request (10 MB). |
Project Structure
notion-terminal-mcp/
├── src/
│ ├── config.ts # Type-safe environment and validation
│ ├── index.ts # Server entry point & lifecycle
│ ├── server.ts # Express setup & MCP Streamable HTTP endpoint
│ ├── middleware/
│ │ ├── auth.ts # Timing-safe token authentication
│ │ └── host.ts # Host header validation
│ ├── tools/
│ │ ├── command.ts # Process tree management & execution
│ │ ├── filesystem.ts # Sandboxed filesystem CRUD operations
│ │ ├── index.ts # MCP tool registrations
│ │ └── types.ts # MCP result helpers & interfaces
│ └── tunnel/
│ └── ngrok.ts # Ngrok SDK manager & Notion connection banner
├── AGENT_SPEC.md # Technical specification for AI Agents
├── package.json
├── tsconfig.json
└── setup.ps1 # PowerShell initial setup script
NPM Scripts
npm run build— Compile TypeScript todist/.npm run start— Run production server fromdist/index.js.npm run dev— Run development server withtsx watch.npm run check— Type-check TypeScript without emitting files.npm run token— Generate a cryptographically secure random token forMCP_API_KEY.
Security Policy
Please review SECURITY.md for security considerations and vulnerability reporting guidelines.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。