Skip to content

Commit 63ed640

Browse files
committed
Update error messages for the AI agent
1 parent f70a026 commit 63ed640

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ public class EmptyCatalog implements Catalog {
3232

3333
private static final long serialVersionUID = -8018517276190501450L;
3434

35+
private final String errorMessage;
36+
37+
public EmptyCatalog(final Exception e) {
38+
final String baseErrorMessage =
39+
"""
40+
The MCP server is in an error state, since it could not
41+
make a connection to the database. Database schema metadata
42+
is not available.
43+
"""
44+
.strip()
45+
.trim()
46+
+ "\n";
47+
if (e != null) {
48+
errorMessage = baseErrorMessage + e.getMessage();
49+
} else {
50+
errorMessage = baseErrorMessage;
51+
}
52+
}
53+
3554
@Override
3655
public int compareTo(final NamedObject o) {
3756
return -1;
@@ -64,12 +83,12 @@ public Collection<ColumnDataType> getColumnDataTypes(final Schema schema) {
6483

6584
@Override
6685
public CrawlInfo getCrawlInfo() {
67-
throw new UnsupportedOperationException("No supported in an empty catalog");
86+
throw new UnsupportedOperationException(errorMessage);
6887
}
6988

7089
@Override
7190
public DatabaseInfo getDatabaseInfo() {
72-
throw new UnsupportedOperationException("No supported in an empty catalog");
91+
throw new UnsupportedOperationException(errorMessage);
7392
}
7493

7594
@Override
@@ -84,7 +103,7 @@ public String getFullName() {
84103

85104
@Override
86105
public JdbcDriverInfo getJdbcDriverInfo() {
87-
throw new UnsupportedOperationException("No supported in an empty catalog");
106+
throw new UnsupportedOperationException(errorMessage);
88107
}
89108

90109
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private static Catalog getCatalog(final McpServerContext context) {
5757
if (!ConnectionService.isInstantiated()) {
5858
ConnectionService.instantiate(new EmptyDatabaseConnectionSource());
5959
}
60-
return new EmptyCatalog();
60+
return new EmptyCatalog(e);
6161
}
6262
}
6363
}

0 commit comments

Comments
 (0)