mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 21:44:18 +02:00
Merge pull request #779 from jlowin/equals
Update FastMCP component with __eq__ and __repr__
This commit is contained in:
commit
b01eb02a88
4 changed files with 6 additions and 18 deletions
|
|
@ -86,12 +86,6 @@ class Resource(FastMCPComponent, abc.ABC):
|
|||
"""Read the resource content."""
|
||||
pass
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if type(self) is not type(other):
|
||||
return False
|
||||
assert isinstance(other, type(self))
|
||||
return self.model_dump() == other.model_dump()
|
||||
|
||||
def to_mcp_resource(self, **overrides: Any) -> MCPResource:
|
||||
"""Convert the resource to an MCPResource."""
|
||||
kwargs = {
|
||||
|
|
@ -102,6 +96,9 @@ class Resource(FastMCPComponent, abc.ABC):
|
|||
}
|
||||
return MCPResource(**kwargs | overrides)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.__class__.__name__}(uri={self.uri!r}, name={self.name!r}, description={self.description!r}, tags={self.tags})"
|
||||
|
||||
|
||||
class FunctionResource(Resource):
|
||||
"""A resource that defers data loading by wrapping a function.
|
||||
|
|
|
|||
|
|
@ -115,12 +115,6 @@ class ResourceTemplate(FastMCPComponent):
|
|||
tags=self.tags,
|
||||
)
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if type(self) is not type(other):
|
||||
return False
|
||||
assert isinstance(other, type(self))
|
||||
return self.model_dump() == other.model_dump()
|
||||
|
||||
def to_mcp_template(self, **overrides: Any) -> MCPResourceTemplate:
|
||||
"""Convert the resource template to an MCPResourceTemplate."""
|
||||
kwargs = {
|
||||
|
|
|
|||
|
|
@ -74,12 +74,6 @@ class Tool(FastMCPComponent, ABC):
|
|||
serializer=serializer,
|
||||
)
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if type(self) is not type(other):
|
||||
return False
|
||||
assert isinstance(other, type(self))
|
||||
return self.model_dump() == other.model_dump()
|
||||
|
||||
@abstractmethod
|
||||
async def run(
|
||||
self, arguments: dict[str, Any]
|
||||
|
|
|
|||
|
|
@ -37,3 +37,6 @@ class FastMCPComponent(FastMCPBaseModel):
|
|||
return False
|
||||
assert isinstance(other, type(self))
|
||||
return self.model_dump() == other.model_dump()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.__class__.__name__}(name={self.name!r}, description={self.description!r}, tags={self.tags})"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue