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.
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.