Skip to content

Consolidate duplicate MCP server implementations#5787

Merged
pelikhan merged 7 commits intomainfrom
copilot/remove-duplicate-mcp-implementations
Dec 8, 2025
Merged

Consolidate duplicate MCP server implementations#5787
pelikhan merged 7 commits intomainfrom
copilot/remove-duplicate-mcp-implementations

Conversation

Copy link
Contributor

Copilot AI commented Dec 7, 2025

Refactoring Complete: Duplicate MCP Server Implementations Eliminated ✅

Changes Summary

Implementation:

  1. Extended mcp_server_core.cjs with handleRequest() function for HTTP transport
  2. Updated mcp_http_transport.cjs to use unified core via MCPServer wrapper
  3. Removed duplicate mcp_server.cjs (~190 lines) and tests
  4. Updated Go embed directives (scripts.go, js.go, mcp_servers.go, mcp_inspect.go)

Latest Updates:

  • ✅ Merged main branch
  • ✅ Recompiled all 102 workflow files
  • ✅ Formatted and linted all code
  • ✅ Fixed TypeScript error in error handling
  • ✅ All core MCP tests passing (mcp_http_transport, mcp_server_core, safe_outputs_mcp_server)

Test Results:

  • ✅ All Go tests passing
  • ✅ TypeScript checks passing
  • ✅ Build succeeds
  • ✅ 97 of 99 JavaScript test files passing
  • ⚠️ 2 pre-existing test failures unrelated to changes (create_pull_request bundler issues, safe_inputs integration tests timing out)

Benefits Achieved:

  • Single source of truth for MCP protocol handling
  • Eliminated maintenance burden of syncing two implementations
  • Reduced code bloat by ~190 lines
  • Simplified future enhancements
Original prompt

This section details on the original issue you should resolve

<issue_title>[duplicate-code] Duplicate Code Detected: Parallel MCP server implementations</issue_title>
<issue_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

  1. Unify MCP server core

    • Extract a single shared server implementation (e.g., reuse mcp_server_core for both HTTP and stdio) and make MCPServer a thin adapter around it.
    • Estimated effort: 4-6 hours (API alignment, tests).
    • Benefits: Single source of truth for JSON-RPC behavior and validation.
  2. 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

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Changeset

  • Type: patch
  • Description: Consolidate duplicate MCP server implementations by using a single shared core implementation and removing the duplicate mcp_server.cjs code. This is an internal refactor that reduces duplicated code and simplifies maintenance for MCP server transports (HTTP and stdio).

🏴‍☠️ Ahoy! This treasure was crafted by Changeset Generator



Smoke Test Summary

  • Timestamp: 2025-12-07T23:02:18Z
  • Status: PASS
  • Summary: All tests passed - GitHub MCP, file I/O, bash, Playwright, cache memory, and gh tool validated

🤖 DIAGNOSTIC REPORT GENERATED BY Smoke Copilot No Firewall

Copilot AI and others added 3 commits December 7, 2025 21:12
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
….cjs

- Extended mcp_server_core.cjs with handleRequest() function for HTTP transport
- Updated mcp_http_transport.cjs to use mcp_server_core.cjs via MCPServer wrapper
- Removed duplicate mcp_server.cjs file and its test
- Updated Go embed directives and script registry
- All MCP transport tests passing (mcp_http_transport.test.cjs, mcp_server_core.test.cjs)
- Single source of truth for JSON-RPC protocol handling

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove duplicate MCP server implementations from codebase Consolidate duplicate MCP server implementations Dec 7, 2025
Copilot AI requested a review from mnkiefer December 7, 2025 21:37
@pelikhan
Copy link
Contributor

pelikhan commented Dec 7, 2025

@copilot merge main, recompile, former, lint, run tests

Copilot AI and others added 2 commits December 7, 2025 22:08
- Merged main branch successfully
- Recompiled all workflow files (102 workflows)
- Ran formatting and linting (all passed)
- Fixed TypeScript error in mcp_server_core.cjs error handling
- All core MCP tests passing

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 7, 2025

