diff --git a/.gitea/workflows/build_push.yml b/.gitea/workflows/build_push.yml index 6848481..ad32387 100644 --- a/.gitea/workflows/build_push.yml +++ b/.gitea/workflows/build_push.yml @@ -35,6 +35,11 @@ jobs: username: armistace password: ${{ secrets.REG_PASSWORD }} + - name: Create .env + run: | + echo "GITEA_TOKEN=${{ secrets.GITEAMCPTOKEN }}" > .env + echo "HOMEASSISTANT_TOKEN=${{ secrets.HOMEASSISTANTMCPTOKEN }}" >> .env + - name: Build and push uses: docker/build-push-action@v5 with: diff --git a/Dockerfile b/Dockerfile index 10ba1d8..e61728a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,15 +4,21 @@ WORKDIR /mcpo COPY requirements.txt requirements.txt -COPY mcpo_config.json mcpo_config.json +COPY mcpo_config.yaml mcpo_config.yaml + +COPY config_builder.py config_builder.py COPY gitea_mcp_set.sh gitea_mcp_set.sh +COPY .env .env + RUN apt-get update -y && apt-get install -y python3 virtualenv wget tar python3-pip python3-pip RUN ./gitea_mcp_set.sh RUN pip install -r requirements.txt --break-system-packages +RUN python3 config_builder.py + EXPOSE 8000 -ENTRYPOINT ["mcpo", "--config", "/mcpo/mcpo_config.json"] +ENTRYPOINT ["mcpo", "--config", "/mcpo/config.json"] diff --git a/config_builder.py b/config_builder.py new file mode 100644 index 0000000..2d708ae --- /dev/null +++ b/config_builder.py @@ -0,0 +1,48 @@ +import yaml +import os +import re +from dotenv import load_dotenv +from pyaml_env import parse_config +import json + +load_dotenv() +#conf = parse_config('mcpo_config.yaml') + +#print(conf) +# pattern for global vars: look for ${word} +pattern = re.compile(r'.*?\${(\w+)}.*?') +loader = yaml.SafeLoader +tag = '!ENV' + +# the tag will be used to mark where to start searching for the pattern +# e.g. somekey: !ENV somestring${MYENVVAR}blah blah blah +loader.add_implicit_resolver(tag, pattern, None) + +conf=None +def constructor_env_variables(loader, node): + """ + Extracts the environment variable from the node's value + :param yaml.Loader loader: the yaml loader + :param node: the current node in the yaml + :return: the parsed string that contains the value of the environment + variable + """ + value = loader.construct_scalar(node) + match = pattern.findall(value) + if match: + full_value = value + for g in match: + full_value = full_value.replace( + f'${{{g}}}', os.environ.get(g, g) + ) + return full_value + return value + +loader.add_constructor(tag, constructor_env_variables) +with open('mcpo_config.yaml') as yaml_conf: + try: + conf = yaml.load(yaml_conf, Loader=loader) + except yaml.YAMLError as exc: + print(exc) +with open("config.json", "w") as json_file: + json.dump(conf, json_file, indent=2) diff --git a/mcpo_config.yaml b/mcpo_config.yaml new file mode 100644 index 0000000..0f93208 --- /dev/null +++ b/mcpo_config.yaml @@ -0,0 +1,11 @@ +mcpServers: + gitea_stdio: + command: "gitea-mcp" + args: ["-t", "stdio", "--host", "https://git.aridgwayweb.com"] + env: + GITEA_ACCESS_TOKEN: !ENV ${GITEA_TOKEN} + homeassistant: + type: sse + url: "https://homeassistant.aridgwayweb.com/mcp_server/sse" + headers: + Authorization: !ENV ${HOMEASSISTANT_TOKEN} diff --git a/requirements.txt b/requirements.txt index 9dbd69b..df16a19 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,4 @@ mcpo +pyyaml +python-dotenv +pyaml_env