diff --git a/docs/error-handling.md b/docs/error-handling.md index d483ebdec2..f043960e02 100644 --- a/docs/error-handling.md +++ b/docs/error-handling.md @@ -68,10 +68,11 @@ Ordinary API and validation errors never expose the SDK-generated zero-value structured output. Handler-provided structured statuses are distinct from generated error output. -For example, `issue_write` can return `IsError: true` with -`status: "awaiting_user_submission"` while an MCP App form is pending. Modern -clients retain that explicit status and its reason; legacy clients retain the -stop message and error flag without structured content. This status does not +For example, `issue_write` can return a non-error result with +`status: "awaiting_user_submission"` while an MCP App form is pending. The +result is not an error because hosts exclude error results from MCP App +rendering. Modern clients retain that explicit status and its reason; legacy +clients retain the stop message without structured content. This status does not mean the issue was created or updated. The output schema includes a strict status variant alongside the mutation's `id`/`url` variant. Multi-round-trip `InputRequests` continue to pass through unchanged. diff --git a/pkg/github/issues.go b/pkg/github/issues.go index 30005854aa..be3a60af4b 100644 --- a/pkg/github/issues.go +++ b/pkg/github/issues.go @@ -2656,10 +2656,10 @@ var issueWriteFormParams = map[string]struct{}{ // issueWriteAwaitingFormResult builds the "awaiting form submission" stub // returned when issue_write hands off to the MCP App form. The body is shared -// by IssueWrite and LegacyIssueWrite. The result is marked IsError=true so -// agents that bail on error don't claim success or chain dependent tool calls -// while the user is still interacting with the form; the host renders the UI -// regardless because rendering is keyed off the tool's _meta.ui resourceUri. +// by IssueWrite and LegacyIssueWrite. The result is not an error because hosts +// exclude error results from MCP App rendering; the stop message and the +// structured status keep the handoff pending so agents don't claim success or +// chain dependent tool calls while the user is still interacting with the form. func issueWriteAwaitingFormResult(method, owner, repo string, issueNumber int) *mcp.CallToolResult { var msg string if method == "update" { @@ -2876,6 +2876,9 @@ Options are: Reason: "An interactive form is being shown to the user. The operation has not been performed.", } result.StructuredContent = output + // Keep the stop message in text; modern clients replace text + // with structured JSON unless the handler content is preserved. + inventory.PreserveToolHandlerContent(ctx) return result, &IssueWriteOutput{Method: method, Awaiting: output}, nil } diff --git a/pkg/github/issues_test.go b/pkg/github/issues_test.go index 79eeb22100..d59e90b87e 100644 --- a/pkg/github/issues_test.go +++ b/pkg/github/issues_test.go @@ -2232,7 +2232,7 @@ func Test_IssueWrite_MCPAppsFeature_UIGate(t *testing.T) { textContent := getTextResult(t, result) assert.Contains(t, textContent.Text, "interactive form has been shown to the user for creating a new issue") - assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success") + assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form") }) 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) { textContent := getTextResult(t, result) assert.Contains(t, textContent.Text, "interactive form has been shown to the user for editing issue #1", "state change should route through UI form") - assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success") + assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form") }) 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) { textContent := getTextResult(t, result) assert.Contains(t, textContent.Text, "interactive form has been shown to the user for editing issue #1", "update without state should show UI form") - assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success") + assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form") }) 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) { textContent := getTextResult(t, result) assert.Contains(t, textContent.Text, "interactive form has been shown to the user for creating a new issue", "issue_fields should route through UI form") - assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success") + assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form") }) 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) { textContent := getTextResult(t, result) assert.Contains(t, textContent.Text, "interactive form has been shown to the user for creating a new issue", "labels should route through UI form") - assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success") + assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form") }) } diff --git a/pkg/github/pullrequests.go b/pkg/github/pullrequests.go index 7f9e337d38..35de2a9d72 100644 --- a/pkg/github/pullrequests.go +++ b/pkg/github/pullrequests.go @@ -783,6 +783,7 @@ func CreatePullRequest(t translations.TranslationHelperFunc) inventory.ServerToo return nil, nil, err } if shouldDeferToForm(ctx, deps, req, formArgs, pullRequestWriteFormParams) { + inventory.PreserveToolHandlerContent(ctx) return pullRequestAwaitingFormResult(fmt.Sprintf( "An interactive form has been shown to the user for creating a new pull request in %s/%s. "+ "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 return nil, nil, err } if shouldDeferToForm(ctx, deps, req, formArgs, pullRequestUpdateFormParams) { + inventory.PreserveToolHandlerContent(ctx) return pullRequestAwaitingFormResult(fmt.Sprintf( "An interactive form has been shown to the user for editing pull request #%d in %s/%s. "+ "STOP — do not call any other tools, do not respond as if the pull request was updated, "+ diff --git a/pkg/github/pullrequests_test.go b/pkg/github/pullrequests_test.go index 2241598eda..9479347f4c 100644 --- a/pkg/github/pullrequests_test.go +++ b/pkg/github/pullrequests_test.go @@ -3060,7 +3060,7 @@ func Test_CreatePullRequest_MCPAppsFeature_UIGate(t *testing.T) { textContent := getTextResult(t, result) assert.Contains(t, textContent.Text, "interactive form has been shown to the user for creating a new pull request") - assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success") + assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form") }) 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) { // Test_UpdatePullRequest_MCPAppsFeature_UIGate verifies the form-routing // behavior for update_pull_request: UI clients without _ui_submitted get a -// pending-form stub (marked IsError so agents don't claim success), UI clients +// pending-form stub (a non-error result so hosts render the form), UI clients // with _ui_submitted execute directly, non-UI clients execute directly, and // UI clients carrying non-form params bypass the form. func Test_UpdatePullRequest_MCPAppsFeature_UIGate(t *testing.T) { @@ -3161,7 +3161,7 @@ func Test_UpdatePullRequest_MCPAppsFeature_UIGate(t *testing.T) { textContent := getTextResult(t, result) assert.Contains(t, textContent.Text, "interactive form has been shown to the user for editing pull request #42") - assert.True(t, result.IsError, "form-routing stub should be marked IsError so agents don't claim success") + assert.False(t, result.IsError, "form-routing stub must not be an error so hosts render the form") }) t.Run("UI client with _ui_submitted executes directly", func(t *testing.T) { diff --git a/pkg/github/typed_consolidated_issue_outputs_test.go b/pkg/github/typed_consolidated_issue_outputs_test.go index 60374e10cb..f47d89f882 100644 --- a/pkg/github/typed_consolidated_issue_outputs_test.go +++ b/pkg/github/typed_consolidated_issue_outputs_test.go @@ -353,10 +353,10 @@ func TestTypedIssueWriteAwaitingForm(t *testing.T) { args := map[string]any{"method": method, "owner": "owner", "repo": "repo", "issue_number": "1", "title": "Subject"} result, err := session.CallTool(context.Background(), &mcp.CallToolParams{Name: "issue_write", Arguments: args}) require.NoError(t, err) - require.True(t, result.IsError) + require.False(t, result.IsError) require.Len(t, result.Content, 1) - assert.Contains(t, getErrorResult(t, result).Text, "interactive form has been shown") - assert.Contains(t, getErrorResult(t, result).Text, "NOT been") + assert.Contains(t, getTextResult(t, result).Text, "interactive form has been shown") + assert.Contains(t, getTextResult(t, result).Text, "NOT been") if protocol == inventory.ProtocolVersionMultiRoundTrip { require.NotNil(t, result.StructuredContent) 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)) diff --git a/pkg/github/typed_consolidated_pull_request_outputs_test.go b/pkg/github/typed_consolidated_pull_request_outputs_test.go index 4c0a76aa8f..331e4f3727 100644 --- a/pkg/github/typed_consolidated_pull_request_outputs_test.go +++ b/pkg/github/typed_consolidated_pull_request_outputs_test.go @@ -369,8 +369,8 @@ func TestTypedPullRequestWriteAwaitingForm(t *testing.T) { } { result, err := session.CallTool(context.Background(), &mcp.CallToolParams{Name: tool, Arguments: args}) require.NoError(t, err) - require.True(t, result.IsError, tool) - assert.Contains(t, getErrorResult(t, result).Text, "interactive form") + require.False(t, result.IsError, tool) + assert.Contains(t, getTextResult(t, result).Text, "interactive form") if protocol == inventory.ProtocolVersionMultiRoundTrip { require.NotNil(t, result.StructuredContent) 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)) diff --git a/pkg/utils/result.go b/pkg/utils/result.go index 99c37602bc..cfe3e90ca4 100644 --- a/pkg/utils/result.go +++ b/pkg/utils/result.go @@ -63,11 +63,11 @@ func NewToolResultResourceLink(message string, link *mcp.ResourceLink) *mcp.Call // NewToolResultAwaitingFormSubmission signals to the agent that a tool call // has been intercepted to show an MCP App form to the user and has NOT // performed the requested operation. The agent must stop, not chain dependent -// tool calls, and not claim the operation succeeded. The result is marked -// IsError=true so agents that bail on error don't proceed; the host still -// renders the UI because rendering is keyed off the tool's _meta.ui, not the -// result. The MCP App form will submit the operation directly when the user -// clicks submit, after which a ui/update-model-context call delivers the real +// tool calls, and not claim the operation succeeded. The result is not an +// error because hosts exclude error results from MCP App rendering; the +// pending state is carried by the message and by StructuredContent instead. +// The MCP App form will submit the operation directly when the user clicks +// submit, after which a ui/update-model-context call delivers the real // outcome to the agent. func NewToolResultAwaitingFormSubmission(message string) *mcp.CallToolResult { return &mcp.CallToolResult{ @@ -80,6 +80,6 @@ func NewToolResultAwaitingFormSubmission(message string) *mcp.CallToolResult { "status": "awaiting_user_submission", "reason": "An interactive form is being shown to the user. The operation has not been performed.", }, - IsError: true, + IsError: false, } } diff --git a/pkg/utils/result_test.go b/pkg/utils/result_test.go new file mode 100644 index 0000000000..8636a5ea50 --- /dev/null +++ b/pkg/utils/result_test.go @@ -0,0 +1,23 @@ +package utils //nolint:revive //TODO: figure out a better name for this package + +import ( + "testing" + + "github.com/modelcontextprotocol/go-sdk/mcp" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// A pending form is a successful handoff, not a failed tool call. Hosts drop +// error results from MCP App rendering, so IsError here hides the form. +func TestNewToolResultAwaitingFormSubmissionIsNotAnError(t *testing.T) { + result := NewToolResultAwaitingFormSubmission("wait for the form") + assert.False(t, result.IsError, "pending form handoff must not be an error result") + require.Len(t, result.Content, 1) + text, ok := result.Content[0].(*mcp.TextContent) + require.True(t, ok) + assert.Equal(t, "wait for the form", text.Text) + payload, ok := result.StructuredContent.(map[string]any) + require.True(t, ok) + assert.Equal(t, "awaiting_user_submission", payload["status"]) +}