@heroku/mcp-server 0.0.1-alpha.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/LICENSE.txt +206 -0
- package/README.md +279 -0
- package/dist/index.js +86 -0
- package/dist/repl/heroku-cli-repl.js +210 -0
- package/dist/repl/heroku-cli-repl.spec.js +106 -0
- package/dist/services/app-service.js +42 -0
- package/dist/services/app-setup-service.js +72 -0
- package/dist/services/build-service.js +149 -0
- package/dist/services/source-service.js +42 -0
- package/dist/tools/addons.js +241 -0
- package/dist/tools/addons.spec.js +335 -0
- package/dist/tools/apps.js +222 -0
- package/dist/tools/apps.spec.js +332 -0
- package/dist/tools/data.js +345 -0
- package/dist/tools/data.spec.js +300 -0
- package/dist/tools/deploy-to-heroku.js +449 -0
- package/dist/tools/deploy-to-heroku.spec.js +166 -0
- package/dist/tools/logs.js +61 -0
- package/dist/tools/logs.spec.js +112 -0
- package/dist/tools/maintenance.js +55 -0
- package/dist/tools/maintenance.spec.js +115 -0
- package/dist/tools/pipelines.js +146 -0
- package/dist/tools/pipelines.spec.js +183 -0
- package/dist/tools/ps.js +99 -0
- package/dist/tools/ps.spec.js +127 -0
- package/dist/tools/spaces.js +34 -0
- package/dist/tools/spaces.spec.js +71 -0
- package/dist/tools/teams.js +37 -0
- package/dist/tools/teams.spec.js +69 -0
- package/dist/utils/app-json.schema.json +232 -0
- package/dist/utils/command-builder.js +61 -0
- package/dist/utils/command-builder.spec.js +95 -0
- package/dist/utils/generate-request-init.js +18 -0
- package/dist/utils/handle-cli-output.js +26 -0
- package/dist/utils/handle-cli-output.spec.js +54 -0
- package/dist/utils/mcp-tool-response.js +1 -0
- package/dist/utils/read-app-json.js +39 -0
- package/dist/utils/read-app-json.spec.js +106 -0
- package/dist/utils/tarball.js +114 -0
- package/dist/utils/tarball.spec.js +98 -0
- package/dist/utils/tool-commands.js +47 -0
- package/package.json +85 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { handleCliOutput } from '../utils/handle-cli-output.js';
|
|
3
|
+
import { CommandBuilder } from '../utils/command-builder.js';
|
|
4
|
+
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
5
|
+
/**
|
|
6
|
+
* Schema for listing Heroku applications with filtering and output format options.
|
|
7
|
+
* This schema defines the structure and validation rules for the list apps operation.
|
|
8
|
+
*/
|
|
9
|
+
export const listAppsOptionsSchema = z.object({
|
|
10
|
+
all: z
|
|
11
|
+
.boolean()
|
|
12
|
+
.optional()
|
|
13
|
+
.describe('When true, displays a comprehensive list including: (1) apps owned by the user and (2) apps where the user ' +
|
|
14
|
+
'is a collaborator through direct access or team membership. When false or omitted, shows only owned apps.'),
|
|
15
|
+
json: z
|
|
16
|
+
.boolean()
|
|
17
|
+
.optional()
|
|
18
|
+
.describe('Controls the output format. When true, returns a detailed JSON response containing app metadata such as ' +
|
|
19
|
+
'generation, buildpacks, owner information, and region. When false or omitted, returns a simplified text ' +
|
|
20
|
+
'format.'),
|
|
21
|
+
personal: z
|
|
22
|
+
.boolean()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe('Forces the tool to list applications from your personal account, even when you have a default team configured. ' +
|
|
25
|
+
'When true, overrides any default team setting and shows only apps owned by your personal account. ' +
|
|
26
|
+
'This is particularly useful when you work with multiple teams but need to specifically view your personal apps. ' +
|
|
27
|
+
'When false or omitted, follows the default behavior of using the default team if one is set.'),
|
|
28
|
+
space: z
|
|
29
|
+
.string()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe('Filters the results to show only apps within a specific private space. Provide the private space name to ' +
|
|
32
|
+
'filter. This parameter is mutually exclusive with the team parameter.'),
|
|
33
|
+
team: z
|
|
34
|
+
.string()
|
|
35
|
+
.optional()
|
|
36
|
+
.describe('Filters the results to show only apps belonging to a specific team. Provide the team name to filter. ' +
|
|
37
|
+
'This parameter is mutually exclusive with the space parameter.')
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Registers the list_apps tool with the MCP server.
|
|
41
|
+
* This tool allows users to list Heroku applications with various filtering options
|
|
42
|
+
* and output formats.
|
|
43
|
+
*
|
|
44
|
+
* @param server - The MCP server instance to register the tool with
|
|
45
|
+
* @param herokuRepl - The Heroku REPL instance for executing commands
|
|
46
|
+
*/
|
|
47
|
+
export const registerListAppsTool = (server, herokuRepl) => {
|
|
48
|
+
server.tool('list_apps', 'List Heroku applications with flexible filtering options. Use this tool when you need to: ' +
|
|
49
|
+
'1) Show all apps owned by the user, 2) Show apps where the user is a collaborator (use all=true), ' +
|
|
50
|
+
'3) Filter apps by team or private space. Note: For checking app name availability, prefer using get_app_info ' +
|
|
51
|
+
'as it returns a more focused dataset. The response includes app names, regions, and ownership information.', listAppsOptionsSchema.shape, async (options) => {
|
|
52
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS)
|
|
53
|
+
.addFlags({
|
|
54
|
+
all: options.all,
|
|
55
|
+
json: options.json,
|
|
56
|
+
personal: options.personal,
|
|
57
|
+
space: options.space,
|
|
58
|
+
team: options.team
|
|
59
|
+
})
|
|
60
|
+
.build();
|
|
61
|
+
const output = await herokuRepl.executeCommand(command);
|
|
62
|
+
return handleCliOutput(output);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Schema for getting information about a Heroku application.
|
|
67
|
+
* This schema defines the structure and validation rules for the get app info operation.
|
|
68
|
+
*/
|
|
69
|
+
export const getAppInfoOptionsSchema = z.object({
|
|
70
|
+
app: z
|
|
71
|
+
.string()
|
|
72
|
+
.describe('The name of the Heroku app to get information about. This must be an existing app that you have access to.'),
|
|
73
|
+
json: z
|
|
74
|
+
.boolean()
|
|
75
|
+
.optional()
|
|
76
|
+
.describe('Controls the output format. When true, returns a detailed JSON response containing app metadata such as ' +
|
|
77
|
+
'add-ons, dynos, buildpack configurations, collaborators, and domain information. When false or omitted, ' +
|
|
78
|
+
'returns a simplified text format.')
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Registers the get_app_info tool with the MCP server.
|
|
82
|
+
* This tool provides detailed information about a specific Heroku application,
|
|
83
|
+
* including configuration, dynos, add-ons, and more.
|
|
84
|
+
*
|
|
85
|
+
* @param server - The MCP server instance to register the tool with
|
|
86
|
+
* @param herokuRepl - The Heroku REPL instance for executing commands
|
|
87
|
+
*/
|
|
88
|
+
export const registerGetAppInfoTool = (server, herokuRepl) => {
|
|
89
|
+
server.tool('get_app_info', 'Get comprehensive information about a Heroku application. Use this tool when you need to: ' +
|
|
90
|
+
'1) View app configuration and settings, 2) Check dyno formation and scaling, ' +
|
|
91
|
+
'3) List add-ons and buildpacks, 4) View collaborators and access details, ' +
|
|
92
|
+
'5) Check domains and certificates. Accepts app name and optional JSON format. ' +
|
|
93
|
+
'Returns detailed app status and configuration.', getAppInfoOptionsSchema.shape, async (options) => {
|
|
94
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.GET_APP_INFO)
|
|
95
|
+
.addFlags({
|
|
96
|
+
app: options.app,
|
|
97
|
+
json: options.json
|
|
98
|
+
})
|
|
99
|
+
.build();
|
|
100
|
+
const output = await herokuRepl.executeCommand(command);
|
|
101
|
+
return handleCliOutput(output);
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Schema for creating a new Heroku application.
|
|
106
|
+
* This schema defines the structure and validation rules for the create app operation.
|
|
107
|
+
*/
|
|
108
|
+
export const createAppOptionsSchema = z.object({
|
|
109
|
+
app: z
|
|
110
|
+
.string()
|
|
111
|
+
.optional()
|
|
112
|
+
.describe('Specifies the desired name for the new Heroku app. If omitted, Heroku will auto-generate a random name. ' +
|
|
113
|
+
"Best practice: Provide a meaningful, unique name that reflects your application's purpose."),
|
|
114
|
+
region: z
|
|
115
|
+
.enum(['us', 'eu'])
|
|
116
|
+
.optional()
|
|
117
|
+
.describe('Determines the geographical region where your app will run. Options: "us" (United States) or "eu" (Europe). ' +
|
|
118
|
+
'Defaults to "us" if not specified. Note: Cannot be used with space parameter.'),
|
|
119
|
+
space: z
|
|
120
|
+
.string()
|
|
121
|
+
.optional()
|
|
122
|
+
.describe('Places the app in a specific private space, which provides enhanced security and networking features. ' +
|
|
123
|
+
'Specify the private space name. Note: When used, the app inherits the region from the private space and ' +
|
|
124
|
+
'the region parameter cannot be used.'),
|
|
125
|
+
team: z
|
|
126
|
+
.string()
|
|
127
|
+
.optional()
|
|
128
|
+
.describe('Associates the app with a specific team for collaborative development and management. Provide the team name ' +
|
|
129
|
+
"to set ownership. The app will be created under the team's account rather than your personal account.")
|
|
130
|
+
});
|
|
131
|
+
/**
|
|
132
|
+
* Registers the create_app tool with the MCP server.
|
|
133
|
+
* This tool enables creation of new Heroku applications with customizable settings
|
|
134
|
+
* for region, team ownership, and private space placement.
|
|
135
|
+
*
|
|
136
|
+
* @param server - The MCP server instance to register the tool with
|
|
137
|
+
* @param herokuRepl - The Heroku REPL instance for executing commands
|
|
138
|
+
*/
|
|
139
|
+
export const registerCreateAppTool = (server, herokuRepl) => {
|
|
140
|
+
server.tool('create_app', 'Create a new Heroku application with customizable settings. Use this tool when a user wants to: ' +
|
|
141
|
+
'1) Create a new app with a specific name, 2) Create an app in a particular region (US/EU), ' +
|
|
142
|
+
'3) Create an app within a team, or 4) Create an app in a private space. ' +
|
|
143
|
+
"The tool handles name generation if not specified and returns the new app's details.", createAppOptionsSchema.shape, async (options) => {
|
|
144
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.CREATE_APP)
|
|
145
|
+
.addPositionalArguments({ app: options.app })
|
|
146
|
+
.addFlags({
|
|
147
|
+
region: options.region,
|
|
148
|
+
space: options.space,
|
|
149
|
+
team: options.team
|
|
150
|
+
})
|
|
151
|
+
.build();
|
|
152
|
+
const output = await herokuRepl.executeCommand(command);
|
|
153
|
+
return handleCliOutput(output);
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Schema for renaming a Heroku application.
|
|
158
|
+
* This schema defines the structure and validation rules for the rename app operation.
|
|
159
|
+
*/
|
|
160
|
+
export const renameAppOptionsSchema = z.object({
|
|
161
|
+
app: z
|
|
162
|
+
.string()
|
|
163
|
+
.describe('The current name of the Heroku app you want to rename. This must be an existing app that you have access to.'),
|
|
164
|
+
newName: z.string().describe('The new name you want to give to the app. Must be unique across all Heroku apps.')
|
|
165
|
+
});
|
|
166
|
+
/**
|
|
167
|
+
* Registers the rename_app tool with the MCP server.
|
|
168
|
+
* This tool allows renaming of existing Heroku applications while ensuring
|
|
169
|
+
* name availability and access permissions.
|
|
170
|
+
*
|
|
171
|
+
* @param server - The MCP server instance to register the tool with
|
|
172
|
+
* @param herokuRepl - The Heroku REPL instance for executing commands
|
|
173
|
+
*/
|
|
174
|
+
export const registerRenameAppTool = (server, herokuRepl) => {
|
|
175
|
+
server.tool('rename_app', 'Rename an existing Heroku application. Use this tool when a user needs to: ' +
|
|
176
|
+
"1) Change an app's name, or 2) Resolve naming conflicts. " +
|
|
177
|
+
'Requires both current app name and desired new name. ' +
|
|
178
|
+
'The tool validates name availability and handles the rename process.', renameAppOptionsSchema.shape, async (options) => {
|
|
179
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.RENAME_APP)
|
|
180
|
+
.addFlags({ app: options.app })
|
|
181
|
+
.addPositionalArguments({ newName: options.newName })
|
|
182
|
+
.build();
|
|
183
|
+
const output = await herokuRepl.executeCommand(command);
|
|
184
|
+
return handleCliOutput(output);
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* Schema for transferring ownership of a Heroku application.
|
|
189
|
+
* This schema defines the structure and validation rules for the transfer app operation.
|
|
190
|
+
*/
|
|
191
|
+
export const transferAppOptionsSchema = z.object({
|
|
192
|
+
app: z
|
|
193
|
+
.string()
|
|
194
|
+
.describe('The name of the Heroku app you want to transfer ownership of. You must be the current owner of this app or ' +
|
|
195
|
+
'a team admin to transfer it.'),
|
|
196
|
+
recipient: z
|
|
197
|
+
.string()
|
|
198
|
+
.describe('The email address of the user or the name of the team who will receive ownership of the app. The recipient ' +
|
|
199
|
+
'must have a Heroku account.')
|
|
200
|
+
});
|
|
201
|
+
/**
|
|
202
|
+
* Registers the transfer_app tool with the MCP server.
|
|
203
|
+
* This tool facilitates ownership transfer of Heroku applications between users
|
|
204
|
+
* or to teams, with appropriate permission checks.
|
|
205
|
+
*
|
|
206
|
+
* @param server - The MCP server instance to register the tool with
|
|
207
|
+
* @param herokuRepl - The Heroku REPL instance for executing commands
|
|
208
|
+
*/
|
|
209
|
+
export const registerTransferAppTool = (server, herokuRepl) => {
|
|
210
|
+
server.tool('transfer_app', 'Transfer ownership of a Heroku application. Use this tool when a user wants to: ' +
|
|
211
|
+
"1) Transfer an app to another user's account, 2) Move an app to a team, " +
|
|
212
|
+
'3) Change app ownership for organizational purposes. ' +
|
|
213
|
+
'Requires the app name and recipient (email for users, name for teams). ' +
|
|
214
|
+
'The current user must be the app owner or a team admin to perform the transfer.', transferAppOptionsSchema.shape, async (options) => {
|
|
215
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.TRANSFER_APP)
|
|
216
|
+
.addFlags({ app: options.app })
|
|
217
|
+
.addPositionalArguments({ recipient: options.recipient })
|
|
218
|
+
.build();
|
|
219
|
+
const output = await herokuRepl.executeCommand(command);
|
|
220
|
+
return handleCliOutput(output);
|
|
221
|
+
});
|
|
222
|
+
};
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import sinon from 'sinon';
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
+
import { HerokuREPL } from '../repl/heroku-cli-repl.js';
|
|
5
|
+
import { listAppsOptionsSchema, getAppInfoOptionsSchema, createAppOptionsSchema, renameAppOptionsSchema, transferAppOptionsSchema, registerListAppsTool, registerGetAppInfoTool, registerCreateAppTool, registerRenameAppTool, registerTransferAppTool } from './apps.js';
|
|
6
|
+
import { CommandBuilder } from '../utils/command-builder.js';
|
|
7
|
+
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
8
|
+
describe('apps topic tools', () => {
|
|
9
|
+
describe('registerListAppsTool', () => {
|
|
10
|
+
let server;
|
|
11
|
+
let herokuRepl;
|
|
12
|
+
let toolCallback;
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
server = sinon.createStubInstance(McpServer);
|
|
15
|
+
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
16
|
+
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
17
|
+
toolCallback = callback;
|
|
18
|
+
return server;
|
|
19
|
+
});
|
|
20
|
+
registerListAppsTool(server, herokuRepl);
|
|
21
|
+
});
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
sinon.restore();
|
|
24
|
+
});
|
|
25
|
+
it('registers the tool with correct name and schema', () => {
|
|
26
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
27
|
+
const call = server.tool.getCall(0);
|
|
28
|
+
expect(call.args[0]).to.equal('list_apps');
|
|
29
|
+
expect(call.args[2]).to.deep.equal(listAppsOptionsSchema.shape);
|
|
30
|
+
});
|
|
31
|
+
it('executes command successfully with all flag', async () => {
|
|
32
|
+
const expectedOutput = '=== user@example.com Apps\n\n' +
|
|
33
|
+
'test-app\n' +
|
|
34
|
+
'=== Collaborated Apps\n\n' +
|
|
35
|
+
'test-app2 test-team@herokumanager.com';
|
|
36
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS).addFlags({ all: true }).build();
|
|
37
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
38
|
+
const result = await toolCallback({ all: true }, {});
|
|
39
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
40
|
+
expect(result).to.deep.equal({
|
|
41
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
it('executes command successfully with json flag', async () => {
|
|
45
|
+
const expectedOutput = '[{"name": "test-app", "team": {"name": "test-team"}, "space": {"name": "test-space"}}]';
|
|
46
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS).addFlags({ json: true }).build();
|
|
47
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
48
|
+
const result = await toolCallback({ json: true }, {});
|
|
49
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
50
|
+
expect(result).to.deep.equal({
|
|
51
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
it('executes command successfully without json flag', async () => {
|
|
55
|
+
const expectedOutput = '=== user@example.com Apps\n\n' + 'test-app';
|
|
56
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS).addFlags({ json: false }).build();
|
|
57
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
58
|
+
const result = await toolCallback({ json: false }, {});
|
|
59
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
60
|
+
expect(result).to.deep.equal({
|
|
61
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
it('executes command successfully with personal flag', async () => {
|
|
65
|
+
const expectedOutput = '=== user@example.com Apps\n\n' + 'test-app';
|
|
66
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS).addFlags({ personal: true }).build();
|
|
67
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
68
|
+
const result = await toolCallback({ personal: true }, {});
|
|
69
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
70
|
+
expect(result).to.deep.equal({
|
|
71
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
it('executes command successfully with space flag', async () => {
|
|
75
|
+
const expectedOutput = '=== Apps in space test-space\n\n' + 'test-app2\n';
|
|
76
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS).addFlags({ space: 'test-space' }).build();
|
|
77
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
78
|
+
const result = await toolCallback({ space: 'test-space' }, {});
|
|
79
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
80
|
+
expect(result).to.deep.equal({
|
|
81
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
it('executes command successfully with team flag', async () => {
|
|
85
|
+
const expectedOutput = '=== Apps in team test-team\n\n' + 'test-app2\n';
|
|
86
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS).addFlags({ team: 'test-team' }).build();
|
|
87
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
88
|
+
const result = await toolCallback({ team: 'test-team' }, {});
|
|
89
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
90
|
+
expect(result).to.deep.equal({
|
|
91
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe('registerGetAppInfoTool', () => {
|
|
96
|
+
let server;
|
|
97
|
+
let herokuRepl;
|
|
98
|
+
let toolCallback;
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
server = sinon.createStubInstance(McpServer);
|
|
101
|
+
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
102
|
+
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
103
|
+
toolCallback = callback;
|
|
104
|
+
return server;
|
|
105
|
+
});
|
|
106
|
+
registerGetAppInfoTool(server, herokuRepl);
|
|
107
|
+
});
|
|
108
|
+
afterEach(() => {
|
|
109
|
+
sinon.restore();
|
|
110
|
+
});
|
|
111
|
+
it('registers the tool with correct name and schema', () => {
|
|
112
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
113
|
+
const call = server.tool.getCall(0);
|
|
114
|
+
expect(call.args[0]).to.equal('get_app_info');
|
|
115
|
+
expect(call.args[2]).to.deep.equal(getAppInfoOptionsSchema.shape);
|
|
116
|
+
});
|
|
117
|
+
it('executes command successfully with json flag', async () => {
|
|
118
|
+
const expectedOutput = '{"name": "test-app"}';
|
|
119
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.GET_APP_INFO)
|
|
120
|
+
.addFlags({ app: 'test-app', json: true })
|
|
121
|
+
.build();
|
|
122
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
123
|
+
const result = await toolCallback({ app: 'test-app', json: true }, {});
|
|
124
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
125
|
+
expect(result).to.deep.equal({
|
|
126
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
it('executes command successfully without json flag', async () => {
|
|
130
|
+
const expectedOutput = '=== test-app\n\n' + 'Addons: heroku-postgresql:essential-0\n' + 'Stack: heroku-24';
|
|
131
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.GET_APP_INFO).addFlags({ app: 'test-app' }).build();
|
|
132
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
133
|
+
const result = await toolCallback({ app: 'test-app' }, {});
|
|
134
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
135
|
+
expect(result).to.deep.equal({
|
|
136
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe('registerCreateAppTool', () => {
|
|
141
|
+
let server;
|
|
142
|
+
let herokuRepl;
|
|
143
|
+
let toolCallback;
|
|
144
|
+
beforeEach(() => {
|
|
145
|
+
server = sinon.createStubInstance(McpServer);
|
|
146
|
+
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
147
|
+
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
148
|
+
toolCallback = callback;
|
|
149
|
+
return server;
|
|
150
|
+
});
|
|
151
|
+
registerCreateAppTool(server, herokuRepl);
|
|
152
|
+
});
|
|
153
|
+
afterEach(() => {
|
|
154
|
+
sinon.restore();
|
|
155
|
+
});
|
|
156
|
+
it('registers the tool with correct name and schema', () => {
|
|
157
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
158
|
+
const call = server.tool.getCall(0);
|
|
159
|
+
expect(call.args[0]).to.equal('create_app');
|
|
160
|
+
expect(call.args[2]).to.deep.equal(createAppOptionsSchema.shape);
|
|
161
|
+
});
|
|
162
|
+
it('executes command successfully with name argument', async () => {
|
|
163
|
+
const expectedOutput = 'Creating test-app... done\n' +
|
|
164
|
+
'https://test-app-7a40ad12ea52.herokuapp.com/ | https://git.heroku.com/test-app.git\n';
|
|
165
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.CREATE_APP)
|
|
166
|
+
.addPositionalArguments({ app: 'test-app' })
|
|
167
|
+
.build();
|
|
168
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
169
|
+
const result = await toolCallback({ app: 'test-app' }, {});
|
|
170
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
171
|
+
expect(result).to.deep.equal({
|
|
172
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
it('executes command successfully with space argument', async () => {
|
|
176
|
+
const expectedOutput = 'Creating test-app in space test-space... done\n' +
|
|
177
|
+
'https://test-app-7a40ad12ea52.herokuapp.com/ | https://git.heroku.com/test-app.git\n';
|
|
178
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.CREATE_APP)
|
|
179
|
+
.addPositionalArguments({ app: 'test-app' })
|
|
180
|
+
.addFlags({ space: 'test-space' })
|
|
181
|
+
.build();
|
|
182
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
183
|
+
const result = await toolCallback({ app: 'test-app', space: 'test-space' }, {});
|
|
184
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
185
|
+
expect(result).to.deep.equal({
|
|
186
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
it('executes command successfully with team argument', async () => {
|
|
190
|
+
const expectedOutput = 'Creating test-app in team test-team... done\n' +
|
|
191
|
+
'https://test-app-7a40ad12ea52.herokuapp.com/ | https://git.heroku.com/test-app.git\n';
|
|
192
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.CREATE_APP)
|
|
193
|
+
.addPositionalArguments({ app: 'test-app' })
|
|
194
|
+
.addFlags({ team: 'test-team' })
|
|
195
|
+
.build();
|
|
196
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
197
|
+
const result = await toolCallback({ app: 'test-app', team: 'test-team' }, {});
|
|
198
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
199
|
+
expect(result).to.deep.equal({
|
|
200
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
it('executes command successfully without flags', async () => {
|
|
204
|
+
const expectedOutput = 'Creating frozen-badlands-12345... done\n' +
|
|
205
|
+
'https://frozen-badlands-89ae2afb35d.herokuapp.com/ | https://git.heroku.com/frozen-badlands.git\n';
|
|
206
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.CREATE_APP).build();
|
|
207
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
208
|
+
const result = await toolCallback({}, {});
|
|
209
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
210
|
+
expect(result).to.deep.equal({
|
|
211
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
describe('registerRenameAppTool', () => {
|
|
216
|
+
let server;
|
|
217
|
+
let herokuRepl;
|
|
218
|
+
let toolCallback;
|
|
219
|
+
beforeEach(() => {
|
|
220
|
+
server = sinon.createStubInstance(McpServer);
|
|
221
|
+
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
222
|
+
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
223
|
+
toolCallback = callback;
|
|
224
|
+
return server;
|
|
225
|
+
});
|
|
226
|
+
registerRenameAppTool(server, herokuRepl);
|
|
227
|
+
});
|
|
228
|
+
afterEach(() => {
|
|
229
|
+
sinon.restore();
|
|
230
|
+
});
|
|
231
|
+
it('registers the tool with correct name and schema', () => {
|
|
232
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
233
|
+
const call = server.tool.getCall(0);
|
|
234
|
+
expect(call.args[0]).to.equal('rename_app');
|
|
235
|
+
expect(call.args[2]).to.deep.equal(renameAppOptionsSchema.shape);
|
|
236
|
+
});
|
|
237
|
+
it('executes command successfully', async () => {
|
|
238
|
+
const expectedOutput = 'Renaming test-app to test-app-2... done\n' +
|
|
239
|
+
'https://test-app-2-0f749ee37cc8.herokuapp.com/ | https://git.heroku.com/test-app-2.git\n';
|
|
240
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.RENAME_APP)
|
|
241
|
+
.addPositionalArguments({ newName: 'test-app-2' })
|
|
242
|
+
.addFlags({ app: 'test-app' })
|
|
243
|
+
.build();
|
|
244
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
245
|
+
const result = await toolCallback({ app: 'test-app', newName: 'test-app-2' }, {});
|
|
246
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
247
|
+
expect(result).to.deep.equal({
|
|
248
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
describe('registerTransferAppTool', () => {
|
|
253
|
+
let server;
|
|
254
|
+
let herokuRepl;
|
|
255
|
+
let toolCallback;
|
|
256
|
+
beforeEach(() => {
|
|
257
|
+
server = sinon.createStubInstance(McpServer);
|
|
258
|
+
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
259
|
+
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
260
|
+
toolCallback = callback;
|
|
261
|
+
return server;
|
|
262
|
+
});
|
|
263
|
+
registerTransferAppTool(server, herokuRepl);
|
|
264
|
+
});
|
|
265
|
+
afterEach(() => {
|
|
266
|
+
sinon.restore();
|
|
267
|
+
});
|
|
268
|
+
it('registers the tool with correct name and schema', () => {
|
|
269
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
270
|
+
const call = server.tool.getCall(0);
|
|
271
|
+
expect(call.args[0]).to.equal('transfer_app');
|
|
272
|
+
expect(call.args[2]).to.deep.equal(transferAppOptionsSchema.shape);
|
|
273
|
+
});
|
|
274
|
+
it('executes command successfully', async () => {
|
|
275
|
+
const expectedOutput = 'Initiating transfer of test-app to user@example.com... email sent\n';
|
|
276
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.TRANSFER_APP)
|
|
277
|
+
.addFlags({ app: 'test-app' })
|
|
278
|
+
.addPositionalArguments({ recipient: 'user@example.com' })
|
|
279
|
+
.build();
|
|
280
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
281
|
+
const result = await toolCallback({ app: 'test-app', recipient: 'user@example.com' }, {});
|
|
282
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
283
|
+
expect(result).to.deep.equal({
|
|
284
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
// Common error handling test for all tools
|
|
289
|
+
describe('error handling', () => {
|
|
290
|
+
let server;
|
|
291
|
+
let herokuRepl;
|
|
292
|
+
let toolCallback;
|
|
293
|
+
beforeEach(() => {
|
|
294
|
+
server = sinon.createStubInstance(McpServer);
|
|
295
|
+
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
296
|
+
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
297
|
+
toolCallback = callback;
|
|
298
|
+
return server;
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
afterEach(() => {
|
|
302
|
+
sinon.restore();
|
|
303
|
+
});
|
|
304
|
+
it('handles CLI errors properly for all tools', async () => {
|
|
305
|
+
const expectedOutput = '<<<BEGIN RESULTS>>>\n<<<ERROR>>>API error<<<END ERROR>>><<<END RESULTS>>>';
|
|
306
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
307
|
+
// Test error handling for each tool
|
|
308
|
+
const tools = [
|
|
309
|
+
{ register: registerListAppsTool, options: {} },
|
|
310
|
+
{ register: registerGetAppInfoTool, options: { app: 'test-app' } },
|
|
311
|
+
{ register: registerCreateAppTool, options: { app: 'test-app' } },
|
|
312
|
+
{ register: registerRenameAppTool, options: { app: 'old-app', newName: 'new-app' } },
|
|
313
|
+
{ register: registerTransferAppTool, options: { app: 'test-app', recipient: 'user@example.com' } }
|
|
314
|
+
];
|
|
315
|
+
for (const tool of tools) {
|
|
316
|
+
tool.register(server, herokuRepl);
|
|
317
|
+
const result = await toolCallback(tool.options, {});
|
|
318
|
+
expect(result).to.deep.equal({
|
|
319
|
+
isError: true,
|
|
320
|
+
content: [
|
|
321
|
+
{
|
|
322
|
+
type: 'text',
|
|
323
|
+
text: '[Heroku MCP Server Error] Please use available tools to resolve this issue. ' +
|
|
324
|
+
'Ignore any Heroku CLI command suggestions that may be provided in the command output or error ' +
|
|
325
|
+
`details. Details:\n${expectedOutput}`
|
|
326
|
+
}
|
|
327
|
+
]
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
});
|