Skip to content

fix(mcp): handle nil request bodies in decodeJSON and search_now (#206) - #207

Closed
Yshuro wants to merge 1 commit into
rdborg:mainfrom
Yshuro:fix/issue-206
Closed

Yshuro wants to merge 1 commit into
rdborg:mainfrom
Yshuro:fix/issue-206

Conversation

@Yshuro

@Yshuro Yshuro commented Nov 21, 2026

Copy link
Copy Markdown

What does this change?

  • Tolerates nil request bodies in decodeJSON by checking if r.Body == nil { return io.EOF } before calling defer r.Body.Close().
  • Updates planSearchNow for series_ids targets to pass an empty JSON body map[string]any{} when calling /api/series/{id}/search-now.
  • Adds unit tests in respond_internal_test.go and mcp_test.go.
  • Adds an entry to CHANGELOG.md under [Unreleased].

Why?

Fixes #206

When the MCP tool search_now is called with series_ids and confirm: true, it calls /api/series/{id}/search-now with a nil body. In handleSeriesSearchNow, decodeJSON(r, &req) is called; since r.Body was nil, defer r.Body.Close() panicked with runtime error: invalid memory address or nil pointer dereference.

How did you test it?

  • Verified with go test -v ./internal/api -run "TestMCPAddTitles|TestDecodeJSONNilBody": both pass cleanly.
  • Verified formatting with gofmt -l . (no output).
  • Verified go vet ./internal/api (clean).
  • Verified go run ./tools/docgen -check and go run ./tools/msgextract -check pass.

Checklist

  • go test ./... passes and gofmt -l . prints nothing
  • Web changes: npm run lint, npm test and npm run build pass in web/
  • Tests added or updated for changed logic
  • Matching page in docs/ updated, and a line added to CHANGELOG.md under "Unreleased"
  • Changed a route, environment variable or setting? Ran go run ./tools/docgen and committed the result
  • Screenshots attached for visible changes
  • No API keys, passwords or personal data in code, logs, tests or screenshots

@rdborg

rdborg commented Nov 23, 2026

Copy link
Copy Markdown
Owner

@Yshuro thank you for this. The same crash is fixed in 4.1.1, a bit more widely (an empty request body is accepted everywhere, not only in this one tool), so I'm closing this pull request. Your fix is credited on the community page. Much appreciated, and pull requests are always welcome.

@rdborg rdborg closed this Nov 23, 2026
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.

MCP search_now crashes (nil pointer) with series_ids

2 participants