import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import {
createErrorResponse,
debugLog,
makeSearchcraftRequest,
} from "../../../helpers.js";
export const registerGetKeyDetails = (server: McpServer) => {
/**
* Tool: get_key_details
* GET /auth/key/:key - Get details for an individual key
*/
server.tool(
"get_key_details",
"Get detailed information for a specific authentication key.",
{
key: z
.string()
.describe("The authentication key to get details for"),
},
async ({ key }) => {
debugLog("[Tool Call] get_key_details");
try {
const endpointUrl = process.env.ENDPOINT_URL;
const adminKey = process.env.ADMIN_KEY;
if (!endpointUrl) {
return createErrorResponse(
"ENDPOINT_URL environment variable is required",
);
}
if (!adminKey) {
return createErrorResponse(
"ADMIN_KEY environment variable is required",
);
}
const endpoint = `${endpointUrl.replace(/\/$/, "")}/auth/key/${key}`;
const response = await makeSearchcraftRequest(
endpoint,
"GET",
adminKey,
);
return {
content: [
{
type: "resource",
resource: {
uri: `searchcraft://key-details/${key}/${Date.now()}`,
mimeType: "application/json",
text: JSON.stringify(response, null, 2),
},
},
],
};
} catch (error) {
const errorMessage =
error instanceof Error
? error.message
: "Unknown error occurred";
return createErrorResponse(
`Failed to get key details: ${errorMessage}`,
);
}
},
);
};