Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/bin/forge/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! ```text
//! forge openapi.json --target ts --out sdk
//! forge openapi.json --target mcp --out server
//! forge openapi.json --target wasm://plugin.wasm --out sdk
//! ```

Expand All @@ -13,6 +14,7 @@ use std::process::ExitCode;
use clap::Parser;
use forge::{Err, Forge};

mod mcp;
mod ts;

/// Generates an SDK from an OpenAPI document.
Expand All @@ -21,8 +23,9 @@ mod ts;
struct Args {
/// The OpenAPI JSON document, or - to read it from standard input.
spec: PathBuf,
/// The language of the SDK: `ts` for TypeScript, or `wasm://PATH` for
/// the plugin compiled to a WebAssembly component at PATH.
/// The language of the SDK: `ts` for TypeScript, `mcp` for an MCP server
/// in Rust, or `wasm://PATH` for the plugin compiled to a WebAssembly
/// component at PATH.
#[arg(long, value_parser = Target::parse)]
target: Target,
/// The directory to write the SDK to.
Expand All @@ -35,6 +38,8 @@ struct Args {
enum Target {
/// The TypeScript generator.
Ts,
/// The MCP server generator.
Mcp,
/// A plugin compiled to a WebAssembly component, at the path.
#[cfg(feature = "wasm")]
Wasm(PathBuf),
Expand All @@ -45,8 +50,11 @@ impl Target {
if s == "ts" {
return Ok(Target::Ts);
}
if s == "mcp" {
return Ok(Target::Mcp);
}
let Some(path) = s.strip_prefix("wasm://") else {
return Err("possible values: ts, wasm://PATH".to_owned());
return Err("possible values: ts, mcp, wasm://PATH".to_owned());
};
if path.is_empty() {
return Err("wasm:// needs the path of a plugin, as in wasm://plugin.wasm".to_owned());
Expand Down Expand Up @@ -75,6 +83,10 @@ fn run(args: Args) -> Result<(), Err> {
let forge = read(&args.spec)?;
forge::write(&args.out, forge::run(&forge, &ts::Generator)?)
}
Target::Mcp => {
let forge = read(&args.spec)?;
forge::write(&args.out, forge::run(&forge, &mcp::Generator)?)
}
#[cfg(feature = "wasm")]
Target::Wasm(path) => {
// Compiling the plugin and reading the document are both slow,
Expand Down
Loading
Loading