diff --git a/agents/mcp_server/server.py b/agents/mcp_server/server.py index 2b0bfc7..753edf5 100644 --- a/agents/mcp_server/server.py +++ b/agents/mcp_server/server.py @@ -25,6 +25,16 @@ def verify_token(x_mcp_key: str = Header(default="")): return True +def _cloudbuild_client(): + """Returnerer CloudBuildClient koblet til regional endpoint.""" + from google.cloud.devtools import cloudbuild_v1 + from google.api_core.client_options import ClientOptions + endpoint = f"{REGION}-cloudbuild.googleapis.com" + return cloudbuild_v1.CloudBuildClient( + client_options=ClientOptions(api_endpoint=endpoint) + ) + + class PushStaticRequest(BaseModel): file_path: str content: str @@ -84,13 +94,13 @@ async def push_static(req: PushStaticRequest, _: bool = Depends(verify_token)): @app.get("/tools/get_build_status") async def get_build_status(_: bool = Depends(verify_token)): """ - Henter siste build fra osvauco-agent-main-trigger (us-central1). - Bruker regional parent-format: projects/{project}/locations/{region} + Henter siste build fra osvauco-agent-main-trigger. + Bruker regional endpoint: {region}-cloudbuild.googleapis.com + og parent: projects/{project}/locations/{region} """ try: from google.cloud.devtools import cloudbuild_v1 - client = cloudbuild_v1.CloudBuildClient() - # Regional builds krever parent i stedet for project_id + client = _cloudbuild_client() parent = f"projects/{PROJECT_ID}/locations/{REGION}" request = cloudbuild_v1.ListBuildsRequest( parent=parent, @@ -129,7 +139,7 @@ async def get_build_status(_: bool = Depends(verify_token)): async def deploy_service(req: DeployServiceRequest, _: bool = Depends(verify_token)): try: from google.cloud.devtools import cloudbuild_v1 - client = cloudbuild_v1.CloudBuildClient() + client = _cloudbuild_client() trigger_id = req.trigger_id or BUILD_TRIGGER_ID subs = {"BRANCH_NAME": req.branch, **req.substitutions} response = client.run_build_trigger(