Skip to content

Commit b9835ac

Browse files
authored
Mcp delete docs (#8532)
* delete docs from MCP firestore * Fix the delete command
1 parent f3825f8 commit b9835ac

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { z } from "zod";
2+
import { tool } from "../../tool.js";
3+
import { mcpError, toContent } from "../../util.js";
4+
import { getDocuments } from "../../../gcp/firestore.js";
5+
import { FirestoreDelete } from "../../../firestore/delete.js";
6+
7+
export const delete_document = tool(
8+
{
9+
name: "delete_document",
10+
description:
11+
"Deletes a Firestore documents from a database in the current project by full document paths. Use this if you know the exact path of a document.",
12+
inputSchema: z.object({
13+
// TODO: Support configurable database
14+
// database: z
15+
// .string()
16+
// .nullish()
17+
// .describe("Database id to use. Defaults to `(default)` if unspecified."),
18+
path: z
19+
.string()
20+
.describe(
21+
"A document path (e.g. `collectionName/documentId` or `parentCollection/parentDocument/collectionName/documentId`)",
22+
),
23+
}),
24+
annotations: {
25+
title: "Delete Firestore document",
26+
destructiveHint: true,
27+
},
28+
_meta: {
29+
requiresAuth: true,
30+
requiresProject: true,
31+
},
32+
},
33+
async ({ path }, { projectId }) => {
34+
// database ??= "(default)";
35+
const { documents, missing } = await getDocuments(projectId!, [path]);
36+
if (missing.length > 0 && documents && documents.length === 0) {
37+
return mcpError(`None of the specified documents were found in project '${projectId}'`);
38+
}
39+
40+
const firestoreDelete = new FirestoreDelete(projectId!, path, { databaseId: "(default)" });
41+
42+
await firestoreDelete.execute();
43+
44+
const { documents: postDeleteDocuments, missing: postDeleteMissing } = await getDocuments(
45+
projectId!,
46+
[path],
47+
);
48+
if (postDeleteMissing.length > 0 && postDeleteDocuments.length === 0) {
49+
return toContent(`Successfully removed document located at : ${path}`);
50+
}
51+
52+
return mcpError(`Failed to remove document located at : ${path}`);
53+
},
54+
);

src/mcp/tools/firestore/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { delete_document } from "./delete_document";
12
import { get_documents } from "./get_documents";
23
import { get_rules } from "./get_rules";
34
import { list_collections } from "./list_collections";
45

5-
export const firestoreTools = [list_collections, get_documents, get_rules];
6+
export const firestoreTools = [delete_document, get_documents, get_rules, list_collections];

0 commit comments

Comments
 (0)