Skip to content

Conversation

@steveluc
Copy link
Contributor

Summary

This PR adds a Model Context Protocol (MCP) server that integrates TypeAgent's command execution capabilities with Claude Code via the Agent SDK. It enables Claude to execute user commands (music, lists, calendar, VSCode automation) through TypeAgent's dispatcher, with proper user confirmation for destructive operations.

Key Features

1. Command Executor MCP Server

  • New package: packages/commandExecutor providing MCP server for TypeAgent integration
  • Connects to TypeAgent's agent server and exposes execute_command tool to Claude
  • Supports commands for:
    • Music & media control (play songs, control playback)
    • List & task management (shopping lists, todo lists)
    • Calendar operations (schedule events, view calendar)
    • VSCode automation (themes, files, tasks, editor layout, terminals)

2. Agent SDK Wrapper

  • New package: packages/agentSdkWrapper wrapping Anthropic's Agent SDK
  • Integrates TypeAgent's shared dispatcher with Claude Code
  • Provides caching support for improved performance
  • Configurable tool permissions and MCP server integration
  • Uses claude_code preset for consistent behavior

3. User Confirmation Flow

  • Implements two-phase confirmation for yes/no prompts (session clear, delete operations)
  • Stateless design works across MCP server restarts
  • Flow:
    1. Command requires confirmation → throws USER_CONFIRMATION_REQUIRED error
    2. Claude asks user via AskUserQuestion
    3. User confirms → Claude retries with confirmed=true parameter
    4. Command executes with approval

4. HTML Image Processing

  • Converts HTML image tags to base64 data URIs for Claude Code display
  • Uses html-to-text for safe HTML parsing
  • Addresses CodeQL security findings with proper sanitization

Test Plan

  • MCP server connects to TypeAgent agent server
  • Commands execute successfully (tested with grocery list operations)
  • User confirmation flow works correctly (tested with session clear)
  • HTML image processing converts images properly
  • Copyright headers present in all new files
  • Prettier formatting applied
  • Package builds successfully
  • Merged with latest main branch

Files Changed

New Packages

  • packages/commandExecutor/ - MCP server implementation
  • packages/agentSdkWrapper/ - Agent SDK wrapper with TypeAgent integration

Key Files

  • packages/commandExecutor/src/commandServer.ts - MCP server with confirmation flow
  • packages/agentSdkWrapper/src/cli.ts - Agent SDK configuration
  • packages/commandExecutor/README.md - Setup and usage documentation
  • packages/agentSdkWrapper/README.md - Integration guide

Related Issues

  • Resolves integration of TypeAgent with Claude Code via MCP
  • Implements safe handling of destructive operations
  • Addresses HTML security concerns in image processing

🤖 Generated with Claude Code

steveluc and others added 27 commits January 16, 2026 23:19
Introduces a new MCP (Model Context Protocol) server that enables Claude Code to execute TypeAgent commands for music playback, list management, calendar operations, and other natural language tasks.

Key features:
- Connects Claude Code to TypeAgent dispatcher via WebSocket
- Automatic reconnection with 5-second retry interval
- Comprehensive logging to temp files for debugging
- Supports natural language commands (e.g., "play bohemian rhapsody", "add milk to grocery list")
- Clean output formatting with HTML image tags stripped

Includes example configuration for .mcp.json and detailed installation instructions in README.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add trademark section to README
- Remove dist-test build outputs from git
- Fix package.json field ordering (use exports instead of main)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Use exact trademark text format with proper line breaks
- Sort package.json scripts alphabetically

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit enhances the split editor command in the Coda extension to support more flexible editor selection and improves TypeAgent schema disambiguation.

**Bug Fixes:**
- Fix off-by-one error when selecting "first" or "last" editor by sorting by viewColumn
- Fix multiple split issue by adding conditionals to focus changes
- Remove unnecessary focus restoration logic for voice command scenarios

**Features:**
- Add support for splitting editors by position: "first", "last", "active", or numeric index
- Add support for splitting editors by file name: "split app.tsx to the right"
- Search all open tabs using tabGroups API, not just visible editors
- Automatically open and focus files found in background tabs before splitting

