Skip to content

Commit d9c3d37

Browse files
make tests work on old fastmcp
1 parent 9716ec9 commit d9c3d37

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

tests/integrations/fastmcp/test_fastmcp.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,9 @@ async def multiply_numbers(x: int, y: int) -> dict:
404404
"result": 42,
405405
"operation": "multiplication",
406406
}
407-
elif isinstance(mcp, StandaloneFastMCP):
407+
elif (
408+
isinstance(mcp, StandaloneFastMCP) and FASTMCP_VERSION is not None
409+
): # Checking for None is not precise.
408410
assert result.json()["result"]["content"][0]["text"] == json.dumps(
409411
{"result": 42, "operation": "multiplication"},
410412
)
@@ -824,21 +826,20 @@ async def read_url(resource: str):
824826
"""Read a URL resource"""
825827
return "resource data"
826828

827-
try:
828-
_, result = json_rpc(
829-
app,
830-
method="resources/read",
831-
params={
832-
"uri": "https://example.com/resource",
833-
},
834-
)
835-
except ValueError as e:
836-
# Older FastMCP versions may not support this URI pattern
837-
if "Unknown resource" in str(e):
838-
pytest.skip(
839-
f"Resource URI not supported in this FastMCP version: {e}"
840-
)
841-
raise
829+
_, result = json_rpc(
830+
app,
831+
method="resources/read",
832+
params={
833+
"uri": "https://example.com/resource",
834+
},
835+
)
836+
# Older FastMCP versions may not support this URI pattern
837+
if (
838+
"error" in result.json()
839+
and "Unknown resource" in result.json()["error"]["message"]
840+
):
841+
pytest.skip("Resource URI not supported in this FastMCP version.")
842+
return
842843

843844
assert "resource data" in result.json()["result"]["contents"][0]["text"]
844845

@@ -1016,7 +1017,9 @@ def http_tool(data: str) -> dict:
10161017
and FASTMCP_VERSION.startswith("2")
10171018
):
10181019
assert result.json()["result"]["structuredContent"] == {"processed": "TEST"}
1019-
elif isinstance(mcp, StandaloneFastMCP):
1020+
elif (
1021+
isinstance(mcp, StandaloneFastMCP) and FASTMCP_VERSION is not None
1022+
): # Checking for None is not precise.
10201023
assert result.json()["result"]["content"][0]["text"] == json.dumps(
10211024
{"processed": "TEST"},
10221025
)

0 commit comments

Comments
 (0)