Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ public class StdioClientTransport implements McpClientTransport {
/** The server process being communicated with */
private Process process;

private McpJsonMapper jsonMapper;
private final McpJsonMapper jsonMapper;

/** Scheduler for handling inbound messages from the server process */
private Scheduler inboundScheduler;
private final Scheduler inboundScheduler;

/** Scheduler for handling outbound messages to the server process */
private Scheduler outboundScheduler;
private final Scheduler outboundScheduler;

/** Scheduler for handling error messages from the server process */
private Scheduler errorScheduler;
private final Scheduler errorScheduler;

/** Parameters for configuring and starting the server process */
private final ServerParameters params;
Expand Down Expand Up @@ -180,7 +180,7 @@ public void awaitForExit() {
private void startErrorProcessing() {
this.errorScheduler.schedule(() -> {
try (BufferedReader processErrorReader = new BufferedReader(
new InputStreamReader(process.getErrorStream()))) {
new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8))) {
String line;
while (!isClosing && (line = processErrorReader.readLine()) != null) {
try {
Expand Down Expand Up @@ -246,7 +246,8 @@ public Mono<Void> sendMessage(JSONRPCMessage message) {
*/
private void startInboundProcessing() {
this.inboundScheduler.schedule(() -> {
try (BufferedReader processReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
try (BufferedReader processReader = new BufferedReader(
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
String line;
while (!isClosing && (line = processReader.readLine()) != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
Expand All @@ -22,7 +21,6 @@
import io.modelcontextprotocol.spec.McpServerSession;
import io.modelcontextprotocol.spec.McpServerTransport;
import io.modelcontextprotocol.spec.McpServerTransportProvider;
import io.modelcontextprotocol.spec.ProtocolVersions;
import io.modelcontextprotocol.util.Assert;
import io.modelcontextprotocol.json.McpJsonMapper;
import org.slf4j.Logger;
Expand Down Expand Up @@ -82,11 +80,6 @@ public StdioServerTransportProvider(McpJsonMapper jsonMapper, InputStream inputS
this.outputStream = outputStream;
}

@Override
public List<String> protocolVersions() {
return List.of(ProtocolVersions.MCP_2024_11_05);
}

@Override
public void setSessionFactory(McpServerSession.Factory sessionFactory) {
// Create a single session for the stdio connection
Expand Down Expand Up @@ -124,10 +117,10 @@ private class StdioMcpSessionTransport implements McpServerTransport {
private final AtomicBoolean isStarted = new AtomicBoolean(false);

/** Scheduler for handling inbound messages */
private Scheduler inboundScheduler;
private final Scheduler inboundScheduler;

/** Scheduler for handling outbound messages */
private Scheduler outboundScheduler;
private final Scheduler outboundScheduler;

private final Sinks.One<Void> outboundReady = Sinks.one();

Expand Down Expand Up @@ -198,9 +191,9 @@ private void startInboundProcessing() {
if (isStarted.compareAndSet(false, true)) {
this.inboundScheduler.schedule(() -> {
inboundReady.tryEmitValue(null);
BufferedReader reader = null;
BufferedReader reader;
try {
reader = new BufferedReader(new InputStreamReader(inputStream));
reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
while (!isClosing.get()) {
try {
String line = reader.readLine();
Expand Down