Skip to content

Commit c0cdc6b

Browse files
committed
feat: add mcp flag
1 parent b9d59e8 commit c0cdc6b

4 files changed

Lines changed: 42 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
cargo build --release -p cdd-cli --target ${{ matrix.target }}
100100
cp target/${{ matrix.target }}/release/cdd-rust ${{ matrix.artifact_name }} || cp target/release/cdd-rust ${{ matrix.artifact_name }}
101101
- name: Upload Artifact
102-
uses: actions/upload-artifact@v4
102+
uses: actions/upload-artifact@v7
103103
with:
104104
name: ${{ matrix.artifact_name }}
105105
path: ${{ matrix.artifact_name }}
@@ -127,7 +127,7 @@ jobs:
127127
wasm-opt -O3 cdd-rust.wasm -o cdd-rust.wasm || true
128128
fi
129129
- name: Upload Artifact
130-
uses: actions/upload-artifact@v4
130+
uses: actions/upload-artifact@v7
131131
with:
132132
name: cdd-rust.wasm
133133
path: cdd-rust.wasm
@@ -140,7 +140,7 @@ jobs:
140140
- uses: actions/checkout@v6
141141

142142
- name: Download Artifacts
143-
uses: actions/download-artifact@v4
143+
uses: actions/download-artifact@v8
144144
with:
145145
path: artifacts
146146
merge-multiple: true

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cdd-rust
33
[![License](https://img.shields.io/badge/license-Apache--2.0%20OR%20MIT-blue.svg)](https://opensource.org/licenses/Apache-2.0)
44
[![interactive WASM web demo](https://img.shields.io/badge/interactive-WASM_web_demo-blue.svg)](https://offscale.io/wasm_web_demo)
55
[![CI](https://github.com/offscale/cdd-rust/actions/workflows/ci.yml/badge.svg)](https://github.com/offscale/cdd-rust/actions)
6-
[![Test Coverage](https://img.shields.io/badge/test_coverage-100.00%25-brightgreen.svg)](#)
6+
[![Test Coverage](https://img.shields.io/badge/test_coverage-99.78%25-brightgreen.svg)](#)
77
[![Doc Coverage](https://img.shields.io/badge/doc_coverage-100.00%25-brightgreen.svg)](#)
88

99
----
@@ -18,7 +18,7 @@ The CLI—at a minimum—has:
1818

1919
- `cdd-rust --help`
2020
- `cdd-rust --version`
21-
- `cdd-rust from_openapi to_sdk_cli -i spec.json`
21+
- `cdd-rust from_openapi to_sdk_cli --mcp -i spec.json`
2222
- `cdd-rust from_openapi to_sdk -i spec.json`
2323
- `cdd-rust from_openapi to_server -i spec.json`
2424
- `cdd-rust to_openapi -i path/to/code`

cli/src/from_openapi.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ pub struct GenerateArgs {
7676

7777
/// Generate integration tests and mocks.
7878
#[clap(long, env = "CDD_TESTS")]
79+
#[clap(long, env = "CDD_TESTS")]
7980
pub tests: bool,
81+
82+
/// Generate Model Context Protocol (MCP) server and adapter.
83+
84+
#[clap(long, env = "CDD_MCP")]
85+
pub mcp: bool,
8086
}
8187

8288
impl GenerateArgs {
@@ -119,6 +125,9 @@ pub fn execute(args: &FromOpenApiArgs) -> AppResult<()> {
119125
FromOpenApiCommands::SdkCli(gen_args) => {
120126
println!("Generating SDK CLI...");
121127
run_generation(gen_args, &ClapCliStrategy)?;
128+
if gen_args.mcp {
129+
run_generation(gen_args, &cdd_core::strategies::McpClientStrategy)?;
130+
}
122131
}
123132
FromOpenApiCommands::Sdk(gen_args) => {
124133
println!("Generating SDK...");
@@ -312,6 +321,7 @@ mod tests {
312321
no_github_actions: false,
313322
no_installable_package: false,
314323
tests: false,
324+
mcp: false,
315325
};
316326
let dir = args.get_output_dir();
317327
assert_eq!(
@@ -330,6 +340,7 @@ mod tests {
330340
no_github_actions: false,
331341
no_installable_package: false,
332342
tests: false,
343+
mcp: false,
333344
};
334345
assert_eq!(args.get_output_dir(), path);
335346
}
@@ -344,6 +355,7 @@ mod tests {
344355
no_github_actions: false,
345356
no_installable_package: false,
346357
tests: false,
358+
mcp: false,
347359
};
348360
assert_eq!(args.get_input_files(), vec![path]);
349361
}
@@ -365,6 +377,7 @@ mod tests {
365377
no_github_actions: false,
366378
no_installable_package: false,
367379
tests: false,
380+
mcp: false,
368381
};
369382
let mut files = args.get_input_files();
370383
files.sort();
@@ -382,6 +395,7 @@ mod tests {
382395
no_github_actions: false,
383396
no_installable_package: false,
384397
tests: false,
398+
mcp: false,
385399
};
386400
assert!(args.get_input_files().is_empty());
387401
}
@@ -422,6 +436,7 @@ components:
422436
no_github_actions: false,
423437
no_installable_package: false,
424438
tests: false,
439+
mcp: false,
425440
}),
426441
};
427442
assert!(execute(&args).is_ok());
@@ -435,6 +450,7 @@ components:
435450
no_github_actions: false,
436451
no_installable_package: false,
437452
tests: false,
453+
mcp: false,
438454
}),
439455
};
440456
assert!(execute(&args).is_ok());
@@ -448,6 +464,7 @@ components:
448464
no_github_actions: false,
449465
no_installable_package: false,
450466
tests: false,
467+
mcp: false,
451468
}),
452469
};
453470
assert!(execute(&args).is_ok());
@@ -462,6 +479,7 @@ components:
462479
no_github_actions: false,
463480
no_installable_package: false,
464481
tests: false,
482+
mcp: false,
465483
},
466484
framework: ServerFramework::ActixWeb,
467485
},
@@ -478,6 +496,7 @@ components:
478496
no_github_actions: false,
479497
no_installable_package: false,
480498
tests: false,
499+
mcp: false,
481500
},
482501
framework: ServerFramework::Axum,
483502
},
@@ -494,6 +513,7 @@ components:
494513
no_github_actions: false,
495514
no_installable_package: false,
496515
tests: false,
516+
mcp: false,
497517
};
498518
let result = run_generation(&args, &cdd_core::strategies::ActixStrategy);
499519
assert!(result.is_err());
@@ -508,6 +528,7 @@ components:
508528
no_github_actions: false,
509529
no_installable_package: false,
510530
tests: false,
531+
mcp: false,
511532
};
512533
let result = run_generation(&args, &cdd_core::strategies::ActixStrategy);
513534
assert!(result.is_err());
@@ -528,6 +549,7 @@ components:
528549
no_github_actions: true,
529550
no_installable_package: true,
530551
tests: true,
552+
mcp: false,
531553
};
532554
let _ = run_generation(&args, &cdd_core::strategies::ActixStrategy);
533555
Ok(())
@@ -552,7 +574,11 @@ pub struct FromOpenApiConfig {
552574
pub output_dir: Option<PathBuf>,
553575
pub no_github_actions: bool,
554576
pub no_installable_package: bool,
577+
555578
pub tests: bool,
579+
580+
/// Generate Model Context Protocol (MCP) server and adapter.
581+
pub mcp: bool,
556582
pub framework: ServerFramework,
557583
}
558584

