Spaces:
Sleeping
Sleeping
File size: 1,495 Bytes
1afdaf6 dd125ca 076e59d 1afdaf6 62cf129 dd125ca 1afdaf6 8397cce 1afdaf6 8397cce 1afdaf6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | import { type InferSchema, type ToolMetadata } from "xmcp";
import { headers } from "xmcp/headers";
import { z } from "zod";
import { getScimBaseUrl } from "../utils/getSCIMBaseUrl";
import { getScimToken } from "../utils/getSCIMToken";
export const metadata: ToolMetadata = {
name: "delete-user",
description: "Delete a user resource",
annotations: {
title: "Delete User Resource",
readOnlyHint: false,
destructiveHint: true,
idempotentHint: true,
openWorldHint: true,
},
};
export const schema = {
userId: z.string().describe("The unique identifier of the user to delete"),
};
export default async function deleteUser(
params: InferSchema<typeof schema>
) {
const requestHeaders = headers();
const apiToken = getScimToken(requestHeaders);
const baseUrl = getScimBaseUrl(requestHeaders);
if (!apiToken) {
throw new Error("Missing required headers: x-scim-api-token or SCIM_API_TOKEN env");
}
if (!baseUrl) {
throw new Error("Missing required headers: x-scim-base-url or SCIM_API_BASE_URL env");
}
const { userId } = params;
const response = await fetch(`${baseUrl}/Users/${userId}`, {
method: "DELETE",
headers: {
"Content-Type": "application/scim+json",
Authorization: `Bearer ${apiToken}`,
},
});
if (!response.ok) {
throw new Error(await response.text());
}
return {
content: [
{
type: "text",
text: `User ${userId} deleted successfully`,
},
],
};
}
|