CodeServer MCP
Provides stateful development session management for code-server, including sandboxed workspace file operations (read, write, patch, search, tree, watch) and persistent terminal shells with background process management.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@CodeServer MCPrun my dev server in a persistent shell and watch the logs"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
CodeServer MCP
A production-oriented Model Context Protocol server for code-server, built around stateful development sessions rather than stateless file operations.
Architecture
Core Modules
workspace/ — Sandboxed file operations scoped to WORKSPACE_ROOT
read.py— Read files with optional line-range slicingwrite.py— Atomic file writes (create/overwrite)patch.py— Targeted edits via unified diff or find/replace (never resend the whole file)search.py— Ripgrep-based search with structured resultstree.py— Recursive directory listing (respects.gitignore-style ignore rules)watch.py— Async file watching; detect changes made by the editor, git, build tools
terminal/ — Persistent shells & background processes
pty.py— Real pseudo-terminal wrapper (ptyprocess) for authentic terminal behavior (colors, pagers, history)shell.py— Persistent shell sessions that survive crashes/restartsprocess.py— Background process manager with log capture
util/
paths.py— Workspace sandboxing: every file operation goes throughresolve_path()which proves the result still lives insideWORKSPACE_ROOTdiff.py— Unified diff helpers for generating and applying patches
Key Design Decisions
Real PTYs, not subprocesses
Shells are real pseudo-terminals (ptyprocess), so programs that check
isatty()behave naturally.Output includes ANSI colors, spinner sequences, and pager control codes.
Shell history and readline state persist across calls.
Stateful vs. Stateless
Unlike generic filesystem MCP servers, shells and processes are first-class, long-lived entities.
A shell can run
npm run dev, and the dev server keeps running. Later calls can read its output, resize its terminal, or send it signals.Session recovery on restart: PTY metadata is stored in SQLite so crashed dev servers can be reconnected.
Sandboxing
Every workspace operation (read/write/patch/search/tree/watch) goes through
util.paths.resolve_path().All paths are canonicalized and checked to be within
WORKSPACE_ROOT— symlinks cannot escape.
Patching, not Overwriting
replace_text()andapply_patch()let Claude make surgical edits without resending entire files.Diffs are generated and returned so clients (Claude) can see what changed.
Async-first
All I/O is async (asyncio, aiofiles, aiosqlite).
Long-lived watches and process log tailing don't block.
Related MCP server: pokeclaw
Installation
Docker (Recommended)
docker-compose up -d
# MCP server now listens on localhost:8080Local (Python 3.12+)
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
export WORKSPACE_ROOT=/path/to/code
export MCP_PORT=8080
python app.pyEnvironment Variables
MCP_HOST(default:0.0.0.0) — Listen addressMCP_PORT(default:8080) — Listen portWORKSPACE_ROOT(default:/workspace) — Sandbox root; all file operations must stay within thisRG_BIN(default:rg) — Path to ripgrep binary if not on PATHLOG_LEVEL(default:info) — Uvicorn log level
MCP Tools
Workspace
workspace_read_file(path, start_line, end_line)— Read a file (with optional line range)workspace_write_file(path, content, mode, create_dirs)— Write or create a fileworkspace_replace_text(path, old, new, expected_count)— Find and replace (safe, requires uniqueness)workspace_apply_patch(path, diff_text)— Apply a unified diffworkspace_search(pattern, path, glob, case_sensitive, fixed_string, max_results)— Ripgrep-based searchworkspace_tree(path, max_depth, max_entries)— Directory listingworkspace_watch_start(path)— Start watching a directory for changesworkspace_watch_poll(watch_id, timeout)— Poll a watch for eventsworkspace_watch_stop(watch_id)— Stop a watchworkspace_watch_list()— List active watches
Terminal
terminal_shell_create(cwd)— Create a new persistent PTY shellterminal_shell_execute(shell_id, command, timeout)— Run a command in a shellterminal_shell_read(shell_id)— Read pending output (non-blocking)terminal_shell_resize(shell_id, rows, cols)— Resize the terminalterminal_shell_list()— List active shellsterminal_shell_terminate(shell_id)— Kill a shellterminal_process_start(command, cwd, proc_id)— Start a background processterminal_process_logs(proc_id, lines)— Read process logsterminal_process_stop(proc_id, timeout)— Stop a processterminal_process_list()— List active processes
Usage Examples
Create a Persistent Dev Server Shell
# Create a shell
shell_resp = await terminal_shell_create(cwd=".")
shell_id = shell_resp["id"] # "shell-abc123"
# Start a dev server (runs in background)
await terminal_shell_execute(shell_id, "npm run dev")
# Read output later
output = await terminal_shell_read(shell_id)
print(output["output"]) # "VITE ready in 314ms..."
# Even if the MCP server crashes, the shell survives.
# On restart, terminal_shell_list() will still see it.Edit a File Without Resending It
# Read a file
file_resp = workspace_read_file("src/app.py")
before = file_resp["content"]
# Client (or Claude) modifies it locally
after = before.replace("const x = 1", "const x = 2")
# Send only the diff
diff = generate_unified_diff(before, after, "src/app.py")
patch_resp = await workspace_apply_patch("src/app.py", diff)
print(patch_resp["diff"]) # Shows what changedWatch for Changes
# Start watching the src/ directory
watch_resp = await workspace_watch_start("src")
watch_id = watch_resp["id"]
# Do work (edit files, run git pull, etc.)
await asyncio.sleep(5)
# Poll for changes
poll_resp = await workspace_watch_poll(watch_id, timeout=1)
for event in poll_resp["events"]:
print(event["change"], event["path"]) # "modified src/main.py"Reconnection & Session Recovery
When the MCP server restarts:
Shells: Their PTY metadata is loaded from the database and re-spawned. Background processes (like
npm run dev) will still be running on the system; reconnecting to the shell picks up where you left off.Processes: Background processes are re-attached to if they're still alive (by PID lookup).
Watches: Not persisted (ephemeral); will need to be recreated.
This design assumes you're running this in a long-lived container (Docker or systemd) and not losing the PID space.
Security
Workspace sandboxing:
resolve_path()ensures all operations stay withinWORKSPACE_ROOT. Symlinks are resolved and validated.No command injection: Process commands are passed as strings to
subprocess.Popen(..., shell=True), so be careful with user input. Consider restricting this tool in production.No authentication: This server is designed for a trusted network (your local machine, or behind a VPN/Tailscale). Run it behind a reverse proxy with auth in production.
Performance
First-call startup: ~50ms (database init, shell spawn)
Shell execute: 5–100ms depending on command
File operations: <5ms (mostly I/O latency, not CPU)
Search: 50–500ms depending on repo size and pattern complexity
Watch poll: 0ms if no changes, else <50ms to report changes
Testing
Run the workspace module smoke test:
export WORKSPACE_ROOT=/tmp/fake_workspace
python test_workspace_manual.pyThis tests sandboxing, file I/O, patching, searching, tree walking, and watching.
TODO / Future
LSP diagnostics integration (pull errors from code-server's language servers)
VS Code Tasks runner
Port detection (surface forwarded ports from code-server)
Editor state (which files are open, cursor position)
Git wrappers (optional; can be used via shells)
Docker wrappers (optional; can be used via shells)
More comprehensive logging and telemetry
Pytest suite (currently only manual smoke tests)
Contributing
This is a single-developer project. If you'd like to extend it:
Add new tools in the appropriate module (
workspace/,terminal/, or a new one).Register them in
app.pywith@mcp.tool().Update this README.
Built for Claude on code-server. Not affiliated with Anthropic or Coder.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Flicense-qualityCmaintenanceProvides AI coding agents with a secure, sandboxed environment for executing coding tasks including file operations, command execution, and testing. Features session management, policy enforcement, and Docker-based sandboxing for safe code execution and development workflows.Last updated
- Alicense-qualityCmaintenanceEnables MCP clients to spawn and control Codex CLI and Claude Code sessions on the host machine, with session management and filesystem access.Last updated4MIT
- Alicense-qualityDmaintenanceA full-featured MCP server for local development with filesystem, shell, editor, session persistence, and security features.Last updated2MIT
- Flicense-qualityCmaintenanceSecure local development platform that exposes controlled developer capabilities (FS, Git, search, command execution) to AI assistants via MCP with deny-by-default security and audit logging.Last updated
Related MCP Connectors
MCP server for interacting with the Supabase platform
A MCP server built for developers enabling Git based project management with project and personal…
Persistent memory and cross-session learning for AI coding assistants (hosted remote MCP).
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/yangkerrrr/CodeserverMCP'
If you have feedback or need assistance with the MCP directory API, please join our Discord server