Affected Area
Code mode execution
Model Provider
N/A
Model ID
N/A (affects all models)
Bug Description
With the introduction of multimedia content return support in commit 75fb1d8 (PR #141, closes #139), the Run function signature changed from error to ([]mcp.Content, error). This requires the github.com/modelcontextprotocol/go-sdk/mcp package to be imported.
The tool description in tooldesc.go instructs the LLM to include this import, but models sometimes forget. When this happens, autoCorrectImports() in executor.go runs goimports which may resolve mcp to a different package (e.g., some other package in the ecosystem named "mcp"), causing compilation errors or unexpected behavior.
Expected Behavior
When the LLM generates code that uses mcp.Content, mcp.TextContent, mcp.ImageContent, or mcp.AudioContent without importing the correct package, CPE should automatically ensure github.com/modelcontextprotocol/go-sdk/mcp is in the imports.
Steps to Reproduce
- Have a model generate code that returns multimedia content but forgets the mcp import:
package main
import (
"context"
"os"
)
func Run(ctx context.Context) ([]mcp.Content, error) {
data, _ := os.ReadFile("image.png")
return []mcp.Content{
&mcp.ImageContent{Data: data, MIMEType: "image/png"},
}, nil
}
- goimports runs and may resolve
mcp to the wrong package
- Compilation fails or unexpected behavior occurs
Relevant Configuration
N/A - affects code mode execution infrastructure
Error Output / Logs
Varies depending on which wrong package goimports resolves to.
Environment
- CPE version: 75fb1d8
- Go version: 1.24.0+
- OS: All
Additional Context
Relevant files:
internal/codemode/executor.go - autoCorrectImports() function (line 225-253)
internal/codemode/tooldesc.go - Tool description that tells LLM to import mcp
Proposed fix:
Add a pre-processing step before calling goimports that:
- Parses the generated code to check if it references
mcp. identifiers
- If mcp is referenced but
github.com/modelcontextprotocol/go-sdk/mcp is not in imports, add it
This ensures goimports won't resolve mcp to the wrong package since it's already present.
Related:
Affected Area
Code mode execution
Model Provider
N/A
Model ID
N/A (affects all models)
Bug Description
With the introduction of multimedia content return support in commit 75fb1d8 (PR #141, closes #139), the
Runfunction signature changed fromerrorto([]mcp.Content, error). This requires thegithub.zerozr99.workers.dev/modelcontextprotocol/go-sdk/mcppackage to be imported.The tool description in
tooldesc.goinstructs the LLM to include this import, but models sometimes forget. When this happens,autoCorrectImports()inexecutor.goruns goimports which may resolvemcpto a different package (e.g., some other package in the ecosystem named "mcp"), causing compilation errors or unexpected behavior.Expected Behavior
When the LLM generates code that uses
mcp.Content,mcp.TextContent,mcp.ImageContent, ormcp.AudioContentwithout importing the correct package, CPE should automatically ensuregithub.zerozr99.workers.dev/modelcontextprotocol/go-sdk/mcpis in the imports.Steps to Reproduce
mcpto the wrong packageRelevant Configuration
N/A - affects code mode execution infrastructure
Error Output / Logs
Varies depending on which wrong package goimports resolves to.
Environment
Additional Context
Relevant files:
internal/codemode/executor.go-autoCorrectImports()function (line 225-253)internal/codemode/tooldesc.go- Tool description that tells LLM to import mcpProposed fix:
Add a pre-processing step before calling goimports that:
mcp.identifiersgithub.zerozr99.workers.dev/modelcontextprotocol/go-sdk/mcpis not in imports, add itThis ensures goimports won't resolve mcp to the wrong package since it's already present.
Related: