refactor: process output writing
This commit is contained in:
parent
8a0cd4ef06
commit
59319e5509
1 changed files with 5 additions and 3 deletions
|
|
@ -19,6 +19,7 @@ package org.springframework.ai.mcp.client.stdio;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -212,9 +213,10 @@ public class StdioServerTransport extends AbstractMcpTransport {
|
||||||
.handle((message, s) -> {
|
.handle((message, s) -> {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
try {
|
try {
|
||||||
this.process.outputWriter().write(objectMapper.writeValueAsString(message));
|
String jsonMessage = objectMapper.writeValueAsString(message);
|
||||||
this.process.outputWriter().newLine();
|
this.process.getOutputStream().write(jsonMessage.getBytes(StandardCharsets.UTF_8));
|
||||||
this.process.outputWriter().flush();
|
this.process.getOutputStream().write("\n".getBytes(StandardCharsets.UTF_8));
|
||||||
|
this.process.getOutputStream().flush();
|
||||||
s.next(message);
|
s.next(message);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue