import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import {
createErrorResponse,
debugLog,
getSearchcraftConfig,
makeSearchcraftRequest,
} from "../../../helpers.js";
export const registerDeleteAllKeys = (server: McpServer) => {
/**
* Tool: delete_all_keys
* DELETE /auth/key - Delete all keys
*/
server.tool(
"delete_all_keys",
"Delete all authentication keys on the Searchcraft cluster. Use with extreme caution!",
{},
async () => {
debugLog("[Tool Call] delete_all_keys");
try {
const config = getSearchcraftConfig();
if (config.error) {
return config.error;
}
const { endpointUrl, apiKey } = config;
const endpoint = `${endpointUrl.replace(/\/$/, "")}/auth/key`;
const response = await makeSearchcraftRequest(
endpoint,
"DELETE",
apiKey,
);
return {
content: [
{
type: "resource",
resource: {
uri: `searchcraft://all-keys-deleted/${Date.now()}`,
mimeType: "application/json",
text: JSON.stringify(
response || {
message:
"All keys deleted successfully",
},
null,
2,
),
},
},
],
};
} catch (error) {
const errorMessage =
error instanceof Error
? error.message
: "Unknown error occurred";
return createErrorResponse(
`Failed to delete all keys: ${errorMessage}`,
);
}
},
);
};