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
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
- **[ClickPipes](https://clickhouse.com/cloud/clickpipes)** ingests data into ClickHouse Cloud from object storage, streams, and databases through change data capture. Create, inspect, update, scale, and troubleshoot pipelines.
- **[ClickStack](https://clickhouse.com/clickstack)** combines ClickHouse, OpenTelemetry, and the HyperDX UI for observability. Manage sources, roles, saved searches, dashboards, alerts, and webhooks for an existing [Managed ClickStack](https://clickhouse.com/cloud/clickstack) service.

The CLI also manages organization access and installs official ClickHouse skills for coding agents.
The CLI also manages organization access, installs official ClickHouse skills for coding agents, and connects them to the hosted Cloud MCP server.

## Install

Expand Down Expand Up @@ -229,6 +229,12 @@ clickhousectl skills --agent claude --agent codex

The common `.agents/skills/` directory is always included. Run `skills` without flags for interactive selection; unattended installs require `--agent`, `--all`, or `--detected-only`.

Register the read-only [Cloud MCP server](docs/guides/cloud-mcp.md) in an agent and sign in. Sign-in opens a browser:

```bash
clickhousectl cloud mcp add claude
```

Structured commands support `--json` and select it automatically for detected coding agents. SQL and native clients retain command-specific formats. Always check the exit status and distinguish an accepted request from a completed operation. See [automation and output contracts](docs/reference/automation.md).

## Documentation
Expand Down
20 changes: 15 additions & 5 deletions crates/clickhousectl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ pub struct Cli {
// Parsing and all help consumers use the same decorated command tree.
impl clap::CommandFactory for Cli {
fn command() -> clap::Command {
crate::cloud::permissions::decorate(Self::augment_args(clap::Command::new("clickhousectl")))
let command = Self::augment_args(clap::Command::new("clickhousectl"));
crate::cloud::mcp::hide_rejected_cloud_flags(crate::cloud::permissions::decorate(command))
}

fn command_for_update() -> clap::Command {
crate::cloud::permissions::decorate(Self::augment_args_for_update(clap::Command::new(
"clickhousectl",
)))
let command = Self::augment_args_for_update(clap::Command::new("clickhousectl"));
crate::cloud::mcp::hide_rejected_cloud_flags(crate::cloud::permissions::decorate(command))
}
}

Expand Down Expand Up @@ -467,13 +467,23 @@ mod tests {
} else {
&[]
};
// `cloud mcp` rejects the credential and organization flags, so it hides them.
let mcp_hidden: &[&str] = if path.starts_with("clickhousectl cloud mcp") {
&["org-id", "org-name", "api-key", "api-secret", "url"]
} else {
&[]
};
for flag in required {
let arg = command
.get_arguments()
.find(|arg| arg.get_long() == Some(flag))
.unwrap_or_else(|| panic!("{path}: missing inherited --{flag}"));
if *flag == "url" {
if mcp_hidden.contains(flag) {
assert!(arg.is_hide_set(), "{path}: --{flag}");
} else if *flag == "url" {
assert_eq!(arg.is_hide_set(), !cfg!(debug_assertions), "{path}");
} else {
assert!(!arg.is_hide_set(), "{path}: --{flag}");
}
}
});
Expand Down
34 changes: 30 additions & 4 deletions crates/clickhousectl/src/cloud/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub(crate) use crate::cloud::clickpipes::{
ObjectStorageCreateArgs, PostgresCreateArgs,
};
pub(crate) use crate::cloud::clickstack::ClickStackCommands;
pub(crate) use crate::cloud::mcp::McpCommands;
pub(crate) use crate::cloud::organizations::{InvitationCommands, MemberCommands, OrgCommands};
pub(crate) use crate::cloud::query_api_endpoints::QueryApiEndpointArgs;
pub(crate) use crate::cloud::saved_queries::SavedQueryArgs;
Expand Down Expand Up @@ -81,6 +82,23 @@ impl CloudArgs {
)
}

/// A Cloud-wide flag passed to `mcp add`, which never uses clickhousectl
/// credentials or an organization: the agent signs in by itself.
pub fn mcp_flag_conflict(&self) -> Option<&'static str> {
if !matches!(self.command, CloudCommands::Mcp { .. }) {
return None;
}
[
(self.org_id.is_some(), "--org-id"),
(self.org_name.is_some(), "--org-name"),
(self.api_key.is_some(), "--api-key"),
(self.api_secret.is_some(), "--api-secret"),
(self.url.is_some(), "--url"),
]
.into_iter()
.find_map(|(set, flag)| set.then_some(flag))
}

/// The schema-discovery source's usage error, checked before credentials.
pub fn clickpipe_schema_discover_validation_error(&self) -> Option<(&'static str, String)> {
let CloudCommands::ClickPipe { command } = &self.command else {
Expand Down Expand Up @@ -273,6 +291,12 @@ CONTEXT FOR AGENTS:
#[command(subcommand)]
command: crate::cloud::postgres::PostgresCommands,
},

/// Connect coding agents to the Cloud MCP server
Mcp {
#[command(subcommand)]
command: McpCommands,
},
}

impl CloudCommands {
Expand All @@ -298,6 +322,7 @@ impl CloudCommands {
CloudCommands::Postgres { command } => command.is_write(),
CloudCommands::ClickPipe { command } => command.is_write(),
CloudCommands::ClickStack { command } => command.is_write(),
CloudCommands::Mcp { command } => command.is_write(),
}
}
}
Expand Down Expand Up @@ -369,15 +394,16 @@ pub(crate) mod tests {

#[test]
fn org_id_is_global_and_visible_throughout_cloud_hierarchy() {
fn walk(command: &clap::Command) {
// `cloud mcp` rejects --org-id, so only that subtree hides it.
fn walk(command: &clap::Command, under_mcp: bool) {
let selectors: Vec<_> = command
.get_arguments()
.filter(|arg| arg.get_id() == "org_id")
.collect();
assert_eq!(selectors.len(), 1, "{}", command.get_name());
let selector = selectors[0];
assert!(selector.is_global_set());
assert!(!selector.is_hide_set());
assert_eq!(selector.is_hide_set(), under_mcp, "{}", command.get_name());
assert!(!selector.is_required_set());
assert_eq!(selector.get_long(), Some("org-id"));
assert!(
Expand All @@ -389,13 +415,13 @@ pub(crate) mod tests {
.get_subcommands()
.filter(|child| child.get_name() != "help")
{
walk(child);
walk(child, under_mcp || child.get_name() == "mcp");
}
}
let mut command = Cli::command();
command.build();
assert!(!command.get_arguments().any(|arg| arg.get_id() == "org_id"));
walk(command.find_subcommand("cloud").unwrap());
walk(command.find_subcommand("cloud").unwrap(), false);
assert!(
Cli::try_parse_from(["chctl", "--org-id", "org-1", "cloud", "org", "get"]).is_err()
);
Expand Down
Loading
Loading