**Schema Improvements:**
- Add clear disambiguation between splitEditor and moveCursorInFile actions
- Add "USE THIS for" and "DO NOT USE for" guidance in schema comments
- Add concrete examples to help LLM choose correct action
- Remove moveCursorInFile reference from main code schema (not useful for voice)

**Documentation:**
- Add VSCODE_CAPABILITIES.md documenting all VSCode automation features
- Update split editor examples to show new position and file-based splitting

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This enhancement allows the player agent to create playlists with songs
specified by title and artist, and to add lists of songs to existing
playlists, eliminating the need to search and build a track list first.

Changes:
- Add SongSpecification interface for specifying songs by track name,
  optional artist, and optional album
- Extend CreatePlaylistAction with optional songs parameter to support
  creating playlists with songs in one action
- Add new AddSongsToPlaylistAction for bulk adding songs to existing
  playlists
- Implement searchSongsAndGetUris helper function to search Spotify
  for songs and collect their URIs
- Update createPlaylist handler to search for and add songs when
  creating playlists
- Add addSongsToPlaylist handler for the new action
- Add validation support for the new action in playerHandlers

Benefits:
- Users can create playlists with songs in a single request
- Supports requests like "create a playlist with the top 10 songs"
- Provides feedback on songs that couldn't be found
- Maintains backward compatibility with existing createPlaylist usage

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This package provides a pseudo terminal wrapper for CLI coding assistants
like Claude Code, with support for transparent I/O passthrough and future
caching capabilities.

Features:
- PTY wrapper using node-pty for proper terminal emulation
- Transparent passthrough of all stdin/stdout/stderr
- Support for multiple CLI assistants (Claude Code, Node REPL, Python, etc.)
- Windows compatibility with automatic .exe handling
- Graceful exit handling (Ctrl+C, SIGTERM)
- Terminal features: colors, cursor control, resizing
- Configurable assistant system for extensibility

Architecture:
- assistantConfig.ts: Pluggable configuration for different assistants
- ptyWrapper.ts: Core PTY wrapper with node-pty
- cli.ts: Command-line interface entry point
- index.ts: Public API exports

Usage:
  coder-wrapper                 # Use Claude Code (default)
  coder-wrapper -a node         # Use Node REPL
  coder-wrapper -a python       # Use Python REPL

Future enhancements:
- Cache checking with TypeAgent dispatcher before forwarding requests
- Request/response logging and performance metrics
- Cache hit/miss statistics

Testing requires a real terminal (TTY) - see TESTING.md for manual test
procedures.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit adds optional caching functionality to the coderWrapper package, allowing
it to check TypeAgent's cache before forwarding commands to the wrapped CLI agent.

Key changes:

**coderWrapper package:**
- Add cacheClient.ts: MCP client for checking TypeAgent cache via command-executor
- Add debugLogger.ts: Debug logging to ~/.tmp/typeagent-coder-wrapper/
- Update ptyWrapper.ts:
  - Add cache checking before forwarding commands to wrapped agent
  - Handle \r\n separately to prevent duplicate command execution on Windows
  - Add processing lock to prevent concurrent command handling
  - Add enableCache option (default: false)
  - Add debug option for detailed logging
- Update CLI to support --enable-cache and --debug flags

**commandExecutor MCP server:**
- Add startup connection race handling (return cache miss instead of error)
- Add CACHE_HIT prefix for detection by cacheClient
- Improve error handling for disconnected dispatcher

**dispatcher:**
- Add checkCache RPC method to dispatcher interface
- Implement checkCache in dispatcher client and server
- Support multi-client cache sharing via AsyncLocalStorage routing

**agentServer:**
- Add AsyncLocalStorage-based request routing for multi-client support
- Wrap checkCache calls with client context to route responses correctly
- Each client gets isolated cache results despite shared dispatcher

The cache is disabled by default and must be explicitly enabled with enableCache: true
or --enable-cache flag. When enabled and cache hits occur, results are returned
immediately without invoking the wrapped CLI agent.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…mcp-server

# Conflicts:
#	ts/packages/coderWrapper/README.md
#	ts/packages/coderWrapper/package.json
#	ts/packages/coderWrapper/src/cli.ts
#	ts/packages/coderWrapper/src/index.ts
#	ts/packages/coderWrapper/src/ptyWrapper.ts
#	ts/pnpm-lock.yaml
This commit introduces a new agentSdkWrapper package that provides direct
integration with the Anthropic Agent SDK, offering an alternative to the
PTY-based coderWrapper approach with enhanced caching capabilities.

