@heroku/mcp-server 1.0.7-alpha.1 → 1.1.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/README.md +133 -50
- package/bin/heroku-mcp-server.mjs +1 -0
- package/dist/index.js +10 -2
- package/dist/repl/heroku-cli-repl.js +44 -2
- package/dist/repl/heroku-cli-repl.spec.js +161 -0
- package/dist/resources/dev-center-resource.js +34 -0
- package/dist/resources/dev-center-resource.spec.js +19 -0
- package/dist/tools/addons.spec.js +53 -84
- package/dist/tools/ai.spec.js +38 -54
- package/dist/tools/apps.js +0 -23
- package/dist/tools/apps.spec.js +56 -120
- package/dist/tools/data.spec.js +110 -92
- package/dist/tools/logs.spec.js +17 -22
- package/dist/tools/maintenance.spec.js +34 -36
- package/dist/tools/pipelines.spec.js +88 -75
- package/dist/tools/ps.spec.js +56 -53
- package/dist/tools/spaces.spec.js +12 -19
- package/dist/tools/teams.spec.js +13 -19
- package/dist/utils/mcp-tool-mocks.spec.js +71 -0
- package/dist/utils/mcp-tool-mocks.spechelper.js +33 -0
- package/package.json +20 -9
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
import sinon from 'sinon';
|
|
3
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
-
import { HerokuREPL } from '../repl/heroku-cli-repl.js';
|
|
5
3
|
import { listAddonsOptionsSchema, getAddonInfoOptionsSchema, createAddonOptionsSchema, listAddonServicesOptionsSchema, listAddonPlansOptionsSchema, registerListAddonsTool, registerGetAddonInfoTool, registerCreateAddonTool, registerListAddonServicesTool, registerListAddonPlansTool } from './addons.js';
|
|
6
4
|
import { CommandBuilder } from '../utils/command-builder.js';
|
|
7
5
|
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
6
|
+
import { setupMcpToolMocks } from '../utils/mcp-tool-mocks.spechelper.js';
|
|
8
7
|
describe('addons topic tools', () => {
|
|
9
8
|
describe('registerListAddonsTool', () => {
|
|
10
|
-
let
|
|
11
|
-
let herokuRepl;
|
|
9
|
+
let mocks;
|
|
12
10
|
let toolCallback;
|
|
13
11
|
beforeEach(() => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
toolCallback = callback;
|
|
18
|
-
return server;
|
|
19
|
-
});
|
|
20
|
-
registerListAddonsTool(server, herokuRepl);
|
|
12
|
+
mocks = setupMcpToolMocks();
|
|
13
|
+
registerListAddonsTool(mocks.server, mocks.herokuRepl);
|
|
14
|
+
toolCallback = mocks.getToolCallback();
|
|
21
15
|
});
|
|
22
16
|
afterEach(() => {
|
|
23
17
|
sinon.restore();
|
|
24
18
|
});
|
|
25
19
|
it('registers the tool with correct name and schema', () => {
|
|
26
|
-
expect(server.tool.calledOnce).to.be.true;
|
|
27
|
-
const call = server.tool.getCall(0);
|
|
20
|
+
expect(mocks.server.tool.calledOnce).to.be.true;
|
|
21
|
+
const call = mocks.server.tool.getCall(0);
|
|
28
22
|
expect(call.args[0]).to.equal('list_addons');
|
|
29
23
|
expect(call.args[2]).to.deep.equal(listAddonsOptionsSchema.shape);
|
|
30
24
|
});
|
|
@@ -34,9 +28,9 @@ describe('addons topic tools', () => {
|
|
|
34
28
|
' test-app postgresql-curved-12345 heroku-postgresql:essential-0 ~$0.007/hour $5/month created \n' +
|
|
35
29
|
' test-app-2 redis-elliptical-12345 heroku-redis:mini ~$0.004/hour $3/month created \n';
|
|
36
30
|
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_ADDONS).addFlags({ all: true }).build();
|
|
37
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
31
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
38
32
|
const result = await toolCallback({ all: true }, {});
|
|
39
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
33
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
40
34
|
expect(result).to.deep.equal({
|
|
41
35
|
content: [{ type: 'text', text: expectedOutput }]
|
|
42
36
|
});
|
|
@@ -47,33 +41,28 @@ describe('addons topic tools', () => {
|
|
|
47
41
|
' heroku-redis (redis-elliptical-12345) mini ~$0.004/hour $3/month created \n' +
|
|
48
42
|
' └─ as REDIS_TEST_DB \n';
|
|
49
43
|
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_ADDONS).addFlags({ app: 'test-app-2' }).build();
|
|
50
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
44
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
51
45
|
const result = await toolCallback({ app: 'test-app-2' }, {});
|
|
52
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
46
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
53
47
|
expect(result).to.deep.equal({
|
|
54
48
|
content: [{ type: 'text', text: expectedOutput }]
|
|
55
49
|
});
|
|
56
50
|
});
|
|
57
51
|
});
|
|
58
52
|
describe('registerGetAddonInfoTool', () => {
|
|
59
|
-
let
|
|
60
|
-
let herokuRepl;
|
|
53
|
+
let mocks;
|
|
61
54
|
let toolCallback;
|
|
62
55
|
beforeEach(() => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
toolCallback = callback;
|
|
67
|
-
return server;
|
|
68
|
-
});
|
|
69
|
-
registerGetAddonInfoTool(server, herokuRepl);
|
|
56
|
+
mocks = setupMcpToolMocks();
|
|
57
|
+
registerGetAddonInfoTool(mocks.server, mocks.herokuRepl);
|
|
58
|
+
toolCallback = mocks.getToolCallback();
|
|
70
59
|
});
|
|
71
60
|
afterEach(() => {
|
|
72
61
|
sinon.restore();
|
|
73
62
|
});
|
|
74
63
|
it('registers the tool with correct name and schema', () => {
|
|
75
|
-
expect(server.tool.calledOnce).to.be.true;
|
|
76
|
-
const call = server.tool.getCall(0);
|
|
64
|
+
expect(mocks.server.tool.calledOnce).to.be.true;
|
|
65
|
+
const call = mocks.server.tool.getCall(0);
|
|
77
66
|
expect(call.args[0]).to.equal('get_addon_info');
|
|
78
67
|
expect(call.args[2]).to.deep.equal(getAddonInfoOptionsSchema.shape);
|
|
79
68
|
});
|
|
@@ -85,9 +74,9 @@ describe('addons topic tools', () => {
|
|
|
85
74
|
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.GET_ADDON_INFO)
|
|
86
75
|
.addPositionalArguments({ addon: 'postgresql-curved-12345' })
|
|
87
76
|
.build();
|
|
88
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
77
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
89
78
|
const result = await toolCallback({ addon: 'postgresql-curved-12345' }, {});
|
|
90
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
79
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
91
80
|
expect(result).to.deep.equal({
|
|
92
81
|
content: [{ type: 'text', text: expectedOutput }]
|
|
93
82
|
});
|
|
@@ -101,33 +90,28 @@ describe('addons topic tools', () => {
|
|
|
101
90
|
.addPositionalArguments({ addon: 'DATABASE' })
|
|
102
91
|
.addFlags({ app: 'test-app' })
|
|
103
92
|
.build();
|
|
104
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
93
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
105
94
|
const result = await toolCallback({ addon: 'DATABASE', app: 'test-app' }, {});
|
|
106
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
95
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
107
96
|
expect(result).to.deep.equal({
|
|
108
97
|
content: [{ type: 'text', text: expectedOutput }]
|
|
109
98
|
});
|
|
110
99
|
});
|
|
111
100
|
});
|
|
112
101
|
describe('registerCreateAddonTool', () => {
|
|
113
|
-
let
|
|
114
|
-
let herokuRepl;
|
|
102
|
+
let mocks;
|
|
115
103
|
let toolCallback;
|
|
116
104
|
beforeEach(() => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
toolCallback = callback;
|
|
121
|
-
return server;
|
|
122
|
-
});
|
|
123
|
-
registerCreateAddonTool(server, herokuRepl);
|
|
105
|
+
mocks = setupMcpToolMocks();
|
|
106
|
+
registerCreateAddonTool(mocks.server, mocks.herokuRepl);
|
|
107
|
+
toolCallback = mocks.getToolCallback();
|
|
124
108
|
});
|
|
125
109
|
afterEach(() => {
|
|
126
110
|
sinon.restore();
|
|
127
111
|
});
|
|
128
112
|
it('registers the tool with correct name and schema', () => {
|
|
129
|
-
expect(server.tool.calledOnce).to.be.true;
|
|
130
|
-
const call = server.tool.getCall(0);
|
|
113
|
+
expect(mocks.server.tool.calledOnce).to.be.true;
|
|
114
|
+
const call = mocks.server.tool.getCall(0);
|
|
131
115
|
expect(call.args[0]).to.equal('create_addon');
|
|
132
116
|
expect(call.args[2]).to.deep.equal(createAddonOptionsSchema.shape);
|
|
133
117
|
});
|
|
@@ -143,14 +127,14 @@ describe('addons topic tools', () => {
|
|
|
143
127
|
})
|
|
144
128
|
.addPositionalArguments({ 'service:plan': 'heroku-postgresql:essential-0' })
|
|
145
129
|
.build();
|
|
146
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
130
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
147
131
|
const result = await toolCallback({
|
|
148
132
|
app: 'test-app',
|
|
149
133
|
as: 'DATABASE',
|
|
150
134
|
name: 'test-app-primary-db',
|
|
151
135
|
serviceAndPlan: 'heroku-postgresql:essential-0'
|
|
152
136
|
}, {});
|
|
153
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
137
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
154
138
|
expect(result).to.deep.equal({
|
|
155
139
|
content: [{ type: 'text', text: expectedOutput }]
|
|
156
140
|
});
|
|
@@ -163,36 +147,31 @@ describe('addons topic tools', () => {
|
|
|
163
147
|
.addFlags({ app: 'test-app' })
|
|
164
148
|
.addPositionalArguments({ 'service:plan': 'heroku-postgresql:essential-0' })
|
|
165
149
|
.build();
|
|
166
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
150
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
167
151
|
const result = await toolCallback({
|
|
168
152
|
app: 'test-app',
|
|
169
153
|
serviceAndPlan: 'heroku-postgresql:essential-0'
|
|
170
154
|
}, {});
|
|
171
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
155
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
172
156
|
expect(result).to.deep.equal({
|
|
173
157
|
content: [{ type: 'text', text: expectedOutput }]
|
|
174
158
|
});
|
|
175
159
|
});
|
|
176
160
|
});
|
|
177
161
|
describe('registerListAddonServicesTool', () => {
|
|
178
|
-
let
|
|
179
|
-
let herokuRepl;
|
|
162
|
+
let mocks;
|
|
180
163
|
let toolCallback;
|
|
181
164
|
beforeEach(() => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
toolCallback = callback;
|
|
186
|
-
return server;
|
|
187
|
-
});
|
|
188
|
-
registerListAddonServicesTool(server, herokuRepl);
|
|
165
|
+
mocks = setupMcpToolMocks();
|
|
166
|
+
registerListAddonServicesTool(mocks.server, mocks.herokuRepl);
|
|
167
|
+
toolCallback = mocks.getToolCallback();
|
|
189
168
|
});
|
|
190
169
|
afterEach(() => {
|
|
191
170
|
sinon.restore();
|
|
192
171
|
});
|
|
193
172
|
it('registers the tool with correct name and schema', () => {
|
|
194
|
-
expect(server.tool.calledOnce).to.be.true;
|
|
195
|
-
const call = server.tool.getCall(0);
|
|
173
|
+
expect(mocks.server.tool.calledOnce).to.be.true;
|
|
174
|
+
const call = mocks.server.tool.getCall(0);
|
|
196
175
|
expect(call.args[0]).to.equal('list_addon_services');
|
|
197
176
|
expect(call.args[2]).to.deep.equal(listAddonServicesOptionsSchema.shape);
|
|
198
177
|
});
|
|
@@ -202,33 +181,28 @@ describe('addons topic tools', () => {
|
|
|
202
181
|
' heroku-postgresql Heroku PostgreSQL ga \n' +
|
|
203
182
|
' heroku-redis Heroku Key-Value Store ga \n';
|
|
204
183
|
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_ADDON_SERVICES).build();
|
|
205
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
184
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
206
185
|
const result = await toolCallback({}, {});
|
|
207
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
186
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
208
187
|
expect(result).to.deep.equal({
|
|
209
188
|
content: [{ type: 'text', text: expectedOutput }]
|
|
210
189
|
});
|
|
211
190
|
});
|
|
212
191
|
});
|
|
213
192
|
describe('registerListAddonPlansTool', () => {
|
|
214
|
-
let
|
|
215
|
-
let herokuRepl;
|
|
193
|
+
let mocks;
|
|
216
194
|
let toolCallback;
|
|
217
195
|
beforeEach(() => {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
toolCallback = callback;
|
|
222
|
-
return server;
|
|
223
|
-
});
|
|
224
|
-
registerListAddonPlansTool(server, herokuRepl);
|
|
196
|
+
mocks = setupMcpToolMocks();
|
|
197
|
+
registerListAddonPlansTool(mocks.server, mocks.herokuRepl);
|
|
198
|
+
toolCallback = mocks.getToolCallback();
|
|
225
199
|
});
|
|
226
200
|
afterEach(() => {
|
|
227
201
|
sinon.restore();
|
|
228
202
|
});
|
|
229
203
|
it('registers the tool with correct name and schema', () => {
|
|
230
|
-
expect(server.tool.calledOnce).to.be.true;
|
|
231
|
-
const call = server.tool.getCall(0);
|
|
204
|
+
expect(mocks.server.tool.calledOnce).to.be.true;
|
|
205
|
+
const call = mocks.server.tool.getCall(0);
|
|
232
206
|
expect(call.args[0]).to.equal('list_addon_plans');
|
|
233
207
|
expect(call.args[2]).to.deep.equal(listAddonPlansOptionsSchema.shape);
|
|
234
208
|
});
|
|
@@ -240,9 +214,9 @@ describe('addons topic tools', () => {
|
|
|
240
214
|
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_ADDON_PLANS)
|
|
241
215
|
.addPositionalArguments({ service: 'heroku-postgresql' })
|
|
242
216
|
.build();
|
|
243
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
217
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
244
218
|
const result = await toolCallback({ service: 'heroku-postgresql' }, {});
|
|
245
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
219
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
246
220
|
expect(result).to.deep.equal({
|
|
247
221
|
content: [{ type: 'text', text: expectedOutput }]
|
|
248
222
|
});
|
|
@@ -250,23 +224,16 @@ describe('addons topic tools', () => {
|
|
|
250
224
|
});
|
|
251
225
|
// Common error handling test for all tools
|
|
252
226
|
describe('error handling', () => {
|
|
253
|
-
let
|
|
254
|
-
let herokuRepl;
|
|
255
|
-
let toolCallback;
|
|
227
|
+
let mocks;
|
|
256
228
|
beforeEach(() => {
|
|
257
|
-
|
|
258
|
-
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
259
|
-
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
260
|
-
toolCallback = callback;
|
|
261
|
-
return server;
|
|
262
|
-
});
|
|
229
|
+
mocks = setupMcpToolMocks();
|
|
263
230
|
});
|
|
264
231
|
afterEach(() => {
|
|
265
232
|
sinon.restore();
|
|
266
233
|
});
|
|
267
234
|
it('handles CLI errors properly for all tools', async () => {
|
|
268
235
|
const expectedOutput = '<<<BEGIN RESULTS>>>\n<<<ERROR>>>API error<<<END ERROR>>><<<END RESULTS>>>';
|
|
269
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
236
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
270
237
|
// Test error handling for each tool
|
|
271
238
|
const tools = [
|
|
272
239
|
{ register: registerListAddonsTool, options: {} },
|
|
@@ -279,8 +246,10 @@ describe('addons topic tools', () => {
|
|
|
279
246
|
{ register: registerListAddonPlansTool, options: { service: 'heroku-postgresql' } }
|
|
280
247
|
];
|
|
281
248
|
for (const tool of tools) {
|
|
282
|
-
tool.register(server, herokuRepl);
|
|
249
|
+
tool.register(mocks.server, mocks.herokuRepl);
|
|
250
|
+
const toolCallback = mocks.getToolCallback();
|
|
283
251
|
const result = await toolCallback(tool.options, {});
|
|
252
|
+
console.log('result', result);
|
|
284
253
|
expect(result).to.deep.equal({
|
|
285
254
|
isError: true,
|
|
286
255
|
content: [
|
package/dist/tools/ai.spec.js
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
import sinon from 'sinon';
|
|
3
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
-
import { HerokuREPL } from '../repl/heroku-cli-repl.js';
|
|
5
3
|
import { registerListAiAvailableModelsTool, registerProvisionAiModelTool, provisionAiModelOptionsSchema, registerMakeAiInferenceTool, aiInferenceOptionsSchema } from './ai.js';
|
|
6
4
|
import { CommandBuilder } from '../utils/command-builder.js';
|
|
7
5
|
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
8
6
|
import fs from 'node:fs/promises';
|
|
9
7
|
import path from 'node:path';
|
|
8
|
+
import { setupMcpToolMocks } from '../utils/mcp-tool-mocks.spechelper.js';
|
|
10
9
|
describe('ai topic tools', () => {
|
|
11
|
-
describe('
|
|
12
|
-
let
|
|
13
|
-
let herokuRepl;
|
|
10
|
+
describe('listAiAvailableModelsTool', () => {
|
|
11
|
+
let mocks;
|
|
14
12
|
let toolCallback;
|
|
15
13
|
beforeEach(() => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
toolCallback = callback;
|
|
20
|
-
return server;
|
|
21
|
-
});
|
|
22
|
-
registerListAiAvailableModelsTool(server, herokuRepl);
|
|
14
|
+
mocks = setupMcpToolMocks();
|
|
15
|
+
registerListAiAvailableModelsTool(mocks.server, mocks.herokuRepl);
|
|
16
|
+
toolCallback = mocks.getToolCallback();
|
|
23
17
|
});
|
|
24
18
|
afterEach(() => {
|
|
25
19
|
sinon.restore();
|
|
26
20
|
});
|
|
27
21
|
it('registers the tool with correct name', () => {
|
|
28
|
-
expect(server.tool.calledOnce).to.be.true;
|
|
29
|
-
const call = server.tool.getCall(0);
|
|
22
|
+
expect(mocks.server.tool.calledOnce).to.be.true;
|
|
23
|
+
const call = mocks.server.tool.getCall(0);
|
|
30
24
|
expect(call.args[0]).to.equal('list_ai_available_models');
|
|
31
25
|
});
|
|
32
26
|
it('executes command successfully', async () => {
|
|
@@ -35,33 +29,28 @@ describe('ai topic tools', () => {
|
|
|
35
29
|
' claude-3-5-haiku text-to-text us \n' +
|
|
36
30
|
' claude-3-5-sonnet-latest text-to-text us \n';
|
|
37
31
|
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_AI_AVAILABLE_MODELS).build();
|
|
38
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
32
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
39
33
|
const result = await toolCallback({}, {});
|
|
40
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
34
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
41
35
|
expect(result).to.deep.equal({
|
|
42
36
|
content: [{ type: 'text', text: expectedOutput }]
|
|
43
37
|
});
|
|
44
38
|
});
|
|
45
39
|
});
|
|
46
40
|
describe('provisionAiModelTool', () => {
|
|
47
|
-
let
|
|
48
|
-
let herokuRepl;
|
|
41
|
+
let mocks;
|
|
49
42
|
let toolCallback;
|
|
50
43
|
beforeEach(() => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
toolCallback = callback;
|
|
55
|
-
return server;
|
|
56
|
-
});
|
|
57
|
-
registerProvisionAiModelTool(server, herokuRepl);
|
|
44
|
+
mocks = setupMcpToolMocks();
|
|
45
|
+
registerProvisionAiModelTool(mocks.server, mocks.herokuRepl);
|
|
46
|
+
toolCallback = mocks.getToolCallback();
|
|
58
47
|
});
|
|
59
48
|
afterEach(() => {
|
|
60
49
|
sinon.restore();
|
|
61
50
|
});
|
|
62
51
|
it('registers the tool with correct name and schema', () => {
|
|
63
|
-
expect(server.tool.calledOnce).to.be.true;
|
|
64
|
-
const call = server.tool.getCall(0);
|
|
52
|
+
expect(mocks.server.tool.calledOnce).to.be.true;
|
|
53
|
+
const call = mocks.server.tool.getCall(0);
|
|
65
54
|
expect(call.args[0]).to.equal('provision_ai_model');
|
|
66
55
|
expect(call.args[2]).to.deep.equal(provisionAiModelOptionsSchema.shape);
|
|
67
56
|
});
|
|
@@ -72,9 +61,9 @@ describe('ai topic tools', () => {
|
|
|
72
61
|
.addPositionalArguments({ modelName: 'claude-3-5-sonnet-latest' })
|
|
73
62
|
.addFlags({ app: 'test-app' })
|
|
74
63
|
.build();
|
|
75
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
64
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
76
65
|
const result = await toolCallback({ app: 'test-app', modelName: 'claude-3-5-sonnet-latest' }, {});
|
|
77
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
66
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
78
67
|
expect(result).to.deep.equal({
|
|
79
68
|
content: [{ type: 'text', text: expectedOutput }]
|
|
80
69
|
});
|
|
@@ -86,43 +75,38 @@ describe('ai topic tools', () => {
|
|
|
86
75
|
.addPositionalArguments({ modelName: 'claude-3-5-sonnet-latest' })
|
|
87
76
|
.addFlags({ app: 'test-app', as: 'MY_MODEL' })
|
|
88
77
|
.build();
|
|
89
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
78
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
90
79
|
const result = await toolCallback({ app: 'test-app', modelName: 'claude-3-5-sonnet-latest', as: 'MY_MODEL' }, {});
|
|
91
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
80
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
92
81
|
expect(result).to.deep.equal({
|
|
93
82
|
content: [{ type: 'text', text: expectedOutput }]
|
|
94
83
|
});
|
|
95
84
|
});
|
|
96
85
|
});
|
|
97
86
|
describe('makeAiInferenceTool', () => {
|
|
98
|
-
let
|
|
99
|
-
let herokuRepl;
|
|
100
|
-
let toolCallback;
|
|
87
|
+
let mocks;
|
|
101
88
|
let mkdtempStub;
|
|
102
89
|
let writeFileStub;
|
|
103
90
|
let rmdirStub;
|
|
104
91
|
let tempDir;
|
|
105
92
|
let optsFilePath;
|
|
93
|
+
let toolCallback;
|
|
106
94
|
beforeEach(() => {
|
|
107
|
-
server = sinon.createStubInstance(McpServer);
|
|
108
|
-
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
109
|
-
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
110
|
-
toolCallback = callback;
|
|
111
|
-
return server;
|
|
112
|
-
});
|
|
113
95
|
tempDir = '/tmp/com.heroku.mcp.ai.inference-12345';
|
|
114
96
|
optsFilePath = path.join(tempDir, 'opts.json');
|
|
115
97
|
mkdtempStub = sinon.stub(fs, 'mkdtemp').resolves(tempDir);
|
|
116
98
|
writeFileStub = sinon.stub(fs, 'writeFile').resolves();
|
|
117
99
|
rmdirStub = sinon.stub(fs, 'rmdir').resolves();
|
|
118
|
-
|
|
100
|
+
mocks = setupMcpToolMocks();
|
|
101
|
+
registerMakeAiInferenceTool(mocks.server, mocks.herokuRepl);
|
|
102
|
+
toolCallback = mocks.getToolCallback();
|
|
119
103
|
});
|
|
120
104
|
afterEach(() => {
|
|
121
105
|
sinon.restore();
|
|
122
106
|
});
|
|
123
107
|
it('registers the tool with correct name and schema', () => {
|
|
124
|
-
expect(server.tool.calledOnce).to.be.true;
|
|
125
|
-
const call = server.tool.getCall(0);
|
|
108
|
+
expect(mocks.server.tool.calledOnce).to.be.true;
|
|
109
|
+
const call = mocks.server.tool.getCall(0);
|
|
126
110
|
expect(call.args[0]).to.equal('make_ai_inference');
|
|
127
111
|
expect(call.args[2]).to.deep.equal(aiInferenceOptionsSchema.shape);
|
|
128
112
|
});
|
|
@@ -141,18 +125,17 @@ describe('ai topic tools', () => {
|
|
|
141
125
|
optfile: optsFilePath
|
|
142
126
|
})
|
|
143
127
|
.build();
|
|
144
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
128
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
145
129
|
const result = await toolCallback({
|
|
146
130
|
modelResource: 'heroku-inference',
|
|
147
131
|
app: 'test-app',
|
|
148
132
|
opts
|
|
149
133
|
}, {});
|
|
150
|
-
const actualCommand = herokuRepl.executeCommand.getCall(0).args[0];
|
|
151
|
-
expect(actualCommand).to.equal(expectedCommand);
|
|
152
134
|
expect(mkdtempStub.calledOnce).to.be.true;
|
|
153
|
-
expect(
|
|
154
|
-
expect(writeFileStub.
|
|
155
|
-
expect(
|
|
135
|
+
expect(writeFileStub.calledOnce).to.be.true;
|
|
136
|
+
expect(writeFileStub.firstCall.args[0]).to.equal(optsFilePath);
|
|
137
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
138
|
+
expect(rmdirStub.calledOnce).to.be.true;
|
|
156
139
|
expect(result).to.deep.equal({
|
|
157
140
|
content: [{ type: 'text', text: expectedOutput }]
|
|
158
141
|
});
|
|
@@ -181,7 +164,7 @@ describe('ai topic tools', () => {
|
|
|
181
164
|
optfile: optsFilePath
|
|
182
165
|
})
|
|
183
166
|
.build();
|
|
184
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
167
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
185
168
|
const result = await toolCallback({
|
|
186
169
|
app: 'test-app',
|
|
187
170
|
modelResource: 'custom-model',
|
|
@@ -189,12 +172,13 @@ describe('ai topic tools', () => {
|
|
|
189
172
|
json: true,
|
|
190
173
|
output: 'output.json'
|
|
191
174
|
}, {});
|
|
192
|
-
const actualCommand = herokuRepl.executeCommand.getCall(0).args[0];
|
|
175
|
+
const actualCommand = mocks.herokuRepl.executeCommand.getCall(0).args[0];
|
|
193
176
|
expect(actualCommand).to.equal(expectedCommand);
|
|
194
177
|
expect(mkdtempStub.calledOnce).to.be.true;
|
|
195
|
-
expect(
|
|
196
|
-
expect(writeFileStub.
|
|
197
|
-
expect(
|
|
178
|
+
expect(writeFileStub.calledOnce).to.be.true;
|
|
179
|
+
expect(writeFileStub.firstCall.args[0]).to.equal(optsFilePath);
|
|
180
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
181
|
+
expect(rmdirStub.calledOnce).to.be.true;
|
|
198
182
|
expect(result).to.deep.equal({
|
|
199
183
|
content: [{ type: 'text', text: expectedOutput }]
|
|
200
184
|
});
|
package/dist/tools/apps.js
CHANGED
|
@@ -108,26 +108,3 @@ export const registerRenameAppTool = (server, herokuRepl) => {
|
|
|
108
108
|
return handleCliOutput(output);
|
|
109
109
|
});
|
|
110
110
|
};
|
|
111
|
-
/**
|
|
112
|
-
* Schema for app ownership transfer
|
|
113
|
-
*/
|
|
114
|
-
export const transferAppOptionsSchema = z.object({
|
|
115
|
-
app: z.string().describe('App to transfer. Requires owner/admin access'),
|
|
116
|
-
recipient: z.string().describe('Target user email or team name')
|
|
117
|
-
});
|
|
118
|
-
/**
|
|
119
|
-
* Register transfer_app tool
|
|
120
|
-
*
|
|
121
|
-
* @param server MCP server instance
|
|
122
|
-
* @param herokuRepl Heroku REPL instance
|
|
123
|
-
*/
|
|
124
|
-
export const registerTransferAppTool = (server, herokuRepl) => {
|
|
125
|
-
server.tool('transfer_app', 'Transfer app ownership to user/team', transferAppOptionsSchema.shape, async (options) => {
|
|
126
|
-
const command = new CommandBuilder(TOOL_COMMAND_MAP.TRANSFER_APP)
|
|
127
|
-
.addFlags({ app: options.app })
|
|
128
|
-
.addPositionalArguments({ recipient: options.recipient })
|
|
129
|
-
.build();
|
|
130
|
-
const output = await herokuRepl.executeCommand(command);
|
|
131
|
-
return handleCliOutput(output);
|
|
132
|
-
});
|
|
133
|
-
};
|