Skip to content

Commit 5383a94

Browse files
authored
Merge pull request #127 from schemacrawler/cleanup
Clean up code
2 parents 324dbfd + bab5c71 commit 5383a94

File tree

18 files changed

+108
-240
lines changed

18 files changed

+108
-240
lines changed

.mvn/extensions.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.mvn/jvm.config

Lines changed: 0 additions & 1 deletion
This file was deleted.

.mvn/maven-build-cache-config.xml

Lines changed: 0 additions & 114 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* SchemaCrawler AI
3+
* http://www.schemacrawler.com
4+
* Copyright (c) 2000-2025, Sualeh Fatehi <sualeh@hotmail.com>.
5+
* All rights reserved.
6+
* SPDX-License-Identifier: CC-BY-NC-4.0
7+
*/
8+
9+
package schemacrawler.tools.ai.mcpserver;
10+
11+
import java.util.Collection;
12+
import java.util.Collections;
13+
import jakarta.annotation.Nullable;
14+
15+
/** Wrapper for bean that would otherwise have a collection of strings */
16+
public record ExcludeTools(@Nullable Collection<String> excludeTools) {
17+
public ExcludeTools {
18+
if (excludeTools == null) {
19+
excludeTools = Collections.emptySet();
20+
}
21+
}
22+
}

schemacrawler-ai-mcpserver/src/main/java/schemacrawler/tools/ai/mcpserver/McpServerContext.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.nio.file.Path;
1616
import java.util.Collection;
17+
import java.util.Set;
1718
import java.util.logging.Level;
1819
import schemacrawler.schema.Catalog;
1920
import schemacrawler.schemacrawler.InfoLevel;
@@ -23,10 +24,10 @@
2324
import schemacrawler.schemacrawler.LoadOptionsBuilder;
2425
import schemacrawler.schemacrawler.SchemaCrawlerOptions;
2526
import schemacrawler.schemacrawler.SchemaCrawlerOptionsBuilder;
26-
import schemacrawler.tools.ai.mcpserver.utility.CollectionsUtility;
2727
import schemacrawler.tools.databaseconnector.EnvironmentalDatabaseConnectionSourceBuilder;
2828
import schemacrawler.tools.offline.jdbc.OfflineConnectionUtility;
2929
import schemacrawler.tools.utility.SchemaCrawlerUtility;
30+
import us.fatehi.utility.CollectionsUtility;
3031
import us.fatehi.utility.LoggingConfig;
3132
import us.fatehi.utility.datasource.DatabaseConnectionSource;
3233
import us.fatehi.utility.ioresource.EnvironmentVariableAccessor;
@@ -107,7 +108,7 @@ protected SchemaCrawlerOptions buildSchemaCrawlerOptions() {
107108
}
108109

109110
protected Collection<String> excludeTools() {
110-
return CollectionsUtility.setOfStrings(envAccessor.getenv(EXCLUDE_TOOLS));
111+
return Set.of(CollectionsUtility.splitList(envAccessor.getenv(EXCLUDE_TOOLS)));
111112
}
112113

113114
protected Catalog getCatalog() {

schemacrawler-ai-mcpserver/src/main/java/schemacrawler/tools/ai/mcpserver/McpServerInitializer.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
package schemacrawler.tools.ai.mcpserver;
1010

11-
import static java.util.Collections.emptySet;
12-
import static java.util.Collections.unmodifiableCollection;
1311
import static java.util.Objects.requireNonNull;
1412

1513
import java.sql.Connection;
@@ -31,7 +29,7 @@ public class McpServerInitializer
3129
private final Catalog catalog;
3230
private final DatabaseConnectionSource connectionSource;
3331
private final McpServerTransportType mcpTransport;
34-
private final Collection<String> excludeTools;
32+
private final ExcludeTools excludeTools;
3533

3634
public McpServerInitializer(
3735
final Catalog catalog,
@@ -61,9 +59,9 @@ public McpServerInitializer(
6159
this.catalog = requireNonNull(catalog, "No catalog provided");
6260

6361
if (excludeTools == null) {
64-
this.excludeTools = emptySet();
62+
this.excludeTools = new ExcludeTools(null);
6563
} else {
66-
this.excludeTools = unmodifiableCollection(excludeTools);
64+
this.excludeTools = new ExcludeTools(excludeTools);
6765
}
6866
}
6967

@@ -99,7 +97,7 @@ public McpServerInitializer(final McpServerContext context) {
9997
}
10098
this.connectionSource = connectionSource;
10199

102-
excludeTools = context.excludeTools();
100+
excludeTools = new ExcludeTools(context.excludeTools());
103101
}
104102

105103
@Override
@@ -115,6 +113,6 @@ public void initialize(@NonNull final GenericApplicationContext context) {
115113
"functionDefinitionRegistry",
116114
FunctionDefinitionRegistry.class,
117115
() -> FunctionDefinitionRegistry.getFunctionDefinitionRegistry());
118-
context.registerBean("excludeTools", Collection.class, () -> excludeTools);
116+
context.registerBean("excludeTools", ExcludeTools.class, () -> excludeTools);
119117
}
120118
}

