Skip to content

fix: Session not found — use stateless ADT sessions by default#79

Open
snymanpaul wants to merge 1 commit intooisee:mainfrom
snymanpaul:fix/stateless-session-default
Open

fix: Session not found — use stateless ADT sessions by default#79
snymanpaul wants to merge 1 commit intooisee:mainfrom
snymanpaul:fix/stateless-session-default

Conversation

@snymanpaul
Copy link
Copy Markdown

Summary

  • Default SessionType was SessionStateful, causing SAP ICF to return sap-contextid cookies bound to the first ADT endpoint (/core/discovery)
  • Subsequent requests to different endpoints (/datapreview/freestyle) failed with 400 "Session not found" because EDZ looked for the context ID in the wrong handler pool
  • All POST-based operations (RunQuery, GetTableContents) were broken; GET operations (SearchObject, GetSource) worked because they skip CSRF

Changes

  • server.go: Set WithSessionType(SessionStateless) — prevents sap-contextid while keeping MYSAPSSO2 + sap-XSRF for CSRF
  • http.go: IsSessionExpired() now matches "session not found" (EDZ's actual error text)
  • http.go: Session recovery clears cookie jar via replacement to discard stale cookies
  • http.go: setDefaultHeaders defaults to X-sap-adt-sessiontype: stateless
  • config.go: Cookie jar always created regardless of session type (needed for CSRF correlation)

Test plan

  • RunQuery works on first call (no prior session)
  • GetTableContents works on first call
  • SearchObject still works
  • GetSource still works
  • Sequential tool calls work without session errors
  • Stateful sessions (debugger) still work when explicitly configured

Root cause: NewConfig defaulted to SessionStateful, which made SAP ICF
return sap-contextid cookies. These cookies bound the session to the
first ADT endpoint (/core/discovery). When subsequent requests went to
different endpoints (/datapreview/freestyle), EDZ looked for the context
ID in the wrong session pool → "Session not found" (400).

Fixes:
1. server.go: Set WithSessionType(SessionStateless) for MCP server —
   prevents sap-contextid from being issued while keeping MYSAPSSO2
   and sap-XSRF cookies for CSRF correlation
2. http.go: IsSessionExpired() now matches "session not found" (EDZ's
   actual error text, previously only matched "session timed out")
3. http.go: Session recovery clears cookie jar to discard stale cookies
4. http.go: setDefaultHeaders defaults to stateless session type
5. config.go: Cookie jar always created (needed for CSRF correlation)
   regardless of session type

Symptoms: Every second MCP tool call failed with 400 "Session not found".
GET-only operations (SearchObject, GetSource) worked because they don't
need CSRF. POST operations (RunQuery, GetTableContents) always failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant