MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / lookupResourceHandler

Method lookupResourceHandler

mcp/server.go:822–836  ·  view source on GitHub ↗

lookupResourceHandler returns the resource handler and MIME type for the resource or resource template matching uri. If none, the last return value is false.

(uri string)

Source from the content-addressed store, hash-verified

820// lookupResourceHandler returns the resource handler and MIME type for the resource or
821// resource template matching uri. If none, the last return value is false.
822func (s *Server) lookupResourceHandler(uri string) (ResourceHandler, string, bool) {
823 s.mu.Lock()
824 defer s.mu.Unlock()
825 // Try resources first.
826 if r, ok := s.resources.get(uri); ok {
827 return r.handler, r.resource.MIMEType, true
828 }
829 // Look for matching template.
830 for rt := range s.resourceTemplates.all() {
831 if rt.Matches(uri) {
832 return rt.handler, rt.resourceTemplate.MIMEType, true
833 }
834 }
835 return nil, "", false
836}
837
838// fileResourceHandler returns a ReadResourceHandler that reads paths using dir as
839// a base directory.

Callers 1

readResourceMethod · 0.95

Calls 3

getMethod · 0.80
allMethod · 0.80
MatchesMethod · 0.80

Tested by

no test coverage detected