Skip to content

refactor: codebase cleanup and consistency improvements#5

Merged
scalvert merged 7 commits into
mainfrom
refactor/codebase-cleanup
Jan 26, 2026
Merged

refactor: codebase cleanup and consistency improvements#5
scalvert merged 7 commits into
mainfrom
refactor/codebase-cleanup

Conversation

@scalvert

Copy link
Copy Markdown
Owner

Summary

A comprehensive cleanup pass addressing code consistency, library usage, and build configuration issues.

Changes

  • Rename flexsearch-indexer → flexsearch-core - Avoid confusion with the provider class in src/providers/indexers/
  • Use hast-util-to-html library - Replace ~70 lines of hand-rolled HTML serialization
  • Refactor tool definitions - Make tool files the single source of truth with Zod schemas; server imports definitions
  • Unify CORS handling - Add shared CORS utility; all adapters now handle CORS consistently
  • Fix build warnings - Resolve mixed exports warning and unused import warning
  • Update README - Document correct 2-tool API (docs_search, docs_fetch)

Commits

Each commit is atomic and addresses one logical change:

  1. refactor: rename flexsearch-indexer.ts to flexsearch-core.ts
  2. refactor: use hast-util-to-html for HTML serialization
  3. refactor: make tool definitions complete and import into server
  4. refactor: unify CORS handling across all adapters
  5. fix: resolve build warnings for exports and externals
  6. docs: update README with correct 2-tool API

Test plan

  • npm run build completes without warnings
  • npm run typecheck passes
  • npm test - all 51 unit tests pass
  • npm run test:mcp - all 11 MCP integration tests pass

🤖 Generated with Claude Code

scalvert and others added 6 commits January 26, 2026 09:36
Rename src/search/flexsearch-indexer.ts to flexsearch-core.ts to avoid
confusion with the provider class in src/providers/indexers/flexsearch-indexer.ts.

Also fixes outdated comment that incorrectly stated docs are "keyed by route"
when they are actually keyed by full URL.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace ~70 lines of hand-rolled HTML serialization with the
hast-util-to-html library. This is more maintainable and handles
edge cases correctly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactor MCP tool files to be the single source of truth for tool
definitions:

- Add Zod schemas for input validation in each tool file
- Export complete tool definitions (name, description, inputSchema)
- Update server.ts to import and use tool definitions from tool files
- Keep execution logic and formatters in their respective tool files

This makes the tool definitions self-contained and ensures the server
always uses the canonical definitions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create shared CORS utility in src/adapters/cors.ts
- Add CORS headers and OPTIONS handling to Vercel adapter
- Add CORS headers and OPTIONS handling to Netlify adapter
- Update Cloudflare adapter to use shared CORS utility

Previously only the Cloudflare adapter had CORS support. Now all
platform adapters handle CORS consistently.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Fix two build warnings:

1. Mixed exports warning: Remove default export from src/index.ts,
   only use named export 'mcpServerPlugin'. This avoids CJS/ESM
   interop issues where consumers would need .default access.

2. Unused createServer warning: Export createNodeServer and
   createNodeHandler from adapters-entry.ts so they're actually
   used and not tree-shaken away.

Also:
- Simplify theme/index.ts to only use named exports
- Add Node.js built-ins to tsup externals (node:*, http, fs, path)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update README to accurately reflect the current implementation:

- Document docs_search and docs_fetch tools (was showing 3 tools)
- Update API reference exports section
- Fix local development example
- Add note about CORS support in adapters

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@scalvert scalvert added documentation Improvements or additions to documentation enhancement New feature or request labels Jan 26, 2026
@scalvert

Copy link
Copy Markdown
Owner Author

Code review

Found 1 issue:

  1. Vercel adapter incorrectly merges CORS headers into JSON response body (bug: inconsistent CORS handling within the same file)

In src/adapters/vercel.ts, the GET health check endpoint merges CORS headers into the JSON body instead of setting them as HTTP headers:

return res.status(200).json({ ...status, ...corsHeaders });

This is inconsistent with how CORS is handled elsewhere in the same file:

  • Line 59: res.writeHead(204, corsHeaders) - correctly sets HTTP headers for OPTIONS
  • Lines 73-75: res.setHeader() - correctly sets HTTP headers for 405 errors
  • Lines 88-90: res.setHeader() - correctly sets HTTP headers for POST requests

The fix should set CORS headers via res.setHeader() before returning the JSON response, similar to lines 88-90.

// Handle GET requests for health check
if (req.method === 'GET') {
const mcpServer = getServer();
const status = await mcpServer.getStatus();
return res.status(200).json({ ...status, ...corsHeaders });
}


Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

Fix bug where CORS headers were incorrectly merged into the JSON
response body instead of being set as HTTP headers. This was
inconsistent with how CORS is handled elsewhere in the same file.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@scalvert
scalvert merged commit 481a668 into main Jan 26, 2026
8 checks passed
@scalvert
scalvert deleted the refactor/codebase-cleanup branch January 26, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant