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

Method AddResourceTemplate

mcp/server.go:538–549  ·  view source on GitHub ↗

AddResourceTemplate adds a [ResourceTemplate] to the server, or replaces one with the same URI. AddResourceTemplate panics if a URI template is invalid or not absolute (has an empty scheme).

(t *ResourceTemplate, h ResourceHandler)

Source from the content-addressed store, hash-verified

536// AddResourceTemplate adds a [ResourceTemplate] to the server, or replaces one with the same URI.
537// AddResourceTemplate panics if a URI template is invalid or not absolute (has an empty scheme).
538func (s *Server) AddResourceTemplate(t *ResourceTemplate, h ResourceHandler) {
539 s.changeAndNotify(notificationResourceListChanged,
540 func() bool {
541 // Validate the URI template syntax
542 _, err := uritemplate.New(t.URITemplate)
543 if err != nil {
544 panic(fmt.Errorf("URI template %q is invalid: %w", t.URITemplate, err))
545 }
546 s.resourceTemplates.add(&serverResourceTemplate{t, h})
547 return true
548 })
549}
550
551// RemoveResourceTemplates removes the resource templates with the given URI templates.
552// It is not an error to remove a nonexistent resource.

Callers 7

TestEndToEndFunction · 0.95
TestListFunction · 0.95
Example_resourcesFunction · 0.95
mainFunction · 0.95
TestServerCapabilitiesFunction · 0.80
registerResourcesFunction · 0.80

Calls 2

changeAndNotifyMethod · 0.95
addMethod · 0.80

Tested by 5

TestEndToEndFunction · 0.76
TestListFunction · 0.76
Example_resourcesFunction · 0.76
TestServerCapabilitiesFunction · 0.64