Skip to content

Commit ea2df9c

Browse files
Don't panic for all resource syntax issues
1 parent fb69971 commit ea2df9c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

mcp/server.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"iter"
1515
"maps"
1616
"net/url"
17+
"os"
1718
"path/filepath"
1819
"reflect"
1920
"slices"
@@ -337,10 +338,13 @@ func (s *Server) AddResource(r *Resource, h ResourceHandler) {
337338
func() bool {
338339
u, err := url.Parse(r.URI)
339340
if err != nil {
340-
panic(err) // url.Parse includes the URI in the error
341-
}
342-
if !u.IsAbs() {
343-
panic(fmt.Errorf("URI %s needs a scheme", r.URI))
341+
//panic(err) // url.Parse includes the URI in the error
342+
fmt.Fprintf(os.Stderr, "invalid resource URI %q: %v\n", r.URI, err)
343+
} else {
344+
if !u.IsAbs() {
345+
//panic(fmt.Errorf("URI %s needs a scheme", r.URI))
346+
fmt.Fprintf(os.Stderr, "invalid resource URI %q: %v\n", r.URI, err)
347+
}
344348
}
345349
s.resources.add(&serverResource{r, h})
346350
return true

0 commit comments

Comments
 (0)