Files
Adam Holt 60aef5d2e3 Convert to modelcontextprotocol/go-sdk (#1428)
Move from `mark3labs/mcp-go` to `modelcontextprotocol/go-sdk`.

This is mostly focused on updating tool schema and tool handler signatures, along with any associated internal changes related to those changes.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: omgitsads <4619+omgitsads@users.noreply.github.com>
Co-authored-by: LuluBeatson <lulubeatson@github.com>
Co-authored-by: Lulu <59149422+LuluBeatson@users.noreply.github.com>
Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
Co-authored-by: Sam Morrow <info@sam-morrow.com>
2025-12-01 14:30:59 +01:00

62 lines
1.3 KiB
Go

package log
import (
"io"
"log/slog"
)
// IOLogger is a wrapper around io.Reader and io.Writer that can be used
// to log the data being read and written from the underlying streams
type IOLogger struct {
io.ReadWriteCloser
reader io.Reader
writer io.Writer
logger *slog.Logger
}
// NewIOLogger creates a new IOLogger instance
func NewIOLogger(r io.Reader, w io.Writer, logger *slog.Logger) *IOLogger {
return &IOLogger{
reader: r,
writer: w,
logger: logger,
}
}
// Read reads data from the underlying io.Reader and logs it.
func (l *IOLogger) Read(p []byte) (n int, err error) {
if l.reader == nil {
return 0, io.EOF
}
n, err = l.reader.Read(p)
if n > 0 {
l.logger.Info("[stdin]: received bytes", "count", n, "data", string(p[:n]))
}
return n, err
}
// Write writes data to the underlying io.Writer and logs it.
func (l *IOLogger) Write(p []byte) (n int, err error) {
if l.writer == nil {
return 0, io.ErrClosedPipe
}
l.logger.Info("[stdout]: sending bytes", "count", len(p), "data", string(p))
return l.writer.Write(p)
}
func (l *IOLogger) Close() error {
var errReader, errWriter error
if closer, ok := l.reader.(io.Closer); ok {
errReader = closer.Close()
}
if closer, ok := l.writer.(io.Closer); ok {
errWriter = closer.Close()
}
if errReader != nil {
return errReader
}
return errWriter
}