export const OPENAPI_OPERATION_MAPPINGS = [
    {
        operationId: "getFileUrl",
        method: "get",
        path: "/get_file_url",
        adapter: "both",
        mcpTool: "retrieve_file_url",
        cliCommand: "request --operation getFileUrl",
    },
    {
        operationId: "healthCheck",
        method: "get",
        path: "/health",
        adapter: "infra",
        notes: "Health endpoint is infrastructure only.",
    },
    {
        operationId: "getOpenApiSpec",
        method: "get",
        path: "/openapi.yaml",
        adapter: "infra",
        notes: "OpenAPI spec fetch is infrastructure only.",
    },
    {
        operationId: "getServerInfo",
        method: "get",
        path: "/server-info",
        adapter: "infra",
        notes: "Server info is infrastructure only.",
    },
    {
        operationId: "oauthServerMetadata",
        method: "get",
        path: "/.well-known/oauth-authorization-server",
        adapter: "infra",
        notes: "OAuth metadata endpoint is infrastructure only.",
    },
    {
        operationId: "oauthProtectedResource",
        method: "get",
        path: "/.well-known/oauth-protected-resource",
        adapter: "infra",
        notes: "OAuth protected resource metadata endpoint is infrastructure only.",
    },
    {
        operationId: "mcpOAuthInitiate",
        method: "post",
        path: "/mcp/oauth/initiate",
        adapter: "cli",
        cliCommand: "request --operation mcpOAuthInitiate",
    },
    {
        operationId: "mcpOAuthAuthorize",
        method: "get",
        path: "/mcp/oauth/authorize",
        adapter: "cli",
        cliCommand: "auth login",
    },
    {
        operationId: "mcpOAuthToken",
        method: "post",
        path: "/mcp/oauth/token",
        adapter: "cli",
        cliCommand: "auth login",
    },
    {
        operationId: "mcpOAuthCallback",
        method: "get",
        path: "/mcp/oauth/callback",
        adapter: "cli",
        cliCommand: "auth login",
    },
    {
        operationId: "mcpOAuthKeyAuthGet",
        method: "get",
        path: "/mcp/oauth/key-auth",
        adapter: "cli",
        cliCommand: "request --operation mcpOAuthKeyAuthGet",
    },
    {
        operationId: "mcpOAuthKeyAuthPost",
        method: "post",
        path: "/mcp/oauth/key-auth",
        adapter: "cli",
        cliCommand: "request --operation mcpOAuthKeyAuthPost",
    },
    {
        operationId: "mcpOAuthLocalLogin",
        method: "get",
        path: "/mcp/oauth/local-login",
        adapter: "cli",
        cliCommand: "auth login --dev-stub",
    },
    {
        operationId: "mcpOAuthRegister",
        method: "post",
        path: "/mcp/oauth/register",
        adapter: "cli",
        cliCommand: "request --operation mcpOAuthRegister",
    },
    {
        operationId: "getMe",
        method: "get",
        path: "/me",
        adapter: "infra",
        notes: "Current user from auth; used by CLI auth status.",
    },
    {
        operationId: "devSignIn",
        method: "post",
        path: "/auth/dev-signin",
        adapter: "cli",
        cliCommand: "auth login --dev-stub",
        notes: "Development-only local sign-in endpoint.",
    },
    {
        operationId: "mcpOAuthStatus",
        method: "get",
        path: "/mcp/oauth/status",
        adapter: "cli",
        cliCommand: "request --operation mcpOAuthStatus",
    },
    {
        operationId: "mcpOAuthListConnections",
        method: "get",
        path: "/mcp/oauth/connections",
        adapter: "cli",
        cliCommand: "request --operation mcpOAuthListConnections",
    },
    {
        operationId: "mcpOAuthAuthorizationDetails",
        method: "get",
        path: "/mcp/oauth/authorization-details",
        adapter: "cli",
        cliCommand: "request --operation mcpOAuthAuthorizationDetails",
    },
    {
        operationId: "mcpOAuthRevokeConnection",
        method: "delete",
        path: "/mcp/oauth/connections/{connection_id}",
        adapter: "cli",
        cliCommand: "request --operation mcpOAuthRevokeConnection",
    },
    {
        operationId: "queryEntities",
        method: "post",
        path: "/entities/query",
        adapter: "both",
        mcpTool: "retrieve_entities",
        cliCommand: "entities list",
    },
    {
        operationId: "bulkCloseIssues",
        method: "post",
        path: "/issues/bulk_close",
        adapter: "cli",
        cliCommand: "request --operation bulkCloseIssues",
        notes: "Inspector UI; callable via neotoma request for automation.",
    },
    {
        operationId: "bulkRemoveIssues",
        method: "post",
        path: "/issues/bulk_remove",
        adapter: "cli",
        cliCommand: "request --operation bulkRemoveIssues",
        notes: "Inspector UI; closes GitHub when linked before soft-delete.",
    },
    {
        operationId: "issuesAddMessage",
        method: "post",
        path: "/issues/add_message",
        adapter: "both",
        mcpTool: "add_issue_message",
        cliCommand: "issues message",
        notes: "Issue thread append; MCP add_issue_message + CLI issues message.",
    },
    {
        operationId: "issuesSubmit",
        method: "post",
        path: "/issues/submit",
        adapter: "both",
        mcpTool: "submit_issue",
        cliCommand: "issues create",
    },
    {
        operationId: "issuesGetStatus",
        method: "post",
        path: "/issues/status",
        adapter: "both",
        mcpTool: "get_issue_status",
        cliCommand: "issues status",
    },
    {
        operationId: "issuesSync",
        method: "post",
        path: "/issues/sync",
        adapter: "both",
        mcpTool: "sync_issues",
        cliCommand: "issues sync",
    },
    {
        operationId: "getEntityById",
        method: "get",
        path: "/entities/{id}",
        adapter: "cli",
        cliCommand: "entities get",
    },
    {
        operationId: "getEntityObservations",
        method: "get",
        path: "/entities/{id}/observations",
        adapter: "cli",
        cliCommand: "request --operation getEntityObservations",
    },
    {
        operationId: "getEntityRelationships",
        method: "get",
        path: "/entities/{id}/relationships",
        adapter: "cli",
        cliCommand: "request --operation getEntityRelationships",
    },
    {
        operationId: "mergeEntities",
        method: "post",
        path: "/entities/merge",
        adapter: "both",
        mcpTool: "merge_entities",
        cliCommand: "request --operation mergeEntities",
    },
    {
        operationId: "splitEntity",
        method: "post",
        path: "/entities/split",
        adapter: "both",
        mcpTool: "split_entity",
        cliCommand: "request --operation splitEntity",
    },
    {
        operationId: "listPotentialDuplicates",
        method: "get",
        path: "/entities/duplicates",
        adapter: "both",
        mcpTool: "list_potential_duplicates",
        cliCommand: "entities find-duplicates",
    },
    {
        operationId: "listSources",
        method: "get",
        path: "/sources",
        adapter: "cli",
        cliCommand: "sources list",
    },
    {
        operationId: "getSourceById",
        method: "get",
        path: "/sources/{id}",
        adapter: "cli",
        cliCommand: "request --operation getSourceById",
    },
    {
        operationId: "getSourceRelationships",
        method: "get",
        path: "/sources/{id}/relationships",
        adapter: "cli",
        cliCommand: "request --operation getSourceRelationships",
    },
    {
        operationId: "listObservations",
        method: "get",
        path: "/observations",
        adapter: "cli",
        cliCommand: "request --operation listObservations",
    },
    {
        operationId: "queryObservations",
        method: "post",
        path: "/observations/query",
        adapter: "cli",
        cliCommand: "observations list",
    },
    {
        operationId: "createObservation",
        method: "post",
        path: "/observations/create",
        adapter: "cli",
        cliCommand: "request --operation createObservation",
    },
    {
        operationId: "listRelationships",
        method: "get",
        path: "/relationships",
        adapter: "cli",
        cliCommand: "request --operation listRelationships",
    },
    {
        operationId: "getRelationshipById",
        method: "get",
        path: "/relationships/{id}",
        adapter: "cli",
        cliCommand: "request --operation getRelationshipById",
    },
    {
        operationId: "listTimeline",
        method: "get",
        path: "/timeline",
        adapter: "both",
        mcpTool: "list_timeline_events",
        cliCommand: "timeline list",
    },
    {
        operationId: "getTimelineById",
        method: "get",
        path: "/timeline/{id}",
        adapter: "cli",
        cliCommand: "timeline get",
    },
    {
        operationId: "listSchemas",
        method: "get",
        path: "/schemas",
        adapter: "both",
        mcpTool: "list_entity_types",
        cliCommand: "schemas list",
    },
    {
        operationId: "getSchemaByEntityType",
        method: "get",
        path: "/schemas/{entity_type}",
        adapter: "cli",
        cliCommand: "schemas get",
    },
    {
        operationId: "listInterpretations",
        method: "get",
        path: "/interpretations",
        adapter: "both",
        mcpTool: "list_interpretations",
        cliCommand: "interpretations list",
    },
    {
        operationId: "createInterpretation",
        method: "post",
        path: "/interpretations/create",
        adapter: "both",
        mcpTool: "create_interpretation",
        cliCommand: "interpretations create",
    },
    {
        operationId: "getStats",
        method: "get",
        path: "/stats",
        adapter: "cli",
        cliCommand: "stats",
    },
    {
        operationId: "getAccessPolicies",
        method: "get",
        path: "/access_policies",
        adapter: "both",
        cliCommand: "access list",
    },
    {
        operationId: "getRecordActivity",
        method: "get",
        path: "/record_activity",
        adapter: "both",
        mcpTool: "list_recent_changes",
        cliCommand: "recent",
    },
    {
        operationId: "getRecentConversations",
        method: "get",
        path: "/recent_conversations",
        adapter: "infra",
        notes: "Inspector HTTP-only; conversations with nested messages.",
    },
    {
        operationId: "getRecentConversation",
        method: "get",
        path: "/recent_conversations/{conversation_id}",
        adapter: "infra",
        notes: "Inspector HTTP-only; single conversation transcript payload.",
    },
    {
        operationId: "getComplianceScorecard",
        method: "get",
        path: "/admin/compliance/scorecard",
        adapter: "infra",
        notes: "Inspector HTTP-only; hook compliance backfill aggregates.",
    },
    {
        operationId: "store",
        method: "post",
        path: "/store",
        adapter: "both",
        mcpTool: "store",
        cliCommand: "store",
    },
    {
        operationId: "getRecordById",
        method: "get",
        path: "/records/{id}",
        adapter: "cli",
        cliCommand: "request --operation getRecordById",
    },
    {
        operationId: "getRecordHistory",
        method: "get",
        path: "/records/{id}/history",
        adapter: "cli",
        cliCommand: "request --operation getRecordHistory",
    },
    {
        operationId: "getEntitySnapshot",
        method: "post",
        path: "/get_entity_snapshot",
        adapter: "both",
        mcpTool: "retrieve_entity_snapshot",
        cliCommand: "request --operation getEntitySnapshot",
    },
    {
        operationId: "listObservationsForEntity",
        method: "post",
        path: "/list_observations",
        adapter: "both",
        mcpTool: "list_observations",
        cliCommand: "request --operation listObservationsForEntity",
    },
    {
        operationId: "getFieldProvenance",
        method: "post",
        path: "/get_field_provenance",
        adapter: "both",
        mcpTool: "retrieve_field_provenance",
        cliCommand: "request --operation getFieldProvenance",
    },
    {
        operationId: "createRelationship",
        method: "post",
        path: "/create_relationship",
        adapter: "both",
        mcpTool: "create_relationship",
        cliCommand: "request --operation createRelationship",
    },
    {
        operationId: "createRelationships",
        method: "post",
        path: "/create_relationships",
        adapter: "both",
        mcpTool: "create_relationships",
        cliCommand: "request --operation createRelationships",
    },
    {
        operationId: "listRelationshipsForEntity",
        method: "post",
        path: "/list_relationships",
        adapter: "both",
        mcpTool: "list_relationships",
        cliCommand: "relationships list",
    },
    {
        operationId: "recordComparison",
        method: "post",
        path: "/record_comparison",
        adapter: "cli",
        cliCommand: "request --operation recordComparison",
    },
    {
        operationId: "generateEmbedding",
        method: "post",
        path: "/generate_embedding",
        adapter: "cli",
        cliCommand: "request --operation generateEmbedding",
    },
    {
        operationId: "retrieveEntityByIdentifier",
        method: "post",
        path: "/retrieve_entity_by_identifier",
        adapter: "both",
        mcpTool: "retrieve_entity_by_identifier",
        cliCommand: "entities search",
    },
    {
        operationId: "retrieveRelatedEntities",
        method: "post",
        path: "/retrieve_related_entities",
        adapter: "both",
        mcpTool: "retrieve_related_entities",
        cliCommand: "entities related",
    },
    {
        operationId: "retrieveGraphNeighborhood",
        method: "post",
        path: "/retrieve_graph_neighborhood",
        adapter: "both",
        mcpTool: "retrieve_graph_neighborhood",
        cliCommand: "entities neighborhood",
    },
    {
        operationId: "deleteEntity",
        method: "post",
        path: "/delete_entity",
        adapter: "both",
        mcpTool: "delete_entity",
        cliCommand: "entities delete",
    },
    {
        operationId: "restoreEntity",
        method: "post",
        path: "/restore_entity",
        adapter: "both",
        mcpTool: "restore_entity",
        cliCommand: "entities restore",
    },
    {
        operationId: "deleteRelationship",
        method: "post",
        path: "/delete_relationship",
        adapter: "both",
        mcpTool: "delete_relationship",
        cliCommand: "relationships delete",
    },
    {
        operationId: "restoreRelationship",
        method: "post",
        path: "/restore_relationship",
        adapter: "both",
        mcpTool: "restore_relationship",
        cliCommand: "relationships restore",
    },
    {
        operationId: "getRelationshipSnapshot",
        method: "post",
        path: "/relationships/snapshot",
        adapter: "both",
        mcpTool: "get_relationship_snapshot",
        cliCommand: "relationships get-snapshot <relationshipType> <sourceEntityId> <targetEntityId>",
    },
    {
        operationId: "analyzeSchemaCandidates",
        method: "post",
        path: "/analyze_schema_candidates",
        adapter: "both",
        mcpTool: "analyze_schema_candidates",
        cliCommand: "schemas analyze-candidates",
    },
    {
        operationId: "getSchemaRecommendations",
        method: "post",
        path: "/get_schema_recommendations",
        adapter: "both",
        mcpTool: "get_schema_recommendations",
        cliCommand: "schemas recommendations",
    },
    {
        operationId: "updateSchemaIncremental",
        method: "post",
        path: "/update_schema_incremental",
        adapter: "both",
        mcpTool: "update_schema_incremental",
        cliCommand: "schemas update-incremental",
    },
    {
        operationId: "registerSchema",
        method: "post",
        path: "/register_schema",
        adapter: "both",
        mcpTool: "register_schema",
        cliCommand: "schemas register",
    },
    {
        operationId: "correct",
        method: "post",
        path: "/correct",
        adapter: "both",
        mcpTool: "correct",
        cliCommand: "corrections create",
    },
    {
        operationId: "getAuthenticatedUser",
        method: "post",
        path: "/get_authenticated_user",
        adapter: "both",
        mcpTool: "get_authenticated_user",
        cliCommand: "auth whoami",
    },
    {
        operationId: "getSessionInfo",
        method: "get",
        path: "/session",
        adapter: "both",
        mcpTool: "get_session_identity",
        cliCommand: "auth session",
    },
    {
        operationId: "healthCheckSnapshots",
        method: "post",
        path: "/health_check_snapshots",
        adapter: "both",
        mcpTool: "health_check_snapshots",
        cliCommand: "snapshots check",
    },
    {
        operationId: "listAgentGrants",
        method: "get",
        path: "/agents/grants",
        adapter: "cli",
        cliCommand: "request --operation listAgentGrants",
        notes: "Inspector and CLI list agent_grant entities; no MCP tool yet.",
    },
    {
        operationId: "createAgentGrant",
        method: "post",
        path: "/agents/grants",
        adapter: "cli",
        cliCommand: "request --operation createAgentGrant",
        notes: "Inspector and CLI create agent_grant entities; no MCP tool yet.",
    },
    {
        operationId: "getAgentGrant",
        method: "get",
        path: "/agents/grants/{id}",
        adapter: "cli",
        cliCommand: "request --operation getAgentGrant",
        notes: "Inspector and CLI fetch one agent_grant entity; no MCP tool yet.",
    },
    {
        operationId: "updateAgentGrant",
        method: "patch",
        path: "/agents/grants/{id}",
        adapter: "cli",
        cliCommand: "request --operation updateAgentGrant",
        notes: "Inspector and CLI update agent_grant entities; no MCP tool yet.",
    },
    {
        operationId: "suspendAgentGrant",
        method: "post",
        path: "/agents/grants/{id}/suspend",
        adapter: "cli",
        cliCommand: "request --operation suspendAgentGrant",
        notes: "Inspector and CLI suspend agent_grant entities; no MCP tool yet.",
    },
    {
        operationId: "revokeAgentGrant",
        method: "post",
        path: "/agents/grants/{id}/revoke",
        adapter: "cli",
        cliCommand: "request --operation revokeAgentGrant",
        notes: "Inspector and CLI revoke agent_grant entities; no MCP tool yet.",
    },
    {
        operationId: "restoreAgentGrant",
        method: "post",
        path: "/agents/grants/{id}/restore",
        adapter: "cli",
        cliCommand: "request --operation restoreAgentGrant",
        notes: "Inspector and CLI restore agent_grant entities; no MCP tool yet.",
    },
    {
        operationId: "subscribe",
        method: "post",
        path: "/subscribe",
        adapter: "both",
        mcpTool: "subscribe",
        cliCommand: "request --operation subscribe",
    },
    {
        operationId: "unsubscribe",
        method: "post",
        path: "/unsubscribe",
        adapter: "both",
        mcpTool: "unsubscribe",
        cliCommand: "request --operation unsubscribe",
    },
    {
        operationId: "listSubscriptions",
        method: "post",
        path: "/list_subscriptions",
        adapter: "both",
        mcpTool: "list_subscriptions",
        cliCommand: "request --operation listSubscriptions",
    },
    {
        operationId: "getSubscriptionStatus",
        method: "post",
        path: "/get_subscription_status",
        adapter: "both",
        mcpTool: "get_subscription_status",
        cliCommand: "request --operation getSubscriptionStatus",
    },
    {
        operationId: "listPeers",
        method: "get",
        path: "/peers",
        adapter: "both",
        mcpTool: "list_peers",
        cliCommand: "request --operation listPeers",
    },
    {
        operationId: "addPeer",
        method: "post",
        path: "/peers",
        adapter: "both",
        mcpTool: "add_peer",
        cliCommand: "request --operation addPeer",
    },
    {
        operationId: "getPeerStatus",
        method: "get",
        path: "/peers/{peer_id}",
        adapter: "both",
        mcpTool: "get_peer_status",
        cliCommand: "request --operation getPeerStatus",
    },
    {
        operationId: "removePeer",
        method: "delete",
        path: "/peers/{peer_id}",
        adapter: "both",
        mcpTool: "remove_peer",
        cliCommand: "request --operation removePeer",
    },
    {
        operationId: "syncPeer",
        method: "post",
        path: "/peers/{peer_id}/sync",
        adapter: "both",
        mcpTool: "sync_peer",
        cliCommand: "request --operation syncPeer",
    },
    {
        operationId: "resolveSyncConflict",
        method: "post",
        path: "/peers/resolve_sync_conflict",
        adapter: "both",
        mcpTool: "resolve_sync_conflict",
        cliCommand: "request --operation resolveSyncConflict",
    },
    {
        operationId: "applySyncWebhook",
        method: "post",
        path: "/sync/webhook",
        adapter: "infra",
        notes: "Peer-to-peer sync webhook; signed with shared secret or AAuth.",
    },
    {
        operationId: "listSyncEntities",
        method: "post",
        path: "/sync/entities",
        adapter: "infra",
        notes: "Peer-to-peer snapshot listing for bilateral sync pulls.",
    },
    {
        operationId: "eventsStream",
        method: "get",
        path: "/events/stream",
        adapter: "infra",
        notes: "SSE stream for subscription_id; long-lived HTTP clients only.",
    },
];
export const MCP_TOOL_TO_OPERATION_ID = {
    retrieve_file_url: "getFileUrl",
    retrieve_entity_snapshot: "getEntitySnapshot",
    list_observations: "listObservationsForEntity",
    retrieve_field_provenance: "getFieldProvenance",
    create_relationship: "createRelationship",
    create_relationships: "createRelationships",
    list_relationships: "listRelationshipsForEntity",
    retrieve_entities: "queryEntities",
    list_timeline_events: "listTimeline",
    list_entity_types: "listSchemas",
    merge_entities: "mergeEntities",
    split_entity: "splitEntity",
    list_potential_duplicates: "listPotentialDuplicates",
    store: "store",
    store_structured: "store",
    store_unstructured: "store",
    create_interpretation: "createInterpretation",
    list_interpretations: "listInterpretations",
    retrieve_entity_by_identifier: "retrieveEntityByIdentifier",
    retrieve_related_entities: "retrieveRelatedEntities",
    retrieve_graph_neighborhood: "retrieveGraphNeighborhood",
    delete_entity: "deleteEntity",
    restore_entity: "restoreEntity",
    delete_relationship: "deleteRelationship",
    restore_relationship: "restoreRelationship",
    get_relationship_snapshot: "getRelationshipSnapshot",
    analyze_schema_candidates: "analyzeSchemaCandidates",
    get_schema_recommendations: "getSchemaRecommendations",
    update_schema_incremental: "updateSchemaIncremental",
    register_schema: "registerSchema",
    correct: "correct",
    get_authenticated_user: "getAuthenticatedUser",
    get_session_identity: "getSessionInfo",
    health_check_snapshots: "healthCheckSnapshots",
    list_recent_changes: "getRecordActivity",
    subscribe: "subscribe",
    unsubscribe: "unsubscribe",
    list_subscriptions: "listSubscriptions",
    get_subscription_status: "getSubscriptionStatus",
    list_peers: "listPeers",
    add_peer: "addPeer",
    remove_peer: "removePeer",
    get_peer_status: "getPeerStatus",
    sync_peer: "syncPeer",
    resolve_sync_conflict: "resolveSyncConflict",
    submit_issue: "issuesSubmit",
    add_issue_message: "issuesAddMessage",
    get_issue_status: "issuesGetStatus",
    sync_issues: "issuesSync",
};
export const MCP_ONLY_TOOLS = [];
export const MCP_TOOL_TO_CLI_COMMAND = {
    get_entity_type_counts: "stats entities",
    get_authenticated_user: "auth whoami",
    get_session_identity: "auth session",
    health_check_snapshots: "snapshots check",
    retrieve_entity_by_identifier: "entities search <identifier>",
    retrieve_related_entities: "entities related <entityId>",
    retrieve_graph_neighborhood: "entities neighborhood <nodeId>",
    get_relationship_snapshot: "relationships get-snapshot <relationshipType> <sourceEntityId> <targetEntityId>",
    analyze_schema_candidates: "schemas analyze",
    get_schema_recommendations: "schemas recommend <entityType>",
    update_schema_incremental: "schemas update <entityType>",
    register_schema: "schemas register <entityType>",
    correct: "corrections create <entityId> <entityType> <field> <value>",
    create_interpretation: "interpretations create",
    list_interpretations: "interpretations list",
};
export function getOpenApiOperationMapping(operationId) {
    return OPENAPI_OPERATION_MAPPINGS.find((mapping) => mapping.operationId === operationId);
}
const SAFE_ARG_FIELDS = new Set([
    "entity_id",
    "entity_type",
    "source_id",
    "relationship_type",
    "source_entity_id",
    "target_entity_id",
    "direction",
    "limit",
    "offset",
    "include_snapshots",
    "include_merged",
    "include_entities",
    "include_sources",
    "include_events",
    "include_observations",
    "max_hops",
    "after_date",
    "before_date",
    "event_type",
    "field",
]);
function stableStringify(value) {
    if (Array.isArray(value)) {
        return `[${value.map((item) => stableStringify(item)).join(",")}]`;
    }
    if (value && typeof value === "object") {
        const entries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b));
        const serialized = entries.map(([key, val]) => `"${key}":${stableStringify(val)}`);
        return `{${serialized.join(",")}}`;
    }
    return JSON.stringify(value);
}
function sanitizeCliArgs(args) {
    if (!args || typeof args !== "object") {
        return {};
    }
    const input = args;
    const sanitizedEntries = Object.keys(input)
        .sort()
        .map((key) => {
        const value = input[key];
        if (!SAFE_ARG_FIELDS.has(key)) {
            return [key, "<redacted>"];
        }
        if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
            return [key, value];
        }
        if (Array.isArray(value)) {
            return [
                key,
                value.map((item) => (typeof item === "string" ? item : "<redacted>")),
            ];
        }
        return [key, "<redacted>"];
    });
    return Object.fromEntries(sanitizedEntries);
}
export function buildCliEquivalentInvocation(toolName, args) {
    const operationId = MCP_TOOL_TO_OPERATION_ID[toolName];
    if (!operationId) {
        const cliCommand = MCP_TOOL_TO_CLI_COMMAND[toolName];
        if (cliCommand) {
            const sanitized = sanitizeCliArgs(args);
            const userId = args &&
                typeof args === "object" &&
                typeof args.user_id === "string"
                ? args.user_id
                : "<user_id>";
            const payload = stableStringify({ args: sanitized });
            return `neotoma ${cliCommand} --user-id ${userId} --args '${payload}' --json`;
        }
        return `neotoma mcp-only --tool ${toolName}`;
    }
    const operation = getOpenApiOperationMapping(operationId);
    const sanitized = sanitizeCliArgs(args);
    const paramKey = operation?.method === "get" ? "query" : "body";
    const payload = stableStringify({ [paramKey]: sanitized });
    return `neotoma request --operation ${operationId} --params '${payload}' --json`;
}
//# sourceMappingURL=contract_mappings.js.map