Skip to content

Commit 79ee998

Browse files
authored
Update server.mdx to including MCP server logging best practices
modelcontextprotocol#840 - MCP Server Logging Best Practices
1 parent 1cfdf1e commit 79ee998

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/quickstart/server.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ This quickstart assumes you have familiarity with:
4646
- Python
4747
- LLMs like Claude
4848

49+
### Guidance on Logging Best Practices in MCP Servers
50+
51+
When implementing MCP servers, it is crucial that developers avoid using print statements that write messages to standard output.
52+
Certain MCP hosts and clients might be able to deal with these extraneous outputs, but it could result in unexpected behavior in majority of the MCP clients.
53+
54+
Logging messages to standard output could corrupt the structured output and format expected by the clients thus breaking the protocol. Using print functionality in your programming language of choice to send log messages to standard output could make your MCP server unusable.
55+
56+
Here are some tips you can use to avoid this problem:
57+
58+
- use the built-in logging functionality available in your language specific SDK
59+
- if you are building your own MCP server from scratch without the SDK, please using logging mechanisms that do not print messages to standard output
60+
- configure the log levels for your application accordingly
61+
4962
### System requirements
5063

5164
- Python 3.10 or higher installed.

0 commit comments

Comments
 (0)