Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions benchmarks/scripts/read_load_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def write_manifest(


def result_payload(result: CallToolResult) -> dict[str, object]:
structured = result.structuredContent
structured = result.structured_content
if isinstance(structured, dict):
wrapped = structured.get("result")
payload = wrapped if isinstance(wrapped, dict) else structured
Expand All @@ -402,7 +402,7 @@ def result_payload(result: CallToolResult) -> dict[str, object]:

def result_text(result: CallToolResult) -> str | None:
"""Return text from a successful text-mode tool response."""
if result.isError:
if result.is_error:
return None
text_parts = [
text for item in result.content if isinstance((text := getattr(item, "text", None)), str)
Expand Down Expand Up @@ -517,7 +517,7 @@ async def write_target(
"output_format": "json",
},
)
if result.isError:
if result.is_error:
raise RuntimeError(f"write_note failed while seeding {title}")
payload = result_payload(result)
identifier = payload.get("permalink")
Expand Down Expand Up @@ -573,7 +573,7 @@ async def searchable_count(session: ClientSession, project: str) -> int:
"output_format": "json",
},
)
if result.isError:
if result.is_error:
return 0
payload = result_payload(result)
total = payload.get("total")
Expand Down Expand Up @@ -742,7 +742,7 @@ async def run(args: argparse.Namespace) -> int:
"create_memory_project",
{"project_name": project, "project_path": str(project_dir)},
)
if created.isError:
if created.is_error:
raise RuntimeError("could not create benchmark project")

targets = await seed_corpus(
Expand Down
16 changes: 16 additions & 0 deletions tests/test_read_load_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from types import ModuleType

import pytest
from mcp.types import CallToolResult, TextContent


def load_read_load_bench() -> ModuleType:
Expand All @@ -26,6 +27,21 @@ def load_read_load_bench() -> ModuleType:
read_load_bench = load_read_load_bench()


def test_result_helpers_use_current_mcp_python_fields() -> None:
success = CallToolResult(
content=[TextContent(type="text", text="plain response")],
structured_content={"result": {"permalink": "notes/example"}},
)
failure = CallToolResult(
content=[TextContent(type="text", text="failed response")],
is_error=True,
)

assert read_load_bench.result_payload(success) == {"permalink": "notes/example"}
assert read_load_bench.result_text(success) == "plain response"
assert read_load_bench.result_text(failure) is None


@dataclass
class RecordingScalarResult:
version: str
Expand Down
Loading