schemacrawler-ai-mcpserver/src/main/java/schemacrawler/tools/ai/mcpserver/server/HealthController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class HealthController {
2424
@GetMapping(
2525
value = {"/", "/health"},
2626
produces = APPLICATION_JSON_VALUE)
27-
public Map<String, String> healthCheck() {
27+
public Map<String, Object> healthCheck() {
2828
return serverHealth.currentState();
2929
}
3030
}

schemacrawler-ai-mcpserver/src/main/java/schemacrawler/tools/ai/mcpserver/server/HeartbeatLogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public class HeartbeatLogger {
3535

3636
private final Supplier<String> heartbeatMessage =
3737
() -> {
38-
final Map<String, String> heartbeatMessage = serverHealth.currentState();
38+
final Map<String, Object> heartbeatMessage = serverHealth.currentState();
3939
try {
4040
return "\n"
4141
+ mapper.writerWithDefaultPrettyPrinter().writeValueAsString(heartbeatMessage);
4242
} catch (final JsonProcessingException e) {
4343
LOGGER.log(Level.WARNING, "Could not convert server state to JSON", e);
44-
return serverHealth.currentStateString();
44+
return heartbeatMessage.toString();
4545
}
4646
};
4747

schemacrawler-ai-mcpserver/src/main/java/schemacrawler/tools/ai/mcpserver/server/ServerHealth.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.springframework.beans.factory.annotation.Autowired;
1818
import org.springframework.beans.factory.annotation.Value;
1919
import org.springframework.stereotype.Component;
20+
import schemacrawler.tools.ai.mcpserver.ExcludeTools;
2021
import schemacrawler.tools.ai.mcpserver.McpServerTransportType;
2122

2223
@Component
@@ -29,25 +30,20 @@ public class ServerHealth {
2930
private String serverVersion;
3031

3132
@Autowired private boolean isInErrorState;
32-
3333
@Autowired private McpServerTransportType mcpTransport;
34+
@Autowired private ExcludeTools excludeTools;
3435

35-
public Map<String, String> currentState() {
36-
final Map<String, String> currentState = new HashMap<>();
36+
public Map<String, Object> currentState() {
37+
final Map<String, Object> currentState = new HashMap<>();
3738
currentState.put("_server", getServerName());
3839
currentState.put("current-timestamp", String.valueOf(ZonedDateTime.now(ZoneOffset.UTC)));
39-
currentState.put("in-error-state", Boolean.toString(isInErrorState));
40+
currentState.put("in-error-state", isInErrorState);
4041
currentState.put("server-uptime", String.valueOf(getServerUptime()));
4142
currentState.put("transport", mcpTransport.name());
43+
currentState.put("exclude-tools", excludeTools.excludeTools());
4244
return currentState;
4345
}
4446

45-
public String currentStateString() {
46-
return String.format(
47-
"%s%nin-error-state=%s; server-uptime=%s; transport=%s",
48-
getServerName(), isInErrorState, getServerUptime(), mcpTransport);
49-
}
50-
5147
public McpServerTransportType getMcpTransport() {
5248
return mcpTransport;
5349
}

schemacrawler-ai-mcpserver/src/main/java/schemacrawler/tools/ai/mcpserver/server/ToolProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import io.modelcontextprotocol.server.McpSyncServerExchange;
1616
import io.modelcontextprotocol.spec.McpSchema.Implementation;
1717
import java.util.ArrayList;
18-
import java.util.Collection;
1918
import java.util.List;
2019
import java.util.logging.Level;
2120
import java.util.logging.Logger;
@@ -26,6 +25,7 @@
2625
import org.springframework.context.annotation.Bean;
2726
import org.springframework.stereotype.Service;
2827
import schemacrawler.Version;
28+
import schemacrawler.tools.ai.mcpserver.ExcludeTools;
2929
import schemacrawler.tools.ai.tools.FunctionDefinition;
3030
import schemacrawler.tools.ai.tools.FunctionDefinitionRegistry;
3131
import schemacrawler.tools.ai.utility.JsonUtility;
@@ -43,7 +43,7 @@ public class ToolProvider {
4343
@Autowired private ServerHealth serverHealth;
4444
@Autowired private FunctionDefinitionRegistry functionDefinitionRegistry;
4545
@Autowired private ToolHelper toolHelper;
46-
@Autowired private Collection<String> excludeTools;
46+
@Autowired private ExcludeTools excludeTools;
4747

4848
@McpTool(
4949
name = "mcp-server-health",
@@ -84,7 +84,7 @@ public List<McpServerFeatures.SyncToolSpecification> schemaCrawlerTools() {
8484
for (final FunctionDefinition<?> functionDefinition :
8585
functionDefinitionRegistry.getFunctionDefinitions()) {
8686
final String functionName = functionDefinition.getFunctionName().getName();
87-
if (excludeTools == null || excludeTools.contains(functionName)) {
87+
if (excludeTools == null || excludeTools.excludeTools().contains(functionName)) {
8888
LOGGER.log(Level.WARNING, new StringFormat("Excluding tool <%s>", functionName));
8989
continue;
9090
}

0 commit comments

Comments
 (0)