Refactor mcp_inspect.go into focused modules (1011→285 lines)#11877
Merged
Refactor mcp_inspect.go into focused modules (1011→285 lines)#11877
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor mcp_inspect.go into focused modules
Refactor mcp_inspect.go into focused modules (1011→285 lines)
Jan 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mcp_inspect.gogrew to 1011 lines with multiple distinct responsibilities (workflow listing, import processing, safe-inputs server lifecycle, inspector spawning). Refactored into 7 focused modules along semantic boundaries.Module Breakdown
Core entry point (285 lines, was 1011)
mcp_inspect.go-InspectWorkflowMCP(),NewMCPInspectSubcommand()New focused modules (6 files, 794 lines total)
mcp_inspect_list.go(58 lines) -listWorkflowsWithMCP(),filterOutSafeOutputs()mcp_inspect_imports.go(78 lines) -applyImportsToFrontmatter()mcp_inspect_safe_inputs_server.go(194 lines) - HTTP server lifecycle:startSafeInputsServer(),findAvailablePort(),waitForServerReady()mcp_inspect_safe_inputs_files.go(111 lines) -writeSafeInputsFiles()mcp_inspect_safe_inputs_inspector.go(131 lines) -spawnSafeInputsInspector()mcp_inspect_inspector.go(222 lines) -spawnMCPInspector()API Compatibility
Public API unchanged. All functions remain package-private. Shared logger (
mcpInspectLog) used across modules.Related Files
Pre-existing separation:
mcp_inspect_mcp.go(619 lines) - MCP connection logicmcp_validation.go- Secret validationmcp_tool_table.go- Tool renderingOriginal prompt
This section details on the original issue you should resolve
<issue_title>[file-diet] Refactor mcp_inspect.go (1011 lines) into focused modules</issue_title>
<issue_description>### Overview
The file
pkg/cli/mcp_inspect.gohas grown to 1011 lines, making it difficult to maintain and test. This task involves refactoring it into smaller, focused files with improved test coverage.Current State
pkg/cli/mcp_inspect.goFull File Analysis
Function Distribution
The file contains 12 functions spanning 4 major functional domains:
Workflow MCP Inspection (3 functions, ~300 lines)
InspectWorkflowMCP(lines 112-294) - Main entry point for workflow inspectionlistWorkflowsWithMCP(lines 297-330) - Lists workflows with MCP configurationsfilterOutSafeOutputs(lines 33-41) - Filters safe-outputs from MCP listapplyImportsToFrontmatter(lines 45-109) - Merges imported MCP servers and toolsSafe-Inputs Server Management (4 functions, ~400 lines)
writeSafeInputsFiles(lines 333-431) - Writes safe-inputs files to diskstartSafeInputsHTTPServer(lines 434-462) - Starts Node.js HTTP serverfindAvailablePort(lines 465-480) - Port discovery logicwaitForServerReady(lines 483-506) - HTTP server health checkingstartSafeInputsServer(lines 509-603) - Orchestrates safe-inputs setupSafe-Inputs Inspector (1 function, ~120 lines)
spawnSafeInputsInspector(lines 607-720) - Generates files, starts server, launches inspectorMCP Inspector Spawning (2 functions, ~200 lines)
spawnMCPInspector(lines 724-928) - Launches@modelcontextprotocol/inspectorwith stdio server managementNewMCPInspectSubcommand(lines 932-1011) - Cobra command configurationComplexity Hotspots
InspectWorkflowMCP(182 lines) - Handles frontmatter parsing, import processing, validation, safe-inputs detection, and server inspectionstartSafeInputsServer(94 lines) - Complex orchestration with temporary directory management, port discovery, server startup, and health checkingspawnMCPInspector(204 lines) - Manages stdio server lifecycle, process monitoring with goroutines, and inspector spawningwriteSafeInputsFiles(98 lines) - Writes 9+ JavaScript files and generates tool handlers dynamicallyCoupling Issues
Refactoring Strategy
Proposed File Splits
Based on semantic analysis, split the file into the following modules:
mcp_inspect.go(Main command entry point)NewMCPInspectSubcommand,InspectWorkflowMCPmcp_inspect_list.go(Workflow listing and filtering)listWorkflowsWithMCP,filterOutSafeOutputsmcp_inspect_imports.go(Import processing)applyImportsToFrontmattermcp_inspect_safe_inputs_server.go(Safe-inputs HTTP server management)startSafeInputsServer,startSafeInputsHTTPServer,findAvailablePort,waitForServerReadymcp_inspect_safe_inputs_files.go(Safe-inputs file generation)writeSafeInputsFilesmcp_inspect_safe_inputs_inspector.go(Safe-inputs inspector)spawnSafeInputsInspectormcp_inspect_inspector.go(MCP inspector spawning)spawnMCPInspector@modelcontextprotocol/inspectorwith stdio server managementInterface Abstractions
Consider introducing interfaces to reduce coupling: