Skip to content

Conversation

@kpavlov
Copy link
Contributor

@kpavlov kpavlov commented Dec 3, 2025

Refactor StdioClientTransport to monitor STDERR

  1. The StdioClientTransport class has been enhanced to monitor the standard error (stderr) stream, enabling the detection of fatal errors that should terminate the connection.
  2. Refactored StdioClientTransport with structured concurrency - Proper cancellation propagation, resource cleanup, and error handling
    using coroutine flows and channels
  3. Added StderrSeverity enum (FATAL, WARNING, INFO, DEBUG, IGNORE)
    classification for flexible error handling
  4. Split client transport tests into focused classes (lifecycle, stderr, messages, error handling) with parameterized tests
    and in-memory streams
  5. StreamableHttpClientTransport now throws IllegalStateException when trying to send before initialization
  6. Improve CI test reporting

Motivation and Context

Fix for #107

How Has This Been Tested?

Regression tests, integration test added

Breaking Changes

  • StreamableHttpClientTransport now throws IllegalStateException when trying to send before initialization

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

@kpavlov kpavlov added bugfix Something was fixed 🎉 refactoring Making things better labels Dec 3, 2025
@kpavlov kpavlov force-pushed the kpavlov/#107-flows branch 2 times, most recently from cb03c52 to b486d61 Compare December 3, 2025 13:34
@kpavlov kpavlov changed the title #107 Refactor StdioClientTransport to use flows #107 Monitor STDERR and refactor StdioClientTransport to use flows Dec 3, 2025
@kpavlov kpavlov force-pushed the kpavlov/#107-flows branch from 3622a8f to f79acd4 Compare December 3, 2025 13:44
@kpavlov kpavlov marked this pull request as ready for review December 3, 2025 13:45
…ndling, and support for optional error stream. Update dependencies in `libs.versions.toml`.
@kpavlov kpavlov force-pushed the kpavlov/#107-flows branch 2 times, most recently from 7cddb91 to da60e7c Compare December 3, 2025 16:28
@github-actions
Copy link

github-actions bot commented Dec 3, 2025

TestsPassed ✅Skipped ⚠️FailedTime ⏱
JUnit Test Report3399 ran3310 passed89 skipped4m 32s 755ms
TestResultTime ⏱
No test annotations available

Replaced a boolean ` processStdError ` callback with `classifyStderr` that returns a `StderrSeverity` enum (FATAL, WARNING, INFO, DEBUG, IGNORE).

This allows fine-grained control over stderr message handling: FATAL terminates the transport, while other levels log at appropriate levels or discard messages. Updated KDoc with comprehensive documentation and usage examples.
Enhance `StdioClientTransportTest` with clean shutdown validation, error handling, and added assertions. Extend timeout for stability.
…p test suites, and avoid stack trace truncation.
@kpavlov kpavlov force-pushed the kpavlov/#107-flows branch from d4e1ba3 to 16da227 Compare December 3, 2025 16:45
@kpavlov kpavlov requested a review from skarpovdev December 3, 2025 17:01
@kpavlov kpavlov mentioned this pull request Dec 3, 2025
9 tasks
@kpavlov kpavlov requested review from sdubov and removed request for sdubov December 3, 2025 18:03
Copy link
Contributor

@e5l e5l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, please check minor comments

transport.onError { errorCalled = true }

transport.start()
delay(100.milliseconds)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runTest is using virtual time, please make sure the delay is used to skip virtual time and not real

} catch (e: McpException) {
logger.debug(e) { "Error while sending message: ${e.message}" }
throw e
} catch (e: Exception) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also handle CancellationException (and add a test);
Exception -> Throwable

handleJSONRPCMessage(event.message)
}

is Event.StderrEvent -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider extracting error handling to a separate method (for readability)

@kpavlov kpavlov merged commit 191b768 into main Dec 4, 2025
5 checks passed
@kpavlov kpavlov deleted the kpavlov/#107-flows branch December 4, 2025 07:18
kpavlov added a commit that referenced this pull request Dec 4, 2025
# Better exception handling in StdioClientTransport

Refactor `McpException` for improved handling with convenience
constructors and enhanced exception wrapping logic in
`StdioClientTransport`. Update tests to use `kotest` matchers and add
JUnit parameterized tests for exception handling.

## Motivation and Context
#442 follow up 

## How Has This Been Tested?
<!-- Have you tested this in a real application? Which scenarios were
tested? -->

## Breaking Changes
<!-- Will users need to update their code or configurations? -->

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] 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
<!-- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [ ] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [ ] 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
<!-- Add any other context, implementation notes, or design decisions
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Something was fixed 🎉 refactoring Making things better

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants