← Files Dataiku HeadlessARCHIVED FILE

runtime/run_mcp.py

3.31 KB · Nov 11, 2026 · 12:58 UTC

↓ Download file

See the change to this file →

#!/usr/bin/env -S uv run --locked --script
# /// script
# requires-python = ">=3.10"
# dependencies = [
#     "fastmcp==3.4.5",
#     "dataiku-api-client==14.7.2",
#     "pydantic==2.13.4",
#     "python-dotenv==1.2.2",
#     "requests==2.34.2",
#     "six==1.17.0",
#     "truststore==0.10.5",
# ]
# ///

# Copyright 2026 Dataiku SAS
#
# 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.

"""PEP 723 entry point for the Dataiku MCP server.

The inline script metadata above lets uv build the runtime environment on the
fly, so a harness with uv 0.12.0 or later can start the server without a
project install:

    uv run --quiet --locked --script runtime/run_mcp.py --transport stdio
    uv run --quiet --locked --script runtime/run_mcp.py --transport http

The plugin manifests invoke this script directly through uv. ``runtime/launcher.sh``
is retained as inactive legacy code for a possible future fallback path.

uv installs the committed ``runtime/run_mcp.py.lock`` resolution into a cached,
isolated environment on the first launch and reuses it afterwards. ``--locked``
prevents a launch from resolving or changing that lock. After deliberately
changing the inline metadata, regenerate the lock with
``uv lock --script runtime/run_mcp.py`` and commit it. The ``==`` pins above remain
the direct dependency constraints; the lock also records their transitive
dependencies.

The third-party runtime dependencies are declared above. Each pin must satisfy
the corresponding entry in ``[project].dependencies`` in ``pyproject.toml``, and
the package set must match it — the test in ``tests/test_pep723_launcher.py``
enforces both.

``dataiku_mcp`` is imported from this clone rather than from an installed
distribution — the package is not published to a package index — so the
repository root goes on ``sys.path`` before the import.
"""

import argparse
import sys
from pathlib import Path

from dotenv import load_dotenv

REPO_ROOT = Path(__file__).resolve().parent.parent
if str(REPO_ROOT) not in sys.path:
    sys.path.insert(0, str(REPO_ROOT))


def main() -> None:
    parser = argparse.ArgumentParser(description="Run the Dataiku MCP server.")
    parser.add_argument("--transport", choices=("stdio", "http"), required=True)
    parser.add_argument(
        "--settings-path",
        type=Path,
        help="Path to the transport-specific settings file.",
    )
    args = parser.parse_args()

    load_dotenv(REPO_ROOT / ".env", override=False)

    # Activate system CA trust before importing any networking libraries.
    # Keep this application-wide SSL patch out of package imports.
    import truststore

    truststore.inject_into_ssl()

    from dataiku_mcp import run_http_server, run_stdio_server

    if args.transport == "stdio":
        run_stdio_server(args.settings_path)
    else:
        run_http_server(args.settings_path)


if __name__ == "__main__":
    main()

SHA-256: d689671a0cabd01eed2598433b56eb659e58b176814b8495cb66c8df8eed1549