Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ __pycache__/
/.playwright-cli/

/examples/*/dist/

# Harness integration build artifacts
integrations/*/node_modules/
integrations/*/*.tgz
integrations/*/package-lock.json
23 changes: 22 additions & 1 deletion crates/cli/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,28 @@ pub fn run(
source: Datasource,
action: Action,
statements: Vec<String>,
) -> Result<bool> {
run_to(
io::stdout().lock(),
root,
manifest,
local,
source,
action,
statements,
)
}
/// Run an execution and write its JSON event stream to `output`.
///
/// The CLI passes stdout; the MCP server passes a buffer so protocol output stays clean.
pub fn run_to<W: Write>(
mut output: W,
root: PathBuf,
manifest: String,
local: Option<PathBuf>,
source: Datasource,
action: Action,
statements: Vec<String>,
) -> Result<bool> {
let id = source.id.clone();
let prepared = prepare(root, manifest, local, source, action, statements)?;
Expand All @@ -128,7 +150,6 @@ pub fn run(
let _ = tokio::signal::ctrl_c().await;
signal.cancel();
});
let mut output = io::stdout().lock();
write!(
output,
"{{\"protocol_version\":1,\"datasource_id\":{},\"events\":[",
Expand Down
1 change: 1 addition & 0 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod components;
pub mod execution;
pub mod mcp;
pub mod plugins;
pub mod prefetch;
pub mod storage;
Expand Down
10 changes: 8 additions & 2 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod skill;
use sqlx_core::{components, execution, plugins, prefetch, storage, ui, updates};
use sqlx_core::{components, execution, mcp, plugins, prefetch, storage, ui, updates};

use anyhow::{anyhow, bail, Context, Result};
use clap::{Args, Parser, Subcommand};
Expand Down Expand Up @@ -39,6 +39,8 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
Init,
/// Serve the Model Context Protocol over stdio so agent harnesses can call SQLX as a tool.
Mcp,
/// Download database workers, the JDBC runtime and the browser UI before they are needed.
Prefetch {
/// Components to download: mysql, postgres, oracle, sqlserver, ui, skill or all.
Expand Down Expand Up @@ -224,7 +226,7 @@ fn main() {
&& io::stdout().is_terminal()
&& !matches!(
&cli.command,
Commands::Update { .. } | Commands::Init | Commands::Prefetch { .. }
Commands::Update { .. } | Commands::Init | Commands::Prefetch { .. } | Commands::Mcp
)
&& cli.worker_dir.is_none()
&& std::env::var("SQLX_NO_UPDATE_CHECK").ok().as_deref() != Some("1");
Expand Down Expand Up @@ -272,6 +274,10 @@ fn run(cli: Cli) -> Result<bool> {
let store = Store::open(root)?;
print(json!({"initialized":true,"identity":store.identity}));
}
Commands::Mcp => {
mcp::serve(root, cli.manifest, cli.worker_dir)?;
return Ok(true);
}
Commands::Prefetch { components } => {
let (report, complete) = prefetch::run(&root, &cli.manifest, &components)?;
print(report);
Expand Down
Loading
Loading