// {{ display_name }} MCP server — generated by mcpify. Do not hand-edit.

use {{ crate_name }}::auth::auth_manager::AuthManager;
use {{ crate_name }}::core::config_manager::load_config;
use {{ crate_name }}::core::errors::McpifyError;
use {{ crate_name }}::data::store::{cached_store_connection, get_endpoint};
use {{ crate_name }}::tools::call_tool::call_operation;

pub async fn run(operation_id: &str, args_json: &str) -> anyhow::Result<()> {
    let config = load_config(serde_json::Map::new())?;
    let mut auth_manager = AuthManager::new(config.auth_method);
    let args: serde_json::Value = serde_json::from_str(args_json)?;

    let endpoint = {
        let conn = cached_store_connection(&config.api_version)?.lock().unwrap();
        get_endpoint(&conn, operation_id)?
            .ok_or_else(|| McpifyError::NotFound(format!("unknown operationId '{operation_id}'")))?
    };

    let result = call_operation(&endpoint, &config, &mut auth_manager, operation_id, args, None).await?;
    println!("{}", serde_json::to_string_pretty(&result)?);
    Ok(())
}
