@@ -140,15 +140,26 @@ func (p *Proxy) CallTool(ctx context.Context, caller CallerContext, name string,
140140
141141 result, err := p.callUpstreamWithRetry(ctx, name, args)
142142
143- if accountStore != nil && result != nil && !result.IsError {
144- p.interceptAuthTools(name, arguments, result)
143+ if result != nil {
144+ if !result.IsError && accountStore != nil {
145+ p.interceptAuthTools(name, arguments, result)
146+ }
147+ if result.IsError {
148+ // Rewrite error messages to guide myses toward correct behavior
149+ for i := range result.Content {
150+ if result.Content[i].Type == "text" {
151+ result.Content[i].Text = p.rewriteSessionError(result.Content[i].Text)
152+ }
153+ }
154+ }
145155 }
146156
147157 return result, err
148158 }
149159
160+ errorMsg := fmt.Sprintf("tool not found: %s", name)
150161 return &ToolResult{
151- Content: []ContentBlock{{Type: "text", Text: fmt.Sprintf("tool not found: %s", name)}},
162+ Content: []ContentBlock{{Type: "text", Text: p.rewriteSessionError(errorMsg)}},
152163 IsError: true,
153164 }, nil
154165 }
@@ -335,6 +346,32 @@ func findStringFieldAtPath(payload interface{}, path ...string) (string, bool) {
335346 return "", false
336347 }
337348
349+// rewriteSessionError improves session-related error messages to guide myses
350+// toward correct behavior instead of causing claim→login loops.
351+func (p *Proxy) rewriteSessionError(errorMsg string) string {
352+ // Handle session_required errors
353+ if strings.Contains(errorMsg, "session_required") {
354+ // Original: "You must provide a session_id. Get one by calling login() or register() first."
355+ // Problem: Tells mysis to login again even if they already have session_id
356+ return strings.Replace(errorMsg,
357+ "Get one by calling login() or register() first.",
358+ "Check your recent tool results for session_id from login/register and use it as a parameter.",
359+ 1)
360+ }
361+
362+ // Handle session_invalid errors
363+ if strings.Contains(errorMsg, "session_invalid") {
364+ // Original: "Call login() again to get a new session_id."
365+ // This is actually correct - session truly expired
366+ // But add clarity about when this happens
367+ if strings.Contains(errorMsg, "Session not found or expired") {
368+ return errorMsg + " This means your session truly expired (server restart, timeout, or duplicate login)."
369+ }
370+ }
371+
372+ return errorMsg
373+}
374+
338375 // Initialize initializes the upstream connection if available.
339376 func (p *Proxy) Initialize(ctx context.Context) error {
340377 if p.upstream == nil {