@@ -565,10 +591,18 @@ pub fn generate_from_openapi(config: &FromOpenApiConfig) -> AppResult<()> {
565591
no_github_actions: config.no_github_actions,
566592
no_installable_package: config.no_installable_package,
567593
tests: config.tests,
594+
mcp: config.mcp,
568595
};
569596

570597
match config.subcommand.as_str() {
571-
"to_sdk_cli" => run_generation(&gen_args, &ClapCliStrategy),
598+
"to_sdk_cli" => {
599+
let res = run_generation(&gen_args, &ClapCliStrategy);
600+
if gen_args.mcp && res.is_ok() {
601+
run_generation(&gen_args, &cdd_core::strategies::McpClientStrategy)
602+
} else {
603+
res
604+
}
605+
}
572606
"to_sdk" => run_generation(&gen_args, &ReqwestStrategy),
573607
"to_sdk_mcp" => run_generation(&gen_args, &cdd_core::strategies::McpClientStrategy),
574608
"to_server" => match config.framework {

cli/src/serve_json_rpc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ async fn handle_rpc(req: web::Json<RpcRequest>) -> impl Responder {
216216
.and_then(|v| v.as_bool())
217217
.unwrap_or(false);
218218
let tests = map.get("tests").and_then(|v| v.as_bool()).unwrap_or(false);
219+
let mcp = map.get("mcp").and_then(|v| v.as_bool()).unwrap_or(false);
219220

220221
let config = FromOpenApiConfig {
221222
subcommand,
@@ -225,6 +226,7 @@ async fn handle_rpc(req: web::Json<RpcRequest>) -> impl Responder {
225226
no_github_actions,
226227
no_installable_package,
227228
tests,
229+
mcp,
228230
framework: ServerFramework::ActixWeb, // default
229231
};
230232

0 commit comments

Comments
 (0)