Files
Matt Godbolt 4dea56e84f MCP: CORS for /mcp, defensive list_libraries, non-mutating getSafeHash
Three findings from a fresh code review on the PR:

- /mcp now goes through the existing cors middleware (same one applied
  to /api by routes-setup.ts) and gains an OPTIONS preflight handler.
  Current MCP clients aren't browsers so this doesn't fix anything live,
  but it brings the new endpoint in line with prior CORS-centralisation
  work and unblocks browser-hosted MCP clients in future.

- list_libraries now wraps the apiHandler.getLibrariesAsArray call in a
  try/catch. The underlying ApiHandler throws via unwrap() if options
  haven't been loaded yet (brief startup window before setOptions runs).
  The HTTP /api handler already guards this; the MCP path didn't, so a
  request landing in that window would surface as an opaque internal
  error rather than a structured MCP isError response. Test added that
  pokes the error path with a throwing fake apiHandler.

- getSafeHash no longer mutates its input. It used to set
  config.nonce = tries directly on the caller's object when the
  profanity-rehash loop ran. No caller relies on the mutation (the
  nonce reaches storage via the returned config string, not via the
  input object), but the side effect was easy to miss now that the
  function is exported at module scope. Shallow clone at the top
  removes the surprise; observable behaviour for callers is unchanged.

A comment was also added to createMcpServer noting that the captured
req object is safe to thread through tool callbacks because the SDK is
in stateless mode and handleRequest resolves before the route handler
exits.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 15:24:35 -04:00
..
2021-10-05 01:45:05 +02:00
2019-08-21 01:26:16 +02:00
2025-01-29 10:41:03 -06:00
2021-09-13 20:22:27 +02:00
2024-10-27 15:28:38 +02:00
2024-10-26 17:42:22 +02:00
2024-03-08 22:25:09 -06:00
2024-03-08 22:25:09 -06:00
2024-03-08 22:25:09 -06:00
2026-02-08 12:50:20 +01:00
2024-03-08 22:25:09 -06:00
2024-03-08 22:25:09 -06:00
2025-07-28 10:34:46 -05:00