Skip to content

Fix MCP server authentication and logging issues#12

Merged
rafalzawadzki merged 1 commit intomainfrom
rafalzawadzki/fix-mcp-auth-logging
Feb 23, 2026
Merged

Fix MCP server authentication and logging issues#12
rafalzawadzki merged 1 commit intomainfrom
rafalzawadzki/fix-mcp-auth-logging

Conversation

@rafalzawadzki
Copy link
Contributor

Summary

Fixed two critical issues with the Cloudflare Worker MCP server preventing proper authentication and exposing sensitive data in logs.

Issue 1 – Claude Code shows "Authenticate" button: The transport was using SSE streaming responses, but server.close() in the finally block terminated the stream before data was delivered. Now uses JSON response mode where responses are fully formed before cleanup.

Issue 2 – API key leaked in error logs: Debug logging exposed the first/last 4 characters of the API key (sd_a...f7c5) and was logged at error level in Cloudflare. Now only logs key length at log level, and removed environment status leaks from error responses.

Changes

  • src/worker.ts: Enable enableJsonResponse: true, handle GET/DELETE before transport creation (return 405), remove API key logging, change console.error to console.warn for missing keys, clean up error responses
  • src/mcp.ts: Change informational trace from console.error to console.log (line 9)
  • package.json: Bump version to 1.2.2

Testing

Verified locally with curl against wrangler dev:

  • initialize → proper JSON-RPC response with capabilities
  • tools/list → all 9 tools returned
  • tools/call → reaches Supadata API successfully
  • GET / → health check 200
  • GET /mcp → 405 (method not allowed, not confusing errors)
  • All 14 existing Jest tests pass

🤖 Generated with Claude Code

- Enable JSON response mode to prevent SSE stream termination by server.close()
- Handle GET/DELETE requests before transport creation (return 405 instead of confusing errors)
- Remove API key prefix/suffix from error logs (security fix)
- Change informational traces from console.error to console.log
- Simplify error responses without leaking environment status

This fixes Claude Code's "Authenticate" button showing up and "Failed to reconnect" errors.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
supadata-mcp 013cf8b Feb 23 2026, 11:02 PM

@rafalzawadzki rafalzawadzki merged commit fbf6f0e into main Feb 23, 2026
2 checks passed
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