@heroku/mcp-server 1.0.7-alpha.0 → 1.0.7
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 +0 -0
- package/dist/index.js +15 -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 +31 -0
- package/package.json +8 -4
package/dist/tools/data.spec.js
CHANGED
|
@@ -1,43 +1,36 @@
|
|
|
1
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import { HerokuREPL } from '../repl/heroku-cli-repl.js';
|
|
3
1
|
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
4
2
|
import { registerPgPsqlTool, registerPgInfoTool, registerPgPsTool, registerPgKillTool, registerPgBackupsTool, registerPgUpgradeTool } from './data.js';
|
|
5
3
|
import { expect } from 'chai';
|
|
6
4
|
import sinon from 'sinon';
|
|
5
|
+
import { setupMcpToolMocks } from '../utils/mcp-tool-mocks.spechelper.js';
|
|
7
6
|
describe('PostgreSQL Tools', () => {
|
|
8
|
-
let server;
|
|
9
|
-
let herokuRepl;
|
|
10
|
-
let toolCallback;
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
server = sinon.createStubInstance(McpServer);
|
|
13
|
-
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
14
|
-
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
15
|
-
toolCallback = callback;
|
|
16
|
-
return server;
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
7
|
afterEach(() => {
|
|
20
8
|
sinon.restore();
|
|
21
9
|
});
|
|
22
10
|
describe('pg:psql', () => {
|
|
11
|
+
let mocks;
|
|
12
|
+
let toolCallback;
|
|
23
13
|
beforeEach(() => {
|
|
24
|
-
|
|
14
|
+
mocks = setupMcpToolMocks();
|
|
15
|
+
registerPgPsqlTool(mocks.server, mocks.herokuRepl);
|
|
16
|
+
toolCallback = mocks.getToolCallback();
|
|
25
17
|
});
|
|
26
18
|
it('should register the tool with correct parameters', () => {
|
|
27
|
-
|
|
28
|
-
expect(
|
|
29
|
-
expect(
|
|
30
|
-
expect(
|
|
31
|
-
expect(
|
|
19
|
+
const tool = mocks.server.tool;
|
|
20
|
+
expect(tool.calledOnce).to.be.true;
|
|
21
|
+
expect(tool.firstCall.args[0]).to.equal('pg_psql');
|
|
22
|
+
expect(tool.firstCall.args[1]).to.be.a('string');
|
|
23
|
+
expect(tool.firstCall.args[2]).to.be.an('object');
|
|
24
|
+
expect(tool.firstCall.args[3]).to.be.a('function');
|
|
32
25
|
});
|
|
33
26
|
it('should build correct command with required parameters', async () => {
|
|
34
|
-
herokuRepl.executeCommand.resolves('psql (14.9)\nType "help" for help.\n\nmyapp::DATABASE=> ');
|
|
27
|
+
mocks.herokuRepl.executeCommand.resolves('psql (14.9)\nType "help" for help.\n\nmyapp::DATABASE=> ');
|
|
35
28
|
await toolCallback({ app: 'myapp' });
|
|
36
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
37
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PSQL} --app=myapp --command=""`);
|
|
29
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
30
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PSQL} --app=myapp --command=""`);
|
|
38
31
|
});
|
|
39
32
|
it('should build correct command with all parameters', async () => {
|
|
40
|
-
herokuRepl.executeCommand.resolves('Query executed successfully\n');
|
|
33
|
+
mocks.herokuRepl.executeCommand.resolves('Query executed successfully\n');
|
|
41
34
|
await toolCallback({
|
|
42
35
|
app: 'myapp',
|
|
43
36
|
command: 'SELECT * FROM users',
|
|
@@ -45,12 +38,12 @@ describe('PostgreSQL Tools', () => {
|
|
|
45
38
|
credential: 'mycred',
|
|
46
39
|
database: 'HEROKU_POSTGRESQL_RED'
|
|
47
40
|
});
|
|
48
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
49
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PSQL} --app=myapp --command="SELECT * FROM users" --file=query.sql --credential=mycred -- HEROKU_POSTGRESQL_RED`);
|
|
41
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
42
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PSQL} --app=myapp --command="SELECT * FROM users" --file=query.sql --credential=mycred -- HEROKU_POSTGRESQL_RED`);
|
|
50
43
|
});
|
|
51
44
|
it('should handle error response', async () => {
|
|
52
45
|
const errorResponse = '<<<ERROR>>>\nError: Database not found\n<<<END ERROR>>>\n';
|
|
53
|
-
herokuRepl.executeCommand.resolves(errorResponse);
|
|
46
|
+
mocks.herokuRepl.executeCommand.resolves(errorResponse);
|
|
54
47
|
const result = await toolCallback({ app: 'myapp' });
|
|
55
48
|
expect(result).to.deep.equal({
|
|
56
49
|
content: [
|
|
@@ -64,33 +57,38 @@ describe('PostgreSQL Tools', () => {
|
|
|
64
57
|
});
|
|
65
58
|
});
|
|
66
59
|
describe('pg:info', () => {
|
|
60
|
+
let mocks;
|
|
61
|
+
let toolCallback;
|
|
67
62
|
beforeEach(() => {
|
|
68
|
-
|
|
63
|
+
mocks = setupMcpToolMocks();
|
|
64
|
+
registerPgInfoTool(mocks.server, mocks.herokuRepl);
|
|
65
|
+
toolCallback = mocks.getToolCallback();
|
|
69
66
|
});
|
|
70
67
|
it('should register the tool with correct parameters', () => {
|
|
71
|
-
|
|
72
|
-
expect(
|
|
73
|
-
expect(
|
|
74
|
-
expect(
|
|
75
|
-
expect(
|
|
68
|
+
const tool = mocks.server.tool;
|
|
69
|
+
expect(tool.calledOnce).to.be.true;
|
|
70
|
+
expect(tool.firstCall.args[0]).to.equal('pg_info');
|
|
71
|
+
expect(tool.firstCall.args[1]).to.be.a('string');
|
|
72
|
+
expect(tool.firstCall.args[2]).to.be.an('object');
|
|
73
|
+
expect(tool.firstCall.args[3]).to.be.a('function');
|
|
76
74
|
});
|
|
77
75
|
it('should build correct command with required parameters', async () => {
|
|
78
76
|
const successResponse = '=== DATABASE_URL\nPlan: Hobby-dev\nStatus: Available\nConnections: 0/20\nPG Version: 14.9\n';
|
|
79
|
-
herokuRepl.executeCommand.resolves(successResponse);
|
|
77
|
+
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
80
78
|
await toolCallback({ app: 'myapp' });
|
|
81
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
82
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_INFO} --app=myapp`);
|
|
79
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
80
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_INFO} --app=myapp`);
|
|
83
81
|
});
|
|
84
82
|
it('should build correct command with database parameter', async () => {
|
|
85
83
|
const successResponse = '=== HEROKU_POSTGRESQL_RED\nPlan: Standard-0\nStatus: Available\n';
|
|
86
|
-
herokuRepl.executeCommand.resolves(successResponse);
|
|
84
|
+
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
87
85
|
await toolCallback({ app: 'myapp', database: 'HEROKU_POSTGRESQL_RED' });
|
|
88
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
89
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_INFO} --app=myapp -- HEROKU_POSTGRESQL_RED`);
|
|
86
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
87
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_INFO} --app=myapp -- HEROKU_POSTGRESQL_RED`);
|
|
90
88
|
});
|
|
91
89
|
it('should handle error response', async () => {
|
|
92
90
|
const errorResponse = '<<<ERROR>>>\nError: Database not found\n<<<END ERROR>>>\n';
|
|
93
|
-
herokuRepl.executeCommand.resolves(errorResponse);
|
|
91
|
+
mocks.herokuRepl.executeCommand.resolves(errorResponse);
|
|
94
92
|
const result = await toolCallback({ app: 'myapp' });
|
|
95
93
|
expect(result).to.deep.equal({
|
|
96
94
|
content: [
|
|
@@ -104,37 +102,42 @@ describe('PostgreSQL Tools', () => {
|
|
|
104
102
|
});
|
|
105
103
|
});
|
|
106
104
|
describe('pg:ps', () => {
|
|
105
|
+
let mocks;
|
|
106
|
+
let toolCallback;
|
|
107
107
|
beforeEach(() => {
|
|
108
|
-
|
|
108
|
+
mocks = setupMcpToolMocks();
|
|
109
|
+
registerPgPsTool(mocks.server, mocks.herokuRepl);
|
|
110
|
+
toolCallback = mocks.getToolCallback();
|
|
109
111
|
});
|
|
110
112
|
it('should register the tool with correct parameters', () => {
|
|
111
|
-
|
|
112
|
-
expect(
|
|
113
|
-
expect(
|
|
114
|
-
expect(
|
|
115
|
-
expect(
|
|
113
|
+
const tool = mocks.server.tool;
|
|
114
|
+
expect(tool.calledOnce).to.be.true;
|
|
115
|
+
expect(tool.firstCall.args[0]).to.equal('pg_ps');
|
|
116
|
+
expect(tool.firstCall.args[1]).to.be.a('string');
|
|
117
|
+
expect(tool.firstCall.args[2]).to.be.an('object');
|
|
118
|
+
expect(tool.firstCall.args[3]).to.be.a('function');
|
|
116
119
|
});
|
|
117
120
|
it('should build correct command with required parameters', async () => {
|
|
118
121
|
const successResponse = ' pid | state | source | running_for | waiting | query\n-----+-------+--------+-------------+---------+-------\n';
|
|
119
|
-
herokuRepl.executeCommand.resolves(successResponse);
|
|
122
|
+
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
120
123
|
await toolCallback({ app: 'myapp' });
|
|
121
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
122
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PS} --app=myapp`);
|
|
124
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
125
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PS} --app=myapp`);
|
|
123
126
|
});
|
|
124
127
|
it('should build correct command with all parameters', async () => {
|
|
125
128
|
const successResponse = ' pid | state | source | running_for | waiting | query | memory\n-----+-------+--------+-------------+---------+-------+--------\n';
|
|
126
|
-
herokuRepl.executeCommand.resolves(successResponse);
|
|
129
|
+
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
127
130
|
await toolCallback({
|
|
128
131
|
app: 'myapp',
|
|
129
132
|
verbose: true,
|
|
130
133
|
database: 'HEROKU_POSTGRESQL_RED'
|
|
131
134
|
});
|
|
132
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
133
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PS} --app=myapp --verbose -- HEROKU_POSTGRESQL_RED`);
|
|
135
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
136
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_PS} --app=myapp --verbose -- HEROKU_POSTGRESQL_RED`);
|
|
134
137
|
});
|
|
135
138
|
it('should handle error response', async () => {
|
|
136
139
|
const errorResponse = '<<<ERROR>>>\nError: Database not found\n<<<END ERROR>>>\n';
|
|
137
|
-
herokuRepl.executeCommand.resolves(errorResponse);
|
|
140
|
+
mocks.herokuRepl.executeCommand.resolves(errorResponse);
|
|
138
141
|
const result = await toolCallback({ app: 'myapp' });
|
|
139
142
|
expect(result).to.deep.equal({
|
|
140
143
|
content: [
|
|
@@ -148,38 +151,43 @@ describe('PostgreSQL Tools', () => {
|
|
|
148
151
|
});
|
|
149
152
|
});
|
|
150
153
|
describe('pg:kill', () => {
|
|
154
|
+
let mocks;
|
|
155
|
+
let toolCallback;
|
|
151
156
|
beforeEach(() => {
|
|
152
|
-
|
|
157
|
+
mocks = setupMcpToolMocks();
|
|
158
|
+
registerPgKillTool(mocks.server, mocks.herokuRepl);
|
|
159
|
+
toolCallback = mocks.getToolCallback();
|
|
153
160
|
});
|
|
154
161
|
it('should register the tool with correct parameters', () => {
|
|
155
|
-
|
|
156
|
-
expect(
|
|
157
|
-
expect(
|
|
158
|
-
expect(
|
|
159
|
-
expect(
|
|
162
|
+
const tool = mocks.server.tool;
|
|
163
|
+
expect(tool.calledOnce).to.be.true;
|
|
164
|
+
expect(tool.firstCall.args[0]).to.equal('pg_kill');
|
|
165
|
+
expect(tool.firstCall.args[1]).to.be.a('string');
|
|
166
|
+
expect(tool.firstCall.args[2]).to.be.an('object');
|
|
167
|
+
expect(tool.firstCall.args[3]).to.be.a('function');
|
|
160
168
|
});
|
|
161
169
|
it('should build correct command with required parameters', async () => {
|
|
162
170
|
const successResponse = 'Terminating process 12345... done\n';
|
|
163
|
-
herokuRepl.executeCommand.resolves(successResponse);
|
|
171
|
+
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
164
172
|
await toolCallback({ app: 'myapp', pid: 12345 });
|
|
165
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
166
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_KILL} --app=myapp -- 12345`);
|
|
173
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
174
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_KILL} --app=myapp -- 12345`);
|
|
167
175
|
});
|
|
168
176
|
it('should build correct command with all parameters', async () => {
|
|
169
177
|
const successResponse = 'Terminating process 12345... done\n';
|
|
170
|
-
herokuRepl.executeCommand.resolves(successResponse);
|
|
178
|
+
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
171
179
|
await toolCallback({
|
|
172
180
|
app: 'myapp',
|
|
173
181
|
pid: 12345,
|
|
174
182
|
force: true,
|
|
175
183
|
database: 'HEROKU_POSTGRESQL_RED'
|
|
176
184
|
});
|
|
177
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
178
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_KILL} --app=myapp --force -- 12345 HEROKU_POSTGRESQL_RED`);
|
|
185
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
186
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_KILL} --app=myapp --force -- 12345 HEROKU_POSTGRESQL_RED`);
|
|
179
187
|
});
|
|
180
188
|
it('should handle error response', async () => {
|
|
181
189
|
const errorResponse = '<<<ERROR>>>\nError: Process not found\n<<<END ERROR>>>\n';
|
|
182
|
-
herokuRepl.executeCommand.resolves(errorResponse);
|
|
190
|
+
mocks.herokuRepl.executeCommand.resolves(errorResponse);
|
|
183
191
|
const result = await toolCallback({ app: 'myapp', pid: 12345 });
|
|
184
192
|
expect(result).to.deep.equal({
|
|
185
193
|
content: [
|
|
@@ -193,26 +201,31 @@ describe('PostgreSQL Tools', () => {
|
|
|
193
201
|
});
|
|
194
202
|
});
|
|
195
203
|
describe('pg:backups', () => {
|
|
204
|
+
let mocks;
|
|
205
|
+
let toolCallback;
|
|
196
206
|
beforeEach(() => {
|
|
197
|
-
|
|
207
|
+
mocks = setupMcpToolMocks();
|
|
208
|
+
registerPgBackupsTool(mocks.server, mocks.herokuRepl);
|
|
209
|
+
toolCallback = mocks.getToolCallback();
|
|
198
210
|
});
|
|
199
211
|
it('should register the tool with correct parameters', () => {
|
|
200
|
-
|
|
201
|
-
expect(
|
|
202
|
-
expect(
|
|
203
|
-
expect(
|
|
204
|
-
expect(
|
|
212
|
+
const tool = mocks.server.tool;
|
|
213
|
+
expect(tool.calledOnce).to.be.true;
|
|
214
|
+
expect(tool.firstCall.args[0]).to.equal('pg_backups');
|
|
215
|
+
expect(tool.firstCall.args[1]).to.be.a('string');
|
|
216
|
+
expect(tool.firstCall.args[2]).to.be.an('object');
|
|
217
|
+
expect(tool.firstCall.args[3]).to.be.a('function');
|
|
205
218
|
});
|
|
206
219
|
it('should build correct command with required parameters', async () => {
|
|
207
220
|
const successResponse = '=== Backups\nID Created at Status Size Database\n──── ───────────────────────── ─────────────────────────────────── ─────── ────────\nb001 2024-01-01 00:00:00 +0000 Completed 2024-01-01 00:01:00 +0000 20.3 MB DATABASE_URL\n';
|
|
208
|
-
herokuRepl.executeCommand.resolves(successResponse);
|
|
221
|
+
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
209
222
|
await toolCallback({ app: 'myapp' });
|
|
210
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
211
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_BACKUPS} --app=myapp`);
|
|
223
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
224
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_BACKUPS} --app=myapp`);
|
|
212
225
|
});
|
|
213
226
|
it('should build correct command with all parameters', async () => {
|
|
214
227
|
const successResponse = 'Scheduling automatic daily backups at 00:00 America/New_York... done\n';
|
|
215
|
-
herokuRepl.executeCommand.resolves(successResponse);
|
|
228
|
+
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
216
229
|
await toolCallback({
|
|
217
230
|
app: 'myapp',
|
|
218
231
|
verbose: true,
|
|
@@ -221,12 +234,12 @@ describe('PostgreSQL Tools', () => {
|
|
|
221
234
|
'wait-interval': '5',
|
|
222
235
|
quiet: true
|
|
223
236
|
});
|
|
224
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
225
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_BACKUPS} --app=myapp`);
|
|
237
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
238
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_BACKUPS} --app=myapp`);
|
|
226
239
|
});
|
|
227
240
|
it('should handle error response', async () => {
|
|
228
241
|
const errorResponse = '<<<ERROR>>>\nError: No backups found\n<<<END ERROR>>>\n';
|
|
229
|
-
herokuRepl.executeCommand.resolves(errorResponse);
|
|
242
|
+
mocks.herokuRepl.executeCommand.resolves(errorResponse);
|
|
230
243
|
const result = await toolCallback({ app: 'myapp' });
|
|
231
244
|
expect(result).to.deep.equal({
|
|
232
245
|
content: [
|
|
@@ -240,38 +253,43 @@ describe('PostgreSQL Tools', () => {
|
|
|
240
253
|
});
|
|
241
254
|
});
|
|
242
255
|
describe('pg:upgrade', () => {
|
|
256
|
+
let mocks;
|
|
257
|
+
let toolCallback;
|
|
243
258
|
beforeEach(() => {
|
|
244
|
-
|
|
259
|
+
mocks = setupMcpToolMocks();
|
|
260
|
+
registerPgUpgradeTool(mocks.server, mocks.herokuRepl);
|
|
261
|
+
toolCallback = mocks.getToolCallback();
|
|
245
262
|
});
|
|
246
263
|
it('should register the tool with correct parameters', () => {
|
|
247
|
-
|
|
248
|
-
expect(
|
|
249
|
-
expect(
|
|
250
|
-
expect(
|
|
251
|
-
expect(
|
|
264
|
+
const tool = mocks.server.tool;
|
|
265
|
+
expect(tool.calledOnce).to.be.true;
|
|
266
|
+
expect(tool.firstCall.args[0]).to.equal('pg_upgrade');
|
|
267
|
+
expect(tool.firstCall.args[1]).to.be.a('string');
|
|
268
|
+
expect(tool.firstCall.args[2]).to.be.an('object');
|
|
269
|
+
expect(tool.firstCall.args[3]).to.be.a('function');
|
|
252
270
|
});
|
|
253
271
|
it('should build correct command with required parameters', async () => {
|
|
254
272
|
const successResponse = 'Starting upgrade of DATABASE_URL to PostgreSQL 14... done\n';
|
|
255
|
-
herokuRepl.executeCommand.resolves(successResponse);
|
|
273
|
+
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
256
274
|
await toolCallback({ app: 'myapp' });
|
|
257
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
258
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_UPGRADE} --app=myapp`);
|
|
275
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
276
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_UPGRADE} --app=myapp`);
|
|
259
277
|
});
|
|
260
278
|
it('should build correct command with all parameters', async () => {
|
|
261
279
|
const successResponse = 'Starting upgrade of HEROKU_POSTGRESQL_RED to PostgreSQL 14... done\n';
|
|
262
|
-
herokuRepl.executeCommand.resolves(successResponse);
|
|
280
|
+
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
263
281
|
await toolCallback({
|
|
264
282
|
app: 'myapp',
|
|
265
283
|
version: '14',
|
|
266
284
|
confirm: 'myapp',
|
|
267
285
|
database: 'HEROKU_POSTGRESQL_RED'
|
|
268
286
|
});
|
|
269
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
270
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_UPGRADE} --app=myapp --version=14 --confirm=myapp -- HEROKU_POSTGRESQL_RED`);
|
|
287
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
288
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PG_UPGRADE} --app=myapp --version=14 --confirm=myapp -- HEROKU_POSTGRESQL_RED`);
|
|
271
289
|
});
|
|
272
290
|
it('should handle error response', async () => {
|
|
273
291
|
const errorResponse = '<<<ERROR>>>\nError: Database is already at version 14\n<<<END ERROR>>>\n';
|
|
274
|
-
herokuRepl.executeCommand.resolves(errorResponse);
|
|
292
|
+
mocks.herokuRepl.executeCommand.resolves(errorResponse);
|
|
275
293
|
const result = await toolCallback({ app: 'myapp' });
|
|
276
294
|
expect(result).to.deep.equal({
|
|
277
295
|
content: [
|
|
@@ -284,7 +302,7 @@ describe('PostgreSQL Tools', () => {
|
|
|
284
302
|
});
|
|
285
303
|
});
|
|
286
304
|
it('should handle undefined response', async () => {
|
|
287
|
-
herokuRepl.executeCommand.resolves(undefined);
|
|
305
|
+
mocks.herokuRepl.executeCommand.resolves(undefined);
|
|
288
306
|
const result = await toolCallback({ app: 'myapp' });
|
|
289
307
|
expect(result).to.deep.equal({
|
|
290
308
|
content: [
|
package/dist/tools/logs.spec.js
CHANGED
|
@@ -1,39 +1,34 @@
|
|
|
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 { getAppGetAppLogsOptionsSchema, registerGetAppLogsTool } from './logs.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('logs topic tools', () => {
|
|
9
8
|
describe('registerGetAppLogsTool', () => {
|
|
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
|
-
registerGetAppLogsTool(server, herokuRepl);
|
|
12
|
+
mocks = setupMcpToolMocks();
|
|
13
|
+
registerGetAppLogsTool(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
|
-
|
|
27
|
-
const call =
|
|
20
|
+
const tool = mocks.server.tool;
|
|
21
|
+
const call = tool.getCall(0);
|
|
22
|
+
expect(tool.calledOnce).to.be.true;
|
|
28
23
|
expect(call.args[0]).to.equal('get_app_logs');
|
|
29
24
|
expect(call.args[2]).to.deep.equal(getAppGetAppLogsOptionsSchema.shape);
|
|
30
25
|
});
|
|
31
26
|
it('executes command successfully with app name only', async () => {
|
|
32
27
|
const expectedOutput = '2025-04-03T18:34:16Z app[web.1]: Server started on port 3000\n';
|
|
33
28
|
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LOGS).addFlags({ app: 'test-app' }).build();
|
|
34
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
29
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
35
30
|
const result = await toolCallback({ app: 'test-app' }, {});
|
|
36
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
31
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
37
32
|
expect(result).to.deep.equal({
|
|
38
33
|
content: [{ type: 'text', text: expectedOutput }]
|
|
39
34
|
});
|
|
@@ -46,12 +41,12 @@ describe('logs topic tools', () => {
|
|
|
46
41
|
'dyno-name': 'web.1'
|
|
47
42
|
})
|
|
48
43
|
.build();
|
|
49
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
44
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
50
45
|
const result = await toolCallback({
|
|
51
46
|
app: 'test-app',
|
|
52
47
|
dynoName: 'web.1'
|
|
53
48
|
}, {});
|
|
54
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
49
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
55
50
|
expect(result).to.deep.equal({
|
|
56
51
|
content: [{ type: 'text', text: expectedOutput }]
|
|
57
52
|
});
|
|
@@ -64,12 +59,12 @@ describe('logs topic tools', () => {
|
|
|
64
59
|
'process-type': 'web'
|
|
65
60
|
})
|
|
66
61
|
.build();
|
|
67
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
62
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
68
63
|
const result = await toolCallback({
|
|
69
64
|
app: 'test-app',
|
|
70
65
|
processType: 'web'
|
|
71
66
|
}, {});
|
|
72
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
67
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
73
68
|
expect(result).to.deep.equal({
|
|
74
69
|
content: [{ type: 'text', text: expectedOutput }]
|
|
75
70
|
});
|
|
@@ -82,19 +77,19 @@ describe('logs topic tools', () => {
|
|
|
82
77
|
source: 'app'
|
|
83
78
|
})
|
|
84
79
|
.build();
|
|
85
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
80
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
86
81
|
const result = await toolCallback({
|
|
87
82
|
app: 'test-app',
|
|
88
83
|
source: 'app'
|
|
89
84
|
}, {});
|
|
90
|
-
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
85
|
+
expect(mocks.herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
91
86
|
expect(result).to.deep.equal({
|
|
92
87
|
content: [{ type: 'text', text: expectedOutput }]
|
|
93
88
|
});
|
|
94
89
|
});
|
|
95
90
|
it('handles CLI errors properly', async () => {
|
|
96
91
|
const expectedOutput = '<<<BEGIN RESULTS>>>\n<<<ERROR>>>API error<<<END ERROR>>><<<END RESULTS>>>';
|
|
97
|
-
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
92
|
+
mocks.herokuRepl.executeCommand.resolves(expectedOutput);
|
|
98
93
|
const result = await toolCallback({ app: 'test-app' }, {});
|
|
99
94
|
expect(result).to.deep.equal({
|
|
100
95
|
isError: true,
|
|
@@ -1,44 +1,37 @@
|
|
|
1
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import { HerokuREPL } from '../repl/heroku-cli-repl.js';
|
|
3
1
|
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
4
2
|
import { registerMaintenanceOnTool, registerMaintenanceOffTool } from './maintenance.js';
|
|
5
3
|
import { expect } from 'chai';
|
|
6
4
|
import sinon from 'sinon';
|
|
5
|
+
import { setupMcpToolMocks } from '../utils/mcp-tool-mocks.spechelper.js';
|
|
7
6
|
describe('Maintenance Tools', () => {
|
|
8
|
-
let server;
|
|
9
|
-
let herokuRepl;
|
|
10
|
-
let toolCallback;
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
server = sinon.createStubInstance(McpServer);
|
|
13
|
-
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
14
|
-
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
15
|
-
toolCallback = callback;
|
|
16
|
-
return server;
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
7
|
afterEach(() => {
|
|
20
8
|
sinon.restore();
|
|
21
9
|
});
|
|
22
10
|
describe('maintenance:on', () => {
|
|
11
|
+
let mocks;
|
|
12
|
+
let toolCallback;
|
|
23
13
|
beforeEach(() => {
|
|
24
|
-
|
|
14
|
+
mocks = setupMcpToolMocks();
|
|
15
|
+
registerMaintenanceOnTool(mocks.server, mocks.herokuRepl);
|
|
16
|
+
toolCallback = mocks.getToolCallback();
|
|
25
17
|
});
|
|
26
18
|
it('should register the tool with correct parameters', () => {
|
|
27
|
-
|
|
28
|
-
expect(
|
|
29
|
-
expect(
|
|
30
|
-
expect(
|
|
31
|
-
expect(
|
|
19
|
+
const tool = mocks.server.tool;
|
|
20
|
+
expect(tool.calledOnce).to.be.true;
|
|
21
|
+
expect(tool.firstCall.args[0]).to.equal('maintenance_on');
|
|
22
|
+
expect(tool.firstCall.args[1]).to.be.a('string');
|
|
23
|
+
expect(tool.firstCall.args[2]).to.be.an('object');
|
|
24
|
+
expect(tool.firstCall.args[3]).to.be.a('function');
|
|
32
25
|
});
|
|
33
26
|
it('should build correct command with required parameters', async () => {
|
|
34
|
-
herokuRepl.executeCommand.resolves('Enabling maintenance mode for myapp... done\n');
|
|
27
|
+
mocks.herokuRepl.executeCommand.resolves('Enabling maintenance mode for myapp... done\n');
|
|
35
28
|
await toolCallback({ app: 'myapp' });
|
|
36
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
37
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.MAINTENANCE_ON} --app=myapp`);
|
|
29
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
30
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.MAINTENANCE_ON} --app=myapp`);
|
|
38
31
|
});
|
|
39
32
|
it('should handle successful response', async () => {
|
|
40
33
|
const successResponse = 'Enabling maintenance mode for myapp... done\n';
|
|
41
|
-
herokuRepl.executeCommand.resolves(successResponse);
|
|
34
|
+
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
42
35
|
const result = await toolCallback({ app: 'myapp' });
|
|
43
36
|
expect(result).to.deep.equal({
|
|
44
37
|
content: [{ type: 'text', text: 'Enabling maintenance mode for myapp... done\n' }]
|
|
@@ -46,7 +39,7 @@ describe('Maintenance Tools', () => {
|
|
|
46
39
|
});
|
|
47
40
|
it('should handle error response', async () => {
|
|
48
41
|
const errorResponse = '<<<ERROR>>>\nError: App not found\n<<<END ERROR>>>\n';
|
|
49
|
-
herokuRepl.executeCommand.resolves(errorResponse);
|
|
42
|
+
mocks.herokuRepl.executeCommand.resolves(errorResponse);
|
|
50
43
|
const result = await toolCallback({ app: 'myapp' });
|
|
51
44
|
expect(result).to.deep.equal({
|
|
52
45
|
content: [
|
|
@@ -60,25 +53,30 @@ describe('Maintenance Tools', () => {
|
|
|
60
53
|
});
|
|
61
54
|
});
|
|
62
55
|
describe('maintenance:off', () => {
|
|
56
|
+
let mocks;
|
|
57
|
+
let toolCallback;
|
|
63
58
|
beforeEach(() => {
|
|
64
|
-
|
|
59
|
+
mocks = setupMcpToolMocks();
|
|
60
|
+
registerMaintenanceOffTool(mocks.server, mocks.herokuRepl);
|
|
61
|
+
toolCallback = mocks.getToolCallback();
|
|
65
62
|
});
|
|
66
63
|
it('should register the tool with correct parameters', () => {
|
|
67
|
-
|
|
68
|
-
expect(
|
|
69
|
-
expect(
|
|
70
|
-
expect(
|
|
71
|
-
expect(
|
|
64
|
+
const tool = mocks.server.tool;
|
|
65
|
+
expect(tool.calledOnce).to.be.true;
|
|
66
|
+
expect(tool.firstCall.args[0]).to.equal('maintenance_off');
|
|
67
|
+
expect(tool.firstCall.args[1]).to.be.a('string');
|
|
68
|
+
expect(tool.firstCall.args[2]).to.be.an('object');
|
|
69
|
+
expect(tool.firstCall.args[3]).to.be.a('function');
|
|
72
70
|
});
|
|
73
71
|
it('should build correct command with required parameters', async () => {
|
|
74
|
-
herokuRepl.executeCommand.resolves('Disabling maintenance mode for myapp... done\n');
|
|
72
|
+
mocks.herokuRepl.executeCommand.resolves('Disabling maintenance mode for myapp... done\n');
|
|
75
73
|
await toolCallback({ app: 'myapp' });
|
|
76
|
-
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
77
|
-
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.MAINTENANCE_OFF} --app=myapp`);
|
|
74
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
75
|
+
expect(mocks.herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.MAINTENANCE_OFF} --app=myapp`);
|
|
78
76
|
});
|
|
79
77
|
it('should handle successful response', async () => {
|
|
80
78
|
const successResponse = 'Disabling maintenance mode for myapp... done\n';
|
|
81
|
-
herokuRepl.executeCommand.resolves(successResponse);
|
|
79
|
+
mocks.herokuRepl.executeCommand.resolves(successResponse);
|
|
82
80
|
const result = await toolCallback({ app: 'myapp' });
|
|
83
81
|
expect(result).to.deep.equal({
|
|
84
82
|
content: [{ type: 'text', text: 'Disabling maintenance mode for myapp... done\n' }]
|
|
@@ -86,7 +84,7 @@ describe('Maintenance Tools', () => {
|
|
|
86
84
|
});
|
|
87
85
|
it('should handle error response', async () => {
|
|
88
86
|
const errorResponse = '<<<ERROR>>>\nError: App not found\n<<<END ERROR>>>\n';
|
|
89
|
-
herokuRepl.executeCommand.resolves(errorResponse);
|
|
87
|
+
mocks.herokuRepl.executeCommand.resolves(errorResponse);
|
|
90
88
|
const result = await toolCallback({ app: 'myapp' });
|
|
91
89
|
expect(result).to.deep.equal({
|
|
92
90
|
content: [
|
|
@@ -99,7 +97,7 @@ describe('Maintenance Tools', () => {
|
|
|
99
97
|
});
|
|
100
98
|
});
|
|
101
99
|
it('should handle undefined response', async () => {
|
|
102
|
-
herokuRepl.executeCommand.resolves(undefined);
|
|
100
|
+
mocks.herokuRepl.executeCommand.resolves(undefined);
|
|
103
101
|
const result = await toolCallback({ app: 'myapp' });
|
|
104
102
|
expect(result).to.deep.equal({
|
|
105
103
|
content: [
|