Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package main
import (
"context"
"fmt"
"os"

"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
Expand Down Expand Up @@ -53,7 +54,7 @@ func main() {

// Start the stdio server
if err := server.ServeStdio(s); err != nil {
fmt.Printf("Server error: %v\n", err)
fmt.Fprintf(os.Stderr, "Server error: %v\n", err)
}
}

Expand Down Expand Up @@ -121,6 +122,7 @@ package main
import (
"context"
"fmt"
"os"

"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
Expand Down Expand Up @@ -191,7 +193,7 @@ func main() {

// Start the server
if err := server.ServeStdio(s); err != nil {
fmt.Printf("Server error: %v\n", err)
fmt.Fprintf(os.Stderr, "Server error: %v\n", err)
}
}
```
Expand Down
6 changes: 2 additions & 4 deletions examples/roots_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import (
"github.com/mark3labs/mcp-go/server"
)

// handleNotification handles JSON-RPC notifications by printing the notification method to standard output.
func handleNotification(ctx context.Context, notification mcp.JSONRPCNotification) {
fmt.Printf("notification received: %v\n", notification.Method)
}
// handleNotification ignores notifications so diagnostic output cannot block the stdio server.
func handleNotification(context.Context, mcp.JSONRPCNotification) {}

// main sets up and runs an MCP stdio server named "roots-stdio-server" with tool and roots capabilities.
// It registers a handler for RootsListChanged notifications and adds a "roots" tool
Expand Down
3 changes: 2 additions & 1 deletion examples/structured_input_and_output/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"os"
"time"

"github.com/mark3labs/mcp-go/mcp"
Expand Down Expand Up @@ -86,7 +87,7 @@ func main() {
s.AddTool(manualTool, mcp.NewTypedToolHandler(manualWeatherHandler))

if err := server.ServeStdio(s); err != nil {
fmt.Printf("Server error: %v\n", err)
fmt.Fprintf(os.Stderr, "Server error: %v\n", err)
}
}

Expand Down
3 changes: 2 additions & 1 deletion examples/typed_tools/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"os"

"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
Expand Down Expand Up @@ -76,7 +77,7 @@ func main() {

// Start the stdio server
if err := server.ServeStdio(s); err != nil {
fmt.Printf("Server error: %v\n", err)
fmt.Fprintf(os.Stderr, "Server error: %v\n", err)
}
}

Expand Down
3 changes: 2 additions & 1 deletion www/docs/pages/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ package main
import (
"context"
"fmt"
"os"

"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
Expand Down Expand Up @@ -69,7 +70,7 @@ func main() {

// Start the stdio server
if err := server.ServeStdio(s); err != nil {
fmt.Printf("Server error: %v\n", err)
fmt.Fprintf(os.Stderr, "Server error: %v\n", err)
}
}

Expand Down
3 changes: 2 additions & 1 deletion www/docs/pages/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package main
import (
"context"
"fmt"
"os"

"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
Expand Down Expand Up @@ -39,7 +40,7 @@ func main() {

// Start the stdio server
if err := server.ServeStdio(s); err != nil {
fmt.Printf("Server error: %v\n", err)
fmt.Fprintf(os.Stderr, "Server error: %v\n", err)
}
}

Expand Down
5 changes: 3 additions & 2 deletions www/docs/pages/servers/advanced.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ func (n *CustomNotifier) BroadcastSystemMessage(message string) {
```go
func main() {
// Initialize components
logger := log.New(os.Stdout, "[MCP] ", log.LstdFlags)
logger := log.New(os.Stderr, "[MCP] ", log.LstdFlags)
metrics := NewPrometheusMetrics()
sessionManager := NewSessionManager()
notifier := NewCustomNotifier()
Expand Down Expand Up @@ -889,6 +889,7 @@ package main
import (
"context"
"fmt"
"os"

"github.com/mark3labs/mcp-go/mcp"
"github.com/mark3labs/mcp-go/server"
Expand Down Expand Up @@ -925,7 +926,7 @@ func handleCalculate(ctx context.Context, req mcp.CallToolRequest) (*mcp.CallToo
if clientSession, ok := session.(server.SessionWithClientInfo); ok {
clientCapabilities := clientSession.GetClientCapabilities()
if clientCapabilities.Sampling == nil {
fmt.Println("sampling is not enabled in client")
fmt.Fprintln(os.Stderr, "sampling is not enabled in client")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
}

Expand Down
3 changes: 2 additions & 1 deletion www/docs/pages/servers/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"time"

"github.com/mark3labs/mcp-go/mcp"
Expand Down Expand Up @@ -83,7 +84,7 @@ func main() {

// Start the server
if err := server.ServeStdio(s); err != nil {
fmt.Printf("Server error: %v\n", err)
fmt.Fprintf(os.Stderr, "Server error: %v\n", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion www/docs/pages/transports/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {
httpServer := server.NewStreamableHTTPServer(s)
httpServer.Start(":" + port)
default:
fmt.Println("Starting STDIO server")
fmt.Fprintln(os.Stderr, "Starting STDIO server")
server.ServeStdio(s)
}
}
Expand Down
Loading