-
Notifications
You must be signed in to change notification settings - Fork 48
Closed
Description
🔍 Duplicate Code Detected: Parallel MCP server implementations
Analysis of commit 8d26b38
Assignee: @copilot
Summary
Two separate MCP server implementations exist in the JavaScript runtime: mcp_server.cjs and mcp_server_core.cjs. Both register tools and handle JSON-RPC requests but differ in data structures, logging, and validation, increasing the risk of divergent behavior across transports (HTTP vs stdio) and duplicated maintenance.
Duplication Details
Pattern: Duplicate MCP server cores for tool registration/JSON-RPC
- Severity: Medium
- Occurrences: 2 implementations
- Locations:
pkg/workflow/js/mcp_server.cjs(lines 23-186)pkg/workflow/js/mcp_server_core.cjs(lines 458-575)
- Code Sample:
// mcp_server.cjs: tool registration and handler dispatch tool(name, description, inputSchema, handler) { this.tools.set(name, { name, description, inputSchema, handler }); } async handleRequest({ id, method, params }) { /* initialize, tools/list, tools/call, ping */ } // mcp_server_core.cjs: duplicated registration and dispatch function registerTool(server, tool) { server.tools[normalizeTool(tool.name)] = { ...tool }; } async function handleMessage(server, req) { /* initialize, tools/list, tools/call */ }
Impact Analysis
- Maintainability: Two code paths to keep in sync for MCP behavior and validation; fixes may land in one server but not the other.
- Bug Risk: Divergent capabilities (e.g., error handling, schema validation) can yield different outcomes between HTTP and stdio transports, complicating debugging.
- Code Bloat: Extra server core inflates surface area and documentation burden.
Refactoring Recommendations
-
Unify MCP server core
- Extract a single shared server implementation (e.g., reuse
mcp_server_corefor both HTTP and stdio) and makeMCPServera thin adapter around it. - Estimated effort: 4-6 hours (API alignment, tests).
- Benefits: Single source of truth for JSON-RPC behavior and validation.
- Extract a single shared server implementation (e.g., reuse
-
Share validation and tool registration utilities
- Export common functions (normalize/register/handle) and have transports depend on them instead of bespoke logic.
- Estimated effort: 2-3 hours.
- Benefits: Eliminates drift between transports and simplifies future fixes.
Implementation Checklist
- Review duplication findings
- Prioritize refactoring tasks
- Create refactoring plan
- Implement changes
- Update tests
- Verify no functionality broken
Analysis Metadata
- Analyzed Files: 4
- Detection Method: Serena semantic code analysis
- Commit: 8d26b38
- Analysis Date: 2025-12-07 21:05:05Z
AI generated by Duplicate Code Detector
Reactions are currently unavailable