Auto-Approval / Auto-Denial for Tool Calls — server + routes + DB + tests #134
Labels
No labels
Epic 5
MCP
P1
PR-0
PR-1
api
api-layer
architecture
area:backend
area:frontend
arrow
authentication
backend
bug
chat
client
clipboard
common-module
compose
cross-cutting
cross-cutting-requirement
data-layer
data-models
database
desktop-client
documentation
duplicate
enhancement
epic
epic-1
epic-2
epic-3
epic-4
epic-5
epic-6
epic-7
epic-llm-config
error-handling
feature
frontend
good first issue
help wanted
implementation
infrastructure
installer
invalid
kotlin
ktor
llm
medium-priority
message
multiplatform
needs-review
needs-triage
packaging
performance
phase-1
phase-2
phase-3
phase-4
phase-5
phase3
phase:3
priority: high
question
refactor
refactoring
resource-sharing
security
server
server-module
services
session
session-management
settings
setup
shutdown
state
storage
streaming
sub-issue
tests
tooling
type:task
ui
ui/ux
user-accounts
user-management
ux
viewmodel
websocket
windows
windows-integration
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Torvian.eu/chatbot#134
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Auto-Approval/Auto-Denial Tool Call Feature - Implementation Summary
Overview
Successfully implemented auto-approval and auto-denial functionality for tool calls, allowing users to configure which tools should be automatically approved or denied without manual intervention.
Changes Made
1. Database Layer
New Table: UserToolApprovalPreferencesTable
server/src/main/kotlin/eu/torvian/chatbot/server/data/tables/UserToolApprovalPreferencesTable.ktuserId(FK to UsersTable) - User who owns the preferencetoolDefinitionId(FK to ToolDefinitionTable) - Tool being configuredautoApprove(BOOL, default: true) - Whether to auto-approve (true) or auto-deny (false)conditions(TEXT, nullable) - Reserved for future conditional logicdenialReason(TEXT, nullable) - Reason text provided to LLM on auto-denial2. Common Models
UserToolApprovalPreference
common/src/commonMain/kotlin/eu/torvian/chatbot/common/models/tool/UserToolApprovalPreference.ktAPI Request DTO
common/src/commonMain/kotlin/eu/torvian/chatbot/common/models/api/tool/SetToolApprovalPreferenceRequest.kt3. Data Access Layer
UserToolApprovalPreferenceDao Interface
server/src/main/kotlin/eu/torvian/chatbot/server/data/dao/UserToolApprovalPreferenceDao.ktgetPreference(userId, toolDefId)- Retrieve single preferencegetAllPreferencesForUser(userId)- List all preferences for a usersetPreference(...)- Create or update preference (upsert)deletePreference(userId, toolDefId)- Delete specific preferencedeleteAllPreferencesForUser(userId)- Cleanup on user deletionUserToolApprovalPreferenceDaoExposed
server/src/main/kotlin/eu/torvian/chatbot/server/data/dao/exposed/UserToolApprovalPreferenceDaoExposed.ktError Types
server/src/main/kotlin/eu/torvian/chatbot/server/data/dao/error/UserToolApprovalPreferenceError.ktNotFound- Preference doesn't existInvalidToolDefinition- Referenced tool doesn't existInvalidUser- Referenced user doesn't exist4. Service Layer
ToolService Interface Extensions
Added methods:
setToolApprovalPreference(...)→ Either<SetToolApprovalPreferenceError, UserToolApprovalPreference>getToolApprovalPreference(...)→ Either<GetToolApprovalPreferenceError, UserToolApprovalPreference>getAllApprovalPreferencesForUser(userId)→ ListdeleteToolApprovalPreference(...)→ Either<DeleteToolApprovalPreferenceError, Unit>ToolServiceImpl Implementation
server/src/main/kotlin/eu/torvian/chatbot/server/service/core/impl/ToolServiceImpl.ktError Types
server/src/main/kotlin/eu/torvian/chatbot/server/service/core/error/tool/ToolServiceErrors.ktSetToolApprovalPreferenceError- ToolNotFound, UserNotFoundGetToolApprovalPreferenceError- PreferenceNotFoundDeleteToolApprovalPreferenceError- PreferenceNotFoundError Mappings
server/src/main/kotlin/eu/torvian/chatbot/server/service/core/error/tool/ToolServiceErrorExtensions.kt5. Auto-Approval Logic Integration
ChatServiceImpl Updates
server/src/main/kotlin/eu/torvian/chatbot/server/service/core/impl/ChatServiceImpl.ktChanges:
userId: Longparameter toprocessNewMessage()andprocessNewMessageStreaming()userId: Longparameter toexecuteAndUpdateToolCalls()private functionUserToolApprovalPreferenceDaointo ChatServiceImpl constructorAuto-Approval Flow (in executeAndUpdateToolCalls):
autoApprove == true: Create synthetic approval response → proceed to executionautoApprove == false: Set status to USER_DENIED with denialReason → skip executionBenefits:
conditionsfield (reserved for Phase 2)denialReasonfield6. API Routes
ToolResource Extensions
common/src/commonMain/kotlin/eu/torvian/chatbot/common/api/resources/ToolResource.ktApprovalPreferencesresource class for type-safe routingEndpoints
server/src/main/kotlin/eu/torvian/chatbot/server/ktor/routes/configureToolRoutes.ktAdded endpoints:
GET /api/v1/tools/approval-preferences- List all preferences for current userPUT /api/v1/tools/approval-preferences- Set/update preferenceGET /api/v1/tools/approval-preferences/{toolId}- Get specific preferenceDELETE /api/v1/tools/approval-preferences/{toolId}- Delete preferenceAll endpoints require
USER_JWTauthentication.7. Dependency Injection
Koin DI Updates
UserToolApprovalPreferenceDaoExposedChatServiceImplandToolServiceImplwith new dependencies8. Database Scheman
Schema Registration
server/src/main/kotlin/eu/torvian/chatbot/server/main/ExposedDataManager.ktUserToolApprovalPreferencesTableto schema creation/dropping9. Route Handler Updates
WebSocket Route
server/src/main/kotlin/eu/torvian/chatbot/server/ktor/routes/configureSessionRoutes.ktprocessNewMessage()andprocessNewMessageStreaming()to passuserIdfrom route context10. Testsn
ChatServiceImplTest
server/src/test/kotlin/eu/torvian/chatbot/server/service/core/impl/ChatServiceImplTest.ktUserToolApprovalPreferenceDaoprocessNewMessage()calls to include userId parameterFuture Enhancements
Conditional Auto-Approval (Phase 2):
conditionsfieldPreference Management UI:
Bulk Preference Operations:
Preference Templates:
Build Status
✅ Server Build: Successful (./gradlew server:assemble)
✅ Server Tests: All passing (./gradlew server:test)
✅ No compilation errors
Architecture Notes