Open
Description
Describe the bug
#247 introduced the ability to mutate tools, prompts, and resources, but the way updating by name/uri works is buggy in that it captures the original identifier and continues using it, even if it's no longer the correct one. This means that updating e.g. a tool name more than once leads to incorrect behavior.
To Reproduce
Steps to reproduce the behavior:
- Register a tool by name - let's say "Foo"
- Call
foo.update({ name: "Bar" })
. This works well and we remove"Foo"
from registered tools and add"Bar"
. - Call
foo.update({ name: "Foo" })
- trying to return to the original name. This has no effect because the checkupdates.name !== name
returns false, sincename
is the captured original name (Foo
) rather than the current tool name (Bar
). - Alternatively, if we call
foo.update({ name: "Baz" })
, we end up with callingdelete this._registeredTools[name]
, which tries to deleteFoo
, which is anyway no longer present in_registeredTools
, and then addsBaz
, ending up with bothBar
andBaz
in the_registeredTools
collection.
Expected behavior
Updating a tool/resource/prompt identifier should compare the new identifier to the current one, rather than the original one.