Skip to content
Closed
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
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cli/golem-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ tracing = { workspace = true }
tracing-log = "0.2.0"
tracing-subscriber = { workspace = true }
tree-sitter = { workspace = true }
axum = { workspace = true }
rmcp = { workspace = true }
tower = { workspace = true }
http = { workspace = true }
tree-sitter-json = { workspace = true }
tree-sitter-rust = { workspace = true }
tree-sitter-typescript = { workspace = true }
Expand Down
17 changes: 16 additions & 1 deletion cli/golem-cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub struct GolemCliCommand {
pub global_flags: GolemCliGlobalFlags,

#[clap(subcommand)]
pub subcommand: GolemCliSubcommand,
pub subcommand: Option<GolemCliSubcommand>,
}

impl GolemCliCommand {
Expand Down Expand Up @@ -196,6 +196,14 @@ pub struct GolemCliGlobalFlags {
#[arg(long, global = true, display_order = 112)]
pub dev_mode: bool,

/// Run golem-cli as an MCP server over HTTP/SSE
#[arg(long, global = true, display_order = 113)]
pub serve: bool,

/// Port for the MCP HTTP/SSE server
#[arg(long, global = true, requires = "serve", display_order = 114)]
pub serve_port: Option<u16>,

#[command(flatten)]
verbosity: Verbosity,

Expand Down Expand Up @@ -407,6 +415,13 @@ impl GolemCliCommand {
}
};

if fallback_command.global_flags.serve {
return GolemCliCommandParseResult::FullMatch(GolemCliCommand {
global_flags: fallback_command.global_flags,
subcommand: None,
});
}

let partial_match = match error.kind() {
ErrorKind::DisplayHelp => {
let positional_args = fallback_command
Expand Down
34 changes: 22 additions & 12 deletions cli/golem-cli/src/command_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::command_handler::worker::WorkerCommandHandler;
use crate::context::Context;
use crate::error::{ContextInitHintError, HintError, NonSuccessfulExit, PipedExitCode};
use crate::log::{log_anyhow_error, logln, set_log_output, Output};
use crate::mcp_adapter::McpServer;
use crate::{command_name, init_tracing};
use anyhow::anyhow;
use clap::CommandFactory;
Expand Down Expand Up @@ -139,18 +140,19 @@ impl<Hooks: CommandHandlerHooks + 'static> CommandHandler<Hooks> {
let result = match GolemCliCommand::try_parse_from_lenient(args_iterator, true) {
GolemCliCommandParseResult::FullMatch(command) => {
#[cfg(feature = "server-commands")]
let verbosity = if matches!(command.subcommand, GolemCliSubcommand::Server { .. }) {
Hooks::override_verbosity(command.global_flags.verbosity())
} else {
command.global_flags.verbosity()
};
let verbosity =
if matches!(command.subcommand, Some(GolemCliSubcommand::Server { .. })) {
Hooks::override_verbosity(command.global_flags.verbosity())
} else {
command.global_flags.verbosity()
};
#[cfg(feature = "server-commands")]
let pretty_mode = if matches!(command.subcommand, GolemCliSubcommand::Server { .. })
{
Hooks::override_pretty_mode()
} else {
false
};
let pretty_mode =
if matches!(command.subcommand, Some(GolemCliSubcommand::Server { .. })) {
Hooks::override_pretty_mode()
} else {
false
};
#[cfg(not(feature = "server-commands"))]
let verbosity = command.global_flags.verbosity();
#[cfg(not(feature = "server-commands"))]
Expand Down Expand Up @@ -250,7 +252,15 @@ impl<Hooks: CommandHandlerHooks + 'static> CommandHandler<Hooks> {
command: GolemCliCommand,
) -> std::pin::Pin<Box<dyn std::future::Future<Output = anyhow::Result<()>> + '_>> {
Box::pin(async move {
match command.subcommand {
if command.global_flags.serve {
let port = command.global_flags.serve_port.unwrap_or(1232);
return McpServer::new(self.ctx.clone()).run(port).await;
}

match command
.subcommand
.expect("subcommand required unless --serve is used")
{
// App scoped root commands
GolemCliSubcommand::New {
application_path,
Expand Down
1 change: 1 addition & 0 deletions cli/golem-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub mod evcxr_repl;
pub mod fs;
pub mod fuzzy;
pub mod log;
pub mod mcp_adapter;
pub mod model;
pub mod process;
pub mod sdk_overrides;
Expand Down
Loading
Loading