@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
package/dist/tools/ps.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
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 processes.
|
|
7
|
+
*/
|
|
8
|
+
export const psListOptionsSchema = z.object({
|
|
9
|
+
app: z.string().describe('Name of the app to list processes for'),
|
|
10
|
+
json: z.boolean().optional().describe('Return process information in json format')
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Schema for scaling processes.
|
|
14
|
+
*/
|
|
15
|
+
export const psScaleOptionsSchema = z.object({
|
|
16
|
+
app: z.string().describe('Name of the app to scale'),
|
|
17
|
+
dyno: z
|
|
18
|
+
.string()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('The type and quantity of dynos to scale (e.g., web=3:Standard-2X, worker+1). Omit to display current formation.')
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Schema for restarting processes.
|
|
24
|
+
*/
|
|
25
|
+
export const psRestartOptionsSchema = z.object({
|
|
26
|
+
app: z.string().describe('Name of the app to restart processes for'),
|
|
27
|
+
'dyno-name': z
|
|
28
|
+
.string()
|
|
29
|
+
.optional()
|
|
30
|
+
.describe('Specific dyno to restart (e.g., web.1). If neither dyno-name nor process-type specified, restarts all dynos'),
|
|
31
|
+
'process-type': z
|
|
32
|
+
.string()
|
|
33
|
+
.optional()
|
|
34
|
+
.describe('Type of dynos to restart (e.g., web). If neither dyno-name nor process-type specified, restarts all dynos')
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Registers the ps tool with the MCP server.
|
|
38
|
+
*
|
|
39
|
+
* @param server - The MCP server instance.
|
|
40
|
+
* @param herokuRepl - The Heroku REPL instance.
|
|
41
|
+
*/
|
|
42
|
+
export const registerPsListTool = (server, herokuRepl) => {
|
|
43
|
+
server.tool('ps_list', 'List and monitor Heroku application dynos. Use this tool when you need to: ' +
|
|
44
|
+
'1) View all running dynos for an app, 2) Check dyno status and health, ' +
|
|
45
|
+
'3) Monitor application process states, 4) Verify dyno configurations. ' +
|
|
46
|
+
'The tool provides process visibility with optional JSON output format.', psListOptionsSchema.shape, async (options) => {
|
|
47
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.PS)
|
|
48
|
+
.addFlags({
|
|
49
|
+
app: options.app,
|
|
50
|
+
json: options.json
|
|
51
|
+
})
|
|
52
|
+
.build();
|
|
53
|
+
const output = await herokuRepl.executeCommand(command);
|
|
54
|
+
return handleCliOutput(output);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Registers the ps:scale tool with the MCP server.
|
|
59
|
+
*
|
|
60
|
+
* @param server - The MCP server instance.
|
|
61
|
+
* @param herokuRepl - The Heroku REPL instance.
|
|
62
|
+
*/
|
|
63
|
+
export const registerPsScaleTool = (server, herokuRepl) => {
|
|
64
|
+
server.tool('ps_scale', 'Scale and resize Heroku application dynos. Use this tool when you need to: ' +
|
|
65
|
+
'1) Adjust dyno quantities up or down, 2) Change dyno sizes for performance, ' +
|
|
66
|
+
'3) View current formation details, 4) Manage resource allocation. ' +
|
|
67
|
+
'The tool handles dyno scaling with support for type-specific adjustments.', psScaleOptionsSchema.shape, async (options) => {
|
|
68
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.PS_SCALE)
|
|
69
|
+
.addFlags({
|
|
70
|
+
app: options.app
|
|
71
|
+
})
|
|
72
|
+
.addPositionalArguments(options.dyno ? { dyno: options.dyno } : {})
|
|
73
|
+
.build();
|
|
74
|
+
const output = await herokuRepl.executeCommand(command);
|
|
75
|
+
return handleCliOutput(output);
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Registers the ps:restart tool with the MCP server.
|
|
80
|
+
*
|
|
81
|
+
* @param server - The MCP server instance.
|
|
82
|
+
* @param herokuRepl - The Heroku REPL instance.
|
|
83
|
+
*/
|
|
84
|
+
export const registerPsRestartTool = (server, herokuRepl) => {
|
|
85
|
+
server.tool('ps_restart', 'Restart Heroku application processes. Use this tool when you need to: ' +
|
|
86
|
+
'1) Restart specific dynos by name, 2) Restart all dynos of a process type, ' +
|
|
87
|
+
'3) Perform full application restarts, 4) Reset dyno states selectively. ' +
|
|
88
|
+
'The tool manages process restarts with flexible targeting options.', psRestartOptionsSchema.shape, async (options) => {
|
|
89
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.PS_RESTART)
|
|
90
|
+
.addFlags({
|
|
91
|
+
app: options.app,
|
|
92
|
+
'dyno-name': options['dyno-name'],
|
|
93
|
+
'process-type': options['process-type']
|
|
94
|
+
})
|
|
95
|
+
.build();
|
|
96
|
+
const output = await herokuRepl.executeCommand(command);
|
|
97
|
+
return handleCliOutput(output);
|
|
98
|
+
});
|
|
99
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
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 { registerPsListTool, registerPsScaleTool, registerPsRestartTool } from './ps.js';
|
|
5
|
+
import { expect } from 'chai';
|
|
6
|
+
import sinon from 'sinon';
|
|
7
|
+
describe('Process Management 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('ps:list', () => {
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
registerPsListTool(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('ps_list');
|
|
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('=== run: one-off processes\n=== web: web processes\nweb.1: up\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.PS} --app=myapp`);
|
|
38
|
+
});
|
|
39
|
+
it('should build correct command with all parameters', async () => {
|
|
40
|
+
herokuRepl.executeCommand.resolves('=== run: one-off processes\n=== web: web processes\nweb.1: up\n');
|
|
41
|
+
await toolCallback({
|
|
42
|
+
app: 'myapp',
|
|
43
|
+
json: true
|
|
44
|
+
});
|
|
45
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
46
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS} --app=myapp --json`);
|
|
47
|
+
});
|
|
48
|
+
it('should handle error response', async () => {
|
|
49
|
+
const errorResponse = '<<<ERROR>>>\nError: App not found\n<<<END ERROR>>>\n';
|
|
50
|
+
herokuRepl.executeCommand.resolves(errorResponse);
|
|
51
|
+
const result = await toolCallback({ app: 'myapp' });
|
|
52
|
+
expect(result).to.deep.equal({
|
|
53
|
+
content: [
|
|
54
|
+
{
|
|
55
|
+
type: 'text',
|
|
56
|
+
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'
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
isError: true
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe('ps:scale', () => {
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
registerPsScaleTool(server, herokuRepl);
|
|
66
|
+
});
|
|
67
|
+
it('should register the tool with correct parameters', () => {
|
|
68
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
69
|
+
expect(server.tool.firstCall.args[0]).to.equal('ps_scale');
|
|
70
|
+
expect(server.tool.firstCall.args[1]).to.be.a('string');
|
|
71
|
+
expect(server.tool.firstCall.args[2]).to.be.an('object');
|
|
72
|
+
expect(server.tool.firstCall.args[3]).to.be.a('function');
|
|
73
|
+
});
|
|
74
|
+
it('should build correct command with required parameters', async () => {
|
|
75
|
+
herokuRepl.executeCommand.resolves('Scaling dynos... done, now running web at 2:Standard-1X\n');
|
|
76
|
+
await toolCallback({ app: 'myapp', dyno: 'web=2' });
|
|
77
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
78
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_SCALE} --app=myapp -- web=2`);
|
|
79
|
+
});
|
|
80
|
+
it('should build correct command with remote parameter', async () => {
|
|
81
|
+
herokuRepl.executeCommand.resolves('Scaling dynos... done, now running web at 2:Standard-1X\n');
|
|
82
|
+
await toolCallback({
|
|
83
|
+
app: 'myapp',
|
|
84
|
+
dyno: 'web=2'
|
|
85
|
+
});
|
|
86
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
87
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_SCALE} --app=myapp -- web=2`);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
describe('ps:restart', () => {
|
|
91
|
+
beforeEach(() => {
|
|
92
|
+
registerPsRestartTool(server, herokuRepl);
|
|
93
|
+
});
|
|
94
|
+
it('should register the tool with correct parameters', () => {
|
|
95
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
96
|
+
expect(server.tool.firstCall.args[0]).to.equal('ps_restart');
|
|
97
|
+
expect(server.tool.firstCall.args[1]).to.be.a('string');
|
|
98
|
+
expect(server.tool.firstCall.args[2]).to.be.an('object');
|
|
99
|
+
expect(server.tool.firstCall.args[3]).to.be.a('function');
|
|
100
|
+
});
|
|
101
|
+
it('should build correct command with required parameters', async () => {
|
|
102
|
+
herokuRepl.executeCommand.resolves('Restarting all dynos... done\n');
|
|
103
|
+
await toolCallback({ app: 'myapp' });
|
|
104
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
105
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_RESTART} --app=myapp`);
|
|
106
|
+
});
|
|
107
|
+
it('should build correct command with specific dyno', async () => {
|
|
108
|
+
herokuRepl.executeCommand.resolves('Restarting web.1 dyno... done\n');
|
|
109
|
+
await toolCallback({
|
|
110
|
+
app: 'myapp',
|
|
111
|
+
'dyno-name': 'web.1'
|
|
112
|
+
});
|
|
113
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
114
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_RESTART} --app=myapp --dyno-name=web.1`);
|
|
115
|
+
});
|
|
116
|
+
it('should build correct command with all parameters', async () => {
|
|
117
|
+
herokuRepl.executeCommand.resolves('Restarting web dynos... done\n');
|
|
118
|
+
await toolCallback({
|
|
119
|
+
app: 'myapp',
|
|
120
|
+
'dyno-name': 'web.1',
|
|
121
|
+
'process-type': 'web'
|
|
122
|
+
});
|
|
123
|
+
expect(herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
124
|
+
expect(herokuRepl.executeCommand.firstCall.args[0]).to.equal(`${TOOL_COMMAND_MAP.PS_RESTART} --app=myapp --dyno-name=web.1 --process-type=web`);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
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 Private Spaces with output format options.
|
|
7
|
+
* This schema defines the structure and validation rules for the list private spaces operation.
|
|
8
|
+
*/
|
|
9
|
+
export const listPrivateSpacesOptionsSchema = z.object({
|
|
10
|
+
json: z
|
|
11
|
+
.boolean()
|
|
12
|
+
.optional()
|
|
13
|
+
.describe('Controls the output format. When true, returns a detailed JSON response containing private space metadata ' +
|
|
14
|
+
"such as generation's unsupported features, IPv4 and IPv6 CIDR blocks. When false or omitted, returns a " +
|
|
15
|
+
'simplified text format.')
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Registers the list_private_spaces tool with the MCP server.
|
|
19
|
+
* This tool provides information about available Heroku Private Spaces,
|
|
20
|
+
* including CIDR blocks, regions, and compliance features.
|
|
21
|
+
*
|
|
22
|
+
* @param server - The MCP server instance to register the tool with
|
|
23
|
+
* @param herokuRepl - The Heroku REPL instance for executing commands
|
|
24
|
+
*/
|
|
25
|
+
export const registerListPrivateSpacesTool = (server, herokuRepl) => {
|
|
26
|
+
server.tool('list_private_spaces', 'List Heroku Private Spaces available to the user. Use this tool when you need to: ' +
|
|
27
|
+
'1) View all private spaces, 2) Get space details like CIDR blocks and regions, ' +
|
|
28
|
+
'3) Check space compliance features, or 4) View space capacity information. ' +
|
|
29
|
+
'Supports JSON output for detailed metadata. Essential for enterprise space management.', listPrivateSpacesOptionsSchema.shape, async (options) => {
|
|
30
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.LIST_PRIVATE_SPACES).addFlags({ json: options.json }).build();
|
|
31
|
+
const output = await herokuRepl.executeCommand(command);
|
|
32
|
+
return handleCliOutput(output);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
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 { listPrivateSpacesOptionsSchema, registerListPrivateSpacesTool } from './spaces.js';
|
|
6
|
+
import { CommandBuilder } from '../utils/command-builder.js';
|
|
7
|
+
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
8
|
+
describe('spaces topic tools', () => {
|
|
9
|
+
describe('registerListPrivateSpacesTool', () => {
|
|
10
|
+
let server;
|
|
11
|
+
let herokuRepl;
|
|
12
|
+
let toolCallback;
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
server = sinon.createStubInstance(McpServer);
|
|
15
|
+
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
16
|
+
// Capture the callback function when tool is registered
|
|
17
|
+
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
18
|
+
toolCallback = callback;
|
|
19
|
+
return server;
|
|
20
|
+
});
|
|
21
|
+
registerListPrivateSpacesTool(server, herokuRepl);
|
|
22
|
+
});
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
sinon.restore();
|
|
25
|
+
});
|
|
26
|
+
it('registers the tool with correct name and schema', () => {
|
|
27
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
28
|
+
const call = server.tool.getCall(0);
|
|
29
|
+
expect(call.args[0]).to.equal('list_private_spaces');
|
|
30
|
+
expect(call.args[2]).to.deep.equal(listPrivateSpacesOptionsSchema.shape);
|
|
31
|
+
});
|
|
32
|
+
it('executes command successfully with json flag', async () => {
|
|
33
|
+
const expectedOutput = '{"spaces": []}';
|
|
34
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_PRIVATE_SPACES).addFlags({ json: true }).build();
|
|
35
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
36
|
+
const result = await toolCallback({ json: true }, {});
|
|
37
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
38
|
+
expect(result).to.deep.equal({
|
|
39
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
it('executes command successfully without json flag', async () => {
|
|
43
|
+
const expectedOutput = 'No spaces found';
|
|
44
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_PRIVATE_SPACES)
|
|
45
|
+
.addFlags({ json: false })
|
|
46
|
+
.build();
|
|
47
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
48
|
+
const result = await toolCallback({ json: false }, {});
|
|
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('handles CLI errors properly', async () => {
|
|
55
|
+
const expectedOutput = '<<<BEGIN RESULTS>>>\n<<<ERROR>>>API error<<<END ERROR>>><<<END RESULTS>>>';
|
|
56
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
57
|
+
const result = await toolCallback({}, {});
|
|
58
|
+
expect(result).to.deep.equal({
|
|
59
|
+
isError: true,
|
|
60
|
+
content: [
|
|
61
|
+
{
|
|
62
|
+
type: 'text',
|
|
63
|
+
text: '[Heroku MCP Server Error] Please use available tools to resolve this issue. ' +
|
|
64
|
+
'Ignore any Heroku CLI command suggestions that may be provided in the command output or error ' +
|
|
65
|
+
`details. Details:\n${expectedOutput}`
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
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 Teams with output format options.
|
|
7
|
+
* This schema defines the structure and validation rules for the list teams operation.
|
|
8
|
+
*
|
|
9
|
+
* [json] - Controls the output format. When true, returns a detailed JSON response containing
|
|
10
|
+
* team metadata such as enterprise account name. When false or omitted, returns a simplified text format.
|
|
11
|
+
*/
|
|
12
|
+
export const listTeamsOptionsSchema = z.object({
|
|
13
|
+
json: z
|
|
14
|
+
.boolean()
|
|
15
|
+
.optional()
|
|
16
|
+
.describe('Controls the output format. When true, returns a detailed JSON response containing team metadata such as ' +
|
|
17
|
+
'enterprise account name. When false or omitted, returns a simplified text format.')
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Registers the list_teams tool with the MCP server.
|
|
21
|
+
* This tool provides information about accessible Heroku Teams,
|
|
22
|
+
* including membership details and enterprise relationships.
|
|
23
|
+
*
|
|
24
|
+
* @param server - The MCP server instance to register the tool with
|
|
25
|
+
* @param herokuRepl - The Heroku REPL instance for executing commands
|
|
26
|
+
*/
|
|
27
|
+
export const registerListTeamsTool = (server, herokuRepl) => {
|
|
28
|
+
server.tool('list_teams', 'List Heroku Teams the user belongs to. Use this tool when you need to: ' +
|
|
29
|
+
'1) View all accessible teams, 2) Check team membership, ' +
|
|
30
|
+
'3) Get team metadata and enterprise relationships, or ' +
|
|
31
|
+
'4) Verify team access for app operations. ' +
|
|
32
|
+
'Supports JSON output for detailed team information.', listTeamsOptionsSchema.shape, async (options) => {
|
|
33
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.LIST_TEAMS).addFlags({ json: options.json }).build();
|
|
34
|
+
const output = await herokuRepl.executeCommand(command);
|
|
35
|
+
return handleCliOutput(output);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
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 { listTeamsOptionsSchema, registerListTeamsTool } from './teams.js';
|
|
6
|
+
import { CommandBuilder } from '../utils/command-builder.js';
|
|
7
|
+
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
8
|
+
describe('teams', () => {
|
|
9
|
+
describe('registerListTeamsTool', () => {
|
|
10
|
+
let server;
|
|
11
|
+
let herokuRepl;
|
|
12
|
+
let toolCallback;
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
server = sinon.createStubInstance(McpServer);
|
|
15
|
+
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
16
|
+
// Capture the callback function when tool is registered
|
|
17
|
+
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
18
|
+
toolCallback = callback;
|
|
19
|
+
return server;
|
|
20
|
+
});
|
|
21
|
+
registerListTeamsTool(server, herokuRepl);
|
|
22
|
+
});
|
|
23
|
+
afterEach(() => {
|
|
24
|
+
sinon.restore();
|
|
25
|
+
});
|
|
26
|
+
it('registers the tool with correct name and schema', () => {
|
|
27
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
28
|
+
const call = server.tool.getCall(0);
|
|
29
|
+
expect(call.args[0]).to.equal('list_teams');
|
|
30
|
+
expect(call.args[2]).to.deep.equal(listTeamsOptionsSchema.shape);
|
|
31
|
+
});
|
|
32
|
+
it('executes command successfully with json flag', async () => {
|
|
33
|
+
const expectedOutput = '[{"name": "test-team", "role": "collaborator"}]';
|
|
34
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_TEAMS).addFlags({ json: true }).build();
|
|
35
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
36
|
+
const result = await toolCallback({ json: true }, {});
|
|
37
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
38
|
+
expect(result).to.deep.equal({
|
|
39
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
it('executes command successfully without json flag', async () => {
|
|
43
|
+
const expectedOutput = ' Team Role \n' + ' ───────── ──────────── \n' + ' test-team collaborator \n';
|
|
44
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_TEAMS).addFlags({ json: false }).build();
|
|
45
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
46
|
+
const result = await toolCallback({ json: false }, {});
|
|
47
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
48
|
+
expect(result).to.deep.equal({
|
|
49
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
it('handles CLI errors properly', async () => {
|
|
53
|
+
const expectedOutput = '<<<BEGIN RESULTS>>>\n<<<ERROR>>>API error<<<END ERROR>>><<<END RESULTS>>>';
|
|
54
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
55
|
+
const result = await toolCallback({}, {});
|
|
56
|
+
expect(result).to.deep.equal({
|
|
57
|
+
isError: true,
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: 'text',
|
|
61
|
+
text: '[Heroku MCP Server Error] Please use available tools to resolve this issue. ' +
|
|
62
|
+
'Ignore any Heroku CLI command suggestions that may be provided in the command output or error ' +
|
|
63
|
+
`details. Details:\n${expectedOutput}`
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "Heroku app.json Schema",
|
|
4
|
+
"description": "app.json is a manifest format for describing web apps. It declares environment variables, add-ons, and other information required to run an app on Heroku. Used for dynamic configurations or converted projects",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"pattern": "^[a-zA-Z-_\\.]+",
|
|
10
|
+
"maxLength": 300
|
|
11
|
+
},
|
|
12
|
+
"description": {
|
|
13
|
+
"type": "string"
|
|
14
|
+
},
|
|
15
|
+
"keywords": {
|
|
16
|
+
"type": "array",
|
|
17
|
+
"items": {
|
|
18
|
+
"type": "string"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"website": {
|
|
22
|
+
"$ref": "#/definitions/uriString"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"$ref": "#/definitions/uriString"
|
|
26
|
+
},
|
|
27
|
+
"logo": {
|
|
28
|
+
"$ref": "#/definitions/uriString"
|
|
29
|
+
},
|
|
30
|
+
"success_url": {
|
|
31
|
+
"type": "string"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"$ref": "#/definitions/scripts"
|
|
35
|
+
},
|
|
36
|
+
"env": {
|
|
37
|
+
"$ref": "#/definitions/env"
|
|
38
|
+
},
|
|
39
|
+
"formation": {
|
|
40
|
+
"$ref": "#/definitions/formation"
|
|
41
|
+
},
|
|
42
|
+
"addons": {
|
|
43
|
+
"$ref": "#/definitions/addons"
|
|
44
|
+
},
|
|
45
|
+
"buildpacks": {
|
|
46
|
+
"$ref": "#/definitions/buildpacks"
|
|
47
|
+
},
|
|
48
|
+
"environments": {
|
|
49
|
+
"$ref": "#/definitions/environments"
|
|
50
|
+
},
|
|
51
|
+
"stack": {
|
|
52
|
+
"$ref": "#/definitions/stack"
|
|
53
|
+
},
|
|
54
|
+
"image": {
|
|
55
|
+
"type": "string"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"additionalProperties": false,
|
|
59
|
+
"definitions": {
|
|
60
|
+
"uriString": {
|
|
61
|
+
"type": "string",
|
|
62
|
+
"format": "uri"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"type": "object",
|
|
66
|
+
"properties": {
|
|
67
|
+
"postdeploy": {
|
|
68
|
+
"type": "string"
|
|
69
|
+
},
|
|
70
|
+
"pr-predestroy": {
|
|
71
|
+
"type": "string"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"additionalProperties": false
|
|
75
|
+
},
|
|
76
|
+
"env": {
|
|
77
|
+
"type": "object",
|
|
78
|
+
"patternProperties": {
|
|
79
|
+
"^[A-Z][A-Z0-9_]*$": {
|
|
80
|
+
"type": "object",
|
|
81
|
+
"properties": {
|
|
82
|
+
"description": {
|
|
83
|
+
"type": "string"
|
|
84
|
+
},
|
|
85
|
+
"value": {
|
|
86
|
+
"type": "string"
|
|
87
|
+
},
|
|
88
|
+
"required": {
|
|
89
|
+
"type": "boolean"
|
|
90
|
+
},
|
|
91
|
+
"generator": {
|
|
92
|
+
"type": "string",
|
|
93
|
+
"enum": ["secret"]
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"additionalProperties": false
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"dynoSize": {
|
|
101
|
+
"type": "string",
|
|
102
|
+
"enum": [
|
|
103
|
+
"free",
|
|
104
|
+
"eco",
|
|
105
|
+
"hobby",
|
|
106
|
+
"basic",
|
|
107
|
+
"standard-1x",
|
|
108
|
+
"standard-2x",
|
|
109
|
+
"performance-m",
|
|
110
|
+
"performance-l",
|
|
111
|
+
"private-s",
|
|
112
|
+
"private-m",
|
|
113
|
+
"private-l",
|
|
114
|
+
"shield-s",
|
|
115
|
+
"shield-m",
|
|
116
|
+
"shield-l"
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
"formation": {
|
|
120
|
+
"type": "object",
|
|
121
|
+
"patternProperties": {
|
|
122
|
+
"^[a-zA-Z0-9_-]+$": {
|
|
123
|
+
"type": "object",
|
|
124
|
+
"properties": {
|
|
125
|
+
"quantity": {
|
|
126
|
+
"type": "integer",
|
|
127
|
+
"minimum": 0
|
|
128
|
+
},
|
|
129
|
+
"size": {
|
|
130
|
+
"$ref": "#/definitions/dynoSize"
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
"required": ["quantity"],
|
|
134
|
+
"additionalProperties": false
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
"addons": {
|
|
139
|
+
"type": "array",
|
|
140
|
+
"items": {
|
|
141
|
+
"oneOf": [
|
|
142
|
+
{
|
|
143
|
+
"type": "string"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"type": "object",
|
|
147
|
+
"properties": {
|
|
148
|
+
"plan": {
|
|
149
|
+
"type": "string"
|
|
150
|
+
},
|
|
151
|
+
"as": {
|
|
152
|
+
"type": "string"
|
|
153
|
+
},
|
|
154
|
+
"options": {
|
|
155
|
+
"type": "object"
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
"required": ["plan"],
|
|
159
|
+
"additionalProperties": false
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
"buildpacks": {
|
|
165
|
+
"type": "array",
|
|
166
|
+
"items": {
|
|
167
|
+
"type": "object",
|
|
168
|
+
"properties": {
|
|
169
|
+
"url": {
|
|
170
|
+
"type": "string"
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
"required": ["url"],
|
|
174
|
+
"additionalProperties": false
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
"environmentConfig": {
|
|
178
|
+
"type": "object",
|
|
179
|
+
"properties": {
|
|
180
|
+
"env": {
|
|
181
|
+
"type": "object"
|
|
182
|
+
},
|
|
183
|
+
"formation": {
|
|
184
|
+
"type": "object"
|
|
185
|
+
},
|
|
186
|
+
"addons": {
|
|
187
|
+
"type": "array"
|
|
188
|
+
},
|
|
189
|
+
"buildpacks": {
|
|
190
|
+
"type": "array"
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
"environments": {
|
|
195
|
+
"type": "object",
|
|
196
|
+
"properties": {
|
|
197
|
+
"test": {
|
|
198
|
+
"allOf": [
|
|
199
|
+
{
|
|
200
|
+
"$ref": "#/definitions/environmentConfig"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"type": "object",
|
|
204
|
+
"properties": {
|
|
205
|
+
"scripts": {
|
|
206
|
+
"type": "object",
|
|
207
|
+
"properties": {
|
|
208
|
+
"test": {
|
|
209
|
+
"type": "string"
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
"additionalProperties": false
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
"review": {
|
|
219
|
+
"$ref": "#/definitions/environmentConfig"
|
|
220
|
+
},
|
|
221
|
+
"production": {
|
|
222
|
+
"$ref": "#/definitions/environmentConfig"
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
"additionalProperties": false
|
|
226
|
+
},
|
|
227
|
+
"stack": {
|
|
228
|
+
"type": "string",
|
|
229
|
+
"enum": ["heroku-18", "heroku-20", "heroku-22", "heroku-24"]
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|