fix: return handler errors and panics as tool results (#230)

Fixes https://gitea.com/gitea/gitea-mcp/issues/229

https://gitea.com/gitea/gitea-mcp/pulls/227 left an unexpected handler error and a recovered panic as JSON-RPC errors, which tell the client the request itself failed and kill the session, as in https://gitea.com/gitea/gitea-mcp/issues/229. Both now return tool results.
Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/230
Reviewed-by: bircni <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
silverwind
2026-08-09 10:09:14 +00:00
committed by bircni
parent 75f1adf979
commit e81df2d9a0
3 changed files with 43 additions and 18 deletions
+19
View File
@@ -233,6 +233,24 @@ func rpcErrorCode(t *testing.T, response rawRPCResponse) int {
return wire.Error.Code
}
// Regression test for https://gitea.com/gitea/gitea-mcp/issues/229
func callMissingRequiredArgument(ctx context.Context, t *testing.T, session *mcp.ClientSession) {
t.Helper()
result, err := session.CallTool(ctx, &mcp.CallToolParams{
Name: "search_issues",
Arguments: map[string]any{"state": "open"},
})
if err != nil {
t.Fatalf("CallTool() error = %v, want a tool result", err)
}
if !result.IsError {
t.Errorf("IsError = false, want true for a call without the required query")
}
if got := textContent(t, result); !strings.Contains(got, "query is required") {
t.Errorf("result = %q, want it to name the missing argument", got)
}
}
func TestOfficialSDKInMemory(t *testing.T) {
exposeAllTools(t)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
@@ -256,6 +274,7 @@ func TestOfficialSDKInMemory(t *testing.T) {
}
assertToolsOnlyCapabilities(t, session.InitializeResult().Capabilities)
listAndCallVersion(ctx, t, session, testServerVersion)
callMissingRequiredArgument(ctx, t, session)
if err := session.Close(); err != nil {
t.Fatalf("Close() error = %v", err)
}