Skip to content

feat: implement MCP Server for real-time sync#5

Closed
houlianpi wants to merge 14 commits intomainfrom
qunmi/feature/mcp-server
Closed

feat: implement MCP Server for real-time sync#5
houlianpi wants to merge 14 commits intomainfrom
qunmi/feature/mcp-server

Conversation

@houlianpi
Copy link
Collaborator

Summary

实现 SuperCrew MCP Server,支持 Web UI 和 Claude Code 之间的实时双向同步。

核心功能

  • SQLite Feature Store: 本地数据库,快速读写
  • Event Bus: 事件广播机制,支持实时通知
  • Branch Scanner: 扫描所有分支,聚合去重 Features
  • MCP Protocol: Claude Code 通过 MCP 协议连接
  • HTTP API + WebSocket: Web UI 通过 HTTP/WS 连接
  • GitHub Sync Worker: 异步同步到 Git 仓库

双模式运行

  • MCP 模式: 当 stdin 来自 Claude Code 时,使用 stdio 通信
  • HTTP 模式: 当终端直接运行时,启动 HTTP (3456) + WebSocket (3457) 服务

新增文件

mcp-server/
├── src/
│   ├── index.ts              # 入口,双模式切换
│   ├── types.ts              # 类型定义
│   ├── store/                # SQLite Feature Store
│   ├── events/               # Event Bus
│   ├── scanner/              # Branch Scanner
│   ├── mcp/                  # MCP Protocol
│   ├── http/                 # HTTP API (Hono)
│   ├── ws/                   # WebSocket Server
│   ├── sync/                 # GitHub Sync Worker
│   └── __tests__/            # 测试文件
├── package.json
├── tsconfig.json
└── README.md

测试

  • 34 个单元测试 + 集成测试全部通过
  • TypeScript 类型检查通过

Test plan

  • bun test - 所有测试通过
  • bun run typecheck - 类型检查通过
  • 手动测试 HTTP API: curl http://localhost:3456/health
  • 手动测试 WebSocket 连接

🤖 Generated with Claude Code

houlianpi and others added 14 commits March 5, 2026 23:44
- Created mcp-server directory with src/ subdirectory
- Added package.json with all required dependencies
- Added tsconfig.json with TypeScript configuration
- Added placeholder index.ts entry point
- Verified server starts correctly

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implements Task 1.2 with Bun's native SQLite support:
- Type definitions for Feature and related types
- Database initialization with schema and indexes
- FeatureStore class with full CRUD operations
- Comprehensive test suite with 12 passing tests

Note: Uses bun:sqlite instead of better-sqlite3 for Bun compatibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add event-driven architecture for Feature synchronization:
- EventBus class with typed events (feature:created/updated/deleted, sync, conflict)
- Convenience methods (featureCreated, featureUpdated, featureDeleted, conflictDetected)
- Comprehensive test coverage (4 test cases)

All tests pass (16/16 total).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove any[] type usage with proper EventMap type definitions
- Add maxListeners(20) in constructor to prevent memory leaks
- Add dispose() method for proper cleanup
- Add missing tests for sync:started and sync:completed events
- Add test for dispose() cleanup functionality

All type checks and tests passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add BranchScanner class to scan git repo branches (main, feature/*, fix/*)
and parse .supercrew/features/* directories. Implement parseMetaYaml to
extract feature metadata from YAML. Include deduplication logic where
feature/fix branches override main branch features.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add MCP Protocol integration to enable Claude Code to call SuperCrew tools via MCP.

Changes:
- Create src/mcp/tools.ts: Define 5 MCP tools (list_features, get_feature,
  create_feature, update_feature_status, log_progress) using Zod schemas
- Create src/mcp/server.ts: McpServer setup with StdioServerTransport
- Update src/index.ts: Initialize DB, FeatureStore, EventBus, BranchScanner,
  and start MCP server

Uses @modelcontextprotocol/sdk McpServer.registerTool() API with Zod schemas
for type-safe tool definitions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implement dual-mode operation for MCP Server:
- MCP mode (stdio): used by Claude Code
- HTTP + WebSocket mode: used by Web UI

Features:
- HTTP REST API with CORS support for feature CRUD operations
- WebSocket server for real-time feature updates
- Auto-detection of runtime mode based on stdin.isTTY
- Periodic branch scanning (30s interval) in HTTP mode
- Event broadcast to all connected WebSocket clients

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add Zod input validation for POST /api/features and PATCH /api/features/:id/status
- Add global error handling middleware using Hono's onError
- Define strict WebSocket message types (WSMessage) to replace any types
- Add try-catch error handling to all store operations
- Remove unused src/http/server.ts file
- Replace unsafe 'as any' type assertion with 'as unknown as WebSocket'

All tests passing and type checking clean.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Create mcp/settings.json template for MCP server config
- Update plugin.json with MCP server command configuration
- Bump version to 0.2.0
- Add 'mcp' to keywords

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add GitHubSyncWorker to asynchronously sync features from SQLite to git repository:
- Queue-based sync with deduplication
- Support create/update/delete operations
- Write features to .supercrew/features/<id>/ with meta.yaml and markdown files
- Auto-commit changes to git

Add ConflictResolver to detect and resolve sync conflicts:
- Detect conflicts when both local and remote updated since last sync
- Register conflicts and emit events via EventBus
- Resolve conflicts with local or remote choice

Add comprehensive test coverage for ConflictResolver

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Security fixes:
- Replace execSync('rm -rf') with fs.rmSync() to prevent command injection
- Add isValidFeatureId() validation to prevent path traversal attacks
- Add sanitizeCommitMessage() to escape special characters in git commit messages
- Add explicit utf-8 encoding to all writeFileSync() calls

All tests passing (26 tests, 0 failures)
TypeScript typecheck successful

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add comprehensive integration tests for the MCP Server HTTP API covering:
- Feature CRUD operations (create, read, list, update, delete)
- Status updates
- Board aggregation
- Health check endpoint
- Error handling (404, 400 validation errors)

All tests use in-memory SQLite database for isolation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Document:
- Quick start guide
- Configuration options
- HTTP API endpoints
- MCP tools
- Dual mode operation
- Architecture diagram
- WebSocket events
- Development commands

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Mar 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
supercrew Ready Ready Preview, Comment Mar 6, 2026 2:54am

Request Review

@houlianpi houlianpi closed this Mar 6, 2026
@houlianpi
Copy link
Collaborator Author

I plan to testing first . I will merge pr after testing completed

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.

1 participant