Skip to content

Commit df1e6a2

Browse files
committed
setting
1 parent 52d47b1 commit df1e6a2

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/main/java/org/springframework/ai/mcp/sample/server/CodeExecutionService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@ public String executeCode(String language, String code) {
195195
String.join(", ", SUPPORTED_LANGUAGES.keySet());
196196
}
197197

198+
// Check if the code contains literal \n characters (backslash followed by n)
199+
// This typically happens when the client sends a string with escaped newlines
200+
if (code.contains("\\n")) {
201+
// Replace all occurrences of \n with actual newlines
202+
// Note: The replace method uses regex, so we need to escape the backslash
203+
code = code.replaceAll("\\\\n", "\n");
204+
}
205+
198206
LanguageConfig config = SUPPORTED_LANGUAGES.get(language);
199207

200208
// Create a temporary directory for the code files

0 commit comments

Comments
 (0)