Repository navigation
fix(engine): use a gateway-supported MCP protocol version + wire gateway list/gw-call
#15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
209a722
feat(cli): wire gateway-backed `list` and `gw-call` subcommands
claude 5ca0c04
fix(engine): advertise a supported MCP protocol version (2025-06-18)
claude fe1621e
fix(cli): redact API key in gateway errors; nonzero exit on tool isError
claude 8f5bf7b
fix: strip URL from reqwest error (key leak), targeted redaction, exi…
claude 33e0646
docs(cli): reword EXIT_TOOL_ERROR comment to not cite an out-of-repo …
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| //! Gateway-backed subcommands for `sealg`. | ||
| //! | ||
| //! `sealg` is a thin MCP client: these subcommands resolve the gateway | ||
| //! coordinates from the environment ([`GatewayConfig::from_env`]), run the MCP | ||
| //! `initialize` handshake, and forward `tools/list` / `tools/call` to the | ||
| //! per-user gateway endpoint. All policy and enforcement lives in the gateway. | ||
|
|
||
| use engine::{GatewayClient, GatewayConfig, GatewayError}; | ||
| use serde_json::{json, Value}; | ||
| use std::time::Duration; | ||
|
|
||
| /// Timeout for the connect + a single request round-trip. | ||
| const TIMEOUT: Duration = Duration::from_secs(30); | ||
|
|
||
| /// Exit code when a gateway tool call returns an MCP error (`isError: true`). | ||
| /// Named rather than magic: `6` denotes an upstream tool error, kept distinct | ||
| /// from `1` (client/transport failure) and `2` (clap's usage-error code) so a | ||
| /// caller can tell a failed tool call apart from a CLI or connection failure. | ||
| const EXIT_TOOL_ERROR: i32 = 6; | ||
|
|
||
| /// `sealg list [--json]` — list the user's gateway tools. | ||
| pub async fn cmd_list(json_out: bool) { | ||
| if let Err(e) = run_list(json_out).await { | ||
| eprintln!("error: {e}"); | ||
| std::process::exit(1); | ||
| } | ||
| } | ||
|
|
||
| async fn run_list(json_out: bool) -> Result<(), GatewayError> { | ||
| let cfg = GatewayConfig::from_env(); | ||
| let client = GatewayClient::connect(cfg, TIMEOUT).await?; | ||
| let tools = client.tools_list().await?; | ||
|
|
||
| if json_out { | ||
| let arr: Vec<Value> = tools | ||
| .iter() | ||
| .map(|t| json!({ "name": t.name, "description": t.description })) | ||
| .collect(); | ||
| println!( | ||
| "{}", | ||
| serde_json::to_string_pretty(&Value::Array(arr)).unwrap_or_else(|_| "[]".to_string()) | ||
| ); | ||
| } else { | ||
| for t in &tools { | ||
| println!("{} — {}", t.name, t.description); | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// `sealg gw-call <tool> [--args '<json>']` — call one gateway tool. | ||
| pub async fn cmd_call(tool: &str, args: &str) { | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| match run_call(tool, args).await { | ||
| Ok(exit_code) => std::process::exit(exit_code), | ||
| Err(e) => { | ||
| eprintln!("error: {e}"); | ||
| std::process::exit(1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Returns the process exit code: `0` on a normal result, non-zero when the | ||
| /// gateway returns an MCP tool error (`isError: true`) — the result is still | ||
| /// printed so the caller sees the error content. | ||
| async fn run_call(tool: &str, args: &str) -> Result<i32, GatewayError> { | ||
| let arguments: Value = serde_json::from_str(args) | ||
| .map_err(|e| GatewayError::Config(format!("invalid --args JSON: {e}")))?; | ||
|
|
||
| let cfg = GatewayConfig::from_env(); | ||
| let client = GatewayClient::connect(cfg, TIMEOUT).await?; | ||
| let result = client.tools_call(tool, arguments).await?; | ||
|
Miyamura80 marked this conversation as resolved.
Miyamura80 marked this conversation as resolved.
|
||
|
|
||
| println!( | ||
| "{}", | ||
| serde_json::to_string_pretty(&result).unwrap_or_else(|_| result.to_string()) | ||
| ); | ||
|
|
||
| // Mirror the MCP tool-call response: an `isError: true` result is a failed | ||
| // call and must not exit 0. | ||
| let is_error = result.get("isError").and_then(Value::as_bool) == Some(true); | ||
| Ok(if is_error { EXIT_TOOL_ERROR } else { 0 }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.