fix(cli): report mcp status without server
This commit is contained in:
parent
9d5edd5812
commit
09277fa77c
|
|
@ -42,6 +42,7 @@ fn run(args: &[String]) -> Result<String, String> {
|
|||
let out = match command {
|
||||
Command::Help => USAGE.to_string(),
|
||||
Command::Version => version_json(),
|
||||
Command::Status => status_json(port),
|
||||
Command::ToolsList => post(port, &tools_list_body())?,
|
||||
Command::ToolCall { tool, args } => {
|
||||
post(port, &tool_call_body(&tool, &args_to_json(&args)))?
|
||||
|
|
@ -64,6 +65,7 @@ struct Parsed {
|
|||
enum Command {
|
||||
Help,
|
||||
Version,
|
||||
Status,
|
||||
ToolsList,
|
||||
ToolCall {
|
||||
tool: String,
|
||||
|
|
@ -170,7 +172,7 @@ fn command_from_positionals(positionals: &[String], flags: &Flags) -> Result<Com
|
|||
"help" | "-h" | "--help" => Ok(Command::Help),
|
||||
"version" => Ok(Command::Version),
|
||||
"tools" => Ok(Command::ToolsList),
|
||||
"status" => tool_call("get_document_info", vec![]),
|
||||
"status" => Ok(Command::Status),
|
||||
"open" => {
|
||||
let args = flag_value(flags, "file")
|
||||
.or_else(|| positionals.get(1).cloned())
|
||||
|
|
@ -674,6 +676,21 @@ fn pretty_json(raw: &str) -> String {
|
|||
.unwrap_or_else(|| raw.to_string())
|
||||
}
|
||||
|
||||
fn status_json(port: u16) -> String {
|
||||
status_json_from_running(
|
||||
port,
|
||||
std::net::TcpStream::connect(("127.0.0.1", port)).is_ok(),
|
||||
)
|
||||
}
|
||||
|
||||
fn status_json_from_running(port: u16, running: bool) -> String {
|
||||
if running {
|
||||
format!(r#"{{"running":true,"port":{port},"url":"http://127.0.0.1:{port}"}}"#)
|
||||
} else {
|
||||
r#"{"running":false}"#.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// JSON-RPC body for `tools/list`.
|
||||
fn tools_list_body() -> String {
|
||||
r#"{"jsonrpc":"2.0","id":1,"method":"tools/list"}"#.to_string()
|
||||
|
|
|
|||
|
|
@ -43,6 +43,24 @@ fn default_port_matches_ts_mcp_http_port() {
|
|||
assert!(USAGE.contains("127.0.0.1:3100/mcp"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_args_maps_ts_status_to_local_status_probe() {
|
||||
let p = parse_args(&["status".to_string()]).expect("parse status");
|
||||
assert_eq!(p.command, Command::Status);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn status_json_matches_ts_running_shape_without_requiring_server() {
|
||||
assert_eq!(
|
||||
status_json_from_running(DEFAULT_PORT, false),
|
||||
r#"{"running":false}"#
|
||||
);
|
||||
assert_eq!(
|
||||
status_json_from_running(3101, true),
|
||||
r#"{"running":true,"port":3101,"url":"http://127.0.0.1:3101"}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn http_request_targets_mcp_endpoint() {
|
||||
let request = http_request("{}");
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ USAGE:
|
|||
op help show this message
|
||||
|
||||
COMMON COMMANDS:
|
||||
op status check whether MCP HTTP is reachable
|
||||
op get [--type T] [--name N] [--id ID] [--depth N] [--parent P]
|
||||
op selection get current selection
|
||||
op insert <json|@file|-> insert a leaf node
|
||||
|
|
|
|||
Loading…
Reference in a new issue