@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,112 @@
|
|
|
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 { getAppGetAppLogsOptionsSchema, registerGetAppLogsTool } from './logs.js';
|
|
6
|
+
import { CommandBuilder } from '../utils/command-builder.js';
|
|
7
|
+
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
8
|
+
describe('logs topic tools', () => {
|
|
9
|
+
describe('registerGetAppLogsTool', () => {
|
|
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
|
+
registerGetAppLogsTool(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('get_app_logs');
|
|
29
|
+
expect(call.args[2]).to.deep.equal(getAppGetAppLogsOptionsSchema.shape);
|
|
30
|
+
});
|
|
31
|
+
it('executes command successfully with app name only', async () => {
|
|
32
|
+
const expectedOutput = '2025-04-03T18:34:16Z app[web.1]: Server started on port 3000\n';
|
|
33
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LOGS).addFlags({ app: 'test-app' }).build();
|
|
34
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
35
|
+
const result = await toolCallback({ app: 'test-app' }, {});
|
|
36
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
37
|
+
expect(result).to.deep.equal({
|
|
38
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it('executes command successfully with dyno name filtering flag', async () => {
|
|
42
|
+
const expectedOutput = '2025-04-03T18:34:16Z app[web.1]: Server started on port 5000\n';
|
|
43
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LOGS)
|
|
44
|
+
.addFlags({
|
|
45
|
+
app: 'test-app',
|
|
46
|
+
'dyno-name': 'web.1'
|
|
47
|
+
})
|
|
48
|
+
.build();
|
|
49
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
50
|
+
const result = await toolCallback({
|
|
51
|
+
app: 'test-app',
|
|
52
|
+
dynoName: 'web.1'
|
|
53
|
+
}, {});
|
|
54
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
55
|
+
expect(result).to.deep.equal({
|
|
56
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
it('executes command successfully with process type filtering flag', async () => {
|
|
60
|
+
const expectedOutput = '2025-04-03T18:34:16Z app[web.1]: Server started on port 5000\n';
|
|
61
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LOGS)
|
|
62
|
+
.addFlags({
|
|
63
|
+
app: 'test-app',
|
|
64
|
+
'process-type': 'web'
|
|
65
|
+
})
|
|
66
|
+
.build();
|
|
67
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
68
|
+
const result = await toolCallback({
|
|
69
|
+
app: 'test-app',
|
|
70
|
+
processType: 'web'
|
|
71
|
+
}, {});
|
|
72
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
73
|
+
expect(result).to.deep.equal({
|
|
74
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
it('executes command successfully with source filtering flag', async () => {
|
|
78
|
+
const expectedOutput = '2025-04-03T18:34:16Z app[web.1]: Server started on port 5000\n';
|
|
79
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LOGS)
|
|
80
|
+
.addFlags({
|
|
81
|
+
app: 'test-app',
|
|
82
|
+
source: 'app'
|
|
83
|
+
})
|
|
84
|
+
.build();
|
|
85
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
86
|
+
const result = await toolCallback({
|
|
87
|
+
app: 'test-app',
|
|
88
|
+
source: 'app'
|
|
89
|
+
}, {});
|
|
90
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
91
|
+
expect(result).to.deep.equal({
|
|
92
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
it('handles CLI errors properly', async () => {
|
|
96
|
+
const expectedOutput = '<<<BEGIN RESULTS>>>\n<<<ERROR>>>API error<<<END ERROR>>><<<END RESULTS>>>';
|
|
97
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
98
|
+
const result = await toolCallback({ app: 'test-app' }, {});
|
|
99
|
+
expect(result).to.deep.equal({
|
|
100
|
+
isError: true,
|
|
101
|
+
content: [
|
|
102
|
+
{
|
|
103
|
+
type: 'text',
|
|
104
|
+
text: '[Heroku MCP Server Error] Please use available tools to resolve this issue. ' +
|
|
105
|
+
'Ignore any Heroku CLI command suggestions that may be provided in the command output or error ' +
|
|
106
|
+
`details. Details:\n${expectedOutput}`
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
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 maintenance mode operations on a Heroku application.
|
|
7
|
+
* This schema defines the structure and validation rules for both enabling and disabling maintenance mode.
|
|
8
|
+
*/
|
|
9
|
+
export const maintenanceModeOptionsSchema = z.object({
|
|
10
|
+
app: z
|
|
11
|
+
.string()
|
|
12
|
+
.describe('The name of the Heroku app to modify maintenance mode for. This must be an existing app that you have access to.')
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Registers the maintenance_on tool with the MCP server.
|
|
16
|
+
* This tool enables maintenance mode for a specified Heroku application.
|
|
17
|
+
*
|
|
18
|
+
* @param server - The MCP server instance to register the tool with
|
|
19
|
+
* @param herokuRepl - The Heroku REPL instance for executing commands
|
|
20
|
+
*/
|
|
21
|
+
export const registerMaintenanceOnTool = (server, herokuRepl) => {
|
|
22
|
+
server.tool('maintenance_on', 'Enable maintenance mode for Heroku applications. Use this tool when you need to: ' +
|
|
23
|
+
'1) Redirect traffic to a maintenance page, 2) Prepare for system updates or deployments, ' +
|
|
24
|
+
'3) Schedule planned maintenance windows, 4) Gracefully handle service interruptions. ' +
|
|
25
|
+
'The tool manages traffic routing and process states while preserving running operations.', maintenanceModeOptionsSchema.shape, async (options) => {
|
|
26
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.MAINTENANCE_ON)
|
|
27
|
+
.addFlags({
|
|
28
|
+
app: options.app
|
|
29
|
+
})
|
|
30
|
+
.build();
|
|
31
|
+
const output = await herokuRepl.executeCommand(command);
|
|
32
|
+
return handleCliOutput(output);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Registers the maintenance_off tool with the MCP server.
|
|
37
|
+
* This tool disables maintenance mode for a specified Heroku application.
|
|
38
|
+
*
|
|
39
|
+
* @param server - The MCP server instance to register the tool with
|
|
40
|
+
* @param herokuRepl - The Heroku REPL instance for executing commands
|
|
41
|
+
*/
|
|
42
|
+
export const registerMaintenanceOffTool = (server, herokuRepl) => {
|
|
43
|
+
server.tool('maintenance_off', 'Disable maintenance mode for Heroku applications. Use this tool when you need to: ' +
|
|
44
|
+
'1) Restore normal application traffic routing, 2) Resume dyno operations after maintenance, ' +
|
|
45
|
+
'3) Complete deployment processes, 4) Verify application health after maintenance. ' +
|
|
46
|
+
'The tool handles service restoration and process resumption.', maintenanceModeOptionsSchema.shape, async (options) => {
|
|
47
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.MAINTENANCE_OFF)
|
|
48
|
+
.addFlags({
|
|
49
|
+
app: options.app
|
|
50
|
+
})
|
|
51
|
+
.build();
|
|
52
|
+
const output = await herokuRepl.executeCommand(command);
|
|
53
|
+
return handleCliOutput(output);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { HerokuREPL } from '../repl/heroku-cli-repl.js';
|
|
3
|
+
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
4
|
+
import { registerMaintenanceOnTool, registerMaintenanceOffTool } from './maintenance.js';
|
|
5
|
+
import { expect } from 'chai';
|
|
6
|
+
import sinon from 'sinon';
|
|
7
|
+
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
|
+
afterEach(() => {
|
|
20
|
+
sinon.restore();
|
|
21
|
+
});
|
|
22
|
+
describe('maintenance:on', () => {
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
registerMaintenanceOnTool(server, herokuRepl);
|
|
25
|
+
});
|
|
26
|
+
it('should register the tool with correct parameters', () => {
|
|
27
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
28
|
+
expect(server.tool.firstCall.args[0]).to.equal('maintenance_on');
|
|
29
|
+
expect(server.tool.firstCall.args[1]).to.be.a('string');
|
|
30
|
+
expect(server.tool.firstCall.args[2]).to.be.an('object');
|
|
31
|
+
expect(server.tool.firstCall.args[3]).to.be.a('function');
|
|
32
|
+
});
|
|
33
|
+
it('should build correct command with required parameters', async () => {
|
|
34
|
+
herokuRepl.executeCommand.resolves('Enabling maintenance mode for myapp... done\n');
|
|
35
|
+
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`);
|
|
38
|
+
});
|
|
39
|
+
it('should handle successful response', async () => {
|
|
40
|
+
const successResponse = 'Enabling maintenance mode for myapp... done\n';
|
|
41
|
+
herokuRepl.executeCommand.resolves(successResponse);
|
|
42
|
+
const result = await toolCallback({ app: 'myapp' });
|
|
43
|
+
expect(result).to.deep.equal({
|
|
44
|
+
content: [{ type: 'text', text: 'Enabling maintenance mode for myapp... done\n' }]
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
it('should handle error response', async () => {
|
|
48
|
+
const errorResponse = '<<<ERROR>>>\nError: App not found\n<<<END ERROR>>>\n';
|
|
49
|
+
herokuRepl.executeCommand.resolves(errorResponse);
|
|
50
|
+
const result = await toolCallback({ app: 'myapp' });
|
|
51
|
+
expect(result).to.deep.equal({
|
|
52
|
+
content: [
|
|
53
|
+
{
|
|
54
|
+
type: 'text',
|
|
55
|
+
text: '[Heroku MCP Server Error] Please use available tools to resolve this issue. Ignore any Heroku CLI command suggestions that may be provided in the command output or error details. Details:\n<<<ERROR>>>\nError: App not found\n<<<END ERROR>>>\n'
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
isError: true
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe('maintenance:off', () => {
|
|
63
|
+
beforeEach(() => {
|
|
64
|
+
registerMaintenanceOffTool(server, herokuRepl);
|
|
65
|
+
});
|
|
66
|
+
it('should register the tool with correct parameters', () => {
|
|
67
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
68
|
+
expect(server.tool.firstCall.args[0]).to.equal('maintenance_off');
|
|
69
|
+
expect(server.tool.firstCall.args[1]).to.be.a('string');
|
|
70
|
+
expect(server.tool.firstCall.args[2]).to.be.an('object');
|
|
71
|
+
expect(server.tool.firstCall.args[3]).to.be.a('function');
|
|
72
|
+
});
|
|
73
|
+
it('should build correct command with required parameters', async () => {
|
|
74
|
+
herokuRepl.executeCommand.resolves('Disabling maintenance mode for myapp... done\n');
|
|
75
|
+
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`);
|
|
78
|
+
});
|
|
79
|
+
it('should handle successful response', async () => {
|
|
80
|
+
const successResponse = 'Disabling maintenance mode for myapp... done\n';
|
|
81
|
+
herokuRepl.executeCommand.resolves(successResponse);
|
|
82
|
+
const result = await toolCallback({ app: 'myapp' });
|
|
83
|
+
expect(result).to.deep.equal({
|
|
84
|
+
content: [{ type: 'text', text: 'Disabling maintenance mode for myapp... done\n' }]
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it('should handle error response', async () => {
|
|
88
|
+
const errorResponse = '<<<ERROR>>>\nError: App not found\n<<<END ERROR>>>\n';
|
|
89
|
+
herokuRepl.executeCommand.resolves(errorResponse);
|
|
90
|
+
const result = await toolCallback({ app: 'myapp' });
|
|
91
|
+
expect(result).to.deep.equal({
|
|
92
|
+
content: [
|
|
93
|
+
{
|
|
94
|
+
type: 'text',
|
|
95
|
+
text: '[Heroku MCP Server Error] Please use available tools to resolve this issue. Ignore any Heroku CLI command suggestions that may be provided in the command output or error details. Details:\n<<<ERROR>>>\nError: App not found\n<<<END ERROR>>>\n'
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
isError: true
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
it('should handle undefined response', async () => {
|
|
102
|
+
herokuRepl.executeCommand.resolves(undefined);
|
|
103
|
+
const result = await toolCallback({ app: 'myapp' });
|
|
104
|
+
expect(result).to.deep.equal({
|
|
105
|
+
content: [
|
|
106
|
+
{
|
|
107
|
+
type: 'text',
|
|
108
|
+
text: '[Heroku MCP Server Error] Please use available tools to resolve this issue. Ignore any Heroku CLI command suggestions that may be provided in the command output or error details. Details:\nNo response from command'
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
isError: true
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
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 creating a new pipeline.
|
|
7
|
+
*/
|
|
8
|
+
export const pipelinesCreateOptionsSchema = z.object({
|
|
9
|
+
name: z.string().describe('Name of the pipeline to create'),
|
|
10
|
+
stage: z
|
|
11
|
+
.enum(['development', 'staging', 'production'])
|
|
12
|
+
.describe('Stage of first app in pipeline (e.g., production, staging, development)'),
|
|
13
|
+
app: z.string().optional().describe('Name of the app to add to the pipeline'),
|
|
14
|
+
team: z.string().optional().describe('Team to create the pipeline in')
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Schema for promoting apps through a pipeline.
|
|
18
|
+
*/
|
|
19
|
+
export const pipelinesPromoteOptionsSchema = z.object({
|
|
20
|
+
app: z.string().describe('Name of the app to promote from'),
|
|
21
|
+
to: z.string().optional().describe('comma separated list of apps to promote to')
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Schema for listing pipelines.
|
|
25
|
+
*/
|
|
26
|
+
export const pipelinesListOptionsSchema = z.object({
|
|
27
|
+
json: z.boolean().optional().describe('Output in json format')
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Schema for getting pipeline information.
|
|
31
|
+
*/
|
|
32
|
+
export const pipelinesInfoOptionsSchema = z.object({
|
|
33
|
+
pipeline: z.string().describe('Name of the pipeline to get info for'),
|
|
34
|
+
json: z.boolean().optional().describe('Output in json format')
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Schema for the base pipelines command.
|
|
38
|
+
*/
|
|
39
|
+
export const pipelinesOptionsSchema = z.object({
|
|
40
|
+
json: z.boolean().optional().describe('Output in json format')
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Registers the pipelines:create tool with the MCP server.
|
|
44
|
+
*
|
|
45
|
+
* @param server - The MCP server instance.
|
|
46
|
+
* @param herokuRepl - The Heroku REPL instance.
|
|
47
|
+
*/
|
|
48
|
+
export const registerPipelinesCreateTool = (server, herokuRepl) => {
|
|
49
|
+
server.tool('pipelines_create', 'Create new Heroku deployment pipelines. Use this tool when you need to: ' +
|
|
50
|
+
'1) Set up new deployment workflows, 2) Create staged application environments, ' +
|
|
51
|
+
'3) Organize apps by development stages, 4) Configure team-based pipeline structures. ' +
|
|
52
|
+
'The tool manages pipeline creation with optional team and initial app configuration.', pipelinesCreateOptionsSchema.shape, async (options) => {
|
|
53
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.PIPELINES_CREATE)
|
|
54
|
+
.addFlags({
|
|
55
|
+
stage: options.stage,
|
|
56
|
+
app: options.app,
|
|
57
|
+
team: options.team
|
|
58
|
+
})
|
|
59
|
+
.addPositionalArguments({ name: options.name })
|
|
60
|
+
.build();
|
|
61
|
+
const output = await herokuRepl.executeCommand(command);
|
|
62
|
+
return handleCliOutput(output);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Registers the pipelines:promote tool with the MCP server.
|
|
67
|
+
*
|
|
68
|
+
* @param server - The MCP server instance.
|
|
69
|
+
* @param herokuRepl - The Heroku REPL instance.
|
|
70
|
+
*/
|
|
71
|
+
export const registerPipelinesPromoteTool = (server, herokuRepl) => {
|
|
72
|
+
server.tool('pipelines_promote', 'Promote applications through pipeline stages. Use this tool when you need to: ' +
|
|
73
|
+
'1) Deploy code to staging or production environments, 2) Manage staged releases, ' +
|
|
74
|
+
'3) Coordinate multi-app promotions, 4) Control deployment workflows. ' +
|
|
75
|
+
'The tool handles safe promotion of apps between pipeline stages.', pipelinesPromoteOptionsSchema.shape, async (options) => {
|
|
76
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.PIPELINES_PROMOTE)
|
|
77
|
+
.addFlags({
|
|
78
|
+
app: options.app,
|
|
79
|
+
to: options.to
|
|
80
|
+
})
|
|
81
|
+
.build();
|
|
82
|
+
const output = await herokuRepl.executeCommand(command);
|
|
83
|
+
return handleCliOutput(output);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Registers the pipelines:list tool with the MCP server.
|
|
88
|
+
*
|
|
89
|
+
* @param server - The MCP server instance.
|
|
90
|
+
* @param herokuRepl - The Heroku REPL instance.
|
|
91
|
+
*/
|
|
92
|
+
export const registerPipelinesListTool = (server, herokuRepl) => {
|
|
93
|
+
server.tool('pipelines_list', 'View available Heroku pipelines. Use this tool when you need to: ' +
|
|
94
|
+
'1) List accessible pipelines, 2) Check pipeline ownership and access, ' +
|
|
95
|
+
'3) View pipeline organization, 4) Find specific pipeline configurations. ' +
|
|
96
|
+
'The tool provides pipeline visibility with optional JSON output format.', pipelinesListOptionsSchema.shape, async (options) => {
|
|
97
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.PIPELINES)
|
|
98
|
+
.addFlags({
|
|
99
|
+
json: options.json
|
|
100
|
+
})
|
|
101
|
+
.build();
|
|
102
|
+
const output = await herokuRepl.executeCommand(command);
|
|
103
|
+
return handleCliOutput(output);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Registers the pipelines:info tool with the MCP server.
|
|
108
|
+
*
|
|
109
|
+
* @param server - The MCP server instance.
|
|
110
|
+
* @param herokuRepl - The Heroku REPL instance.
|
|
111
|
+
*/
|
|
112
|
+
export const registerPipelinesInfoTool = (server, herokuRepl) => {
|
|
113
|
+
server.tool('pipelines_info', 'Display detailed pipeline configuration. Use this tool when you need to: ' +
|
|
114
|
+
'1) View pipeline stage configuration, 2) Check connected applications, ' +
|
|
115
|
+
'3) Verify pipeline settings, 4) Monitor pipeline status. ' +
|
|
116
|
+
'The tool provides comprehensive pipeline information and structure details.', pipelinesInfoOptionsSchema.shape, async (options) => {
|
|
117
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.PIPELINES_INFO)
|
|
118
|
+
.addFlags({
|
|
119
|
+
json: options.json
|
|
120
|
+
})
|
|
121
|
+
.addPositionalArguments({ pipeline: options.pipeline })
|
|
122
|
+
.build();
|
|
123
|
+
const output = await herokuRepl.executeCommand(command);
|
|
124
|
+
return handleCliOutput(output);
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Registers the base pipelines tool with the MCP server.
|
|
129
|
+
*
|
|
130
|
+
* @param server - The MCP server instance.
|
|
131
|
+
* @param herokuRepl - The Heroku REPL instance.
|
|
132
|
+
*/
|
|
133
|
+
export const registerPipelinesTool = (server, herokuRepl) => {
|
|
134
|
+
server.tool('pipelines', 'List and manage Heroku pipelines. Use this tool when you need to: ' +
|
|
135
|
+
'1) View all accessible pipelines, 2) Monitor pipeline configurations, ' +
|
|
136
|
+
'3) Check pipeline availability, 4) Review pipeline organization. ' +
|
|
137
|
+
'The tool provides high-level pipeline management and visibility.', pipelinesOptionsSchema.shape, async (options) => {
|
|
138
|
+
const command = new CommandBuilder('pipelines')
|
|
139
|
+
.addFlags({
|
|
140
|
+
json: options.json
|
|
141
|
+
})
|
|
142
|
+
.build();
|
|
143
|
+
const output = await herokuRepl.executeCommand(command);
|
|
144
|
+
return handleCliOutput(output);
|
|
145
|
+
});
|
|
146
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { HerokuREPL } from '../repl/heroku-cli-repl.js';
|
|
3
|
+
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
4
|
+
import { registerPipelinesCreateTool, registerPipelinesPromoteTool, registerPipelinesListTool, registerPipelinesInfoTool, registerPipelinesTool } from './pipelines.js';
|
|
5
|
+
import { expect } from 'chai';
|
|
6
|
+
import sinon from 'sinon';
|
|
7
|
+
describe('Pipeline 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
|
+
afterEach(() => {
|
|
20
|
+
sinon.restore();
|
|
21
|
+
});
|
|
22
|
+
describe('pipelines:create', () => {
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
registerPipelinesCreateTool(server, herokuRepl);
|
|
25
|
+
});
|
|
26
|
+
it('should register the tool with correct parameters', () => {
|
|
27
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
28
|
+
expect(server.tool.firstCall.args[0]).to.equal('pipelines_create');
|
|
29
|
+
expect(server.tool.firstCall.args[1]).to.be.a('string');
|
|
30
|
+
expect(server.tool.firstCall.args[2]).to.be.an('object');
|
|
31
|
+
expect(server.tool.firstCall.args[3]).to.be.a('function');
|
|
32
|
+
});
|
|
33
|
+
it('should build correct command with required parameters', async () => {
|
|
34
|
+
herokuRepl.executeCommand.resolves('Creating pipeline myapp-pipeline... done\n');
|
|
35
|
+
await toolCallback({ name: 'myapp-pipeline' });
|
|
36
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
37
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_CREATE} -- myapp-pipeline`);
|
|
38
|
+
});
|
|
39
|
+
it('should build correct command with all parameters', async () => {
|
|
40
|
+
herokuRepl.executeCommand.resolves('Creating pipeline myapp-pipeline... done\n');
|
|
41
|
+
await toolCallback({
|
|
42
|
+
name: 'myapp-pipeline',
|
|
43
|
+
stage: 'production',
|
|
44
|
+
app: 'myapp',
|
|
45
|
+
team: 'myteam'
|
|
46
|
+
});
|
|
47
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
48
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_CREATE} --stage=production --app=myapp --team=myteam -- myapp-pipeline`);
|
|
49
|
+
});
|
|
50
|
+
it('should handle error response', async () => {
|
|
51
|
+
const errorResponse = '<<<ERROR>>>\nError: Pipeline already exists\n<<<END ERROR>>>\n';
|
|
52
|
+
herokuRepl.executeCommand.resolves(errorResponse);
|
|
53
|
+
const result = await toolCallback({ name: 'myapp-pipeline' });
|
|
54
|
+
expect(result).to.deep.equal({
|
|
55
|
+
content: [
|
|
56
|
+
{
|
|
57
|
+
type: 'text',
|
|
58
|
+
text: '[Heroku MCP Server Error] Please use available tools to resolve this issue. Ignore any Heroku CLI command suggestions that may be provided in the command output or error details. Details:\n<<<ERROR>>>\nError: Pipeline already exists\n<<<END ERROR>>>\n'
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
isError: true
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe('pipelines:promote', () => {
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
registerPipelinesPromoteTool(server, herokuRepl);
|
|
68
|
+
});
|
|
69
|
+
it('should register the tool with correct parameters', () => {
|
|
70
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
71
|
+
expect(server.tool.firstCall.args[0]).to.equal('pipelines_promote');
|
|
72
|
+
expect(server.tool.firstCall.args[1]).to.be.a('string');
|
|
73
|
+
expect(server.tool.firstCall.args[2]).to.be.an('object');
|
|
74
|
+
expect(server.tool.firstCall.args[3]).to.be.a('function');
|
|
75
|
+
});
|
|
76
|
+
it('should build correct command with required parameters', async () => {
|
|
77
|
+
herokuRepl.executeCommand.resolves('Promoting myapp to production... done\n');
|
|
78
|
+
await toolCallback({ app: 'myapp' });
|
|
79
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
80
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_PROMOTE} --app=myapp`);
|
|
81
|
+
});
|
|
82
|
+
it('should build correct command with all parameters', async () => {
|
|
83
|
+
herokuRepl.executeCommand.resolves('Promoting myapp to production... done\n');
|
|
84
|
+
await toolCallback({
|
|
85
|
+
app: 'myapp',
|
|
86
|
+
to: 'production'
|
|
87
|
+
});
|
|
88
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
89
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_PROMOTE} --app=myapp --to=production`);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
describe('pipelines:list', () => {
|
|
93
|
+
beforeEach(() => {
|
|
94
|
+
registerPipelinesListTool(server, herokuRepl);
|
|
95
|
+
});
|
|
96
|
+
it('should register the tool with correct parameters', () => {
|
|
97
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
98
|
+
expect(server.tool.firstCall.args[0]).to.equal('pipelines_list');
|
|
99
|
+
expect(server.tool.firstCall.args[1]).to.be.a('string');
|
|
100
|
+
expect(server.tool.firstCall.args[2]).to.be.an('object');
|
|
101
|
+
expect(server.tool.firstCall.args[3]).to.be.a('function');
|
|
102
|
+
});
|
|
103
|
+
it('should build correct command with no parameters', async () => {
|
|
104
|
+
herokuRepl.executeCommand.resolves('=== My Pipelines\nmyapp-pipeline\n');
|
|
105
|
+
await toolCallback({});
|
|
106
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
107
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(TOOL_COMMAND_MAP.PIPELINES);
|
|
108
|
+
});
|
|
109
|
+
it('should build correct command with all parameters', async () => {
|
|
110
|
+
herokuRepl.executeCommand.resolves('=== My Pipelines\nmyapp-pipeline\n');
|
|
111
|
+
await toolCallback({
|
|
112
|
+
json: true,
|
|
113
|
+
team: 'myteam'
|
|
114
|
+
});
|
|
115
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
116
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES} --json`);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe('pipelines:info', () => {
|
|
120
|
+
beforeEach(() => {
|
|
121
|
+
registerPipelinesInfoTool(server, herokuRepl);
|
|
122
|
+
});
|
|
123
|
+
it('should register the tool with correct parameters', () => {
|
|
124
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
125
|
+
expect(server.tool.firstCall.args[0]).to.equal('pipelines_info');
|
|
126
|
+
expect(server.tool.firstCall.args[1]).to.be.a('string');
|
|
127
|
+
expect(server.tool.firstCall.args[2]).to.be.an('object');
|
|
128
|
+
expect(server.tool.firstCall.args[3]).to.be.a('function');
|
|
129
|
+
});
|
|
130
|
+
it('should build correct command with required parameters', async () => {
|
|
131
|
+
herokuRepl.executeCommand.resolves('=== myapp-pipeline\nStaging: myapp-staging\nProduction: myapp-prod\n');
|
|
132
|
+
await toolCallback({ pipeline: 'myapp-pipeline' });
|
|
133
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
134
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_INFO} -- myapp-pipeline`);
|
|
135
|
+
});
|
|
136
|
+
it('should build correct command with all parameters', async () => {
|
|
137
|
+
herokuRepl.executeCommand.resolves('{"pipeline": "myapp-pipeline", "apps": {...}}\n');
|
|
138
|
+
await toolCallback({
|
|
139
|
+
pipeline: 'myapp-pipeline',
|
|
140
|
+
json: true
|
|
141
|
+
});
|
|
142
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
143
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PIPELINES_INFO} --json -- myapp-pipeline`);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
describe('pipelines', () => {
|
|
147
|
+
beforeEach(() => {
|
|
148
|
+
registerPipelinesTool(server, herokuRepl);
|
|
149
|
+
});
|
|
150
|
+
it('should register the tool with correct parameters', () => {
|
|
151
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
152
|
+
expect(server.tool.firstCall.args[0]).to.equal('pipelines');
|
|
153
|
+
expect(server.tool.firstCall.args[1]).to.be.a('string');
|
|
154
|
+
expect(server.tool.firstCall.args[2]).to.be.an('object');
|
|
155
|
+
expect(server.tool.firstCall.args[3]).to.be.a('function');
|
|
156
|
+
});
|
|
157
|
+
it('should build correct command with no parameters', async () => {
|
|
158
|
+
herokuRepl.executeCommand.resolves('=== My Pipelines\nmyapp-pipeline\n');
|
|
159
|
+
await toolCallback({});
|
|
160
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
161
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal('pipelines');
|
|
162
|
+
});
|
|
163
|
+
it('should build correct command with json parameter', async () => {
|
|
164
|
+
herokuRepl.executeCommand.resolves('{"pipelines": [...]}\n');
|
|
165
|
+
await toolCallback({ json: true });
|
|
166
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
167
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal('pipelines --json');
|
|
168
|
+
});
|
|
169
|
+
it('should handle undefined response', async () => {
|
|
170
|
+
herokuRepl.executeCommand.resolves(undefined);
|
|
171
|
+
const result = await toolCallback({});
|
|
172
|
+
expect(result).to.deep.equal({
|
|
173
|
+
content: [
|
|
174
|
+
{
|
|
175
|
+
type: 'text',
|
|
176
|
+
text: '[Heroku MCP Server Error] Please use available tools to resolve this issue. Ignore any Heroku CLI command suggestions that may be provided in the command output or error details. Details:\nNo response from command'
|
|
177
|
+
}
|
|
178
|
+
],
|
|
179
|
+
isError: true
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|