Notion Terminal MCP

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.

Category
Visit Server

README

Notion Terminal MCP

MCP Node.js TypeScript License: MIT

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 start or npm 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 configured FILES_ROOT with 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.
  • šŸ¤– 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

  1. In Notion, open Settings & members → Connections (or open your Notion Agent configuration).
  2. Add a new Custom MCP Connection.
  3. Set Server URL to:
    https://your-domain.ngrok-free.app/mcp
    
  4. Set Authentication:
    • Header Name: Authorization
    • Header Value: Bearer <YOUR_MCP_API_KEY>
  5. 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 to dist/.
  • npm run start — Run production server from dist/index.js.
  • npm run dev — Run development server with tsx watch.
  • npm run check — Type-check TypeScript without emitting files.
  • npm run token — Generate a cryptographically secure random token for MCP_API_KEY.

Security Policy

Please review SECURITY.md for security considerations and vulnerability reporting guidelines.

Recommended Servers

playwright-mcp

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured