Skip to content

Conversation

KamdynS
Copy link
Contributor

@KamdynS KamdynS commented Aug 15, 2025

mcp/server.go: implement server‑side logging

  • Thread a *slog.Logger through server paths to improve debuggability
  • Introduce no‑op discard handler + ensureLogger so loggers are never nil
  • Use ensured loggers in Server, SSEHandler/SSEServerTransport; remove nil checks
  • Route jsonrpc2 internal errors to an internal logger

All tests are passing and no functionality should change with this PR

Fixes #170

@findleyr findleyr requested a review from jba August 19, 2025 13:37
type ServerOptions struct {
// Optional instructions for connected clients.
Instructions string
// Logger is used for server-side logging. If nil, slog.Default() is used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nil should mean no logging.

if opts.UnsubscribeHandler != nil && opts.SubscribeHandler == nil {
panic("UnsubscribeHandler requires SubscribeHandler")
}
l := ensureLogger(opts.Logger)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline this into L119

}

func (h *SSEHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
h.ensureLogger()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this only occurs in one place, inline it.

@ramongalate
Copy link

could this also extend to streamable http?
I can add it to this, if needed

@jba
Copy link
Contributor

jba commented Aug 23, 2025

@ramongalate I think that should be separate, since the transport is lower level. Maybe a field on StreamableHTTPOptions and StreamableServerTransport?

I think you can make a separate PR, not dependent on this one.

@IAmSurajBobade
Copy link
Contributor

@KamdynS there is no activity on this PR for over a month. Do you mind if I take this up? Will address open review comments.

@KamdynS
Copy link
Contributor Author

KamdynS commented Sep 17, 2025

@IAmSurajBobade Yes please

@IAmSurajBobade
Copy link
Contributor

IAmSurajBobade commented Sep 18, 2025

Hi @KamdynS I have addressed review comments and made minor tweaks. To update the same PR , could you please provide contributer access to your repo/branch. Otherwise, I can create new PR.

@jba
Copy link
Contributor

jba commented Sep 22, 2025

Superseded by #501.

@jba jba closed this Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

server-side logging
4 participants