Skip to content

Commit 26f6358

Browse files
committed
fix(forms): return pending form handoffs as non-error results
Hosts treat isError results as failed tool calls and exclude them from MCP App rendering, so the deferred create_pull_request, update_pull_request, and issue_write forms never appeared. The pending handoff is now a normal result that keeps its stop message and awaiting_user_submission status. Handler content is preserved so modern clients keep the stop message in text instead of replacing it with the structured JSON.
1 parent df32d7e commit 26f6358

9 files changed

Lines changed: 56 additions & 27 deletions

‎docs/error-handling.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ Ordinary API and validation errors never expose the SDK-generated zero-value
6868
structured output.
6969

7070
Handler-provided structured statuses are distinct from generated error output.
71-
For example, `issue_write` can return `IsError: true` with
72-
`status: "awaiting_user_submission"` while an MCP App form is pending. Modern
73-
clients retain that explicit status and its reason; legacy clients retain the
74-
stop message and error flag without structured content. This status does not
71+
For example, `issue_write` can return a non-error result with
72+
`status: "awaiting_user_submission"` while an MCP App form is pending. The
73+
result is not an error because hosts exclude error results from MCP App
74+
rendering. Modern clients retain that explicit status and its reason; legacy
75+
clients retain the stop message without structured content. This status does not
7576
mean the issue was created or updated. The output schema includes a strict
7677
status variant alongside the mutation's `id`/`url` variant. Multi-round-trip
7778
`InputRequests` continue to pass through unchanged.

‎pkg/github/issues.go‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,10 +2656,10 @@ var issueWriteFormParams = map[string]struct{}{
26562656

26572657
// issueWriteAwaitingFormResult builds the "awaiting form submission" stub
26582658
// returned when issue_write hands off to the MCP App form. The body is shared
2659-
// by IssueWrite and LegacyIssueWrite. The result is marked IsError=true so
2660-
// agents that bail on error don't claim success or chain dependent tool calls
2661-
// while the user is still interacting with the form; the host renders the UI
2662-
// regardless because rendering is keyed off the tool's _meta.ui resourceUri.
2659+
// by IssueWrite and LegacyIssueWrite. The result is not an error because hosts
2660+
// exclude error results from MCP App rendering; the stop message and the
2661+
// structured status keep the handoff pending so agents don't claim success or
2662+
// chain dependent tool calls while the user is still interacting with the form.
26632663
func issueWriteAwaitingFormResult(method, owner, repo string, issueNumber int) *mcp.CallToolResult {
26642664
var msg string
26652665
if method == "update" {
@@ -2876,6 +2876,9 @@ Options are:
28762876
Reason: "An interactive form is being shown to the user. The operation has not been performed.",
28772877
}
28782878
result.StructuredContent = output
2879+
// Keep the stop message in text; modern clients replace text
2880+
// with structured JSON unless the handler content is preserved.
2881+
inventory.PreserveToolHandlerContent(ctx)
28792882
return result, &IssueWriteOutput{Method: method, Awaiting: output}, nil
28802883
}
28812884

‎pkg/github/issues_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,7 @@ func Test_IssueWrite_MCPAppsFeature_UIGate(t *testing.T) {
22322232

22332233
textContent := getTextResult(t, result)
22342234
assert.Contains(t, textContent.Text, "interactive form has been shown to the user for creating a new issue")
2235-
assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success")
2235+
assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form")
22362236
})
22372237

