Skip to content

Commit 5bb3af8

Browse files
committed
Test with YAML
1 parent 23b4e37 commit 5bb3af8

File tree

1 file changed

+44
-54
lines changed

1 file changed

+44
-54
lines changed

dsc/src/mcp/invoke_dsc_config.rs

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ pub struct InvokeDscConfigResponse {
4646
pub struct InvokeDscConfigRequest {
4747
#[schemars(description = "The operation to perform on the DSC configuration")]
4848
pub operation: ConfigOperation,
49-
#[schemars(description = "The DSC configuration document as JSON or YAML string")]
49+
#[schemars(description = "The DSC configuration document as a YAML string")]
5050
pub configuration: String,
5151
#[schemars(
52-
description = "Optional parameters to pass to the configuration as JSON or YAML string"
52+
description = "Optional parameters to pass to the configuration as a YAML string"
5353
)]
5454
pub parameters: Option<String>,
5555
}
@@ -75,33 +75,10 @@ impl McpServer {
7575
}): Parameters<InvokeDscConfigRequest>,
7676
) -> Result<Json<InvokeDscConfigResponse>, McpError> {
7777
let result = task::spawn_blocking(move || {
78-
let config: Configuration = match serde_json::from_str(&configuration) {
79-
Ok(config) => config,
80-
Err(_) => {
81-
match serde_yaml::from_str::<serde_yaml::Value>(&configuration) {
82-
Ok(yaml_value) => match serde_json::to_value(yaml_value) {
83-
Ok(json_value) => match serde_json::from_value(json_value) {
84-
Ok(config) => config,
85-
Err(e) => {
86-
return Err(McpError::invalid_request(
87-
format!(
88-
"{}: {e}",
89-
t!("mcp.invoke_dsc_config.invalidConfiguration")
90-
),
91-
None,
92-
))
93-
}
94-
},
95-
Err(e) => {
96-
return Err(McpError::invalid_request(
97-
format!(
98-
"{}: {e}",
99-
t!("mcp.invoke_dsc_config.failedConvertJson")
100-
),
101-
None,
102-
))
103-
}
104-
},
78+
let config: Configuration = match serde_yaml::from_str::<serde_yaml::Value>(&configuration) {
79+
Ok(yaml_value) => match serde_json::to_value(yaml_value) {
80+
Ok(json_value) => match serde_json::from_value(json_value) {
81+
Ok(config) => config,
10582
Err(e) => {
10683
return Err(McpError::invalid_request(
10784
format!(
@@ -111,7 +88,25 @@ impl McpServer {
11188
None,
11289
))
11390
}
91+
},
92+
Err(e) => {
93+
return Err(McpError::invalid_request(
94+
format!(
95+
"{}: {e}",
96+
t!("mcp.invoke_dsc_config.failedConvertJson")
97+
),
98+
None,
99+
))
114100
}
101+
},
102+
Err(e) => {
103+
return Err(McpError::invalid_request(
104+
format!(
105+
"{}: {e}",
106+
t!("mcp.invoke_dsc_config.invalidConfiguration")
107+
),
108+
None,
109+
))
115110
}
116111
};
117112

@@ -133,32 +128,27 @@ impl McpServer {
133128
configurator.context.dsc_version = Some(env!("CARGO_PKG_VERSION").to_string());
134129

135130
let parameters_value: Option<serde_json::Value> = if let Some(params_str) = parameters {
136-
let params_json = match serde_json::from_str(&params_str) {
137-
Ok(json) => json,
138-
Err(_) => {
139-
match serde_yaml::from_str::<serde_yaml::Value>(&params_str) {
140-
Ok(yaml) => match serde_json::to_value(yaml) {
141-
Ok(json) => json,
142-
Err(e) => {
143-
return Err(McpError::invalid_request(
144-
format!(
145-
"{}: {e}",
146-
t!("mcp.invoke_dsc_config.failedConvertJson")
147-
),
148-
None,
149-
))
150-
}
151-
},
152-
Err(e) => {
153-
return Err(McpError::invalid_request(
154-
format!(
155-
"{}: {e}",
156-
t!("mcp.invoke_dsc_config.invalidParameters")
157-
),
158-
None,
159-
))
160-
}
131+
let params_json = match serde_yaml::from_str::<serde_yaml::Value>(&params_str) {
132+
Ok(yaml) => match serde_json::to_value(yaml) {
133+
Ok(json) => json,
134+
Err(e) => {
135+
return Err(McpError::invalid_request(
136+
format!(
137+
"{}: {e}",
138+
t!("mcp.invoke_dsc_config.failedConvertJson")
139+
),
140+
None,
141+
))
161142
}
143+
},
144+
Err(e) => {
145+
return Err(McpError::invalid_request(
146+
format!(
147+
"{}: {e}",
148+
t!("mcp.invoke_dsc_config.invalidParameters")
149+
),
150+
None,
151+
))
162152
}
163153
};
164154

0 commit comments

Comments
 (0)