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
4 changes: 3 additions & 1 deletion mcp/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ func (r *CallToolResult) UnmarshalJSON(data []byte) error {
// Unmarshal Meta
if meta, ok := raw["_meta"]; ok {
if metaMap, ok := meta.(map[string]any); ok {
r.Meta = metaMap
r.Meta = &Meta{
AdditionalFields: metaMap,
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions server/stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -457,11 +458,18 @@ func (s *StdioServer) writeResponse(
response mcp.JSONRPCMessage,
writer io.Writer,
) error {
responseBytes, err := json.Marshal(response)
if err != nil {
// Create a buffer to write JSON with custom encoding settings
var buf bytes.Buffer
encoder := json.NewEncoder(&buf)
encoder.SetEscapeHTML(false) // Disable HTML escaping, which also prevents Unicode escaping

if err := encoder.Encode(response); err != nil {
return err
}

// Remove the trailing newline added by Encode() and add our own
responseBytes := bytes.TrimSuffix(buf.Bytes(), []byte("\n"))

// Write response followed by newline
if _, err := fmt.Fprintf(writer, "%s\n", responseBytes); err != nil {
return err
Expand Down