mirror of
https://github.com/instructkr/claude-code.git
synced 2026-06-05 03:56:45 +00:00
Compare commits
1 Commits
caeac828b5
...
fix/permis
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e9b21f415 |
@@ -2674,44 +2674,10 @@ fn render_mcp_report_for(
|
|||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(args) if args.split_whitespace().next() == Some("list") && args.contains(' ') => {
|
|
||||||
// `mcp list <filter>` — list does not accept arguments; treat as unsupported action.
|
|
||||||
Ok(render_mcp_unsupported_action_text(
|
|
||||||
args,
|
|
||||||
"list accepts no filter argument; use `claw mcp list`",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
Some(args) if matches!(args.split_whitespace().next(), Some("info" | "describe")) => {
|
|
||||||
Ok(render_mcp_unsupported_action_text(
|
|
||||||
args,
|
|
||||||
"use `claw mcp show <server>` to inspect a server",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
Some(args) => Ok(render_mcp_usage(Some(args))),
|
Some(args) => Ok(render_mcp_usage(Some(args))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_mcp_unsupported_action_text(action: &str, hint: &str) -> String {
|
|
||||||
format!(
|
|
||||||
"MCP\n Error unsupported action '{action}'\n Hint {hint}\n Usage /mcp [list|show <server>|help]"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_mcp_unsupported_action_json(action: &str, hint: &str) -> Value {
|
|
||||||
json!({
|
|
||||||
"kind": "mcp",
|
|
||||||
"action": "error",
|
|
||||||
"ok": false,
|
|
||||||
"error_kind": "unsupported_action",
|
|
||||||
"requested_action": action,
|
|
||||||
"hint": hint,
|
|
||||||
"usage": {
|
|
||||||
"slash_command": "/mcp [list|show <server>|help]",
|
|
||||||
"direct_cli": "claw mcp [list|show <server>|help]",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn render_mcp_report_json_for(
|
fn render_mcp_report_json_for(
|
||||||
loader: &ConfigLoader,
|
loader: &ConfigLoader,
|
||||||
cwd: &Path,
|
cwd: &Path,
|
||||||
@@ -2792,18 +2758,6 @@ fn render_mcp_report_json_for(
|
|||||||
})),
|
})),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(args) if args.split_whitespace().next() == Some("list") && args.contains(' ') => {
|
|
||||||
Ok(render_mcp_unsupported_action_json(
|
|
||||||
args,
|
|
||||||
"list accepts no filter argument; use `claw mcp list`",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
Some(args) if matches!(args.split_whitespace().next(), Some("info" | "describe")) => {
|
|
||||||
Ok(render_mcp_unsupported_action_json(
|
|
||||||
args,
|
|
||||||
"use `claw mcp show <server>` to inspect a server",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
Some(args) => Ok(render_mcp_usage_json(Some(args))),
|
Some(args) => Ok(render_mcp_usage_json(Some(args))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4791,38 +4745,6 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn mcp_unsupported_actions_return_typed_error_not_generic_help() {
|
|
||||||
// `mcp info <name>` and `mcp list <filter>` must return typed errors, not raw help.
|
|
||||||
// Regression for #504: these previously fell through to render_mcp_usage with
|
|
||||||
// unexpected=arg, giving no machine-readable error_kind.
|
|
||||||
use crate::handle_mcp_slash_command_json;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
let cwd = PathBuf::from("/tmp");
|
|
||||||
|
|
||||||
let info_json = handle_mcp_slash_command_json(Some("info nonexistent"), &cwd)
|
|
||||||
.expect("info nonexistent should not error at IO level");
|
|
||||||
assert_eq!(info_json["kind"], "mcp");
|
|
||||||
assert_eq!(info_json["ok"], false);
|
|
||||||
assert_eq!(info_json["error_kind"], "unsupported_action");
|
|
||||||
assert!(info_json["hint"]
|
|
||||||
.as_str()
|
|
||||||
.unwrap_or_default()
|
|
||||||
.contains("show"));
|
|
||||||
|
|
||||||
let list_filter_json = handle_mcp_slash_command_json(Some("list nonexistent"), &cwd)
|
|
||||||
.expect("list nonexistent should not error at IO level");
|
|
||||||
assert_eq!(list_filter_json["kind"], "mcp");
|
|
||||||
assert_eq!(list_filter_json["ok"], false);
|
|
||||||
assert_eq!(list_filter_json["error_kind"], "unsupported_action");
|
|
||||||
|
|
||||||
let describe_json = handle_mcp_slash_command_json(Some("describe myserver"), &cwd)
|
|
||||||
.expect("describe myserver should not error at IO level");
|
|
||||||
assert_eq!(describe_json["kind"], "mcp");
|
|
||||||
assert_eq!(describe_json["ok"], false);
|
|
||||||
assert_eq!(describe_json["error_kind"], "unsupported_action");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rejects_invalid_mcp_arguments() {
|
fn rejects_invalid_mcp_arguments() {
|
||||||
let show_error = parse_error_message("/mcp show alpha beta");
|
let show_error = parse_error_message("/mcp show alpha beta");
|
||||||
|
|||||||
@@ -877,17 +877,13 @@ fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
|||||||
// `missing Anthropic credentials` even though the command is purely
|
// `missing Anthropic credentials` even though the command is purely
|
||||||
// local introspection. Mirror `agents`/`mcp`/`skills`: action is the
|
// local introspection. Mirror `agents`/`mcp`/`skills`: action is the
|
||||||
// first positional arg, target is the second.
|
// first positional arg, target is the second.
|
||||||
// `plugin` (singular) and `marketplace` are aliases for `plugins`.
|
"plugins" => {
|
||||||
// All three must route to the same local handler so that no form
|
|
||||||
// falls through to the LLM/prompt path.
|
|
||||||
"plugins" | "plugin" | "marketplace" => {
|
|
||||||
let tail = &rest[1..];
|
let tail = &rest[1..];
|
||||||
let action = tail.first().cloned();
|
let action = tail.first().cloned();
|
||||||
let target = tail.get(1).cloned();
|
let target = tail.get(1).cloned();
|
||||||
if tail.len() > 2 {
|
if tail.len() > 2 {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"unexpected extra arguments after `claw {} {}`: {}",
|
"unexpected extra arguments after `claw plugins {}`: {}",
|
||||||
rest[0],
|
|
||||||
tail[..2].join(" "),
|
tail[..2].join(" "),
|
||||||
tail[2..].join(" ")
|
tail[2..].join(" ")
|
||||||
));
|
));
|
||||||
|
|||||||
Reference in New Issue
Block a user