fix: improve MCP server logging and transport reliability#84
Open
dionlow wants to merge 4 commits into
Open
Conversation
…uption Replace all console.log() calls with logger.info() using stderr (console.error) to prevent JSON-RPC protocol corruption in stdio transport. Console.log writes to stdout which interferes with MCP protocol messages, causing JSON parsing errors in Claude Desktop. Changes: - Add logger utility to mcp-server and sdk packages - Replace console.log with logger.info in all source files - Replace console.error with logger.error for consistency - All logs now include timestamps and structured formatting Fixes errors like: - "Unexpected token 'C', 'Connecting'... is not valid JSON" - "Unexpected token 'W', '[WRITE]'... is not valid JSON" - "Unexpected token 'A', '[Ampersand]'... is not valid JSON" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Logger methods (info, error, warn, debug) accept only 2 parameters (message and optional data), but were being called with 3-4 arguments causing TypeScript errors. Consolidated multiple arguments into objects for the data parameter. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Export logger from sdk/lib/adapters/mcp.ts for use by mcp-server - Update all mcp-server files to import logger from @amp-labs/ai/mcp - Remove duplicate mcp-server/src/logger.ts file - Make providerWorkspaceRef optional in ClientSettings type - Improve providerWorkspaceRef handling with proper fallback logic This eliminates code duplication, ensures consistency across packages, and reduces maintenance burden. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add Error object handling in logger to preserve stack traces - Add try-catch around JSON.stringify to handle circular references - Remove unused logger import from write.ts - Move logger re-export after imports for better organization 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Contributor
Author
|
split from previous branch that was reverted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Details
MCP Protocol Fix
The MCP protocol uses stdio for JSON-RPC communication. Using
console.logwrites to stdout, which corrupts the protocol. This PR fixes the issue by:console.error(stderr) for all loggingLogger Improvements
Code Quality
Test plan
🤖 Generated with Claude Code