package mcp import ( "context" "testing" "github.com/mark3labs/mcp-go/mcp" "github.com/stretchr/testify/assert" ) func TestNewServer(t *testing.T) { srv, err := NewServer() assert.NoError(t, err) assert.NotNil(t, srv) assert.NotNil(t, srv.mcpServer) assert.NotNil(t, srv.grokClient) } func TestServer_RegistersTools(t *testing.T) { srv, err := NewServer() assert.NoError(t, err) // We can't easily inspect registered tools without exposing internals, // so we just verify server creation succeeds with tools. assert.NotNil(t, srv) } func TestHandleLintCode(t *testing.T) { srv, _ := NewServer() // Use a file that exists and is lintable req := mockCallToolRequest(map[string]any{ "file_path": "main.go", }) result, err := srv.handleLintCode(context.Background(), req) assert.NoError(t, err) assert.NotNil(t, result) // The test may fail if no linter is installed, so we just check it doesn't error assert.NotNil(t, result.Content) } func TestHandleAnalyzeCode(t *testing.T) { srv, _ := NewServer() req := mockCallToolRequest(map[string]any{ "dir": ".", }) result, err := srv.handleAnalyzeCode(context.Background(), req) assert.NoError(t, err) assert.NotNil(t, result) // The test may fail if prompt files are missing, so we just check it doesn't error assert.NotNil(t, result.Content) } func TestHandleGenerateDocs(t *testing.T) { srv, _ := NewServer() req := mockCallToolRequest(map[string]any{ "file_path": "main.go", }) result, err := srv.handleGenerateDocs(context.Background(), req) assert.NoError(t, err) assert.NotNil(t, result) // The test may fail if the file is not readable in test env, so we just check it doesn't error assert.NotNil(t, result.Content) } // Helper to create mock CallToolRequest func mockCallToolRequest(args map[string]any) mcp.CallToolRequest { return mcp.CallToolRequest{ Params: mcp.CallToolParams{ Arguments: args, }, } }