@google-cloud/cloud-run-mcp 1.8.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +13 -0
- package/.env.gcloud-sdk-oauth +13 -0
- package/README.md +38 -0
- package/constants.js +8 -0
- package/gemini-extension.json +12 -0
- package/lib/clients.js +72 -2
- package/lib/cloud-api/auth.js +1 -0
- package/lib/cloud-api/billing.js +16 -10
- package/lib/cloud-api/build.js +6 -4
- package/lib/cloud-api/helpers.js +19 -6
- package/lib/cloud-api/projects.js +15 -10
- package/lib/cloud-api/registry.js +5 -1
- package/lib/cloud-api/run.js +12 -11
- package/lib/cloud-api/storage.js +2 -1
- package/lib/deployment/constants.js +3 -0
- package/lib/deployment/deployer.js +75 -9
- package/lib/deployment/helpers.js +41 -48
- package/lib/deployment/source-processor.js +0 -48
- package/lib/deployment/universal-maker.js +274 -0
- package/lib/middleware/oauth.js +92 -0
- package/lib/util/helpers.js +12 -0
- package/mcp-server.js +51 -7
- package/package.json +2 -2
- package/test/local/clients.test.js +33 -3
- package/test/local/deployment-helpers.test.js +34 -86
- package/test/local/mcp-server-stdio.test.js +0 -1
- package/test/local/mcp-server-streamable-http.test.js +69 -0
- package/test/local/mcp-server.test.js +1 -0
- package/test/local/middleware/oauth.test.js +156 -0
- package/test/local/source-processor.test.js +0 -165
- package/test/local/tools.test.js +2 -2
- package/test/local/universal-maker.test.js +248 -0
- package/tools/register-tools.js +18 -5
- package/.kokoro/kokoro_build.sh +0 -22
- package/.kokoro/presubmit.cfg +0 -21
- package/.kokoro/run_tests.sh +0 -31
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { describe, it, mock, beforeEach, afterEach } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import esmock from 'esmock';
|
|
4
|
+
|
|
5
|
+
describe('oauthMiddleware', () => {
|
|
6
|
+
let req;
|
|
7
|
+
let res;
|
|
8
|
+
let next;
|
|
9
|
+
let originalEnv;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
originalEnv = process.env;
|
|
13
|
+
process.env = { ...originalEnv };
|
|
14
|
+
req = {
|
|
15
|
+
headers: {},
|
|
16
|
+
body: {},
|
|
17
|
+
};
|
|
18
|
+
res = {
|
|
19
|
+
headersSent: false,
|
|
20
|
+
status: mock.fn(() => res),
|
|
21
|
+
json: mock.fn(),
|
|
22
|
+
};
|
|
23
|
+
next = mock.fn();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
process.env = originalEnv;
|
|
28
|
+
mock.restoreAll();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should call next() if OAUTH_ENABLED is not "true"', async () => {
|
|
32
|
+
process.env.OAUTH_ENABLED = 'false';
|
|
33
|
+
const { oauthMiddleware } = await esmock(
|
|
34
|
+
'../../../lib/middleware/oauth.js',
|
|
35
|
+
{}
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
await oauthMiddleware(req, res, next);
|
|
39
|
+
|
|
40
|
+
assert.strictEqual(next.mock.callCount(), 1);
|
|
41
|
+
assert.strictEqual(res.status.mock.callCount(), 0);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should call next() if method is not tools/call', async () => {
|
|
45
|
+
process.env.OAUTH_ENABLED = 'true';
|
|
46
|
+
req.body.method = 'other/method';
|
|
47
|
+
|
|
48
|
+
// We don't verify token if it's not a tool call (based on current implementation)
|
|
49
|
+
// So we don't need to mock successful verification here
|
|
50
|
+
const { oauthMiddleware } = await esmock(
|
|
51
|
+
'../../../lib/middleware/oauth.js',
|
|
52
|
+
{}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
await oauthMiddleware(req, res, next);
|
|
56
|
+
|
|
57
|
+
assert.strictEqual(next.mock.callCount(), 1);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should return 401 if Authorization header is missing for tool call', async () => {
|
|
61
|
+
process.env.OAUTH_ENABLED = 'true';
|
|
62
|
+
req.body.method = 'tools/call';
|
|
63
|
+
|
|
64
|
+
const { oauthMiddleware } = await esmock(
|
|
65
|
+
'../../../lib/middleware/oauth.js',
|
|
66
|
+
{}
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
await oauthMiddleware(req, res, next);
|
|
70
|
+
|
|
71
|
+
assert.strictEqual(next.mock.callCount(), 0);
|
|
72
|
+
assert.strictEqual(res.status.mock.callCount(), 1);
|
|
73
|
+
assert.deepStrictEqual(res.status.mock.calls[0].arguments, [401]);
|
|
74
|
+
assert.strictEqual(res.json.mock.callCount(), 1);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should verify token and call next() for valid tool call', async () => {
|
|
78
|
+
process.env.OAUTH_ENABLED = 'true';
|
|
79
|
+
req.body.method = 'tools/call';
|
|
80
|
+
req.headers.authorization = 'Bearer valid-token';
|
|
81
|
+
|
|
82
|
+
const mockGetTokenInfo = mock.fn(async () => ({ aud: 'valid-audience' }));
|
|
83
|
+
const mockGetOAuthClient = mock.fn(async () => ({
|
|
84
|
+
getTokenInfo: mockGetTokenInfo,
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
const { oauthMiddleware } = await esmock(
|
|
88
|
+
'../../../lib/middleware/oauth.js',
|
|
89
|
+
{
|
|
90
|
+
'../../../lib/clients.js': {
|
|
91
|
+
getOAuthClient: mockGetOAuthClient,
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
await oauthMiddleware(req, res, next);
|
|
97
|
+
|
|
98
|
+
assert.strictEqual(next.mock.callCount(), 1);
|
|
99
|
+
assert.strictEqual(mockGetOAuthClient.mock.callCount(), 1);
|
|
100
|
+
assert.strictEqual(mockGetTokenInfo.mock.callCount(), 1);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should return 401 if token verification fails', async () => {
|
|
104
|
+
process.env.OAUTH_ENABLED = 'true';
|
|
105
|
+
req.body.method = 'tools/call';
|
|
106
|
+
req.headers.authorization = 'Bearer invalid-token';
|
|
107
|
+
|
|
108
|
+
const mockGetOAuthClient = mock.fn(async () => ({
|
|
109
|
+
getTokenInfo: async () => {
|
|
110
|
+
throw new Error('Invalid token');
|
|
111
|
+
},
|
|
112
|
+
}));
|
|
113
|
+
|
|
114
|
+
const { oauthMiddleware } = await esmock(
|
|
115
|
+
'../../../lib/middleware/oauth.js',
|
|
116
|
+
{
|
|
117
|
+
'../../../lib/clients.js': {
|
|
118
|
+
getOAuthClient: mockGetOAuthClient,
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
await oauthMiddleware(req, res, next);
|
|
124
|
+
|
|
125
|
+
assert.strictEqual(next.mock.callCount(), 0);
|
|
126
|
+
assert.strictEqual(res.status.mock.callCount(), 1);
|
|
127
|
+
assert.deepStrictEqual(res.status.mock.calls[0].arguments, [401]);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should return 401 if audience does not match', async () => {
|
|
131
|
+
process.env.OAUTH_ENABLED = 'true';
|
|
132
|
+
process.env.GOOGLE_OAUTH_AUDIENCE = 'expected-audience';
|
|
133
|
+
req.body.method = 'tools/call';
|
|
134
|
+
req.headers.authorization = 'Bearer valid-token-wrong-audience';
|
|
135
|
+
|
|
136
|
+
const mockGetTokenInfo = mock.fn(async () => ({ aud: 'wrong-audience' }));
|
|
137
|
+
const mockGetOAuthClient = mock.fn(async () => ({
|
|
138
|
+
getTokenInfo: mockGetTokenInfo,
|
|
139
|
+
}));
|
|
140
|
+
|
|
141
|
+
const { oauthMiddleware } = await esmock(
|
|
142
|
+
'../../../lib/middleware/oauth.js',
|
|
143
|
+
{
|
|
144
|
+
'../../../lib/clients.js': {
|
|
145
|
+
getOAuthClient: mockGetOAuthClient,
|
|
146
|
+
},
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
await oauthMiddleware(req, res, next);
|
|
151
|
+
|
|
152
|
+
assert.strictEqual(next.mock.callCount(), 0);
|
|
153
|
+
assert.strictEqual(res.status.mock.callCount(), 1);
|
|
154
|
+
assert.deepStrictEqual(res.status.mock.calls[0].arguments, [401]);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -75,171 +75,6 @@ describe('Source Processor', () => {
|
|
|
75
75
|
assert.ok(cpCall, 'Should call cp -R for directories');
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
test('installDependencies runs npm install for Node.js', async () => {
|
|
79
|
-
// We need to mock fs.existsSync as well
|
|
80
|
-
const fsMock = {
|
|
81
|
-
existsSync: mock.fn(),
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const sourceProcessor = await esmock(
|
|
85
|
-
'../../lib/deployment/source-processor.js',
|
|
86
|
-
{
|
|
87
|
-
'node:fs': fsMock,
|
|
88
|
-
'node:fs/promises': fspMock,
|
|
89
|
-
'node:child_process': childProcessMock,
|
|
90
|
-
}
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
const targetDir = '/temp/dir';
|
|
94
|
-
const deploymentAttrs = {
|
|
95
|
-
runtime: 'nodejs',
|
|
96
|
-
cmd: ['node', 'server.js'],
|
|
97
|
-
args: ['server.js'],
|
|
98
|
-
baseImage: 'node:22',
|
|
99
|
-
};
|
|
100
|
-
const progressCallback = mock.fn();
|
|
101
|
-
|
|
102
|
-
// Mock existsSync
|
|
103
|
-
fsMock.existsSync.mock.mockImplementation((p) => {
|
|
104
|
-
if (p.includes('node_modules')) return false; // not installed yet
|
|
105
|
-
if (p.includes('package-lock.json')) return false; // no lock file
|
|
106
|
-
return false;
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// Mock exec for npm install
|
|
110
|
-
childProcessMock.exec.mock.mockImplementation((cmd, opts, callback) => {
|
|
111
|
-
if (typeof opts === 'function') callback = opts;
|
|
112
|
-
if (callback) callback(null, 'ok', '');
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
await sourceProcessor.installDependencies(
|
|
116
|
-
targetDir,
|
|
117
|
-
deploymentAttrs,
|
|
118
|
-
progressCallback
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const calls = childProcessMock.exec.mock.calls;
|
|
122
|
-
const npmCall = calls.find((call) =>
|
|
123
|
-
call.arguments[0].includes('npm install')
|
|
124
|
-
);
|
|
125
|
-
assert.ok(npmCall, 'Should run npm install');
|
|
126
|
-
assert.strictEqual(npmCall.arguments[1].cwd, targetDir);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test('installDependencies uses npm ci if lockfile exists', async () => {
|
|
130
|
-
const fsMock = {
|
|
131
|
-
existsSync: mock.fn(),
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const sourceProcessor = await esmock(
|
|
135
|
-
'../../lib/deployment/source-processor.js',
|
|
136
|
-
{
|
|
137
|
-
'node:fs': fsMock,
|
|
138
|
-
'node:child_process': childProcessMock,
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
const targetDir = '/temp/dir';
|
|
143
|
-
const deploymentAttrs = {
|
|
144
|
-
runtime: 'nodejs',
|
|
145
|
-
cmd: ['node', 'server.js'],
|
|
146
|
-
args: ['server.js'],
|
|
147
|
-
baseImage: 'node:22',
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
// Mock existsSync
|
|
151
|
-
fsMock.existsSync.mock.mockImplementation((p) => {
|
|
152
|
-
if (p.includes('node_modules')) return false;
|
|
153
|
-
if (p.includes('package-lock.json')) return true; // has lock file
|
|
154
|
-
return false;
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
childProcessMock.exec.mock.mockImplementation((cmd, opts, callback) => {
|
|
158
|
-
if (typeof opts === 'function') callback = opts;
|
|
159
|
-
if (callback) callback(null, 'ok', '');
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
await sourceProcessor.installDependencies(
|
|
163
|
-
targetDir,
|
|
164
|
-
deploymentAttrs,
|
|
165
|
-
() => {}
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
const calls = childProcessMock.exec.mock.calls;
|
|
169
|
-
const npmCall = calls.find((call) => call.arguments[0].includes('npm ci'));
|
|
170
|
-
assert.ok(npmCall, 'Should run npm ci');
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test('installDependencies skips if node_modules exists', async () => {
|
|
174
|
-
const fsMock = {
|
|
175
|
-
existsSync: mock.fn(),
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
const sourceProcessor = await esmock(
|
|
179
|
-
'../../lib/deployment/source-processor.js',
|
|
180
|
-
{
|
|
181
|
-
'node:fs': fsMock,
|
|
182
|
-
'node:child_process': childProcessMock,
|
|
183
|
-
}
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
fsMock.existsSync.mock.mockImplementation((p) => {
|
|
187
|
-
if (p.includes('node_modules')) return true;
|
|
188
|
-
return false;
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// clear mock calls
|
|
192
|
-
childProcessMock.exec.mock.resetCalls();
|
|
193
|
-
|
|
194
|
-
await sourceProcessor.installDependencies(
|
|
195
|
-
'/dir',
|
|
196
|
-
{
|
|
197
|
-
runtime: 'nodejs',
|
|
198
|
-
cmd: ['node', 'server.js'],
|
|
199
|
-
args: ['server.js'],
|
|
200
|
-
baseImage: 'node:22',
|
|
201
|
-
},
|
|
202
|
-
() => {}
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
assert.equal(childProcessMock.exec.mock.callCount(), 0);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
test('installDependencies logs warn on failure but does not throw', async () => {
|
|
209
|
-
const fsMock = { existsSync: mock.fn(() => false) };
|
|
210
|
-
const sourceProcessor = await esmock(
|
|
211
|
-
'../../lib/deployment/source-processor.js',
|
|
212
|
-
{
|
|
213
|
-
'node:fs': fsMock,
|
|
214
|
-
'node:child_process': childProcessMock,
|
|
215
|
-
}
|
|
216
|
-
);
|
|
217
|
-
|
|
218
|
-
childProcessMock.exec.mock.mockImplementation((cmd, opts, callback) => {
|
|
219
|
-
if (typeof opts === 'function') callback = opts;
|
|
220
|
-
callback(new Error('npm failed'));
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
const consoleLogMock = mock.method(console, 'log');
|
|
224
|
-
|
|
225
|
-
await assert.doesNotReject(async () => {
|
|
226
|
-
await sourceProcessor.installDependencies('/dir', { runtime: 'nodejs' });
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
assert.equal(
|
|
230
|
-
consoleLogMock.mock.callCount(),
|
|
231
|
-
1,
|
|
232
|
-
'console.log should be called once'
|
|
233
|
-
);
|
|
234
|
-
const logArgs = consoleLogMock.mock.calls[0].arguments;
|
|
235
|
-
assert.ok(
|
|
236
|
-
logArgs[0].includes('Dependency installation failed: npm failed'),
|
|
237
|
-
'console.log should contain the error message'
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
consoleLogMock.mock.restore();
|
|
241
|
-
});
|
|
242
|
-
|
|
243
78
|
test('cleanupTempDirectory removes directory', async () => {
|
|
244
79
|
const fsMock = {
|
|
245
80
|
existsSync: mock.fn(() => true),
|
package/test/local/tools.test.js
CHANGED
|
@@ -42,7 +42,7 @@ describe('registerTools', () => {
|
|
|
42
42
|
{},
|
|
43
43
|
{
|
|
44
44
|
'../../lib/cloud-api/projects.js': {
|
|
45
|
-
listProjects: () =>
|
|
45
|
+
listProjects: (token) =>
|
|
46
46
|
Promise.resolve([{ id: 'project1' }, { id: 'project2' }]),
|
|
47
47
|
},
|
|
48
48
|
}
|
|
@@ -433,7 +433,7 @@ describe('registerTools', () => {
|
|
|
433
433
|
content: [
|
|
434
434
|
{
|
|
435
435
|
type: 'text',
|
|
436
|
-
text: 'GCP credentials are not available. Please configure your environment
|
|
436
|
+
text: 'GCP credentials are not available. Please configure your environment using OAuth or `gcloud auth`.',
|
|
437
437
|
},
|
|
438
438
|
],
|
|
439
439
|
});
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2025 Google LLC
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { test, describe, mock } from 'node:test';
|
|
18
|
+
import assert from 'node:assert/strict';
|
|
19
|
+
import esmock from 'esmock';
|
|
20
|
+
|
|
21
|
+
describe('Universal Maker', () => {
|
|
22
|
+
const fsMock = {
|
|
23
|
+
existsSync: mock.fn(),
|
|
24
|
+
mkdirSync: mock.fn(),
|
|
25
|
+
chmodSync: mock.fn(),
|
|
26
|
+
readFileSync: mock.fn(),
|
|
27
|
+
rmSync: mock.fn(),
|
|
28
|
+
unlinkSync: mock.fn(),
|
|
29
|
+
createWriteStream: mock.fn(),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const cryptoMock = {
|
|
33
|
+
createHash: mock.fn(),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const childProcessMock = {
|
|
37
|
+
exec: mock.fn(),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const osMock = {
|
|
41
|
+
homedir: () => '/home/user',
|
|
42
|
+
tmpdir: () => '/tmp',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const helpersMock = {
|
|
46
|
+
logAndProgress: mock.fn(),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const clientsMock = {
|
|
50
|
+
getArtifactRegistryClient: mock.fn(),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
test('runUniversalMaker skips download if binary exists and runs successfully', async () => {
|
|
54
|
+
fsMock.existsSync.mock.resetCalls();
|
|
55
|
+
fsMock.readFileSync.mock.resetCalls();
|
|
56
|
+
childProcessMock.exec.mock.resetCalls();
|
|
57
|
+
|
|
58
|
+
const localContent = 'local content';
|
|
59
|
+
const sha256 =
|
|
60
|
+
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';
|
|
61
|
+
|
|
62
|
+
cryptoMock.createHash.mock.mockImplementation(() => ({
|
|
63
|
+
update: mock.fn(() => ({
|
|
64
|
+
digest: mock.fn(() => sha256),
|
|
65
|
+
})),
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
// Mock binary exists
|
|
69
|
+
fsMock.existsSync.mock.mockImplementation((p) => {
|
|
70
|
+
if (p.includes('universal_maker')) return true;
|
|
71
|
+
if (p.includes('build_output.json')) return true;
|
|
72
|
+
return false;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
fsMock.readFileSync.mock.mockImplementation((p) => {
|
|
76
|
+
if (p.includes('universal_maker')) return localContent;
|
|
77
|
+
if (p.includes('build_output.json')) {
|
|
78
|
+
return JSON.stringify({
|
|
79
|
+
command: 'node',
|
|
80
|
+
args: ['index.js'],
|
|
81
|
+
runtime: 'nodejs20',
|
|
82
|
+
envVars: { DEBUG: 'true' },
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return '';
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Mock Artifact Registry client
|
|
89
|
+
const artifactRegistryClientMock = {
|
|
90
|
+
filePath: mock.fn(
|
|
91
|
+
(p, l, r, f) =>
|
|
92
|
+
`projects/${p}/locations/${l}/repositories/${r}/files/${f}`
|
|
93
|
+
),
|
|
94
|
+
getFile: mock.fn(() => [
|
|
95
|
+
{
|
|
96
|
+
hashes: [
|
|
97
|
+
{
|
|
98
|
+
type: 'SHA256',
|
|
99
|
+
value: Buffer.from(sha256, 'hex').toString('base64'),
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
]),
|
|
104
|
+
};
|
|
105
|
+
clientsMock.getArtifactRegistryClient.mock.mockImplementation(
|
|
106
|
+
() => artifactRegistryClientMock
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const um = await esmock('../../lib/deployment/universal-maker.js', {
|
|
110
|
+
fs: fsMock,
|
|
111
|
+
child_process: childProcessMock,
|
|
112
|
+
os: osMock,
|
|
113
|
+
crypto: cryptoMock,
|
|
114
|
+
'../../lib/util/helpers.js': helpersMock,
|
|
115
|
+
'../../lib/clients.js': clientsMock,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Mock exec only for binary execution
|
|
119
|
+
childProcessMock.exec.mock.mockImplementation((cmd, cb) => {
|
|
120
|
+
cb(null, { stdout: '', stderr: '' });
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// runUniversalMaker(appDir, accessToken, progressCallback)
|
|
124
|
+
const result = await um.runUniversalMaker(
|
|
125
|
+
'/app/dir',
|
|
126
|
+
'fake-token',
|
|
127
|
+
mock.fn()
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
assert.ok(result);
|
|
131
|
+
assert.equal(result.command, 'node');
|
|
132
|
+
assert.deepEqual(result.args, ['index.js']);
|
|
133
|
+
assert.equal(result.runtime, 'nodejs20');
|
|
134
|
+
|
|
135
|
+
// Verify bin check was performed
|
|
136
|
+
const binExistsCall = fsMock.existsSync.mock.calls.find((c) =>
|
|
137
|
+
c.arguments[0].includes('universal_maker')
|
|
138
|
+
);
|
|
139
|
+
assert.ok(binExistsCall);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('runUniversalMaker downloads binary if missing', async () => {
|
|
143
|
+
fsMock.existsSync.mock.resetCalls();
|
|
144
|
+
fsMock.readFileSync.mock.resetCalls();
|
|
145
|
+
childProcessMock.exec.mock.resetCalls();
|
|
146
|
+
|
|
147
|
+
let downloaded = false;
|
|
148
|
+
|
|
149
|
+
// Mock binary missing first, then exists after "download"
|
|
150
|
+
fsMock.existsSync.mock.mockImplementation((p) => {
|
|
151
|
+
if (p.includes('universal_maker')) return downloaded;
|
|
152
|
+
if (p.includes('build_output.json')) return true;
|
|
153
|
+
return true; // for dir checks
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Mock Artifact Registry client for download
|
|
157
|
+
const artifactRegistryClientMock = {
|
|
158
|
+
filePath: mock.fn(
|
|
159
|
+
(p, l, r, f) =>
|
|
160
|
+
`projects/${p}/locations/${l}/repositories/${r}/files/${f}`
|
|
161
|
+
),
|
|
162
|
+
getFile: mock.fn(() => [{ hashes: [] }]), // trigger download
|
|
163
|
+
auth: {
|
|
164
|
+
request: mock.fn(() => {
|
|
165
|
+
downloaded = true;
|
|
166
|
+
return {
|
|
167
|
+
data: {
|
|
168
|
+
pipe: (dest) => {
|
|
169
|
+
setTimeout(() => dest.emit('finish'), 10);
|
|
170
|
+
return dest;
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}),
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
clientsMock.getArtifactRegistryClient.mock.mockImplementation(
|
|
178
|
+
() => artifactRegistryClientMock
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const writeStreamMock = {
|
|
182
|
+
on: mock.fn(function (event, cb) {
|
|
183
|
+
if (event === 'finish') this.finishCb = cb;
|
|
184
|
+
return this;
|
|
185
|
+
}),
|
|
186
|
+
emit: mock.fn(function (event) {
|
|
187
|
+
if (event === 'finish' && this.finishCb) this.finishCb();
|
|
188
|
+
}),
|
|
189
|
+
pipeFrom: mock.fn(),
|
|
190
|
+
};
|
|
191
|
+
fsMock.createWriteStream = mock.fn(() => writeStreamMock);
|
|
192
|
+
|
|
193
|
+
fsMock.readFileSync.mock.mockImplementation(() =>
|
|
194
|
+
JSON.stringify({ command: 'npm', args: ['start'] })
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
const um = await esmock('../../lib/deployment/universal-maker.js', {
|
|
198
|
+
fs: fsMock,
|
|
199
|
+
child_process: childProcessMock,
|
|
200
|
+
os: osMock,
|
|
201
|
+
crypto: cryptoMock,
|
|
202
|
+
'../../lib/util/helpers.js': helpersMock,
|
|
203
|
+
'../../lib/clients.js': clientsMock,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Mock exec only for binary execution
|
|
207
|
+
childProcessMock.exec.mock.mockImplementation((cmd, cb) => {
|
|
208
|
+
cb(null, { stdout: '', stderr: '' });
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// runUniversalMaker(appDir, accessToken, progressCallback)
|
|
212
|
+
const result = await um.runUniversalMaker(
|
|
213
|
+
'/app/dir',
|
|
214
|
+
'fake-token',
|
|
215
|
+
mock.fn()
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
assert.ok(result);
|
|
219
|
+
assert.equal(result.command, 'npm');
|
|
220
|
+
assert.ok(downloaded);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('runUniversalMaker returns null if binary not supported on platform', async () => {
|
|
224
|
+
// Save original platform
|
|
225
|
+
const originalPlatform = process.platform;
|
|
226
|
+
Object.defineProperty(process, 'platform', { value: 'win32' });
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
const um = await esmock('../../lib/deployment/universal-maker.js', {
|
|
230
|
+
fs: fsMock,
|
|
231
|
+
child_process: childProcessMock,
|
|
232
|
+
os: osMock,
|
|
233
|
+
crypto: cryptoMock,
|
|
234
|
+
'../../lib/util/helpers.js': helpersMock,
|
|
235
|
+
'../../lib/clients.js': clientsMock,
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const result = await um.runUniversalMaker(
|
|
239
|
+
'/app/dir',
|
|
240
|
+
'fake-token',
|
|
241
|
+
mock.fn()
|
|
242
|
+
);
|
|
243
|
+
assert.equal(result, null);
|
|
244
|
+
} finally {
|
|
245
|
+
Object.defineProperty(process, 'platform', { value: originalPlatform });
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
});
|
package/tools/register-tools.js
CHANGED
|
@@ -41,7 +41,7 @@ function gcpTool(gcpCredentialsAvailable, fn) {
|
|
|
41
41
|
content: [
|
|
42
42
|
{
|
|
43
43
|
type: 'text',
|
|
44
|
-
text: 'GCP credentials are not available. Please configure your environment
|
|
44
|
+
text: 'GCP credentials are not available. Please configure your environment using OAuth or `gcloud auth`.',
|
|
45
45
|
},
|
|
46
46
|
],
|
|
47
47
|
});
|
|
@@ -59,7 +59,7 @@ function registerListProjectsTool(server, options) {
|
|
|
59
59
|
},
|
|
60
60
|
gcpTool(options.gcpCredentialsAvailable, async () => {
|
|
61
61
|
try {
|
|
62
|
-
const projects = await listProjects();
|
|
62
|
+
const projects = await listProjects(options.accessToken);
|
|
63
63
|
return {
|
|
64
64
|
content: [
|
|
65
65
|
{
|
|
@@ -113,7 +113,11 @@ function registerCreateProjectTool(server, options) {
|
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
try {
|
|
116
|
-
const result = await createProjectAndAttachBilling(
|
|
116
|
+
const result = await createProjectAndAttachBilling(
|
|
117
|
+
projectId,
|
|
118
|
+
undefined,
|
|
119
|
+
options.accessToken
|
|
120
|
+
);
|
|
117
121
|
return {
|
|
118
122
|
content: [
|
|
119
123
|
{
|
|
@@ -161,7 +165,7 @@ function registerListServicesTool(server, options) {
|
|
|
161
165
|
};
|
|
162
166
|
}
|
|
163
167
|
try {
|
|
164
|
-
const allServices = await listServices(project);
|
|
168
|
+
const allServices = await listServices(project, options.accessToken);
|
|
165
169
|
const content = [];
|
|
166
170
|
for (const region of Object.keys(allServices)) {
|
|
167
171
|
const serviceList = allServices[region];
|
|
@@ -230,7 +234,12 @@ function registerGetServiceTool(server, options) {
|
|
|
230
234
|
};
|
|
231
235
|
}
|
|
232
236
|
try {
|
|
233
|
-
const serviceDetails = await getService(
|
|
237
|
+
const serviceDetails = await getService(
|
|
238
|
+
project,
|
|
239
|
+
region,
|
|
240
|
+
service,
|
|
241
|
+
options.accessToken
|
|
242
|
+
);
|
|
234
243
|
if (serviceDetails) {
|
|
235
244
|
return {
|
|
236
245
|
content: [
|
|
@@ -299,6 +308,7 @@ function registerGetServiceLogTool(server, options) {
|
|
|
299
308
|
project,
|
|
300
309
|
region,
|
|
301
310
|
service,
|
|
311
|
+
options.accessToken,
|
|
302
312
|
requestOptions
|
|
303
313
|
);
|
|
304
314
|
|
|
@@ -394,6 +404,7 @@ function registerDeployLocalFolderTool(server, options) {
|
|
|
394
404
|
region: region,
|
|
395
405
|
files: [folderPath],
|
|
396
406
|
skipIamCheck: options.skipIamCheck, // Pass the new flag
|
|
407
|
+
accessToken: options.accessToken,
|
|
397
408
|
progressCallback,
|
|
398
409
|
});
|
|
399
410
|
return {
|
|
@@ -495,6 +506,7 @@ function registerDeployFileContentsTool(server, options) {
|
|
|
495
506
|
region: region,
|
|
496
507
|
files: files,
|
|
497
508
|
skipIamCheck: options.skipIamCheck, // Pass the new flag
|
|
509
|
+
accessToken: options.accessToken,
|
|
498
510
|
progressCallback,
|
|
499
511
|
});
|
|
500
512
|
return {
|
|
@@ -575,6 +587,7 @@ function registerDeployContainerImageTool(server, options) {
|
|
|
575
587
|
region: region,
|
|
576
588
|
imageUrl: imageUrl,
|
|
577
589
|
skipIamCheck: options.skipIamCheck,
|
|
590
|
+
accessToken: options.accessToken,
|
|
578
591
|
progressCallback,
|
|
579
592
|
});
|
|
580
593
|
return {
|
package/.kokoro/kokoro_build.sh
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Copyright 2022 Google LLC
|
|
4
|
-
#
|
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
# you may not use this file except in compliance with the License.
|
|
7
|
-
# You may obtain a copy of the License at
|
|
8
|
-
#
|
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
#
|
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
# See the License for the specific language governing permissions and
|
|
15
|
-
# limitations under the License.
|
|
16
|
-
|
|
17
|
-
# Code under repo is checked out to ${KOKORO_ARTIFACTS_DIR}/git.
|
|
18
|
-
# The final directory name in this path is determined by the scm name specified
|
|
19
|
-
# in the job configuration.
|
|
20
|
-
|
|
21
|
-
cd "${KOKORO_ARTIFACTS_DIR}/github/cloud-run-mcp"
|
|
22
|
-
.kokoro/run_tests.sh
|