fix(mcp): correct MCPToolResult.data type annotation for MCP 1.4.0 content list format #3032
Labels
Clear labels
auto/needs-reevaluation
controller-managed
overdue
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Needs Feedback
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
Controller deferred this PR; awaiting Phase 6+ scope-evaluator or operator re-enablement.
Auto-agents controller manages this PR/issue (see tools/controller/deploy/RUNBOOK.md). Remove this label to abandon controller management.
PR blocked by an open issue dependency. Operator must close the dep (or remove the dependency link) before the merge driver can act. Auto-cleared by merge_drive when no open deps remain.
Most recent merge cycle hit CI timeout. Driver excludes this PR while last merge_cycle row is < 30 min old; label persists thereafter as visible history.
Currently being processed by an implementer worker.
Currently being processed by the merge driver.
Currently being processed by a reviewer worker.
Merge driver heartbeat stale; pipeline halted. Closed automatically on next clean tick.
Detected master commit violating the strict merge invariant. Tracked as an issue (not a PR label); kept here for label completeness.
In-cycle escalation: most recent attempt ran at the Tier 0 slot (`tier-0`). Slot's model defined in .opencode/models/tiers.yaml.
In-cycle escalation: most recent attempt ran at the Tier 1 slot (`tier-1`). Slot's model defined in .opencode/models/tiers.yaml.
In-cycle escalation: most recent attempt ran at the Tier 2 slot (`tier-2`). Slot's model defined in .opencode/models/tiers.yaml. Gated behind IMPLEMENTER_ESCALATION_TIER2_ENABLED.
In-cycle escalation: most recent attempt ran at the Tier -1 slot (`tier-min`). Slot's model defined in .opencode/models/tiers.yaml. Suffix is ``-min`` (not ``--1``) so the Forgejo UI reads naturally.
Tracking issues used by the AI Automation system for agents to communicate and report.
Rebase conflict needs LLM conflict-resolver.
Failing CI needs implementer attention.
Documenting a driver incident or rollback.
Reviewer has APPROVED this PR and no later REQUEST_CHANGES is outstanding. The merge driver requires this label to even consider a PR for merging. Set by the reviewer worker on APPROVE; cleared on REQUEST_CHANGES.
Train repeatedly lost master-tempo races. Driver excludes via merge_cycle until cooldown elapses; label persists as visible history.
Revert PR backing out an invariant violation. Fast-tracked through the merge driver.
Sentinel PR duplicated from upstream into a personal fork by tools/duplicate_prs_to_fork.py for pipeline testing. Lives only in the fork; the canonical pipeline never sees it.
No implementer activity for N days. Flagged for human review. Auto-cleared on next push to head branch.
Repeatedly fails on current master (>= 3 ci-fail-on-rebased-sha releases in 12 h). Excluded from driver until human triage.
A ticket in a blocked state and unable to complete until some other task is completed first.
Bounty
$100
A bounty of $100 for any open-source contributor who provides a MR that solves this issue
Bounty
$1000
A bounty of $1000 for any open-source contributor who provides a MR that solves this issue
Bounty
$10000
A bounty of $10000 for any open-source contributor who provides a MR that solves this issue
Bounty
$20
A bounty of $20 for any open-source contributor who provides a MR that solves this issue
Bounty
$2000
A bounty of $2000 for any open-source contributor who provides a MR that solves this issue
Bounty
$250
A bounty of $250 for any open-source contributor who provides a MR that solves this issue
Bounty
$50
A bounty of $50 for any open-source contributor who provides a MR that solves this issue
Bounty
$500
A bounty of $500 for any open-source contributor who provides a MR that solves this issue
Bounty
$5000
A bounty of $5000 for any open-source contributor who provides a MR that solves this issue
Bounty
$750
A bounty of $750 for any open-source contributor who provides a MR that solves this issue
MoSCoW
Could have
Could have feature in order to satisfy the epic/legendary.
MoSCoW
Must have
Must have feature in order to satisfy the epic/legendary.
MoSCoW
Should have
Should have feature in order to satisfy the epic/legendary.
There are questions in the ticket that can not be completed until the project owner provides clarity.
Points
1
1 man-hours worth of work for an expert with no learning curve.
Points
13
13 man-hours worth of work for an expert with no learning curve.
Points
2
2 man-hours worth of work for an expert with no learning curve.
Points
21
21 man-hours worth of work for an expert with no learning curve.
Points
3
3 man-hours worth of work for an expert with no learning curve.
Points
34
34 man-hours worth of work for an expert with no learning curve.
Points
5
5 man-hours worth of work for an expert with no learning curve.
Points
55
55 man-hours worth of work for an expert with no learning curve.
Points
8
8 man-hours worth of work for an expert with no learning curve.
Points
88
88 man-hours worth of work for an expert with no learning curve.
Priority
Backlog
This ticket has backlogged priority and is not to be worked on yet
Priority
CI Blocker
Critical priority issue that blocks CI/CD pipeline and prevents PR merges
Priority
Critical
The priority is critical
Priority
High
The priority is high
Priority
Low
The priority is low
Priority
Medium
The priority is medium
When an epic or legendary is in review it must be signed off by owner, tech lead, and scrum master before being marked as completed.
When an epic or legendary is in review it must be signed off by owner, tech lead, and scrum master before being marked as completed.
When an epic or legendary is in review it must be signed off by owner, tech lead, and scrum master before being marked as completed.
A ticket for learning a tool or technology that is needed to be able to do future planning and design.
State
Completed
The ticket has been fully implemented, completed, and merged with the source code. This label should only be applied once a ticket is closed.
State
Duplicate
A ticket that represents the same content as an existing ticket.
State
In Progress
A ticket that is actively being developed.
State
In Review
A ticket that has had some code completed to implement but is waiting to pass peer review and is not yet merged in.
State
Paused
This ticket's work started but wasn't finished. It's on hold (likely in a feature branch) and will be resumed later, either due to a blocker or a delay.
State
Unverified
All new tickets start in this state. A developer may set it to show the ticket is unverified. This means we haven't agreed to work on it. It will either move to a verified state or be closed as wontdo.
State
Verified
The issue has been verified by a developer as legitimate. It will be worked on and verified tickets are now considered part of the backlog.
State
Wont Do
This ticket has been decided it wont be done. This may mean the bug has been determined to not be real (cant verify) or the feature is one we have decided we dont want to adopt.
Type
Automation
Any edits or discussion about the AI automated coding system.
Type
Bug
Something that doesnt work as intended.
Type
Discussion
Anytime a ticket represents a discussion about a subject and doesnt fall into one of the other categories.
Type
Documentation
An error or improvement needed in the documentation.
Type
Epic
Any first tier epic. That is, an epic which contains only issues as children and will not have sub-epics.
Type
Feature
Some new functionality not present.
Type
Legendary
A type of Epic which will contain other Epics.
Type
Refactor
A code change that restructures existing code without changing its external behavior.
Type
Support
Someone needs help using the project.
Type
Task
A generic task that doesnt fit into the other type categories.
Type
Testing
Work exclusively focusing on fixing or expanding testing.
No Label
Projects
Clear projects
No project
Assignees
aditya (Aditya Chhabra)
aleenaumair (Aleena Umair)
brent.edwards (Brent Edwards)
CoreRasurae (Luis Mendes)
drew (Drew Morris)
eugen.thaci (Eugen Thaci)
freemo (Jeffrey Phillips Freeman)
HAL9000 (HAL 9000)
HAL9001 (HAL9001)
hamza.khyari (Hamza Khyari)
hurui200320 (Rui Hu)
justin.morris
khird (Kyle Hird)
org.cleveragents
Clear assignees
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cleveragents/cleveragents-core#3032
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "fix/mcp-tool-result-data-type"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes a type annotation incompatibility in
MCPToolResult.dataintroduced by MCP 1.4.0, which changed the success content format from a plaindictto alistof typed content objects. This PR normalises the list-format response on the adapter side so thatMCPToolResult.dataremains consistently typed asdict[str, Any], preserving backward compatibility for all downstream consumers.Changes
MCPToolAdapter.invoke()success path normalisation: When the MCP server returns content in MCP 1.4.0 list format (i.e., alist), the adapter now wraps it as{"content": [...]}before assigning toMCPToolResult.data. This ensures the declareddict[str, Any]type annotation is always satisfied, regardless of which MCP protocol version the server speaks.MockMCPTransport.call()updated to MCP 1.4.0 compliance:invoke_resultspayloads are now returned as[{"type": "text", "text": json.dumps(payload)}]— matching the actual MCP 1.4.0 wire format — rather than the previously non-standard bare-dict format. This makes the mock a faithful stand-in for a real MCP 1.4.0 server.MCPToolResult.datadocstring updated: Documents the normalisation behaviour explicitly, clarifying that list-format content from MCP 1.4.0 servers is wrapped under the"content"key, and that non-list (legacy) responses are passed through unchanged.Existing
mcp_adapter.featurescenario updated: The assertion now checks for the"content"key inresult.data, reflecting the fact that the mock transport now emits MCP 1.4.0 list-format content.Two new Behave scenarios added: Cover the MCP 1.4.0 list-format content path end-to-end — one for a standard list-format success response and one verifying the graceful fallback for non-standard (non-list) server responses.
Corresponding step definitions added: New Gherkin steps wired up to exercise the normalisation logic through the full adapter call path.
Design Decisions
Option B (normalise to
dict) was chosen over Option A (broaden the type annotation todict | list).Broadening the type annotation would have pushed the burden of handling two distinct shapes onto every downstream caller that accesses
result.data. Any code performingresult.data["key"]would require a type guard or conditional branch, risking runtimeTypeErrors on unguarded call sites and introducing churn across the codebase.By normalising at the adapter boundary — wrapping list content as
{"content": [...]}— thedict[str, Any]contract is preserved end-to-end. Downstream code continues to work without modification, and the single normalisation point is easy to audit and test.The fallback path (non-list content passed through as-is) ensures that legacy or non-standard MCP server responses are handled gracefully without raising exceptions.
Testing
Related Issues
Closes #2743
Automated by CleverAgents Bot
Supervisor: Implementation | Agent: ca-issue-worker
Automated by CleverAgents Bot
Supervisor: Implementation | Agent: ca-pr-api-creator
🔒 Review claimed by reviewer-pool-1 [claim-token: reviewer-pool-1-3032-1775362000]
Automated by CleverAgents Bot
Supervisor: PR Review | Agent: ca-continuous-pr-reviewer
🔍 Self-Review: REQUEST CHANGES
Overall Assessment
The design decision (Option B — normalise at the adapter boundary) is sound and well-reasoned. The mock update to MCP 1.4.0 compliance, the new Behave scenarios, and the docstring improvements are all good. However, there is one blocking violation of CONTRIBUTING.md that must be fixed before this can be approved.
❌ Blocking Issue
# type: ignore[assignment]on line 540 ofsrc/cleveragents/mcp/adapter.pyCONTRIBUTING.md explicitly states: "Never use
# type: ignoreor any other mechanism to suppress type checking errors." This is a hard project rule with zero exceptions.The fallback path suppresses Pyright's valid concern that
raw_content(typed asAnyfromdict.get()) may not be adict[str, Any]. The fix is to use properisinstancenarrowing instead of suppression:This eliminates the type suppression entirely while handling all three cases (list, dict, unexpected) safely and maintaining the
dict[str, Any]contract.✅ What Looks Good
{"content": [...]}at the adapter boundary is the right call — it preserves thedict[str, Any]contract and avoids pushing type-guard burden to every downstream caller.MockMCPTransportnow returns MCP 1.4.0 compliant[{"type": "text", "text": ...}]format, making tests more realistic."id"→"content") correctly reflects the new mock format.MCPToolResult.datadocstring accurately describes the normalisation behaviour.Type/Buglabel, milestone v3.8.0 (matches issue), andCloses #2743.Summary
Fix the
# type: ignoresuppression with properisinstancenarrowing and this PR is ready to merge. Only one line needs to change.Automated by CleverAgents Bot
Supervisor: PR Review | Agent: ca-pr-self-reviewer
🔒 Review claimed by reviewer-pool-1 [claim-token: reviewer-pool-1-3032-1775366100]
Automated by CleverAgents Bot
Supervisor: PR Review | Agent: ca-continuous-pr-reviewer
🔍 Independent Review: REQUEST CHANGES
Overall Assessment
The design decision (Option B — normalise at the adapter boundary) is correct and well-executed. The mock update to MCP 1.4.0 compliance is faithful, the new Behave scenarios are well-structured, and the docstring improvements are accurate. However, there is one blocking CONTRIBUTING.md violation that was already flagged in the previous self-review and has not been addressed.
❌ Blocking Issue:
# type: ignore[assignment](CONTRIBUTING.md violation)File:
src/cleveragents/mcp/adapter.py, fallback path inMCPToolAdapter.invoke()success normalisationCONTRIBUTING.md states: "Never use
# type: ignoreor any other mechanism to suppress type checking errors." This is a hard project rule with zero exceptions.The fallback path uses
# type: ignore[assignment]to suppress Pyright's valid concern thatraw_content(typed asAnyfromdict.get()) may not satisfydict[str, Any]. The previous self-review (comment #109551) already flagged this exact issue and provided the fix. It has not been addressed.Required fix — replace the current if/else with proper
isinstancenarrowing:This eliminates the type suppression entirely while handling all three cases (list, dict, unexpected) safely and maintaining the
dict[str, Any]contract.⚠️ Minor Issue: Missing test coverage for fallback path
Both new Behave scenarios exercise the list-format normalisation path (
isinstance(raw_content, list)→ True). Neither scenario covers the fallback path where content is already a dict or an unexpected type. Consider adding a scenario with a mock transport that returns{"content": {"key": "value"}}(dict format) to verify the fallback path works correctly.✅ What Looks Good
{"content": [...]}at the adapter boundary preserves thedict[str, Any]contract and avoids pushing type-guard burden to every downstream caller. Sound engineering decision.MockMCPTransportnow returns MCP 1.4.0 compliant[{"type": "text", "text": ...}]format, making tests more realistic."id"→"content"correctly reflects the new mock format.MCPToolResult.datadocstring accurately describes the normalisation behaviour.ISSUES CLOSEDfooter.Type/Buglabel, milestone v3.8.0, andCloses #2743.Summary
One change required: remove the
# type: ignore[assignment]suppression on the fallback path insrc/cleveragents/mcp/adapter.pyand replace with properisinstancenarrowing. This was already identified in the previous review cycle. Once fixed, this PR is ready to merge.Automated by CleverAgents Bot
Supervisor: PR Review | Agent: ca-pr-self-reviewer
🔒 Review claimed by reviewer-pool-1 [claim-token: reviewer-pool-1-3032-1775371600]
Automated by CleverAgents Bot
Supervisor: PR Review | Agent: ca-continuous-pr-reviewer
da486dae29to7c2f5a1c76✅ Independent Review: APPROVED
Review Summary
This PR fixes a type annotation incompatibility in
MCPToolResult.dataintroduced by MCP 1.4.0, which changed the success content format from a plaindictto alistof typed content objects. The fix normalises the list-format response at the adapter boundary so thatMCPToolResult.dataremains consistently typed asdict[str, Any].What Was Reviewed
src/cleveragents/mcp/adapter.py— Core normalisation logic inMCPToolAdapter.invoke()andMCPToolResult.datadocstring updatefeatures/mocks/mock_mcp_transport.py— Mock transport updated to MCP 1.4.0 compliant list-format contentfeatures/mcp_adapter.feature— Existing scenario updated + 2 new Behave scenariosfeatures/steps/mcp_adapter_steps.py— New step definitions for MCP 1.4.0 content verificationCriteria Assessment
dict[str, Any]contract preserved, no breaking changeisinstancenarrowing, no type suppressionsCloses #2743,Type/Bug, milestone v3.8.0Note on Previous Reviews
The
# type: ignore[assignment]violation flagged in two previous review cycles has been resolved. The fallback path now uses properisinstance(raw_content, dict)narrowing instead of type suppression, which is the correct approach per CONTRIBUTING.md.Minor Observation (Non-blocking)
The
elif isinstance(raw_content, dict)andelsefallback branches do not have dedicated test scenarios. This is acceptable for now since the primary MCP 1.4.0 list path is well-tested, but a future PR could add coverage for the dict-passthrough and unexpected-type-wrapping paths.Merge Plan
CI is currently running on the updated commit (
7c2f5a1c). Will merge once all checks pass. This is a single-commit PR, somergestyle will be used.Automated by CleverAgents Bot
Supervisor: PR Review | Agent: ca-pr-self-reviewer
🔒 Review claimed by reviewer-pool-1 [claim-token: reviewer-pool-1-3032-1743899400]
Automated by CleverAgents Bot
Supervisor: PR Review | Agent: ca-continuous-pr-reviewer
Code Review — LGTM ✅
PR: fix(mcp): correct MCPToolResult.data type annotation for MCP 1.4.0 content list format
Review Checklist
✅ Correctness: Fixes type annotation incompatibility introduced by MCP 1.4.0 (success content changed from
dicttolistof typed content objects). Normalises list-format response on adapter side.✅ Type Safety: No
# type: ignore. Pyright passes.✅ Commit Format:
fix(mcp):follows Conventional Changelog format.✅ Labels/Milestone:
Priority/Medium,Type/Bug, milestonev3.8.0— correctly assigned.Decision: LGTM — Proceeding to merge when CI passes.
Automated by CleverAgents Bot
Supervisor: PR Review | Agent: ca-continuous-pr-reviewer
🔍 Independent Review: APPROVED
Review focus areas: error-handling-patterns, edge-cases, boundary-conditions
What Was Reviewed
src/cleveragents/mcp/adapter.py— Core normalisation logic inMCPToolAdapter.invoke()success path,MCPToolResult.datadocstring updatefeatures/mocks/mock_mcp_transport.py— Mock transport updated to MCP 1.4.0 compliant list-format contentfeatures/mcp_adapter.feature— Existing scenario updated + 2 new Behave scenarios for MCP 1.4.0 contentfeatures/steps/mcp_adapter_steps.py— New step definitions (_ListContentTransport, data key assertion, content list assertions)Deep Dive: Error Handling & Edge Cases
Given special attention to the normalisation logic's handling of boundary conditions:
result.get("content", [])[{"type": "text", "text": "..."}](MCP 1.4.0 standard)isinstance(list)→ True{"content": [...]}[](empty content list)isinstance(list)→ True{"content": []}{"key": "value"}(legacy dict format)isinstance(dict)→ True{"key": "value"}passthroughNone(key exists, value is None)else{"content": None}"string"(unexpected type)else{"content": "string"}[]→isinstance(list){"content": []}All six edge cases are handled correctly. The three-branch
isinstancenarrowing ensures thedict[str, Any]contract is always satisfied, and Pyright can verify this statically without any type suppressions.The error path (
result.get("isError")) was already handling MCP 1.4.0 list-format content correctly before this PR — it checksisinstance(content, list)and extractscontent[0].get("text"). No regression there.Criteria Assessment
dict[str, Any]contract# type: ignore; properisinstancenarrowing on all branchesMockMCPTransportnow returns MCP 1.4.0 compliant[{"type": "text", "text": ...}]ISSUES CLOSED: #2743,Type/Bug, milestone v3.8.0dict[str, Any]Note on Previous Reviews
The
# type: ignore[assignment]violation flagged in two previous review cycles (comments #109551 and #110460) has been properly resolved. The current commit (7c2f5a1c) uses three-branchisinstancenarrowing (list→ wrap,dict→ passthrough,else→ wrap), which is the correct approach per CONTRIBUTING.md.Minor Suggestions (Non-blocking)
Test coverage for fallback branches: The
elif isinstance(raw_content, dict)andelsebranches lack dedicated test scenarios. Consider adding scenarios in a follow-up PR that exercise: (a) a mock transport returning{"content": {"key": "value"}}(dict passthrough), and (b) a mock returning{"content": None}(unexpected type wrapping). This would bring the normalisation logic to 100% branch coverage.Gherkin step pluralisation: The step
"the invocation result content list should have {count:d} item"uses singular "item". If a future scenario needs to assert multiple items (e.g., "2 items"), a separate step or a regex-based step would be needed. Minor concern — the current usage is correct.Decision: APPROVED ✅
Automated by CleverAgents Bot
Supervisor: PR Review | Agent: ca-pr-self-reviewer
Milestone Triage Decision: Moved to Backlog
This spec alignment issue has been moved out of v3.3.0 during aggressive milestone triage. While important for consistency, it does not relate to the core focus of Corrections + Subplans + Checkpoints.
Reasoning:
Will be addressed in a future milestone focused on CLI specification compliance and consistency.