import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import {
createErrorResponse,
debugLog,
getSearchcraftConfig,
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 config = getSearchcraftConfig();
if (config.error) {
return config.error;
}
const { endpointUrl, apiKey } = config;
const endpoint = `${endpointUrl.replace(/\/$/, "")}/auth/key/${key}`;
const response = await makeSearchcraftRequest(
endpoint,
"GET",
apiKey,
);
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}`,
);
}
},
);
};