From b1eb3c88041b11e5d7c79aab880c74c8cd916a12 Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Wed, 4 Jun 2025 11:10:58 -0400 Subject: [PATCH] internal/mcp: unexport FileResourceHandler Unexport our nice root-respecting local-filesystem resource handler. It's unclear how roots should interact with a resource handler that uses the local filesystem. All we know from the spec is that servers should "respect root boundaries during operations," but it's not clear how they can do that reliably if root changes are notifications, meaning there is no causality between a client changing a root and then asking the server for a file. (Maybe the server sees the new roots, maybe it doesn't.) The spec is loose about all this: it feels more like a sketch. No other SDK seems to devote much to providing a local helper, and those that do (Python) don't look at roots. Change-Id: Ia4d9abb9bc1a6450e1fc8e607df5d7bc6aa227e3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/678855 Reviewed-by: Robert Findley LUCI-TryBot-Result: Go LUCI --- mcp/server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mcp/server.go b/mcp/server.go index 15f4994..afb2575 100644 --- a/mcp/server.go +++ b/mcp/server.go @@ -291,7 +291,7 @@ func (s *Server) readResource(ctx context.Context, ss *ServerSession, params *Re return res, nil } -// FileResourceHandler returns a ReadResourceHandler that reads paths using dir as +// fileResourceHandler returns a ReadResourceHandler that reads paths using dir as // a base directory. // It honors client roots and protects against path traversal attacks. // @@ -303,7 +303,7 @@ func (s *Server) readResource(ctx context.Context, ss *ServerSession, params *Re // Lexical path traversal attacks, where the path has ".." elements that escape dir, // are always caught. Go 1.24 and above also protects against symlink-based attacks, // where symlinks under dir lead out of the tree. -func (s *Server) FileResourceHandler(dir string) ResourceHandler { +func (s *Server) fileResourceHandler(dir string) ResourceHandler { return fileResourceHandler(dir) }