Skip to content

fix(codemode): ensure correct mcp import before goimports runs#144

Merged
spachava753 merged 1 commit intomainfrom
fix/goimports-mcp-resolution
Jan 19, 2026
Merged

fix(codemode): ensure correct mcp import before goimports runs#144
spachava753 merged 1 commit intomainfrom
fix/goimports-mcp-resolution

Conversation

@spachava753
Copy link
Copy Markdown
Owner

Summary

Fixes #142

When LLM-generated code uses mcp.* types without importing the MCP SDK package, goimports may resolve "mcp" to an incorrect package in the ecosystem.

Changes

  • Added ensureMCPImport() function that uses astutil.AddImport to inject the correct MCP SDK import path before goimports processes the file
  • Modified autoCorrectImports() to call the new function as a preprocessing step
  • If the import is unused, goimports removes it afterward

Testing

  • Added unit tests for ensureMCPImport() covering various import scenarios
  • Added integration test verifying code with missing mcp import compiles after preprocessing

When LLM-generated code uses mcp.* types without importing the MCP SDK package, goimports may resolve "mcp" to an incorrect package. This adds a preprocessing step that injects the correct import path using AST manipulation before goimports processes the file. If the import is unused, goimports removes it afterward.

Closes #142
@spachava753 spachava753 merged commit e4c523e into main Jan 19, 2026
@spachava753 spachava753 deleted the fix/goimports-mcp-resolution branch April 10, 2026 00:23
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.

[Bug]: goimports may resolve mcp package incorrectly when LLM omits import

1 participant