Skip to content

Commit 462db9c

Browse files
committed
mcp(fix[option_tools]): Reject target without scope instead of ignoring
why: When `target` was provided without `scope`, `_resolve_option_target` silently ignored the target and returned the server object. This caused `show_option(option="x", target="my_session")` to query the server instead of the intended session — a fail-open behavior. what: - Raise ToolError when target is provided but scope is None - Add test for target-without-scope error path
1 parent 7dfedbe commit 462db9c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/libtmux/mcp/tools/option_tools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ def _resolve_option_target(
4343
msg = f"Invalid scope: {scope!r}. Valid: {valid}"
4444
raise ToolError(msg)
4545

46+
if target is not None and opt_scope is None:
47+
from fastmcp.exceptions import ToolError
48+
49+
msg = "scope is required when target is specified"
50+
raise ToolError(msg)
51+
4652
if target is not None and opt_scope is not None:
4753
if opt_scope == OptionScope.Session:
4854
return _resolve_session(server, session_name=target), opt_scope

tests/mcp/test_option_tools.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ def test_show_option_invalid_scope(mcp_server: Server, mcp_session: Session) ->
3838
)
3939

4040

41+
def test_show_option_target_without_scope(
42+
mcp_server: Server, mcp_session: Session
43+
) -> None:
44+
"""show_option raises ToolError when target is given without scope."""
45+
with pytest.raises(ToolError, match="scope is required"):
46+
show_option(
47+
option="base-index",
48+
target="some_session",
49+
socket_name=mcp_server.socket_name,
50+
)
51+
52+
4153
def test_set_option(mcp_server: Server, mcp_session: Session) -> None:
4254
"""set_option sets a tmux option."""
4355
result = set_option(

0 commit comments

Comments
 (0)