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

Method AddResource

mcp/server.go:519–528  ·  view source on GitHub ↗

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

(r *Resource, h ResourceHandler)

Source from the content-addressed store, hash-verified

517// AddResource adds a [Resource] to the server, or replaces one with the same URI.
518// AddResource panics if the resource URI is invalid or not absolute (has an empty scheme).
519func (s *Server) AddResource(r *Resource, h ResourceHandler) {
520 s.changeAndNotify(notificationResourceListChanged,
521 func() bool {
522 if _, err := url.Parse(r.URI); err != nil {
523 panic(err) // url.Parse includes the URI in the error
524 }
525 s.resources.add(&serverResource{r, h})
526 return true
527 })
528}
529
530// RemoveResources removes the resources with the given URIs.
531// It is not an error to remove a nonexistent resource.

Callers 9

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

Calls 2

changeAndNotifyMethod · 0.95
addMethod · 0.80

Tested by 6

TestEndToEndFunction · 0.76
TestListFunction · 0.76
Example_resourcesFunction · 0.76
runServerTestFunction · 0.76
TestServerCapabilitiesFunction · 0.64
TestServerErrorsFunction · 0.64