Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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")
})
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/github/pullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "+
Expand Down Expand Up @@ -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, "+
Expand Down
6 changes: 3 additions & 3 deletions pkg/github/pullrequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/github/typed_consolidated_issue_outputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions pkg/github/typed_consolidated_pull_request_outputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 6 additions & 6 deletions pkg/utils/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
}
}
23 changes: 23 additions & 0 deletions pkg/utils/result_test.go
Original file line number Diff line number Diff line change
@@ -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"])
}