Skip to content

Commit ac217c7

Browse files
committed
fix server quickstart
1 parent 540f385 commit ac217c7

File tree

1 file changed

+70
-8
lines changed

1 file changed

+70
-8
lines changed

docs/quickstart/server.mdx

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,10 @@ Writing to stdout will corrupt the JSON-RPC messages and break your server.
6363

6464
### Best Practices
6565

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.
6867

6968
### Quick Examples
7069

71-
````javascript
72-
// ❌ Bad (STDIO)
73-
console.log("Server started");
74-
75-
// ✅ Good (STDIO)
76-
console.error("Server started"); // stderr is safe
7770
```python
7871
# ❌ Bad (STDIO)
7972
print("Processing request")
@@ -382,6 +375,36 @@ This quickstart assumes you have familiarity with:
382375
- TypeScript
383376
- LLMs like Claude
384377

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+
385408
### System requirements
386409

387410
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!
835858
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.
836859
For manual MCP Server implementation, refer to the [MCP Server Java SDK documentation](/sdk/java/mcp-server).
837860

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+
838881
### System requirements
839882

840883
- Java 17 or higher installed.
@@ -1527,6 +1570,25 @@ This quickstart assumes you have familiarity with:
15271570
- LLMs like Claude
15281571
- .NET 8 or higher
15291572

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+
15301592
### System requirements
15311593

15321594
- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) or higher installed.

0 commit comments

Comments
 (0)