test_case_id: "mcp_late_embed_resolution_001"
description: "Tests that MCP tools properly resolve late embeds (artifact_content)
  in their parameters"
tags: ["all", "agent", "mcp"]
skip_intermediate_events: true

test_runner_config_overrides:
  agent_config:
    mcp_tool_response_save_threshold_bytes: 10 # Force saving


# Setup artifacts for late embed resolution testing
setup_artifacts:
  - filename: "source_data.txt"
    user_id: "mcp_late_embed_tester@example.com"
    mime_type: "text/plain"
    content: "This is test content from an artifact"

gateway_input:
  target_agent_name: "TestAgent"
  user_identity: "mcp_late_embed_tester@example.com"
  parts:
    - type: "text"
      text: "Call the MCP tool with late embed parameters: artifact content."
  external_context:
    a2a_session_id: "session_mcp_late_embed_001"

llm_interactions:
  - static_response:
      choices:
        - message:
            role: "assistant"
            tool_calls:
              - id: "call_mcp_with_late_embeds"
                type: "function"
                function:
                  name: "get_data_stdio"
                  # Test late embeds (artifact_content) - these should be resolved before reaching MCP server
                  arguments: >
                    {
                      "response_to_return": {
                        "content": [
                          {
                            "type": "text", 
                            "text": "Artifact content is «artifact_content:source_data.txt»"
                          }
                        ]
                      }
                    }

  - expected_request:
      expected_tool_responses_in_llm_messages:
        - tool_name: "get_data_stdio"
          response_json_matches:
            status: "processed_and_saved"
            message_to_llm_matches_regex: "The full response has been saved as artifact
              'get_data_stdio_text_0_.*\\.txt' \\(version 0\\)\\."
            saved_mcp_response_artifact_details:
              status: "success"
              artifacts_saved:
                - data_filename_matches_regex: "get_data_stdio_text_0_.*\\.txt"
                  status: "success"

    static_response:
      choices:
        - message:
            role: "assistant"
            content: "Successfully called MCP tool with resolved late embed parameters."

expected_gateway_output:
  - type: "final_response"
    kind: task
    id: '*'
    contextId: "session_mcp_late_embed_001"
    status:
      state: completed
      message:
        kind: message
        messageId: '*'
        role: agent
        parts:
          - type: "text"
            text_exact: "Successfully called MCP tool with resolved late embed parameters."
    assert_artifact_state:
      - filename_matches_regex: "get_data_stdio_text_0_.*\\.txt$"
        version: 0
        expected_content_text: "Artifact content is This is test content from an artifact"
