Convert McpServerConfig to OpenCode JSON format
(config: &McpServerConfig)
| 903 | |
| 904 | /// Convert McpServerConfig to OpenCode JSON format |
| 905 | fn server_to_opencode_json(config: &McpServerConfig) -> Value { |
| 906 | let mut obj = Map::new(); |
| 907 | |
| 908 | if let Some(ref url) = config.url { |
| 909 | obj.insert("type".to_string(), json!("remote")); |
| 910 | obj.insert("url".to_string(), json!(url)); |
| 911 | if !config.headers.is_empty() { |
| 912 | obj.insert( |
| 913 | "headers".to_string(), |
| 914 | serde_json::to_value(&config.headers).unwrap_or_else(|_| json!({})), |
| 915 | ); |
| 916 | } |
| 917 | } else { |
| 918 | obj.insert("type".to_string(), json!("local")); |
| 919 | |
| 920 | let mut command_parts = Vec::new(); |
| 921 | if let Some(ref cmd) = config.command { |
| 922 | command_parts.push(cmd.clone()); |
| 923 | } |
| 924 | command_parts.extend(config.args.clone()); |
| 925 | |
| 926 | obj.insert("command".to_string(), json!(command_parts)); |
| 927 | |
| 928 | if !config.env.is_empty() { |
| 929 | obj.insert( |
| 930 | "environment".to_string(), |
| 931 | serde_json::to_value(&config.env).unwrap_or_else(|_| json!({})), |
| 932 | ); |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | // Explicitly set enabled status |
| 937 | obj.insert("enabled".to_string(), json!(!config.disabled)); |
| 938 | |
| 939 | Value::Object(obj) |
| 940 | } |
| 941 | |
| 942 | // ============================================================================= |
| 943 | // Helper Functions |
no outgoing calls
no test coverage detected