Merge pull request 'config_builder' (#1) from config_builder into master
All checks were successful
Build and Push Image / Build and push image (push) Successful in 22m49s

Reviewed-on: #1
This commit is contained in:
armistace 2025-07-23 13:05:12 +10:00
commit ea91c3e495
5 changed files with 75 additions and 2 deletions

View File

@ -35,6 +35,11 @@ jobs:
username: armistace username: armistace
password: ${{ secrets.REG_PASSWORD }} password: ${{ secrets.REG_PASSWORD }}
- name: Create .env
run: |
echo "GITEA_TOKEN=${{ secrets.GITEAMCPTOKEN }}" > .env
echo "HOMEASSISTANT_TOKEN=${{ secrets.HOMEASSISTANTMCPTOKEN }}" >> .env
- name: Build and push - name: Build and push
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:

View File

@ -4,15 +4,21 @@ WORKDIR /mcpo
COPY requirements.txt requirements.txt 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 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 apt-get update -y && apt-get install -y python3 virtualenv wget tar python3-pip python3-pip
RUN ./gitea_mcp_set.sh RUN ./gitea_mcp_set.sh
RUN pip install -r requirements.txt --break-system-packages RUN pip install -r requirements.txt --break-system-packages
RUN python3 config_builder.py
EXPOSE 8000 EXPOSE 8000
ENTRYPOINT ["mcpo", "--config", "/mcpo/mcpo_config.json"] ENTRYPOINT ["mcpo", "--config", "/mcpo/config.json"]

48
config_builder.py Normal file
View File

@ -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)

11
mcpo_config.yaml Normal file
View File

@ -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}

View File

@ -1 +1,4 @@
mcpo mcpo
pyyaml
python-dotenv
pyaml_env