File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,41 @@ This quickstart assumes you have familiarity with:
46
46
- Python
47
47
- LLMs like Claude
48
48
49
+ ### Logging in MCP Servers
50
+
51
+ When implementing MCP servers, be careful about how you handle logging:
52
+
53
+ ** For STDIO-based servers:** Never write to standard output (stdout). This includes:
54
+
55
+ - ` print() ` statements in Python
56
+ - ` console.log() ` in JavaScript
57
+ - ` fmt.Println() ` in Go
58
+ - Similar stdout functions in other languages
59
+
60
+ Writing to stdout will corrupt the JSON-RPC messages and break your server.
61
+
62
+ ** For HTTP-based servers:** Standard output logging is fine since it doesn't interfere with HTTP responses.
63
+
64
+ ### Best Practices
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
68
+
69
+ ### Quick Examples
70
+
71
+ ```` javascript
72
+ // ❌ Bad (STDIO)
73
+ console .log (" Server started" );
74
+
75
+ // ✅ Good (STDIO)
76
+ console .error (" Server started" ); // stderr is safe
77
+ ` ` ` python
78
+ # ❌ Bad (STDIO)
79
+ print("Processing request")
80
+
81
+ # ✅ Good (STDIO)
82
+ import logging
83
+ logging.info("Processing request")
49
84
### System requirements
50
85
51
86
- Python 3.10 or higher installed.
You can’t perform that action at this time.
0 commit comments