@heroku/mcp-server 1.2.4 → 1.2.6
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/dist/index.js +2 -2
- package/dist/repl/heroku-cli-repl.spec.js +31 -0
- package/dist/resources/dev-center-resource.spec.js +1 -1
- package/dist/tools/apps.spec.js +51 -0
- package/dist/tools/data.spec.js +50 -0
- package/dist/utils/command-builder.js +31 -3
- package/dist/utils/command-builder.spec.js +34 -0
- package/dist/utils/mcp-tool-mocks.spechelper.js +1 -1
- package/package.json +1 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp
|
|
3
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio';
|
|
4
4
|
import * as pjson from '../package.json' with { type: 'json' };
|
|
5
5
|
import * as apps from './tools/apps.js';
|
|
6
6
|
import * as spaces from './tools/spaces.js';
|
|
@@ -76,6 +76,37 @@ describe('HerokuREPL', () => {
|
|
|
76
76
|
expect(result).to.include('The command failed to complete in 500ms');
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
|
+
describe('stdin protocol', () => {
|
|
80
|
+
// This test locks in the exact bytes written to the CLI process stdin.
|
|
81
|
+
// Commands are newline-delimited on stdin, so the REPL appends a single
|
|
82
|
+
// trailing '\n' to signal "end of command". This is why a command string
|
|
83
|
+
// must itself be a single line: the CLI treats everything after an embedded
|
|
84
|
+
// newline as a separate command. The CommandBuilder CR/LF validation
|
|
85
|
+
// upstream enforces that; this test documents the exact-bytes behavior it
|
|
86
|
+
// relies on.
|
|
87
|
+
it('should write exactly command + a single trailing newline to stdin', async () => {
|
|
88
|
+
const command = 'apps';
|
|
89
|
+
// Deterministically resolve the moment the async iterator writes to
|
|
90
|
+
// stdin, rather than waiting a fixed duration.
|
|
91
|
+
let onWrite;
|
|
92
|
+
const written = new Promise((resolve) => {
|
|
93
|
+
onWrite = resolve;
|
|
94
|
+
});
|
|
95
|
+
mockProcess.stdin.write.callsFake(() => {
|
|
96
|
+
onWrite();
|
|
97
|
+
return true;
|
|
98
|
+
});
|
|
99
|
+
const commandPromise = repl.executeCommand(command);
|
|
100
|
+
// Proceed as soon as the write actually happens.
|
|
101
|
+
await written;
|
|
102
|
+
expect(mockProcess.stdin.write.calledOnce).to.be.true;
|
|
103
|
+
const writtenValue = mockProcess.stdin.write.firstCall.args[0];
|
|
104
|
+
expect(writtenValue).to.equal(command + '\n');
|
|
105
|
+
// Clean up the outstanding command promise.
|
|
106
|
+
setTimeout(() => mockProcess.stdout.emit('data', 'Command output\n<<<END RESULTS>>>'));
|
|
107
|
+
await commandPromise;
|
|
108
|
+
});
|
|
109
|
+
});
|
|
79
110
|
describe('process management', () => {
|
|
80
111
|
it('should restart process on unexpected close', () => {
|
|
81
112
|
mockProcess.emit('close', 1);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
import sinon from 'sinon';
|
|
3
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
|
|
4
4
|
import { registerDevCenterResource } from './dev-center-resource.js';
|
|
5
5
|
describe('registerDevCenterResource', () => {
|
|
6
6
|
let server;
|
package/dist/tools/apps.spec.js
CHANGED
|
@@ -255,4 +255,55 @@ describe('apps topic tools', () => {
|
|
|
255
255
|
}
|
|
256
256
|
});
|
|
257
257
|
});
|
|
258
|
+
// Input validation: a multi-line value routed through a real tool handler must be
|
|
259
|
+
// rejected by CommandBuilder before it can reach the Heroku REPL.
|
|
260
|
+
describe('input validation', () => {
|
|
261
|
+
let mocks;
|
|
262
|
+
beforeEach(() => {
|
|
263
|
+
mocks = setupMcpToolMocks();
|
|
264
|
+
});
|
|
265
|
+
afterEach(() => {
|
|
266
|
+
sinon.restore();
|
|
267
|
+
});
|
|
268
|
+
it('rejects a multi-line team flag on list_apps without executing it', async () => {
|
|
269
|
+
const multiLineTeam = 'my-team\nsecond-line';
|
|
270
|
+
registerListAppsTool(mocks.server, mocks.herokuRepl);
|
|
271
|
+
const toolCallback = mocks.getToolCallback();
|
|
272
|
+
let error;
|
|
273
|
+
try {
|
|
274
|
+
await toolCallback({ team: multiLineTeam }, {});
|
|
275
|
+
}
|
|
276
|
+
catch (caught) {
|
|
277
|
+
error = caught;
|
|
278
|
+
}
|
|
279
|
+
// The invalid value must be surfaced as an error...
|
|
280
|
+
expect(error).to.be.an('Error');
|
|
281
|
+
// ...and must never reach the REPL.
|
|
282
|
+
expect(mocks.herokuRepl.executeCommand.called).to.be.false;
|
|
283
|
+
const executedWithLineBreak = mocks.herokuRepl.executeCommand
|
|
284
|
+
.getCalls()
|
|
285
|
+
.some((call) => typeof call.args[0] === 'string' && call.args[0].includes('\n'));
|
|
286
|
+
expect(executedWithLineBreak).to.be.false;
|
|
287
|
+
});
|
|
288
|
+
it('rejects a multi-line newName argument on rename_app without executing it', async () => {
|
|
289
|
+
const multiLineNewName = 'renamed-app\nsecond-line';
|
|
290
|
+
registerRenameAppTool(mocks.server, mocks.herokuRepl);
|
|
291
|
+
const toolCallback = mocks.getToolCallback();
|
|
292
|
+
let error;
|
|
293
|
+
try {
|
|
294
|
+
await toolCallback({ app: 'test-app', newName: multiLineNewName }, {});
|
|
295
|
+
}
|
|
296
|
+
catch (caught) {
|
|
297
|
+
error = caught;
|
|
298
|
+
}
|
|
299
|
+
// The invalid value must be surfaced as an error...
|
|
300
|
+
expect(error).to.be.an('Error');
|
|
301
|
+
// ...and must never reach the REPL.
|
|
302
|
+
expect(mocks.herokuRepl.executeCommand.called).to.be.false;
|
|
303
|
+
const executedWithLineBreak = mocks.herokuRepl.executeCommand
|
|
304
|
+
.getCalls()
|
|
305
|
+
.some((call) => typeof call.args[0] === 'string' && call.args[0].includes('\n'));
|
|
306
|
+
expect(executedWithLineBreak).to.be.false;
|
|
307
|
+
});
|
|
308
|
+
});
|
|
258
309
|
});
|
package/dist/tools/data.spec.js
CHANGED
|
@@ -55,6 +55,56 @@ describe('PostgreSQL Tools', () => {
|
|
|
55
55
|
isError: true
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// CHARACTERIZATION TESTS: newline handling in the `command` value.
|
|
60
|
+
//
|
|
61
|
+
// These tests document the CURRENT (and intentionally inconsistent) behavior
|
|
62
|
+
// of pg:psql. Unlike every other tool -- which relies on CommandBuilder's
|
|
63
|
+
// CR/LF validation to REJECT any value containing a line break -- pg:psql
|
|
64
|
+
// pre-processes its `command` value with `replaceAll('\n', ' ')` in data.ts
|
|
65
|
+
// BEFORE it reaches CommandBuilder (see the `command:` flag in
|
|
66
|
+
// registerPgPsqlTool). As a result:
|
|
67
|
+
// * a line feed (\n) is SILENTLY REWRITTEN to a space (strip, not reject),
|
|
68
|
+
// * but a carriage return (\r) is NOT touched by that replace and still
|
|
69
|
+
// reaches CommandBuilder's validation.
|
|
70
|
+
//
|
|
71
|
+
// If pg:psql is ever unified with the reject-everywhere validation (i.e. the
|
|
72
|
+
// `replaceAll('\n', ' ')` is removed so LF is rejected like everywhere else),
|
|
73
|
+
// these tests will intentionally break -- signalling that the documented
|
|
74
|
+
// behavior changed on purpose.
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
it('CHARACTERIZATION: strips (does not reject) a LF in command, replacing it with a space', async () => {
|
|
77
|
+
mocks.herokuRepl.executeCommand.resolves('Query executed successfully\n');
|
|
78
|
+
// Multi-line SQL: the LF between the two statements should be converted to a space.
|
|
79
|
+
await toolCallback({ app: 'myapp', command: 'SELECT 1;\nSELECT 2;' });
|
|
80
|
+
expect(mocks.herokuRepl.executeCommand.calledOnce).to.be.true;
|
|
81
|
+
const builtCommand = mocks.herokuRepl.executeCommand.firstCall.args[0];
|
|
82
|
+
// The newline was replaced by a space BEFORE reaching CommandBuilder, so the
|
|
83
|
+
// command is NOT rejected and the built command contains the space-joined SQL.
|
|
84
|
+
expect(builtCommand).to.equal(`${TOOL_COMMAND_MAP.PG_PSQL} --app=myapp --command="SELECT 1; SELECT 2;"`);
|
|
85
|
+
// Confirm no raw LF survived in the command sent to the CLI.
|
|
86
|
+
expect(builtCommand).to.not.include('\n');
|
|
87
|
+
});
|
|
88
|
+
// OBSERVED BEHAVIOR (verified by running this spec): a carriage return (\r) in
|
|
89
|
+
// `command` is NOT stripped by `replaceAll('\n', ' ')`, so it reaches
|
|
90
|
+
// CommandBuilder's CR/LF validation and is REJECTED -- the tool callback REJECTS
|
|
91
|
+
// (throws) and executeCommand is never called. This differs from the LF case
|
|
92
|
+
// above, which is silently stripped.
|
|
93
|
+
it('CHARACTERIZATION: rejects a CR in command (not stripped) via CommandBuilder validation', async () => {
|
|
94
|
+
mocks.herokuRepl.executeCommand.resolves('Query executed successfully\n');
|
|
95
|
+
let thrownError;
|
|
96
|
+
try {
|
|
97
|
+
await toolCallback({ app: 'myapp', command: 'SELECT 1;\rSELECT 2;' });
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
thrownError = error;
|
|
101
|
+
}
|
|
102
|
+
// The \r is not touched by replaceAll('\n', ' '), so CommandBuilder rejects it.
|
|
103
|
+
expect(thrownError, 'expected the tool callback to throw for a CR in command').to.be.an('error');
|
|
104
|
+
expect(thrownError?.message).to.include('line breaks (CR/LF) are not allowed');
|
|
105
|
+
// Because building the command threw, the command was never executed.
|
|
106
|
+
expect(mocks.herokuRepl.executeCommand.called).to.be.false;
|
|
107
|
+
});
|
|
58
108
|
});
|
|
59
109
|
describe('pg:info', () => {
|
|
60
110
|
let mocks;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Characters that are not permitted in a flag value or positional argument.
|
|
3
|
+
*
|
|
4
|
+
* Each built command is delivered to the Heroku CLI as a single line — the REPL
|
|
5
|
+
* writes `command + '\n'` to the CLI process's stdin (see `HerokuREPL`). Because
|
|
6
|
+
* commands are line-delimited, a value that spans multiple lines would not be
|
|
7
|
+
* handled as a single, self-contained value. There is no legitimate reason for a
|
|
8
|
+
* flag value or positional argument to contain a line break, so we apply strict
|
|
9
|
+
* input validation and reject them.
|
|
10
|
+
*/
|
|
11
|
+
const LINE_BREAK_PATTERN = /[\r\n]/;
|
|
1
12
|
/**
|
|
2
13
|
* A builder class for constructing Heroku CLI commands with flags and positional arguments.
|
|
3
14
|
* This class provides a fluent interface for building command-line arguments in a structured way.
|
|
@@ -14,6 +25,19 @@ export class CommandBuilder {
|
|
|
14
25
|
constructor(baseCommand) {
|
|
15
26
|
this.baseCommand = baseCommand;
|
|
16
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Validates that a value is a single line, as required for a well-formed command.
|
|
30
|
+
*
|
|
31
|
+
* @param kind - Whether the value is a flag value or a positional argument (for the error message).
|
|
32
|
+
* @param name - The flag/argument name the value is associated with (for the error message).
|
|
33
|
+
* @param value - The value to validate.
|
|
34
|
+
* @throws {Error} If the value contains a carriage return or line feed.
|
|
35
|
+
*/
|
|
36
|
+
static assertNoLineBreaks(kind, name, value) {
|
|
37
|
+
if (LINE_BREAK_PATTERN.test(value)) {
|
|
38
|
+
throw new Error(`Invalid ${kind} value for "${name}": line breaks (CR/LF) are not allowed. Commands are sent one per line to the Heroku CLI, so a value must be contained on a single line.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
17
41
|
/**
|
|
18
42
|
* Adds command-line flags to the command.
|
|
19
43
|
*
|
|
@@ -26,8 +50,10 @@ export class CommandBuilder {
|
|
|
26
50
|
if (value) {
|
|
27
51
|
if (typeof value === 'boolean')
|
|
28
52
|
this.flags.push(`--${flag}`);
|
|
29
|
-
else
|
|
53
|
+
else {
|
|
54
|
+
CommandBuilder.assertNoLineBreaks('flag', flag, value);
|
|
30
55
|
this.flags.push(`--${flag}=${value}`);
|
|
56
|
+
}
|
|
31
57
|
}
|
|
32
58
|
}
|
|
33
59
|
return this;
|
|
@@ -39,9 +65,11 @@ export class CommandBuilder {
|
|
|
39
65
|
* @returns The builder instance for method chaining
|
|
40
66
|
*/
|
|
41
67
|
addPositionalArguments(args) {
|
|
42
|
-
for (const [, value] of Object.entries(args)) {
|
|
43
|
-
if (value)
|
|
68
|
+
for (const [name, value] of Object.entries(args)) {
|
|
69
|
+
if (value) {
|
|
70
|
+
CommandBuilder.assertNoLineBreaks('argument', name, value);
|
|
44
71
|
this.args.push(value);
|
|
72
|
+
}
|
|
45
73
|
}
|
|
46
74
|
return this;
|
|
47
75
|
}
|
|
@@ -43,6 +43,19 @@ describe('CommandBuilder', () => {
|
|
|
43
43
|
const result = builder.addFlags({ all: true });
|
|
44
44
|
expect(result).to.equal(builder);
|
|
45
45
|
});
|
|
46
|
+
it('rejects flag values containing line breaks', () => {
|
|
47
|
+
const builder = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS);
|
|
48
|
+
expect(() => builder.addFlags({ team: 'my-team\nsecond-line' })).to.throw(/line breaks \(CR\/LF\) are not allowed/);
|
|
49
|
+
expect(() => builder.addFlags({ team: 'my-team\rother' })).to.throw(/line breaks/);
|
|
50
|
+
});
|
|
51
|
+
it('still allows flag values that contain spaces (only line breaks are rejected)', () => {
|
|
52
|
+
const builder = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS);
|
|
53
|
+
expect(() => builder.addFlags({ team: 'my team' })).to.not.throw();
|
|
54
|
+
});
|
|
55
|
+
it('names the offending flag and the "flag" kind in the error message', () => {
|
|
56
|
+
const builder = new CommandBuilder(TOOL_COMMAND_MAP.LIST_APPS);
|
|
57
|
+
expect(() => builder.addFlags({ team: 'my-team\nsecond-line' })).to.throw(/Invalid flag value for "team"/);
|
|
58
|
+
});
|
|
46
59
|
});
|
|
47
60
|
describe('addPositionalArguments', () => {
|
|
48
61
|
it('adds positional arguments correctly', () => {
|
|
@@ -65,6 +78,14 @@ describe('CommandBuilder', () => {
|
|
|
65
78
|
const result = builder.addPositionalArguments({ new_name: 'new-app-name' });
|
|
66
79
|
expect(result).to.equal(builder);
|
|
67
80
|
});
|
|
81
|
+
it('rejects positional argument values containing line breaks', () => {
|
|
82
|
+
const builder = new CommandBuilder(TOOL_COMMAND_MAP.RENAME_APP);
|
|
83
|
+
expect(() => builder.addPositionalArguments({ new_name: 'ok\nsecond-line' })).to.throw(/line breaks \(CR\/LF\) are not allowed/);
|
|
84
|
+
});
|
|
85
|
+
it('names the offending argument and the "argument" kind in the error message', () => {
|
|
86
|
+
const builder = new CommandBuilder(TOOL_COMMAND_MAP.RENAME_APP);
|
|
87
|
+
expect(() => builder.addPositionalArguments({ new_name: 'ok\nsecond-line' })).to.throw(/Invalid argument value for "new_name"/);
|
|
88
|
+
});
|
|
68
89
|
});
|
|
69
90
|
describe('build', () => {
|
|
70
91
|
it('combines flags and positional arguments correctly', () => {
|
|
@@ -91,5 +112,18 @@ describe('CommandBuilder', () => {
|
|
|
91
112
|
builder.addFlags({ region: 'eu' }).addPositionalArguments({ app: 'my-app' }).addFlags({ team: 'my-team' });
|
|
92
113
|
expect(builder.build()).to.equal('apps:create --region=eu --team=my-team -- my-app');
|
|
93
114
|
});
|
|
115
|
+
it('can never emit a command containing carriage returns or line feeds', () => {
|
|
116
|
+
// Validation rejects CR/LF at add-time, so a value with a line break is never
|
|
117
|
+
// stored and the build output is always free of them. This test depends on that
|
|
118
|
+
// validation: it asserts the invalid add throws AND that the command built from
|
|
119
|
+
// the remaining valid values contains no CR/LF.
|
|
120
|
+
const builder = new CommandBuilder(TOOL_COMMAND_MAP.CREATE_APP);
|
|
121
|
+
builder.addFlags({ region: 'eu' });
|
|
122
|
+
expect(() => builder.addFlags({ team: 'my-team\nsecond-line' })).to.throw(/line breaks \(CR\/LF\) are not allowed/);
|
|
123
|
+
expect(() => builder.addPositionalArguments({ app: 'my-app\rsecond-line' })).to.throw(/line breaks \(CR\/LF\) are not allowed/);
|
|
124
|
+
const command = builder.build();
|
|
125
|
+
expect(command).to.not.match(/[\r\n]/);
|
|
126
|
+
expect(command).to.equal('apps:create --region=eu');
|
|
127
|
+
});
|
|
94
128
|
});
|
|
95
129
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import sinon from 'sinon';
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp';
|
|
3
3
|
import { HerokuREPL } from '../repl/heroku-cli-repl.js';
|
|
4
4
|
/**
|
|
5
5
|
* Helper function to set up common MCP tool mocks for testing
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heroku/mcp-server",
|
|
3
3
|
"description": "Heroku Platform MCP Server",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.6",
|
|
5
5
|
"author": "Heroku",
|
|
6
6
|
"bugs": "https://github.com/heroku/heroku-mcp-server/issues",
|
|
7
7
|
"bin": {
|
|
@@ -78,7 +78,6 @@
|
|
|
78
78
|
"start": "node bin/heroku-mcp-server.mjs",
|
|
79
79
|
"format": "prettier . --write --config ./.prettier.mjs",
|
|
80
80
|
"lint": "cd src && eslint ./",
|
|
81
|
-
"posttest": "npm run lint",
|
|
82
81
|
"prepare": "husky",
|
|
83
82
|
"pretest": "npm run build",
|
|
84
83
|
"type-check": "tsc --noEmit",
|