MCPcopy Create free account
hub / github.com/dallay/agentsync / server_to_opencode_json

Function server_to_opencode_json

src/mcp.rs:905–940  ·  view source on GitHub ↗

Convert McpServerConfig to OpenCode JSON format

(config: &McpServerConfig)

Source from the content-addressed store, hash-verified

903
904/// Convert McpServerConfig to OpenCode JSON format
905fn 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

Callers 2

mergeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected