Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,4 @@ func BenchmarkIntegration_ExecuteQuery(b *testing.B) {
b.Fatal(err)
}
}
}
}
2 changes: 1 addition & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,4 @@ func (a *App) ensureConnection() error {
}

return nil
}
}
5 changes: 1 addition & 4 deletions internal/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -534,4 +531,4 @@ func TestApp_ListIndexes(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, expectedIndexes, indexes)
mockClient.AssertExpectations(t)
}
}
8 changes: 4 additions & 4 deletions internal/app/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -461,4 +461,4 @@ func (c *PostgreSQLClientImpl) ExplainQuery(query string, args ...interface{}) (
Rows: result,
RowCount: len(result),
}, nil
}
}
8 changes: 4 additions & 4 deletions internal/app/client_mocked_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
{
Expand Down Expand Up @@ -256,4 +256,4 @@ func TestPostgreSQLClient_SchemaDefaults(t *testing.T) {
assert.Contains(t, err.Error(), "no database connection")
})
}
}
}
10 changes: 5 additions & 5 deletions internal/app/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
30 changes: 15 additions & 15 deletions internal/app/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -109,4 +109,4 @@ type PostgreSQLClient interface {
DatabaseExplorer
TableExplorer
QueryExecutor
}
}
2 changes: 1 addition & 1 deletion internal/app/interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
2 changes: 1 addition & 1 deletion internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ func NewLogger(level string) *slog.Logger {

handler := slog.NewTextHandler(os.Stderr, opts)
return slog.New(handler)
}
}
2 changes: 1 addition & 1 deletion internal/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,4 @@ func TestLoggerCaseInsensitive(t *testing.T) {
assert.NotNil(t, logger)
})
}
}
}
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -522,4 +521,4 @@ func main() {
fmt.Fprintf(os.Stderr, "Server error: %v\n", err)
return
}
}
}
2 changes: 1 addition & 1 deletion main_additional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,4 @@ func TestEnvironmentVariableHandling(t *testing.T) {
}

assert.Equal(t, "postgres://test2@localhost/db2", connectionString)
}
}
2 changes: 1 addition & 1 deletion main_command_line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ func TestMainFunctionLogic(t *testing.T) {
registerAllTools(server, app, logger)
})
})
}
}
5 changes: 1 addition & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -261,7 +259,6 @@ func TestErrorVariables(t *testing.T) {

// Test MCP tool parameter validation


func TestDescribeTableTool_ParameterValidation(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion main_tool_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,4 @@ func TestParameterParsingLogic(t *testing.T) {
assert.NotEmpty(t, query)
assert.Greater(t, limit, 0.0)
})
}
}
Loading