{"record":{"id":"5b1311f1d1de76e5","repo":"PrefectHQ/fastmcp","slug":"tool-name-r-version-version-r-not-found","errorCode":null,"errorMessage":"Tool {name!r} version {version!r} not found","messagePattern":"Tool (.+?) version (.+?) not found","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/server/providers/local_provider/local_provider.py","lineNumber":254,"sourceCode":"        Raises:\n            KeyError: If no matching tool is found.\n        \"\"\"\n        if version is None:\n            # Remove all versions\n            keys_to_remove = [\n                k\n                for k, c in self._components.items()\n                if isinstance(c, Tool) and c.name == name\n            ]\n            if not keys_to_remove:\n                raise KeyError(f\"Tool {name!r} not found\")\n            for key in keys_to_remove:\n                self._remove_component(key)\n        else:\n            # Remove specific version - key format is \"tool:name@version\"\n            key = f\"{Tool.make_key(name)}@{version}\"\n            if key not in self._components:\n                raise KeyError(f\"Tool {name!r} version {version!r} not found\")\n            self._remove_component(key)\n\n    def remove_resource(self, uri: str, version: str | None = None) -> None:\n        \"\"\"Remove resource(s) from this provider's storage.\n\n        Args:\n            uri: The resource URI.\n            version: If None, removes ALL versions. If specified, removes only that version.\n\n        Raises:\n            KeyError: If no matching resource is found.\n        \"\"\"\n        if version is None:\n            # Remove all versions\n            keys_to_remove = [\n                k\n                for k, c in self._components.items()\n                if isinstance(c, Resource) and str(c.uri) == uri","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/providers/local_provider/local_provider.py#L236-L272","documentation":"When remove_tool is called with an explicit version, LocalProvider builds the versioned key f\"{Tool.make_key(name)}@{version}\" and raises KeyError if that exact key is absent. This means the tool name exists in concept but that specific version string does not match any registered version.","triggerScenarios":"provider.remove_tool(\"name\", \"1.0.0\") where the tool was registered with version \"1.0\" (no patch), unversioned, or under a different version string entirely.","commonSituations":"Version-string mismatches between registration and removal (e.g. \"v1\" vs \"1.0.0\"); removing a version after an earlier teardown already deleted it; assuming a default version exists when the tool was added unversioned.","solutions":["List the tool's registered versions (list all Tool components with that name) and remove an existing version string","Omit the version argument to remove ALL versions of the tool","Catch KeyError for idempotent teardown","Ensure the version string used at removal exactly matches the one used at registration"],"exampleFix":"// before\nprovider.remove_tool(\"get_weather\", \"v1\")  # registered as \"1.0.0\" -> KeyError\n// after\nprovider.remove_tool(\"get_weather\", \"1.0.0\")  # exact version match","handlingStrategy":"validation","validationCode":"versions = [c.version for c in provider._components.values()\n            if isinstance(c, Tool) and c.name == \"my_tool\"]\nif \"1.0.0\" not in versions:\n    provider.remove_tool(\"my_tool\")  # remove all instead","typeGuard":"def version_registered(provider, name: str, version: str) -> bool:\n    key = f\"{Tool.make_key(name)}@{version}\"\n    return key in provider._components","tryCatchPattern":"try:\n    provider.remove_tool(\"my_tool\", \"1.0.0\")\nexcept KeyError:\n    provider.remove_tool(\"my_tool\")  # fall back to removing all versions","preventionTips":["Use one canonical version string constant for both add and remove","Never pass a version unless you know the tool was registered versioned","Prefer omitting version (removes all) in teardown code"],"tags":["keyerror","tool","versioning","removal"],"backgroundTag":"component-version-mismatch","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}