Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(StdioClientTransport): fix error during typescript-server-sdk using console.log api #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

weiyuc
Copy link

@weiyuc weiyuc commented Apr 24, 2025

while (!isClosing && (line = processReader.readLine()) != null) {
    try {
        JSONRPCMessage message = McpSchema.deserializeJsonRpcMessage(this.objectMapper, line);
        if (!this.inboundSink.tryEmitNext(message).isSuccess()) {
	        if (!isClosing) {
		        logger.error("Failed to enqueue inbound message: {}", message);
	        }
	        break;
        }
        }
        catch (Exception e) {
        if (e instanceof JacksonException) {
	        // in typescript-server-sdk, console.log will use stdout, so ignore
	        logger.debug(line);
	        continue;
        }
        if (!isClosing) {
	        logger.error("Error processing inbound message for line: " + line, e);
        }
        break;
    }
}

Motivation and Context

How Has This Been Tested?

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@see #196

@tzolov
Copy link
Contributor

tzolov commented May 7, 2025

Hey @weiyuc , can you please explain how to reproduce the issue you're trying to solve?

@chemicL
Copy link
Member

chemicL commented May 7, 2025

Personally, I am against this change. Ignoring malformed JSON data is not part of the specification. It looks like a server issue which breaks the contract of sending JSON-RPC messages over the pipe. Please report the error against the typescript-sdk.

@weiyuc
Copy link
Author

weiyuc commented May 9, 2025

Hey @weiyuc , can you please explain how to reproduce the issue you're trying to solve?

thanks for your reply, I provided a demo to reproduce the issue.
if you run the app, the console will print error:
image

this is the mcp server code:

#!/usr/bin/env node
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'

async function runServer() {
  const transport = new StdioServerTransport()

  const server = new McpServer({
    name: 'proof-demo',
    version: '1.0.0'
  })

  server.tool('get_current_time', () => ({
    content: [
      {
        type: 'text',
        text: new Date().toISOString()
      }
    ]
  }))
  // if remove the log, mcp client will start successful
  console.log('server started...')

  await server.connect(transport)
}

runServer()

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.

3 participants