mcp_delete_document
Permanently delete a document from a CosmosDB container by specifying container, document ID, and partition key. Irreversible action, use with caution.
Instructions
Delete a document from a CosmosDB container.
WARNING: This operation is irreversible. The document will be permanently deleted.
Example: mcp_delete_document({ container_id: 'users', document_id: 'user-456', partition_key: 'user-456', connection_id: 'athlete' })
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| container_id | Yes | The ID/name of the container | |
| document_id | Yes | The ID of the document to delete | |
| partition_key | Yes | The partition key value for the document | |
| connection_id | No | ID of the connection to use. Use mcp_list_connections to see available connections. If not specified, uses the default connection. |
Implementation Reference
- src/tools/dataOperations.ts:283-315 (handler)The main handler function for mcp_delete_document. Deletes a document from a CosmosDB container by container_id, document_id, and partition_key. Returns deleted: true on success or an error message on failure (e.g., 404 not found).
export const mcp_delete_document = async (args: DeleteDocumentArgs & { connection_id?: string }): Promise<ToolResult<DeleteOperationResult>> => { const { container_id, document_id, partition_key, connection_id } = args; log(`Executing mcp_delete_document with: ${JSON.stringify(args)}`); try { // Validate modifications are allowed validateModificationAllowed('delete_document', connection_id); const container = getContainer(container_id, connection_id); const { requestCharge } = await container .item(document_id, partition_key) .delete(); return { success: true, data: { deleted: true, id: document_id, requestCharge: requestCharge || 0 } }; } catch (error: any) { log(`Error in mcp_delete_document for document ${document_id}: ${error.message}`); // Provide more helpful error messages if (error.code === 404) { return { success: false, error: `Document with id '${document_id}' not found` }; } return { success: false, error: error.message }; } }; - src/tools/types.ts:89-93 (schema)The DeleteDocumentArgs interface defining input types: container_id, document_id, partition_key.
export interface DeleteDocumentArgs { container_id: string; document_id: string; partition_key: PartitionKeyValue; } - src/tools.ts:316-348 (registration)Tool registration/definition with name 'mcp_delete_document', description, example usage, and inputSchema (container_id, document_id, partition_key required).
// 11. Delete Document { name: "mcp_delete_document", description: `Delete a document from a CosmosDB container. WARNING: This operation is irreversible. The document will be permanently deleted. Example: mcp_delete_document({ container_id: 'users', document_id: 'user-456', partition_key: 'user-456', connection_id: 'athlete' })`, inputSchema: { type: "object", properties: { container_id: { type: "string", description: "The ID/name of the container" }, document_id: { type: "string", description: "The ID of the document to delete" }, partition_key: { type: ["string", "number", "boolean"], description: "The partition key value for the document" }, ...connectionIdProperty }, required: ["container_id", "document_id", "partition_key"] } }, - src/server.ts:155-157 (handler)Server routing: the case handler that dispatches mcp_delete_document to the toolHandlers function.
case 'mcp_delete_document': result = await toolHandlers.mcp_delete_document(input as any); break; - src/tools/index.ts:20-20 (registration)Re-exports mcp_delete_document from dataOperations.ts as part of the tools module.
mcp_delete_document,