Enhance MCP Server: Add Model Context Protocol Server for External Tool Integration #2192

Closed
opened 2026-02-16 17:34:35 -05:00 by yindo · 2 comments
Owner

Originally created by @kierr on GitHub (Oct 20, 2025).

Feature Overview

Add native MCP (Model Context Protocol) server functionality to OpenCode, enabling external MCP clients to connect and use OpenCode's capabilities with their own tools and workflows. This positions OpenCode as both an AI platform and an extensible tool orchestration system.

Current State & Problem

OpenCode currently excels as an MCP client with comprehensive support for external MCP servers via opencode mcp add. However, it lacks the inverse capability to act as an MCP server that external clients can connect to.

This creates a limitation where tools built for platforms like Happy (with mobile control, encryption, permission systems) cannot be seamlessly integrated into OpenCode workflows.

Proposed Solution

Implement a native MCP server within OpenCode that:

  1. Accepts MCP client connections via stdio and HTTP transports
  2. Exposes OpenCode's native capabilities as MCP tools to clients
  3. Enables external tool registration from connected clients
  4. Maintains OpenCode's security model while extending functionality
  5. Preserves existing architecture with minimal breaking changes

Implementation Plan

Phase 1: Core MCP Server Infrastructure

  • Add MCP server endpoint to packages/opencode/src/server/server.ts
  • Implement Model Context Protocol handlers
  • Add stdio/HTTP transport support for client connections
  • Create tool registry system for external tools

Phase 2: Tool Integration & Security

  • Enable external tool registration and execution
  • Implement OpenCode capability exposure as MCP tools
  • Add authentication and authorization for external connections
  • Ensure sandbox compatibility and security boundaries

Phase 3: Configuration & Management

  • Extend opencode.json to support acting as MCP server
  • Add CLI commands for server management (opencode mcp serve)
  • Implement client connection management and monitoring
  • Add comprehensive logging and debugging tools

Technical Approach

The implementation leverages OpenCode's existing:

  • Architecture: Hono-based HTTP server with established patterns
  • TypeScript: Existing type system and build processes
  • Configuration: JSON-based config system already present
  • Security: Existing authentication and sandbox mechanisms

Strategic Benefits

  1. Ecosystem Expansion: Transforms OpenCode into extensible tool platform
  2. Integration Capability: Enables platforms like Happy to integrate natively
  3. Competitive Advantage: Unique position as both AI platform and tool orchestration system
  4. Backward Compatibility: Existing MCP client functionality preserved
  5. Community Growth: Enables new tool categories and integrations

Success Metrics

  • API Endpoints: Add /mcp endpoint with full Model Context Protocol support
  • External Tools: Support for registration and execution of client tools
  • Connection Management: Handle multiple concurrent MCP client connections
  • Security: Maintain OpenCode's security model while enabling external integrations
  • Performance: Target <100ms response times for MCP protocol operations

This enhancement represents a significant evolution of OpenCode's capabilities while maintaining architectural consistency and security standards.

Originally created by @kierr on GitHub (Oct 20, 2025). ## Feature Overview Add native MCP (Model Context Protocol) server functionality to OpenCode, enabling external MCP clients to connect and use OpenCode's capabilities with their own tools and workflows. This positions OpenCode as both an AI platform and an extensible tool orchestration system. ## Current State & Problem OpenCode currently excels as an MCP **client** with comprehensive support for external MCP servers via `opencode mcp add`. However, it lacks the inverse capability to act as an MCP **server** that external clients can connect to. This creates a limitation where tools built for platforms like Happy (with mobile control, encryption, permission systems) cannot be seamlessly integrated into OpenCode workflows. ## Proposed Solution Implement a native MCP server within OpenCode that: 1. **Accepts MCP client connections** via stdio and HTTP transports 2. **Exposes OpenCode's native capabilities** as MCP tools to clients 3. **Enables external tool registration** from connected clients 4. **Maintains OpenCode's security model** while extending functionality 5. **Preserves existing architecture** with minimal breaking changes ## Implementation Plan ### Phase 1: Core MCP Server Infrastructure - Add MCP server endpoint to `packages/opencode/src/server/server.ts` - Implement Model Context Protocol handlers - Add stdio/HTTP transport support for client connections - Create tool registry system for external tools ### Phase 2: Tool Integration & Security - Enable external tool registration and execution - Implement OpenCode capability exposure as MCP tools - Add authentication and authorization for external connections - Ensure sandbox compatibility and security boundaries ### Phase 3: Configuration & Management - Extend `opencode.json` to support acting as MCP server - Add CLI commands for server management (`opencode mcp serve`) - Implement client connection management and monitoring - Add comprehensive logging and debugging tools ## Technical Approach The implementation leverages OpenCode's existing: - **Architecture**: Hono-based HTTP server with established patterns - **TypeScript**: Existing type system and build processes - **Configuration**: JSON-based config system already present - **Security**: Existing authentication and sandbox mechanisms ## Strategic Benefits 1. **Ecosystem Expansion**: Transforms OpenCode into extensible tool platform 2. **Integration Capability**: Enables platforms like Happy to integrate natively 3. **Competitive Advantage**: Unique position as both AI platform and tool orchestration system 4. **Backward Compatibility**: Existing MCP client functionality preserved 5. **Community Growth**: Enables new tool categories and integrations ## Success Metrics - **API Endpoints**: Add `/mcp` endpoint with full Model Context Protocol support - **External Tools**: Support for registration and execution of client tools - **Connection Management**: Handle multiple concurrent MCP client connections - **Security**: Maintain OpenCode's security model while enabling external integrations - **Performance**: Target <100ms response times for MCP protocol operations This enhancement represents a significant evolution of OpenCode's capabilities while maintaining architectural consistency and security standards.
yindo closed this issue 2026-02-16 17:34:35 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Oct 20, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #296: Request for OpenCode to run in MCP server mode (like claude mcp serve command) for agentic workflows
  • #1507: Question about instructions on how to connect to OpenCode as MCP server
  • #2953: Feature request for ability to dynamically turn on MCP server for specific agents

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Oct 20, 2025): This issue might be a duplicate of existing issues. Please check: - #296: Request for OpenCode to run in MCP server mode (like claude mcp serve command) for agentic workflows - #1507: Question about instructions on how to connect to OpenCode as MCP server - #2953: Feature request for ability to dynamically turn on MCP server for specific agents Feel free to ignore if none of these address your specific case.
Author
Owner

@kierr commented on GitHub (Oct 20, 2025):

Excuse me excuse the slop

@kierr commented on GitHub (Oct 20, 2025): Excuse me excuse the slop
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2192