Skip to content

Commit 8713465

Browse files
committed
Implement Delete Database Service #7506
1 parent 2e79fbb commit 8713465

4 files changed

Lines changed: 55 additions & 1 deletion

File tree

.github/ISSUE/epic-architect-knowledge-base-as-mcp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ We will employ a rapid and agile development approach. The scope and API specifi
3232
- **Sub-Tasks:**
3333
- `ticket-kb-implement-tool-service.md`: Implement the core tool service to dynamically load tools from the OpenAPI spec.
3434
- `ticket-kb-implement-healthcheck-service.md`: Implement the healthcheck service to verify the connection to ChromaDB.
35+
- `ticket-kb-implement-delete-db-service.md`: Implement the service to delete the ChromaDB collection.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: Implement Delete Database Service
3+
labels: enhancement, AI
4+
---
5+
6+
Parent epic: #7501
7+
GH ticket id: #placeholder
8+
9+
**Phase:** 2
10+
**Assignee:** tobiu
11+
**Status:** Done
12+
13+
## Description
14+
15+
This ticket covers the implementation of the `delete_database` service for the AI Knowledge Base MCP server. This service will expose the destructive but necessary functionality to completely remove the knowledge base collection from ChromaDB, allowing for a clean reset.
16+
17+
## Acceptance Criteria
18+
19+
1. A new `ai/mcp/server/knowledge-base/services/databaseService.mjs` file is created.
20+
2. The service contains a `deleteDatabase` function that connects to ChromaDB and deletes the collection specified in `aiConfig`.
21+
3. The function returns a success message upon completion.
22+
4. The `toolService.mjs` `serviceMapping` is updated to point the `delete_database` operationId to the new service function.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { ChromaClient } from 'chromadb';
2+
import aiConfig from '../../../../buildScripts/ai/aiConfig.mjs';
3+
4+
/**
5+
* Permanently deletes the entire knowledge base collection from ChromaDB.
6+
* This is a destructive operation used for a clean reset.
7+
* @returns {Promise<object>} A promise that resolves to a success message.
8+
*/
9+
async function deleteDatabase() {
10+
const dbClient = new ChromaClient();
11+
const collectionName = aiConfig.knowledgeBase.collectionName;
12+
13+
try {
14+
await dbClient.deleteCollection({ name: collectionName });
15+
return {
16+
message: `Knowledge base collection '${collectionName}' deleted successfully.`
17+
};
18+
} catch (error) {
19+
// ChromaDB throws an error if the collection doesn't exist, which we can treat as a success for this operation.
20+
if (error.message.includes(`Collection ${collectionName} does not exist.`)) {
21+
return {
22+
message: `Knowledge base collection '${collectionName}' did not exist. No action taken.`
23+
};
24+
}
25+
// Re-throw other unexpected errors.
26+
throw error;
27+
}
28+
}
29+
30+
export { deleteDatabase };

ai/mcp/server/knowledge-base/services/toolService.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { z } from 'zod';
55
import { zodToJsonSchema } from 'zod-to-json-schema';
66
import { fileURLToPath } from 'url';
77
import * as healthService from './healthService.mjs';
8+
import * as databaseService from './databaseService.mjs';
89

910
const __filename = fileURLToPath(import.meta.url);
1011
const __dirname = path.dirname(__filename);
@@ -23,7 +24,7 @@ let allToolsForListing = null;
2324
const serviceMapping = {
2425
healthcheck : healthService.healthcheck,
2526
sync_database : async () => 'sync_database not implemented',
26-
delete_database: async () => 'delete_database not implemented',
27+
delete_database: databaseService.deleteDatabase,
2728
query_documents: async () => 'query_documents not implemented'
2829
};
2930

0 commit comments

Comments
 (0)