diff --git a/integration_test.go b/integration_test.go index ca9c2d9..8f7be86 100644 --- a/integration_test.go +++ b/integration_test.go @@ -557,4 +557,4 @@ func BenchmarkIntegration_ExecuteQuery(b *testing.B) { b.Fatal(err) } } -} \ No newline at end of file +} diff --git a/internal/app/app.go b/internal/app/app.go index 89d5f9c..1f321c5 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -323,4 +323,4 @@ func (a *App) ensureConnection() error { } return nil -} \ No newline at end of file +} diff --git a/internal/app/app_test.go b/internal/app/app_test.go index 45a6037..72c2cca 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -127,9 +127,6 @@ func TestApp_SetLogger(t *testing.T) { assert.Equal(t, newLogger, app.logger) } - - - func TestApp_Disconnect(t *testing.T) { app, _ := New() mockClient := &MockPostgreSQLClient{} @@ -534,4 +531,4 @@ func TestApp_ListIndexes(t *testing.T) { assert.NoError(t, err) assert.Equal(t, expectedIndexes, indexes) mockClient.AssertExpectations(t) -} \ No newline at end of file +} diff --git a/internal/app/client.go b/internal/app/client.go index 066a61b..c7bb070 100644 --- a/internal/app/client.go +++ b/internal/app/client.go @@ -42,9 +42,9 @@ func (c *PostgreSQLClientImpl) Connect(connectionString string) error { func (c *PostgreSQLClientImpl) Close() error { if c.db != nil { if err := c.db.Close(); err != nil { - return fmt.Errorf("failed to close database: %w", err) - } - return nil + return fmt.Errorf("failed to close database: %w", err) + } + return nil } return nil } @@ -461,4 +461,4 @@ func (c *PostgreSQLClientImpl) ExplainQuery(query string, args ...interface{}) ( Rows: result, RowCount: len(result), }, nil -} \ No newline at end of file +} diff --git a/internal/app/client_mocked_test.go b/internal/app/client_mocked_test.go index 4134aa8..a86bb2a 100644 --- a/internal/app/client_mocked_test.go +++ b/internal/app/client_mocked_test.go @@ -96,9 +96,9 @@ func TestPostgreSQLClient_QueryValidationLogic(t *testing.T) { shouldAllow: true, }, { - name: "select lowercase", - query: "select * from users", - shouldAllow: false, + name: "select lowercase", + query: "select * from users", + shouldAllow: false, expectedError: "only SELECT and WITH queries are allowed", }, { @@ -256,4 +256,4 @@ func TestPostgreSQLClient_SchemaDefaults(t *testing.T) { assert.Contains(t, err.Error(), "no database connection") }) } -} \ No newline at end of file +} diff --git a/internal/app/client_test.go b/internal/app/client_test.go index b5f29a2..f5489d6 100644 --- a/internal/app/client_test.go +++ b/internal/app/client_test.go @@ -273,10 +273,10 @@ func TestPostgreSQLClient_ExecuteQueryInvalidQueries(t *testing.T) { if tt.expectError { assert.Error(t, err) if tt.errorMsg == "only SELECT and WITH queries are allowed" { - assert.Contains(t, err.Error(), "no database connection") - } else { - assert.Contains(t, err.Error(), tt.errorMsg) - } + assert.Contains(t, err.Error(), "no database connection") + } else { + assert.Contains(t, err.Error(), tt.errorMsg) + } assert.Nil(t, result) } else { assert.NoError(t, err) @@ -465,4 +465,4 @@ func TestExecuteQueryEmptyResult(t *testing.T) { assert.Equal(t, 0, result.RowCount) assert.Len(t, result.Rows, 0) assert.Len(t, result.Columns, 0) -} \ No newline at end of file +} diff --git a/internal/app/interfaces.go b/internal/app/interfaces.go index defc7e2..18d5d92 100644 --- a/internal/app/interfaces.go +++ b/internal/app/interfaces.go @@ -10,10 +10,10 @@ var ( ErrConnectionRequired = errors.New( "database connection failed. Please check POSTGRES_URL or DATABASE_URL environment variable", ) - ErrSchemaRequired = errors.New("schema name is required") - ErrTableRequired = errors.New("table name is required") - ErrQueryRequired = errors.New("query is required") - ErrInvalidQuery = errors.New("only SELECT and WITH queries are allowed") + ErrSchemaRequired = errors.New("schema name is required") + ErrTableRequired = errors.New("table name is required") + ErrQueryRequired = errors.New("query is required") + ErrInvalidQuery = errors.New("only SELECT and WITH queries are allowed") ErrNoConnectionString = errors.New( "no database connection string found in POSTGRES_URL or DATABASE_URL environment variables", ) @@ -58,20 +58,20 @@ type ColumnInfo struct { // IndexInfo represents index metadata. type IndexInfo struct { - Name string `json:"name"` - Table string `json:"table"` - Columns []string `json:"columns"` - IsUnique bool `json:"is_unique"` - IsPrimary bool `json:"is_primary"` - IndexType string `json:"index_type"` - Size string `json:"size,omitempty"` + Name string `json:"name"` + Table string `json:"table"` + Columns []string `json:"columns"` + IsUnique bool `json:"is_unique"` + IsPrimary bool `json:"is_primary"` + IndexType string `json:"index_type"` + Size string `json:"size,omitempty"` } // QueryResult represents the result of a query execution. type QueryResult struct { - Columns []string `json:"columns"` - Rows [][]interface{} `json:"rows"` - RowCount int `json:"row_count"` + Columns []string `json:"columns"` + Rows [][]interface{} `json:"rows"` + RowCount int `json:"row_count"` } // ConnectionManager handles database connection operations. @@ -109,4 +109,4 @@ type PostgreSQLClient interface { DatabaseExplorer TableExplorer QueryExecutor -} \ No newline at end of file +} diff --git a/internal/app/interfaces_test.go b/internal/app/interfaces_test.go index 50b2f2f..b60e58b 100644 --- a/internal/app/interfaces_test.go +++ b/internal/app/interfaces_test.go @@ -315,4 +315,4 @@ func TestQueryResultWithMixedTypes(t *testing.T) { assert.Equal(t, float64(30), deserializedResult.Rows[0][2]) assert.Equal(t, true, deserializedResult.Rows[0][3]) assert.Equal(t, 95.5, deserializedResult.Rows[0][4]) -} \ No newline at end of file +} diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 16fe0b1..4d0d7da 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -24,4 +24,4 @@ func NewLogger(level string) *slog.Logger { handler := slog.NewTextHandler(os.Stderr, opts) return slog.New(handler) -} \ No newline at end of file +} diff --git a/internal/logger/logger_test.go b/internal/logger/logger_test.go index 26772e6..c085088 100644 --- a/internal/logger/logger_test.go +++ b/internal/logger/logger_test.go @@ -213,4 +213,4 @@ func TestLoggerCaseInsensitive(t *testing.T) { assert.NotNil(t, logger) }) } -} \ No newline at end of file +} diff --git a/main.go b/main.go index 8751fd1..4c12552 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,6 @@ var ( ErrInvalidConnectionParameters = errors.New("invalid connection parameters") ) - // setupListDatabasesTool creates and registers the list_databases tool. func setupListDatabasesTool(s *server.MCPServer, appInstance *app.App, debugLogger *slog.Logger) { listDBTool := mcp.NewTool("list_databases", @@ -522,4 +521,4 @@ func main() { fmt.Fprintf(os.Stderr, "Server error: %v\n", err) return } -} \ No newline at end of file +} diff --git a/main_additional_test.go b/main_additional_test.go index c87b697..eedfe75 100644 --- a/main_additional_test.go +++ b/main_additional_test.go @@ -269,4 +269,4 @@ func TestEnvironmentVariableHandling(t *testing.T) { } assert.Equal(t, "postgres://test2@localhost/db2", connectionString) -} \ No newline at end of file +} diff --git a/main_command_line_test.go b/main_command_line_test.go index f57f11c..f280f81 100644 --- a/main_command_line_test.go +++ b/main_command_line_test.go @@ -77,4 +77,4 @@ func TestMainFunctionLogic(t *testing.T) { registerAllTools(server, app, logger) }) }) -} \ No newline at end of file +} diff --git a/main_test.go b/main_test.go index d47e661..ada34ed 100644 --- a/main_test.go +++ b/main_test.go @@ -18,7 +18,6 @@ type MockApp struct { mock.Mock } - func (m *MockApp) GetCurrentDatabase() (string, error) { args := m.Called() return args.String(0), args.Error(1) @@ -97,7 +96,6 @@ func (m *MockApp) Disconnect() error { return args.Error(0) } - func TestSetupListDatabasesTool(t *testing.T) { s := server.NewMCPServer("test", "1.0.0") realApp, err := app.New() @@ -261,7 +259,6 @@ func TestErrorVariables(t *testing.T) { // Test MCP tool parameter validation - func TestDescribeTableTool_ParameterValidation(t *testing.T) { tests := []struct { name string @@ -441,4 +438,4 @@ func TestToolResponseFormatting(t *testing.T) { assert.NoError(t, err) assert.Len(t, unmarshalled, 2) assert.Equal(t, "db1", unmarshalled[0].Name) -} \ No newline at end of file +} diff --git a/main_tool_coverage_test.go b/main_tool_coverage_test.go index 51170c8..f898b6e 100644 --- a/main_tool_coverage_test.go +++ b/main_tool_coverage_test.go @@ -237,4 +237,4 @@ func TestParameterParsingLogic(t *testing.T) { assert.NotEmpty(t, query) assert.Greater(t, limit, 0.0) }) -} \ No newline at end of file +}