You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/quickstart/server.mdx
+70-8Lines changed: 70 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,17 +63,10 @@ Writing to stdout will corrupt the JSON-RPC messages and break your server.
63
63
64
64
### Best Practices
65
65
66
-
1. Use a logging library that writes to stderr or files, such as `logging` in Python.
67
-
2. For JavaScript, be especially careful - `console.log()` writes to stdout by default
66
+
1. Use a logging library that writes to stderr or files.
68
67
69
68
### Quick Examples
70
69
71
-
````javascript
72
-
// ❌ Bad (STDIO)
73
-
console.log("Server started");
74
-
75
-
// ✅ Good (STDIO)
76
-
console.error("Server started"); // stderr is safe
77
70
```python
78
71
# ❌ Bad (STDIO)
79
72
print("Processing request")
@@ -382,6 +375,36 @@ This quickstart assumes you have familiarity with:
382
375
- TypeScript
383
376
- LLMs like Claude
384
377
378
+
### Logging in MCP Servers
379
+
380
+
When implementing MCP servers, be careful about how you handle logging:
381
+
382
+
**For STDIO-based servers:** Never write to standard output (stdout). This includes:
383
+
384
+
-`print()` statements in Python
385
+
-`console.log()` in JavaScript
386
+
-`fmt.Println()` in Go
387
+
- Similar stdout functions in other languages
388
+
389
+
Writing to stdout will corrupt the JSON-RPC messages and break your server.
390
+
391
+
**For HTTP-based servers:** Standard output logging is fine since it doesn't interfere with HTTP responses.
392
+
393
+
### Best Practices
394
+
395
+
1. Use a logging library that writes to stderr or files, such as `logging` in Python.
396
+
2. For JavaScript, be especially careful - `console.log()` writes to stdout by default
397
+
398
+
### Quick Examples
399
+
400
+
```javascript
401
+
// ❌ Bad (STDIO)
402
+
console.log("Server started");
403
+
404
+
// ✅ Good (STDIO)
405
+
console.error("Server started"); // stderr is safe
406
+
```
407
+
385
408
### System requirements
386
409
387
410
For TypeScript, make sure you have the latest version of Node installed.
@@ -835,6 +858,26 @@ Let's get started with building our weather server!
835
858
For more information, see the [MCP Server Boot Starter](https://docs.spring.io/spring-ai/reference/api/mcp/mcp-server-boot-starter-docs.html) reference documentation.
836
859
For manual MCP Server implementation, refer to the [MCP Server Java SDK documentation](/sdk/java/mcp-server).
837
860
861
+
### Logging in MCP Servers
862
+
863
+
When implementing MCP servers, be careful about how you handle logging:
864
+
865
+
**For STDIO-based servers:** Never write to standard output (stdout). This includes:
866
+
867
+
-`print()` statements in Python
868
+
-`console.log()` in JavaScript
869
+
-`fmt.Println()` in Go
870
+
- Similar stdout functions in other languages
871
+
872
+
Writing to stdout will corrupt the JSON-RPC messages and break your server.
873
+
874
+
**For HTTP-based servers:** Standard output logging is fine since it doesn't interfere with HTTP responses.
875
+
876
+
### Best Practices
877
+
878
+
1. Use a logging library that writes to stderr or files.
879
+
2. Ensure any configured logging library will not write to STDOUT
880
+
838
881
### System requirements
839
882
840
883
- Java 17 or higher installed.
@@ -1527,6 +1570,25 @@ This quickstart assumes you have familiarity with:
1527
1570
- LLMs like Claude
1528
1571
- .NET 8 or higher
1529
1572
1573
+
### Logging in MCP Servers
1574
+
1575
+
When implementing MCP servers, be careful about how you handle logging:
1576
+
1577
+
**For STDIO-based servers:** Never write to standard output (stdout). This includes:
1578
+
1579
+
-`print()` statements in Python
1580
+
-`console.log()` in JavaScript
1581
+
-`fmt.Println()` in Go
1582
+
- Similar stdout functions in other languages
1583
+
1584
+
Writing to stdout will corrupt the JSON-RPC messages and break your server.
1585
+
1586
+
**For HTTP-based servers:** Standard output logging is fine since it doesn't interfere with HTTP responses.
1587
+
1588
+
### Best Practices
1589
+
1590
+
1. Use a logging library that writes to stderr or files
1591
+
1530
1592
### System requirements
1531
1593
1532
1594
-[.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) or higher installed.
0 commit comments