Skip to content

GET /fmsg/search: define the optional search contract; answer 501 - #70

Open
markmnl wants to merge 2 commits into
mainfrom
search-endpoint
Open

markmnl wants to merge 2 commits into
mainfrom
search-endpoint

Conversation

@markmnl

@markmnl markmnl commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Defines GET /fmsg/search as an optional endpoint: the route, its delegated OAuth scope and the response shapes, documented in the README, so that clients can rely on one contract. This server doesn't implement search: it answers 501 Not Implemented to a signed-in caller and 401 otherwise. A deployment that indexes message text can implement it.

Before this change, /fmsg/search fell through to GET /fmsg/:id and answered 400 "invalid message id".

Changes

  • cmd/fmsg-webapi/main.go: fmsg.GET("/search", msgHandler.Search), registered before /:id.
  • internal/middleware/oauth.go: GET /fmsg/search requires fmsg:read.
  • internal/handlers/search.go: the contract types and a Search handler that answers 501.
  • README: an endpoint-table row and a GET /fmsg/search section. It covers:
    • query parameters: q, sort, files, unread, scope, trash, limit, offset;
    • the response: total, next_offset, terms, threads with match, and messages;
    • the 503 answer when a search runs too long;
    • a note to keep q out of logs.
  • The README also specifies that a q with no words (only punctuation) answers 200 with no threads. That gives clients a cheap way to tell whether a server implements search: 200 means yes, 501/404 means no.

Testing

  • New cmd/fmsg-webapi/search_route_test.go: 501 when signed in, 401 when not, and the request reaches the search handler rather than GET /fmsg/:id.
  • go vet ./... and go test ./... pass.

🤖 Generated with Claude Code

Adds the route, its delegated OAuth scope (fmsg:read) and the response
shapes for an optional thread search, documented in the README, so clients
can rely on one contract. This server does not implement it and answers
501 Not Implemented to an authenticated caller. Before, the path fell
through to GET /fmsg/:id and answered 400 "invalid message id".

A q with no words (only punctuation) is specified to answer 200 with no
threads, which gives clients a cheap way to tell whether a server
implements search.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@markmnl markmnl left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I checked the contract against a working implementation of this endpoint. The parameters, defaults, 400/503 answers and response fields all match, so clients written to this README will work against it. One fix and a few clarifications:

1. Client guidance should include 400 (fix). The README tells clients to treat `501` "(or `404` from older servers)" as "search is not available". But as this PR's own description says, servers before this change route `/fmsg/search` to `GET /fmsg/:id` and answer 400 "invalid message id", not 404. Suggest: "Clients should treat `501`, or `400`/`404` from servers that predate this endpoint, as search not being available." (markmnl/fmsg-mcp#39 already treats 400 that way in its probe.)

2. Document the probe. The "`q` with no words answers `200`" rule is the cheap support check. It's worth saying so outright, with the exact request, e.g. "To check whether a server implements search, request `GET /fmsg/search?q=-&limit=1`: 200 means yes." Then clients don't each invent a different probe.

3. Smaller clarifications:

  • `messages`: it says reactions are left out. Are FMSG-008 edit messages left out too? The fmsg-mcp client filters them out itself, which suggests they might appear. Worth stating either way.
  • `limit`: "at most 50": is a larger value clamped to 50, or a 400? The implementation I checked clamps.
  • `match.field: to`: does it include recipients added later (add-to)?
  • `trash=exclude`: `messages` includes trashed messages "so the thread can be grouped". Say explicitly that clients should leave them out of counts and previews unless `trash=only`. Otherwise unread counts include deleted messages (see my comment on fmsg-mcp#39).

4. Nits, no change needed:

  • `searchMatch`/`searchThread`/`searchResponse` are unused in this server. `go vet` is fine with that, but staticcheck's U1000 would flag them if it's ever added. A one-line `var _ = searchResponse{}`, or a comment that they're the contract, would keep it quiet.
  • The handler-level 401 is redundant behind the JWT middleware in production, but it keeps the route test meaningful. Fine as is.

- Clients treat 501, or 400/404 from servers predating the endpoint, as no
  search; document the q=- probe.
- limit above 50 is treated as 50; match field to includes added recipients.
- messages include edit and trashed messages for grouping; clients leave them
  out of counts unless trash=only.
- Keep the contract types referenced so unused-code checks stay quiet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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