New Package: agentSdkWrapper
- Direct API integration using Agent SDK's query() function
- Programmatic control over request/response cycle
- Intelligent caching through TypeAgent's cache infrastructure
- Cache context injection via UserPromptSubmit hooks
- Extended thinking/reasoning display support
- MCP server integration for music, lists, calendar, and VSCode automation
- Configurable model selection (Sonnet/Opus) and tool restrictions
- Debug mode with detailed timing and logging

Key Features:
- Cache-first architecture: checks TypeAgent cache before API calls
- Context injection: follow-up questions can reference cached interactions
- Streaming support: displays responses and reasoning in real-time
- Session continuity: maintains conversation context across queries
- MCP command-executor integration with acceptEdits permission mode

Improvements to Existing Packages:
- commandExecutor: Added lifecycle documentation explaining transient/persistent
  connection patterns, HTML-to-plaintext conversion for cache results
- agentServer: Enhanced error handling for disconnected clients, maintains
  connection logging for debugging

Architecture Notes:
- Agent SDK spawns new Claude Code process per query (transient connections)
- Each process spawns fresh MCP server instance connecting to shared dispatcher
- agentServer maintains single persistent dispatcher across all connections
- Connection/disconnection messages retained for debugging purposes

Benefits over PTY wrapper:
- Better performance (no process spawning/PTY overhead)
- More control over API calls and tool configuration
- Easier testing (pure TypeScript functions)
- Cleaner code (no terminal escape codes)
- Programmatic access for TypeScript integration

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Resolved conflicts in:
- packages/agentServer/server/src/server.ts: Kept our error handling for disconnected clients
- pnpm-lock.yaml: Accepted theirs and regenerated
Replaced regex-based HTML sanitization with html-to-text library to address:
1. Incomplete multi-character sanitization (High severity)
2. Double escaping/unescaping vulnerability (High severity)

Changes:
- Removed manual regex chains for HTML tag stripping
- Removed unsafe entity decoding sequence
- Added html-to-text library with proper HTML parsing
- Configured to skip images and preserve formatting
- Added @types/html-to-text for TypeScript support

This eliminates injection risks from incomplete tag removal and
prevents double-decoding vulnerabilities.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fix build failures by properly declaring html-to-text dependencies:
- Added html-to-text ^9.0.5 to dependencies
- Added @types/html-to-text ^9.0.4 to devDependencies
- Updated pnpm-lock.yaml to match package.json

This resolves the ERR_PNPM_OUTDATED_LOCKFILE errors in CI builds.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implemented a two-phase confirmation flow to handle TypeAgent's askYesNo
prompts in the MCP server context. Since MCP tools are request-response
based and cannot pause for user input, the flow works as follows:

1. When a command requires confirmation, askYesNo() throws a
   USER_CONFIRMATION_REQUIRED error instead of blocking
2. The MCP server catches this error and returns a user-friendly message
3. Claude uses AskUserQuestion to confirm with the user
4. If approved, Claude retries the command with confirmed=true parameter
5. On retry, askYesNo() sees the confirmed flag and returns true immediately

Changes:
- Added optional 'confirmed' parameter to ExecuteCommandRequest schema
- Added currentRequestConfirmed state tracking to CommandServer
- Modified askYesNo() to check confirmation flag and throw error if not confirmed
- Updated executeCommand() to handle USER_CONFIRMATION_REQUIRED errors
- Enhanced tool description to document the confirmation flow
- Added proper cleanup in finally block to reset confirmation state

This implementation is stateless and works across MCP server restarts,
providing a clean API for handling destructive operations safely.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@steveluc steveluc deployed to development-fork January 20, 2026 20:00 — with GitHub Actions Active
@steveluc steveluc temporarily deployed to development-fork January 20, 2026 20:00 — with GitHub Actions Inactive
@steveluc steveluc added this pull request to the merge queue Jan 20, 2026
Merged via the queue into main with commit d523ef4 Jan 20, 2026
21 checks passed
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.

2 participants