Skip to content

feat(mcp): add mcp support for emdash#2938

Draft
kchung wants to merge 6 commits into
generalaction:mainfrom
kchung:chung/feat-mcp
Draft

feat(mcp): add mcp support for emdash#2938
kchung wants to merge 6 commits into
generalaction:mainfrom
kchung:chung/feat-mcp

Conversation

@kchung

@kchung kchung commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Description

POC for MCP support in emdash: a local, token-protected MCP server that lets the agents emdash runs create and manage tasks themselves. Emdash registers the server with the agents it manages, and it shows up in the MCP library as a managed entry.

Tool Params Description
list_projects none List open projects
list_tasks projectId List tasks in a project with status
create_task projectId, prompt?, name?, provider?, model?, branchName?, baseBranch?, chatUi? Create a task in an isolated worktree; with a prompt, start an agent on it, otherwise leave it idle
rename_task projectId, taskId, name Rename a task
archive_task projectId, taskId Archive a task
delete_task projectId, taskId, confirm? Delete a task; requires confirm: true when the worktree has uncommitted changes
run_task_script projectId, taskId, type Start a task's setup, run, or teardown worktree lifecycle script
stop_task_script projectId, taskId, type Stop a running lifecycle script started by run_task_script

Also includes a fix for the delete preflight, which reported dirty worktrees as clean; the delete_task confirmation gate depends on it.

High risk areas: a new localhost HTTP listener in the main process, writes to agent MCP configs, task deletion tooling, and one new dependency (@modelcontextprotocol/sdk).

Related issues

Resolves #2937

Testing

  • pnpm run typecheck, pnpm run lint, pnpm run format clean
  • pnpm run test: desktop node suite (2113 tests), core (481), including new suites for the HTTP server, tools, self-registration, task creation, controller redaction, and the preflight fix
  • Manual: registered against Claude Code, exercised the tools end to end, verified 401 without token, the dirty-worktree confirm flow, and that the catalog card disappears when a second instance owns the port

Screenshot/Recording (if applicable)

Screenshot 2026-07-21 at 4 44 24 PM
mcp.mp4

kchung and others added 3 commits July 21, 2026 16:06
The staged/unstaged result computed for a successful git status was
unconditionally overwritten on the next line, so every worktree whose
status check succeeded was reported clean, and status errors also
reported clean. Report the real state on success and fail closed
(dirty) when the status is unavailable (error, too-many-files, or a
thrown exception) so delete flows err toward preserving the worktree.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Serve a Streamable HTTP MCP server from the main process on
127.0.0.1:8212 (EMDASH_MCP_PORT overrides it, EMDASH_MCP_SERVER=false
disables it), authenticated with a bearer token generated into
userData. Requests must pass loopback Host/Origin checks and the
token.

Tools: list_projects, list_tasks, create_task (prompt plus optional
provider, model, branch name, base branch, and chat UI), rename_task,
archive_task, and delete_task, which requires confirm: true when the
worktree has uncommitted changes.

On boot emdash registers the server in the MCP configs of the agents
it manages and heals stale URLs and tokens.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Surface the built-in server as a catalog entry whose live URL is
injected by the main process and which is hidden while the server is
down. Managed servers get their connection details from the main
process on save (only providers are user-editable), bearer headers are
redacted from renderer and agent-facing loads, and the add/edit modal
renders managed connection fields read-only. Servers merely named
"emdash" that point elsewhere are left untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kchung

kchung commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@greptile review

@greptile-apps

greptile-apps Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a managed local MCP server for emdash agents. The main changes are:

  • Token-protected MCP access over a localhost HTTP listener.
  • Tools for creating, listing, renaming, archiving, deleting, and running tasks.
  • Automatic agent registration and managed MCP catalog integration.
  • MCP configuration redaction and ownership handling in the main process.
  • Correct dirty-worktree detection for task deletion.

Confidence Score: 5/5

The reviewed updates look safe to merge.

  • The managed-server ownership fix covers the reported custom HTTP server case.
  • No distinct blocking issue qualified for this follow-up review.

Important Files Changed

Filename Overview
apps/emdash-desktop/src/main/core/mcp/controller.ts Adds managed-server redaction, live catalog data, and ownership-aware configuration saves.
apps/emdash-desktop/src/main/core/mcp/server/mcp-http-server.ts Adds the authenticated localhost MCP listener, request filtering, token persistence, and lifecycle handling.
apps/emdash-desktop/src/main/core/mcp/server/register-tools.ts Registers MCP tools for project and task management.
apps/emdash-desktop/src/main/core/mcp/server/create-task-from-prompt.ts Adds task creation, branch and model validation, worktree provisioning, and optional agent startup.
apps/emdash-desktop/src/main/core/tasks/operations/getDeletePreflight.ts Corrects dirty-worktree detection used by the task deletion confirmation flow.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Agent[Managed coding agent] -->|Bearer token| MCP[Local MCP HTTP server]
  MCP --> Tools[Task management tools]
  Tools --> Projects[Project manager]
  Tools --> Tasks[Task service]
  Tasks --> Worktree[Isolated worktree]
  Renderer[MCP settings UI] --> Controller[MCP controller]
  Controller --> Configs[Agent MCP configs]
  Controller --> MCP
Loading

Reviews (3): Last reviewed commit: "feat(mcp): make create_task prompt optio..." | Re-trigger Greptile

Comment thread apps/emdash-desktop/src/main/core/mcp/controller.ts
Comment thread apps/emdash-desktop/src/main/core/mcp/server/register-tools.ts
resolveServerForSave only passed through foreign emdash-named servers
that were already installed. A brand-new custom server saved under the
managed name had its URL and headers replaced with the loopback
connection details, or failed to save when the built-in server was
down. Apply the same ownership check to the submitted entry: a new
save with its own URL is the user's server and is written as-is.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kchung

kchung commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@greptile review

kchung added 2 commits July 22, 2026 08:25
Add run_task_script and stop_task_script MCP tools so agents can drive a
task's setup/run/teardown worktree lifecycle scripts, the same scripts the
Scripts panel runs. Both start fire-and-forget and are visible live in the UI;
stop_task_script can stop any script type via the shared PTY session.

Export isLifecycleScriptSessionActive from the coordinator so run_task_script
reports already_running instead of a false started.
Allow create_task without a prompt: the worktree is provisioned and the task
created, but no agent conversation is started, leaving the task idle for the
user to drive later. Provider/model are only resolved when a prompt is present,
and the result reports conversationType 'none' with a null provider/model.
@kchung

kchung commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@greptile review

@meik1998dev

Copy link
Copy Markdown

I have been waiting for this for a long time 🎉 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat]: Add MCP support for emdash

2 participants