Here's a script you can follow to attach data assets to the code ocean interface. 

In order for the following script to work, the user should have attched their code ocean token as "CO_TOKEN" in their capsule secrets.

Use the AIND data access API to find the relevant co_links to attach in the function below.

from codeocean import CodeOcean
from codeocean.data_asset import DataAssetAttachParams

def attach_co_data_assets(co_links: list):
    """
    Attatch data assets to code ocean capsule using a list of external links,
    which can be found in the metadata -> 'external_links.Code Ocean'

    Parameters
    ----------
    co_links : list
        List of code ocean external links

    Returns
    -------
    List of DataAssetAttachResults to determine successful attachment of assets
    """

    if not HAS_CODE_OCEAN:
        raise ImportError(
            "In order to use Code Ocean functionality, "
            "ensure that you're on Code Ocean."
            "Install with: uv tool install aind-metadata-mcp[co]"
        )

    CO_DOMAIN = "https://codeocean.allenneuraldynamics.org"
    co_client = CodeOcean(domain=CO_DOMAIN, token=os.getenv("CO_TOKEN"))

    all_data_asset_attach_params = [
        DataAssetAttachParams(id=co_id) for co_id in co_links
    ]

    co_capsule_id = os.getenv("CO_CAPSULE_ID")
    response = co_client.capsules.attach_data_assets(
        capsule_id=co_capsule_id,
        attach_params=all_data_asset_attach_params,
    )

    return response

When generating code, be concise