@copilot merge main, recompile, former, lint, run tests

Completed all requested tasks:

✅ Merged main branch
✅ Recompiled all 102 workflow files
✅ Formatted code
✅ Linted code
✅ Ran tests - all core MCP tests passing

Fixed TypeScript error in error handling. Changes in commit 5c94a1b.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

📰 DEVELOPING STORY: Smoke Copilot Playwright reports failed. Our correspondents are investigating the incident...

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

🤖 SYSTEM_INIT: Smoke Copilot No Firewall ACTIVATED. PROCESSING pull request. ALL SUBSYSTEMS ONLINE.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

📰⚠️🔥❌🚨🔧 https://github.com/githubnext/gh-aw/actions/runs/20011669496

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

🔮 The ancient spirits stir... Smoke Codex awakens to divine this pull request...

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

📰 BREAKING: Smoke Copilot is now investigating this pull request. Sources say the story is developing...

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

🎉 Yo ho ho! Changeset Generator found the treasure and completed successfully! ⚓💰

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

💥 WHOOSH! Smoke Claude springs into action on this pull request! [Panel 1 begins...]

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

Smoke Test: Copilot Engine - PASS

Last 2 Merged PRs:

Test Results:

  • ✅ GitHub MCP (list PRs)
  • ✅ File writing (/tmp/gh-aw/agent/smoke-test-copilot-20011669512.txt)
  • ✅ Bash tool (verified file creation)
  • ✅ get_me NOT available (correctly failed - not in default toolset)
  • ✅ Cache memory test (/tmp/gh-aw/cache-memory/smoke-test-20011669512.txt)
  • ✅ gh safe-input tool (issues list verified)

Overall Status: PASS

📰 BREAKING: Report filed by Smoke Copilot fer issue #5787 🗺️

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

Smoke Test Results: Claude Engine

Recent PRs:

Test Results:

  • ✅ GitHub MCP: Listed recent merged PRs
  • ✅ File Writing: Created test file in /tmp/gh-aw/agent/
  • ✅ Bash Tool: Verified file creation successful
  • ✅ Playwright MCP: Navigated to GitHub, title contains "GitHub"
  • ✅ Cache Memory: Created and verified test file in /tmp/gh-aw/cache-memory/
  • ❌ Safe Input gh Tool: Tool not available (no gh safe-input tool found)

Overall Status: PASS (5/6 tests passed)

💥 [THE END] — Illustrated by Smoke Claude fer issue #5787 🗺️

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

Smoke Test Results (Run 20011669519)

Last 2 Merged PRs:

Test Results:

  • ✅ GitHub MCP Testing
  • ✅ File Writing Testing
  • ✅ Bash Tool Testing
  • ✅ Playwright MCP Testing
  • ✅ Cache Memory Testing
  • ✅ Safe Input gh Tool Testing

Overall Status: PASS

🤖 DIAGNOSTIC REPORT GENERATED BY Smoke Copilot No Firewall fer issue #5787 🗺️

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

PRs: [docs] Remove bloat from memory.md reference documentation; Fix agentics-maintenance.yml syntax by updating generator to use bundler
GitHub MCP: ✅
File write/read: ✅
Playwright title check: ✅
Cache memory write/read: ✅
gh issues list --limit 3: ❌ (auth required)
Overall: FAIL

🔮 The oracle has spoken through Smoke Codex fer issue #5787 🗺️

@pelikhan pelikhan marked this pull request as ready for review December 8, 2025 01:08
@pelikhan pelikhan merged commit 7de3333 into main Dec 8, 2025
14 of 15 checks passed
@pelikhan pelikhan deleted the copilot/remove-duplicate-mcp-implementations branch December 8, 2025 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[duplicate-code] Duplicate Code Detected: Parallel MCP server implementations

3 participants