fix(mcp-elicit): skipping every field of an optional form declines

The all-skipped guard only fired when the form had a required field, so a user
who skipped every field of an all-optional form (no defaults) sent "accept"
with empty content. Any fully skipped form without defaults now declines.
This commit is contained in:
Teknium
2026-10-25 22:34:51 -07:00
parent 9a35483743
commit 1d18278d71
3 changed files with 11 additions and 3 deletions

View File

@@ -156,3 +156,10 @@ def test_enum_pick_is_never_swapped_for_another_option(answer, outcome):
field = parse_form({"properties": {"region": {"type": "string", "enum": ["US", "us"]}}})[0]
assert coerce_answer(field, answer) == outcome
def test_skipping_every_optional_field_declines():
schema = {"type": "object", "properties": {"note": {"type": "string"}, "rating": {"type": "integer"}}}
ctx = _call_context(lambda _questions: {"outcome": "submitted", "answers": {}})
handler = ElicitationHandler("formprobe", {"timeout": 5}, call_context=lambda: ctx)
result = asyncio.run(handler(context=None, params=_params(schema)))
assert result.action == "decline"

View File

@@ -309,8 +309,9 @@ def _collect(asker: FormAsker, fields: list[FormField], header: str, ended: Call
break
if pending: # still invalid after the re-asks
return FormOutcome("decline")
# A form whose every field was skipped and has no default is the user saying no.
if not answered_any and not content and any(f.required for f in fields):
# A form whose every field was skipped and has no default is the user saying no (optional
# fields included: an accepted empty form would read as the user agreeing).
if not answered_any and not content:
return FormOutcome("decline")
return FormOutcome("accept", content)

View File

@@ -1017,7 +1017,7 @@ A [portable plugin package](../../developer-guide/plugins/index.md#portable-agen
## MCP Elicitation Support
MCP servers can ask the user for structured input mid-tool-call via the `elicitation/create` protocol (mcp Python SDK ≥ 1.11.0). Hermes asks **form-mode** elicitations on the session's own clarify surface — the question panel in the CLI/TUI, a card in Desktop, the clarify prompt on messaging platforms — so the request reaches you wherever the session lives. Each field the server asks for becomes a question (choices for enums and yes/no fields, free text otherwise); answers are checked against the server's schema (whole numbers, ranges, lengths, `email`/`uri`/`date`/`date-time` formats) and a wrong answer is asked again, twice at most, before the form is declined. Skipping every field of a form with required fields declines; dismissing the prompt cancels. Your answers go to that MCP server only, not into the conversation. A form with no fields is a yes/no question. Where no clarify surface is bound, the request falls back to the approval prompt, which can only answer forms that a single Allow Once can fill. YOLO and `approvals.mode: off` do not answer these for you: the server is asking you a question, not asking permission. Cron and other unattended sessions decline. **URL-mode** elicitations (where a server points you at an external URL) are declined as unsupported.
MCP servers can ask the user for structured input mid-tool-call via the `elicitation/create` protocol (mcp Python SDK ≥ 1.11.0). Hermes asks **form-mode** elicitations on the session's own clarify surface — the question panel in the CLI/TUI, a card in Desktop, the clarify prompt on messaging platforms — so the request reaches you wherever the session lives. Each field the server asks for becomes a question (choices for enums and yes/no fields, free text otherwise); answers are checked against the server's schema (whole numbers, ranges, lengths, `email`/`uri`/`date`/`date-time` formats) and a wrong answer is asked again, twice at most, before the form is declined. Skipping every field (with no defaults to fall back on) declines; dismissing the prompt cancels. Your answers go to that MCP server only, not into the conversation. A form with no fields is a yes/no question. Where no clarify surface is bound, the request falls back to the approval prompt, which can only answer forms that a single Allow Once can fill. YOLO and `approvals.mode: off` do not answer these for you: the server is asking you a question, not asking permission. Cron and other unattended sessions decline. **URL-mode** elicitations (where a server points you at an external URL) are declined as unsupported.
Elicitation is **enabled by default** per server. Configure it under the `elicitation` key: