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
The "Logging in MCP Servers" section was copy-pasted across language
tabs with examples from Python, JavaScript, and Go regardless of which
tab the reader was viewing. Each tab now only references its own
language:
- Python: `print()` with `file=sys.stderr` workaround
- TypeScript: `console.log()` / `console.error()`
- Java: `System.out.println()`
- Kotlin: Added missing logging section with `println()`
- C#: `Console.WriteLine()`
- Rust: `println!()` / `print!()`
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/docs/develop/build-server.mdx
+31-52Lines changed: 31 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,30 +45,27 @@ This quickstart assumes you have familiarity with:
45
45
46
46
When implementing MCP servers, be careful about how you handle logging:
47
47
48
-
**For STDIO-based servers:** Never write to standard output (stdout). This includes:
49
-
50
-
-`print()` statements in Python
51
-
-`console.log()` in JavaScript
52
-
-`fmt.Println()` in Go
53
-
- Similar stdout functions in other languages
54
-
55
-
Writing to stdout will corrupt the JSON-RPC messages and break your server.
48
+
**For STDIO-based servers:** Never write to stdout. Writing to stdout will corrupt the JSON-RPC messages and break your server. The `print()` function writes to stdout by default, but can be used safely with `file=sys.stderr`.
56
49
57
50
**For HTTP-based servers:** Standard output logging is fine since it doesn't interfere with HTTP responses.
58
51
59
52
### Best Practices
60
53
61
-
1. Use a logging library that writes to stderr or files.
62
-
1. For Python, be especially careful - `print()` writes to stdout by default.
54
+
- Use a logging library that writes to stderr or files.
63
55
64
56
### Quick Examples
65
57
66
58
```python
59
+
import sys
60
+
import logging
61
+
67
62
# ❌ Bad (STDIO)
68
63
print("Processing request")
69
64
70
65
# ✅ Good (STDIO)
71
-
import logging
66
+
print("Processing request", file=sys.stderr)
67
+
68
+
# ✅ Good (STDIO)
72
69
logging.info("Processing request")
73
70
```
74
71
@@ -369,21 +366,13 @@ This quickstart assumes you have familiarity with:
369
366
370
367
When implementing MCP servers, be careful about how you handle logging:
371
368
372
-
**For STDIO-based servers:** Never write to standard output (stdout). This includes:
373
-
374
-
-`print()` statements in Python
375
-
-`console.log()` in JavaScript
376
-
-`fmt.Println()` in Go
377
-
- Similar stdout functions in other languages
378
-
379
-
Writing to stdout will corrupt the JSON-RPC messages and break your server.
369
+
**For STDIO-based servers:** Never use `console.log()`, as it writes to standard output (stdout) by default. Writing to stdout will corrupt the JSON-RPC messages and break your server.
380
370
381
371
**For HTTP-based servers:** Standard output logging is fine since it doesn't interfere with HTTP responses.
382
372
383
373
### Best Practices
384
374
385
-
1. Use a logging library that writes to stderr or files, such as `logging` in Python.
386
-
2. For JavaScript, be especially careful - `console.log()` writes to stdout by default.
375
+
- Use `console.error()` which writes to stderr, or use a logging library that writes to stderr or files.
387
376
388
377
### Quick Examples
389
378
@@ -842,21 +831,14 @@ For manual MCP Server implementation, refer to the [MCP Server Java SDK document
842
831
843
832
When implementing MCP servers, be careful about how you handle logging:
844
833
845
-
**For STDIO-based servers:** Never write to standard output (stdout). This includes:
846
-
847
-
-`print()` statements in Python
848
-
-`console.log()` in JavaScript
849
-
-`fmt.Println()` in Go
850
-
- Similar stdout functions in other languages
851
-
852
-
Writing to stdout will corrupt the JSON-RPC messages and break your server.
834
+
**For STDIO-based servers:** Never use `System.out.println()` or `System.out.print()`, as they write to standard output (stdout). Writing to stdout will corrupt the JSON-RPC messages and break your server.
853
835
854
836
**For HTTP-based servers:** Standard output logging is fine since it doesn't interfere with HTTP responses.
855
837
856
838
### Best Practices
857
839
858
-
1. Use a logging library that writes to stderr or files.
859
-
2. Ensure any configured logging library will not write to STDOUT
840
+
- Use a logging library that writes to stderr or files.
841
+
- Ensure any configured logging library will not write to stdout.
860
842
861
843
### System requirements
862
844
@@ -1151,6 +1133,18 @@ This quickstart assumes you have familiarity with:
1151
1133
- Kotlin
1152
1134
- LLMs like Claude
1153
1135
1136
+
### Logging in MCP Servers
1137
+
1138
+
When implementing MCP servers, be careful about how you handle logging:
1139
+
1140
+
**For STDIO-based servers:** Never use `println()`, as it writes to standard output (stdout) by default. Writing to stdout will corrupt the JSON-RPC messages and break your server.
1141
+
1142
+
**For HTTP-based servers:** Standard output logging is fine since it doesn't interfere with HTTP responses.
1143
+
1144
+
### Best Practices
1145
+
1146
+
- Use a logging library that writes to stderr or files.
1147
+
1154
1148
### System requirements
1155
1149
1156
1150
- Java 17 or higher installed.
@@ -1538,20 +1532,13 @@ This quickstart assumes you have familiarity with:
1538
1532
1539
1533
When implementing MCP servers, be careful about how you handle logging:
1540
1534
1541
-
**For STDIO-based servers:** Never write to standard output (stdout). This includes:
1542
-
1543
-
-`print()` statements in Python
1544
-
-`console.log()` in JavaScript
1545
-
-`fmt.Println()` in Go
1546
-
- Similar stdout functions in other languages
1547
-
1548
-
Writing to stdout will corrupt the JSON-RPC messages and break your server.
1535
+
**For STDIO-based servers:** Never use `Console.WriteLine()` or `Console.Write()`, as they write to standard output (stdout). Writing to stdout will corrupt the JSON-RPC messages and break your server.
1549
1536
1550
1537
**For HTTP-based servers:** Standard output logging is fine since it doesn't interfere with HTTP responses.
1551
1538
1552
1539
### Best Practices
1553
1540
1554
-
1. Use a logging library that writes to stderr or files
1541
+
- Use a logging library that writes to stderr or files.
1555
1542
1556
1543
### System requirements
1557
1544
@@ -1811,21 +1798,14 @@ This quickstart assumes you have familiarity with:
1811
1798
1812
1799
When implementing MCP servers, be careful about how you handle logging:
1813
1800
1814
-
**For STDIO-based servers:** Never write to standard output (stdout). This includes:
1815
-
1816
-
-`print()` statements in Python
1817
-
-`console.log()` in JavaScript
1818
-
-`println!()` in Rust
1819
-
- Similar stdout functions in other languages
1820
-
1821
-
Writing to stdout will corrupt the JSON-RPC messages and break your server.
1801
+
**For STDIO-based servers:** Never use `println!()` or `print!()`, as they write to standard output (stdout). Writing to stdout will corrupt the JSON-RPC messages and break your server.
1822
1802
1823
1803
**For HTTP-based servers:** Standard output logging is fine since it doesn't interfere with HTTP responses.
1824
1804
1825
1805
### Best Practices
1826
1806
1827
-
1. Use a logging library that writes to stderr or files, such as `tracing` or `log` in Rust.
1828
-
2. Configure your logging framework to avoid stdout output.
1807
+
- Use a logging library that writes to stderr or files, such as `tracing` or `log` in Rust.
1808
+
- Configure your logging framework to avoid stdout output.
1829
1809
1830
1810
### Quick Examples
1831
1811
@@ -1834,8 +1814,7 @@ Writing to stdout will corrupt the JSON-RPC messages and break your server.
1834
1814
println!("Processing request");
1835
1815
1836
1816
// ✅ Good (STDIO)
1837
-
usetracing::info;
1838
-
info!("Processing request"); // writes to stderr
1817
+
eprintln!("Processing request"); // writes to stderr
0 commit comments