mcp/helpers.jsjavascript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUserFromRequest = getUserFromRequest;
exports.formatError = formatError;
/**
 * Extract user info from MCP request handler extra.
 *
 * The AuthInfo.extra field carries userId, ownerIds, and isAdmin
 * set by the JwtTokenVerifier during authentication.
 */
function getUserFromRequest(authInfo) {
    if (!authInfo?.extra) {
        throw new Error("Not authenticated");
    }
    return authInfo.extra;
}
/**
 * Format an error into an MCP tool result.
 *
 * Returns a consistent error response shape that the MCP SDK expects.
 */
function formatError(error) {
    const message = error instanceof Error ? error.message : "Unknown error occurred";
    return {
        content: [{ type: "text", text: message }],
        isError: true,
    };
}