OtterMind/Chat2DB · error · IllegalArgumentException
No database connection context found. Provide dataSourceId/d
Error message
No database connection context found. Provide dataSourceId/databaseName.
What it means
Thrown by requireConnectInfo when resolveConnectionProfile returns null — i.e. toolContext is null, or it has no connectionProfile and no dataSourceId. This is the hard precondition used by tools that must execute against an already-resolved connection and cannot build one lazily.
Source
Thrown at chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/ai/AiToolServiceImpl.java:745
}
if (toolContext.getConnectionProfile() != null) {
return toolContext.getConnectionProfile();
}
Long dataSourceId = toolContext.getDataSourceId();
if (Objects.isNull(dataSourceId)) {
return null;
}
String databaseName = toolContext.getDatabaseName();
String schemaName = toolContext.getSchemaName();
return buildProfile(dataSourceId, databaseName, schemaName);
}
private ConnectionProfile requireConnectInfo(AiToolContextRequest toolContext) {
ConnectionProfile profile = resolveConnectionProfile(toolContext);
if (Objects.nonNull(profile)) {
return profile;
}
throw new IllegalArgumentException("No database connection context found. Provide dataSourceId/databaseName.");
}
private ConnectionProfile buildProfile(Long dataSourceId, String databaseName, String schemaName) {
DbConnectionContextRequest param = new DbConnectionContextRequest();
param.setDataSourceId(dataSourceId);
param.setDatabaseName(databaseName);
param.setSchemaName(schemaName);
return connectionContextService.buildProfile(param);
}
}
View on GitHub (pinned to 5ee1e990e7)
Solutions
- Populate toolContext.dataSourceId (plus databaseName/schemaName) before calling the tool.
- Alternatively, set toolContext.connectionProfile to a resolved ConnectionProfile from a prior buildProfile call.
- Verify the client is forwarding the active datasource session into every tool request that requires it.
Example fix
// before request.setToolContext(new AiToolContextRequest()); // empty // after AiToolContextRequest ctx = new AiToolContextRequest(); ctx.setDataSourceId(activeDsId); ctx.setDatabaseName(activeDb); request.setToolContext(ctx);
Defensive patterns
Strategy: validation
Validate before calling
public boolean hasConnectInfo(AiToolContextRequest ctx) {
if (ctx == null) return false;
return ctx.getConnectionProfile() != null || ctx.getDataSourceId() != null;
}
// call: if (!hasConnectInfo(ctx)) throw new IllegalStateException("connection required"); Type guard
public boolean hasResolvedConnection(AiToolContextRequest ctx) {
return ctx != null && (ctx.getConnectionProfile() != null || ctx.getDataSourceId() != null);
} Try / catch
try {
return aiToolService.requireConnectInfo(toolContext);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("No database connection context found.")) {
return Optional.empty(); // or prompt for connection input
}
throw e;
} Prevention
- Never dispatch a connection-requiring tool with an empty toolContext.
- Validate connection inputs at the API/transport boundary before reaching the service.
- Centralize connection resolution so all tools share one guard.
When it happens
Trigger: A tool path calling requireConnectInfo(toolContext) where the request carries neither connectionProfile nor dataSourceId, and the caller did not establish a session first.
Common situations: Same family as error 61 but the stricter variant: the tool has no optional-resolution fallback, so any missing connection input fails immediately. Common when an MCP caller forwards an empty toolContext object.
Related errors
- No database connection context found. Call list_all_datasour
- database.delete.invalidDataSource
- datasource_not_found
- invalid_connection_test_args
- invalid_datasource_create_args
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/17a316cdbe31dcbc.
Report an issue: GitHub.