22382238
t.Run("UI client with _ui_submitted executes directly", func(t *testing.T) {
@@ -2284,7 +2284,7 @@ func Test_IssueWrite_MCPAppsFeature_UIGate(t *testing.T) {
22842284
textContent := getTextResult(t, result)
22852285
assert.Contains(t, textContent.Text, "interactive form has been shown to the user for editing issue #1",
22862286
"state change should route through UI form")
2287-
assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success")
2287+
assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form")
22882288
})
22892289

22902290
t.Run("UI client update without state change returns form message", func(t *testing.T) {
@@ -2301,7 +2301,7 @@ func Test_IssueWrite_MCPAppsFeature_UIGate(t *testing.T) {
23012301
textContent := getTextResult(t, result)
23022302
assert.Contains(t, textContent.Text, "interactive form has been shown to the user for editing issue #1",
23032303
"update without state should show UI form")
2304-
assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success")
2304+
assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form")
23052305
})
23062306

23072307
t.Run("UI client with issue_fields routes through UI form", func(t *testing.T) {
@@ -2323,7 +2323,7 @@ func Test_IssueWrite_MCPAppsFeature_UIGate(t *testing.T) {
23232323
textContent := getTextResult(t, result)
23242324
assert.Contains(t, textContent.Text, "interactive form has been shown to the user for creating a new issue",
23252325
"issue_fields should route through UI form")
2326-
assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success")
2326+
assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form")
23272327
})
23282328

23292329
t.Run("UI client with labels routes through UI form", func(t *testing.T) {
@@ -2343,7 +2343,7 @@ func Test_IssueWrite_MCPAppsFeature_UIGate(t *testing.T) {
23432343
textContent := getTextResult(t, result)
23442344
assert.Contains(t, textContent.Text, "interactive form has been shown to the user for creating a new issue",
23452345
"labels should route through UI form")
2346-
assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success")
2346+
assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form")
23472347
})
23482348
}
23492349

‎pkg/github/pullrequests.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ func CreatePullRequest(t translations.TranslationHelperFunc) inventory.ServerToo
783783
return nil, nil, err
784784
}
785785
if shouldDeferToForm(ctx, deps, req, formArgs, pullRequestWriteFormParams) {
786+
inventory.PreserveToolHandlerContent(ctx)
786787
return pullRequestAwaitingFormResult(fmt.Sprintf(
787788
"An interactive form has been shown to the user for creating a new pull request in %s/%s. "+
788789
"STOP — do not call any other tools, do not respond as if the pull request was created, "+
@@ -1013,6 +1014,7 @@ func UpdatePullRequest(t translations.TranslationHelperFunc) inventory.ServerToo
10131014
return nil, nil, err
10141015
}
10151016
if shouldDeferToForm(ctx, deps, req, formArgs, pullRequestUpdateFormParams) {
1017+
inventory.PreserveToolHandlerContent(ctx)
10161018
return pullRequestAwaitingFormResult(fmt.Sprintf(
10171019
"An interactive form has been shown to the user for editing pull request #%d in %s/%s. "+
10181020
"STOP — do not call any other tools, do not respond as if the pull request was updated, "+

‎pkg/github/pullrequests_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,7 +3060,7 @@ func Test_CreatePullRequest_MCPAppsFeature_UIGate(t *testing.T) {
30603060

30613061
textContent := getTextResult(t, result)
30623062
assert.Contains(t, textContent.Text, "interactive form has been shown to the user for creating a new pull request")
3063-
assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success")
3063+
assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form")
30643064
})
30653065

30663066
t.Run("UI client with _ui_submitted executes directly", func(t *testing.T) {
@@ -3120,7 +3120,7 @@ func Test_CreatePullRequest_MCPAppsFeature_UIGate(t *testing.T) {
31203120

31213121
// Test_UpdatePullRequest_MCPAppsFeature_UIGate verifies the form-routing
31223122
// behavior for update_pull_request: UI clients without _ui_submitted get a
3123-
// pending-form stub (marked IsError so agents don't claim success), UI clients
3123+
// pending-form stub (a non-error result so hosts render the form), UI clients
31243124
// with _ui_submitted execute directly, non-UI clients execute directly, and
31253125
// UI clients carrying non-form params bypass the form.
31263126
func Test_UpdatePullRequest_MCPAppsFeature_UIGate(t *testing.T) {
@@ -3161,7 +3161,7 @@ func Test_UpdatePullRequest_MCPAppsFeature_UIGate(t *testing.T) {
31613161

31623162
textContent := getTextResult(t, result)
31633163
assert.Contains(t, textContent.Text, "interactive form has been shown to the user for editing pull request #42")
3164-
assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success")
3164+
assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form")
31653165
})
31663166

31673167
t.Run("UI client with _ui_submitted executes directly", func(t *testing.T) {

‎pkg/github/typed_consolidated_issue_outputs_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,10 @@ func TestTypedIssueWriteAwaitingForm(t *testing.T) {
353353
args := map[string]any{"method": method, "owner": "owner", "repo": "repo", "issue_number": "1", "title": "Subject"}
354354
result, err := session.CallTool(context.Background(), &mcp.CallToolParams{Name: "issue_write", Arguments: args})
355355
require.NoError(t, err)
356-
require.True(t, result.IsError)
356+
require.False(t, result.IsError)
357357
require.Len(t, result.Content, 1)
358-
assert.Contains(t, getErrorResult(t, result).Text, "interactive form has been shown")
359-
assert.Contains(t, getErrorResult(t, result).Text, "NOT been")
358+
assert.Contains(t, getTextResult(t, result).Text, "interactive form has been shown")
359+
assert.Contains(t, getTextResult(t, result).Text, "NOT been")
360360
if protocol == inventory.ProtocolVersionMultiRoundTrip {
361361
require.NotNil(t, result.StructuredContent)
362362
assert.JSONEq(t, `{"status":"awaiting_user_submission","reason":"An interactive form is being shown to the user. The operation has not been performed."}`, mustMarshalJSON(t, result.StructuredContent))

‎pkg/github/typed_consolidated_pull_request_outputs_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ func TestTypedPullRequestWriteAwaitingForm(t *testing.T) {
369369
} {
370370
result, err := session.CallTool(context.Background(), &mcp.CallToolParams{Name: tool, Arguments: args})
371371
require.NoError(t, err)
372-
require.True(t, result.IsError, tool)
373-
assert.Contains(t, getErrorResult(t, result).Text, "interactive form")
372+
require.False(t, result.IsError, tool)
373+
assert.Contains(t, getTextResult(t, result).Text, "interactive form")
374374
if protocol == inventory.ProtocolVersionMultiRoundTrip {
375375
require.NotNil(t, result.StructuredContent)
376376
assert.JSONEq(t, `{"status":"awaiting_user_submission","reason":"An interactive form is being shown to the user. The operation has not been performed."}`, mustMarshalJSON(t, result.StructuredContent))

‎pkg/utils/result.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ func NewToolResultResourceLink(message string, link *mcp.ResourceLink) *mcp.Call
6363
// NewToolResultAwaitingFormSubmission signals to the agent that a tool call
6464
// has been intercepted to show an MCP App form to the user and has NOT
6565
// performed the requested operation. The agent must stop, not chain dependent
66-
// tool calls, and not claim the operation succeeded. The result is marked
67-
// IsError=true so agents that bail on error don't proceed; the host still
68-
// renders the UI because rendering is keyed off the tool's _meta.ui, not the
69-
// result. The MCP App form will submit the operation directly when the user
70-
// clicks submit, after which a ui/update-model-context call delivers the real
66+
// tool calls, and not claim the operation succeeded. The result is not an
67+
// error because hosts exclude error results from MCP App rendering; the
68+
// pending state is carried by the message and by StructuredContent instead.
69+
// The MCP App form will submit the operation directly when the user clicks
70+
// submit, after which a ui/update-model-context call delivers the real
7171
// outcome to the agent.
7272
func NewToolResultAwaitingFormSubmission(message string) *mcp.CallToolResult {
7373
return &mcp.CallToolResult{
@@ -80,6 +80,6 @@ func NewToolResultAwaitingFormSubmission(message string) *mcp.CallToolResult {
8080
"status": "awaiting_user_submission",
8181
"reason": "An interactive form is being shown to the user. The operation has not been performed.",
8282
},
83-
IsError: true,
83+
IsError: false,
8484
}
8585
}

‎pkg/utils/result_test.go‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package utils //nolint:revive //TODO: figure out a better name for this package
2+
3+
import (
4+
"testing"
5+
6+
"github.com/modelcontextprotocol/go-sdk/mcp"
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
// A pending form is a successful handoff, not a failed tool call. Hosts drop
12+
// error results from MCP App rendering, so IsError here hides the form.
13+
func TestNewToolResultAwaitingFormSubmissionIsNotAnError(t *testing.T) {
14+
result := NewToolResultAwaitingFormSubmission("wait for the form")
15+
assert.False(t, result.IsError, "pending form handoff must not be an error result")
16+
require.Len(t, result.Content, 1)
17+
text, ok := result.Content[0].(*mcp.TextContent)
18+
require.True(t, ok)
19+
assert.Equal(t, "wait for the form", text.Text)
20+
payload, ok := result.StructuredContent.(map[string]any)
21+
require.True(t, ok)
22+
assert.Equal(t, "awaiting_user_submission", payload["status"])
23+
}

0 commit comments

Comments
 (0)