#!/usr/bin/env python3
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This script starts the MCP server directly by using the Python import approach."""

import argparse
import os
import sys
from awslabs.aws_iot_sitewise_mcp_server.server import main


# Add the project root to the Python path
root_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, root_dir)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='AWS IoT SiteWise MCP Server')
    parser.add_argument(
        '--allow-writes',
        action='store_true',
        help='Enable write operations (create, update, delete). By default, '
        'server runs in read-only mode.',
    )

    args = parser.parse_args()

    # Set environment variable to pass the flag to the server
    os.environ['SITEWISE_MCP_ALLOW_WRITES'] = str(args.allow_writes)

    if args.allow_writes:
        print('Starting server with WRITE operations enabled...')
    else:
        print('Starting server in READ-ONLY mode. Use --allow-writes to enable write operations.')

    main()
