@heroku/mcp-server 1.0.5 → 1.0.7-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/README.md +37 -0
- package/bin/heroku-mcp-server.mjs +9 -0
- package/dist/index.js +20 -21
- package/dist/repl/heroku-cli-repl.js +45 -31
- package/dist/repl/heroku-cli-repl.spec.js +33 -1
- package/dist/services/app-service.js +0 -1
- package/dist/services/app-setup-service.js +0 -1
- package/dist/services/build-service.js +0 -1
- package/dist/services/dyno-service.js +0 -1
- package/dist/services/rendezvous.js +0 -1
- package/dist/services/source-service.js +0 -1
- package/dist/tools/addons.js +0 -1
- package/dist/tools/addons.spec.js +0 -1
- package/dist/tools/ai.js +14 -30
- package/dist/tools/ai.spec.js +109 -2
- package/dist/tools/apps.js +0 -1
- package/dist/tools/apps.spec.js +0 -1
- package/dist/tools/data.js +0 -1
- package/dist/tools/data.spec.js +0 -1
- package/dist/tools/deploy-to-heroku.js +0 -1
- package/dist/tools/deploy-to-heroku.spec.js +0 -1
- package/dist/tools/logs.js +0 -1
- package/dist/tools/logs.spec.js +0 -1
- package/dist/tools/maintenance.js +0 -1
- package/dist/tools/maintenance.spec.js +0 -1
- package/dist/tools/pipelines.js +0 -1
- package/dist/tools/pipelines.spec.js +0 -1
- package/dist/tools/ps.js +0 -1
- package/dist/tools/ps.spec.js +0 -1
- package/dist/tools/spaces.js +0 -1
- package/dist/tools/spaces.spec.js +0 -1
- package/dist/tools/teams.js +0 -1
- package/dist/tools/teams.spec.js +0 -1
- package/dist/utils/command-builder.js +0 -1
- package/dist/utils/command-builder.spec.js +0 -1
- package/dist/utils/generate-request-init.js +0 -1
- package/dist/utils/handle-cli-output.js +0 -1
- package/dist/utils/handle-cli-output.spec.js +0 -1
- package/dist/utils/mcp-tool-response.js +0 -1
- package/dist/utils/read-app-json.js +0 -1
- package/dist/utils/read-app-json.spec.js +0 -1
- package/dist/utils/tarball.js +0 -1
- package/dist/utils/tarball.spec.js +0 -1
- package/dist/utils/tool-commands.js +0 -1
- package/package.json +9 -6
- package/dist/index.js.map +0 -1
- package/dist/repl/heroku-cli-repl.js.map +0 -1
- package/dist/repl/heroku-cli-repl.spec.js.map +0 -1
- package/dist/services/app-service.js.map +0 -1
- package/dist/services/app-setup-service.js.map +0 -1
- package/dist/services/build-service.js.map +0 -1
- package/dist/services/dyno-service.js.map +0 -1
- package/dist/services/rendezvous.js.map +0 -1
- package/dist/services/source-service.js.map +0 -1
- package/dist/tools/addons.js.map +0 -1
- package/dist/tools/addons.spec.js.map +0 -1
- package/dist/tools/ai.js.map +0 -1
- package/dist/tools/ai.spec.js.map +0 -1
- package/dist/tools/apps.js.map +0 -1
- package/dist/tools/apps.spec.js.map +0 -1
- package/dist/tools/data.js.map +0 -1
- package/dist/tools/data.spec.js.map +0 -1
- package/dist/tools/deploy-to-heroku.js.map +0 -1
- package/dist/tools/deploy-to-heroku.spec.js.map +0 -1
- package/dist/tools/logs.js.map +0 -1
- package/dist/tools/logs.spec.js.map +0 -1
- package/dist/tools/maintenance.js.map +0 -1
- package/dist/tools/maintenance.spec.js.map +0 -1
- package/dist/tools/pipelines.js.map +0 -1
- package/dist/tools/pipelines.spec.js.map +0 -1
- package/dist/tools/ps.js.map +0 -1
- package/dist/tools/ps.spec.js.map +0 -1
- package/dist/tools/spaces.js.map +0 -1
- package/dist/tools/spaces.spec.js.map +0 -1
- package/dist/tools/teams.js.map +0 -1
- package/dist/tools/teams.spec.js.map +0 -1
- package/dist/utils/command-builder.js.map +0 -1
- package/dist/utils/command-builder.spec.js.map +0 -1
- package/dist/utils/generate-request-init.js.map +0 -1
- package/dist/utils/handle-cli-output.js.map +0 -1
- package/dist/utils/handle-cli-output.spec.js.map +0 -1
- package/dist/utils/mcp-tool-response.js.map +0 -1
- package/dist/utils/read-app-json.js.map +0 -1
- package/dist/utils/read-app-json.spec.js.map +0 -1
- package/dist/utils/tarball.js.map +0 -1
- package/dist/utils/tarball.spec.js.map +0 -1
- package/dist/utils/tool-commands.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
> The Heroku Platform MCP Server works on Common Runtime, Cedar Private and Shield Spaces, and Fir Private Spaces.
|
|
6
6
|
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
- **Heroku CLI** must be installed globally on your system, version **10.8.1 or higher**.
|
|
10
|
+
- [Install or upgrade the Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli)
|
|
11
|
+
|
|
7
12
|
## Deploy on Heroku
|
|
8
13
|
|
|
9
14
|
[](https://www.heroku.com/deploy?template=https://github.com/heroku/heroku-mcp-server)
|
|
@@ -24,6 +29,9 @@ Note: The Heroku Platform MCP Server is currently in early development. As we co
|
|
|
24
29
|
implementation, the available functionality and tools may evolve. We welcome feedback and contributions to help shape
|
|
25
30
|
the future of this project.
|
|
26
31
|
|
|
32
|
+
> **Note:** The Heroku Platform MCP Server requires the Heroku CLI to be installed globally (v10.8.1+). Ensure you have
|
|
33
|
+
> the correct version by running `heroku --version`.
|
|
34
|
+
|
|
27
35
|
## Authentication
|
|
28
36
|
|
|
29
37
|
Generate a Heroku authorization token with one of these methods:
|
|
@@ -395,3 +403,32 @@ To install Heroku Platform MCP Server for Claude Desktop automatically via
|
|
|
395
403
|
```bash
|
|
396
404
|
npx -y @smithery/cli install @heroku/heroku-mcp-server --client claude
|
|
397
405
|
```
|
|
406
|
+
|
|
407
|
+
## Environment Variables
|
|
408
|
+
|
|
409
|
+
The Heroku Platform MCP Server supports the following environment variables:
|
|
410
|
+
|
|
411
|
+
### `HEROKU_API_KEY`
|
|
412
|
+
|
|
413
|
+
Your Heroku authorization token. Required for authentication with the Heroku Platform.
|
|
414
|
+
|
|
415
|
+
### `MCP_SERVER_REQUEST_TIMEOUT`
|
|
416
|
+
|
|
417
|
+
Timeout in milliseconds for command execution. Defaults to 15000 (15 seconds) if not set.
|
|
418
|
+
|
|
419
|
+
Example configuration with custom timeout:
|
|
420
|
+
|
|
421
|
+
```json
|
|
422
|
+
{
|
|
423
|
+
"mcpServers": {
|
|
424
|
+
"heroku": {
|
|
425
|
+
"command": "npx",
|
|
426
|
+
"args": ["-y", "@heroku/mcp-server"],
|
|
427
|
+
"env": {
|
|
428
|
+
"HEROKU_API_KEY": "<YOUR_HEROKU_AUTH_TOKEN>",
|
|
429
|
+
"MCP_SERVER_REQUEST_TIMEOUT": "30000"
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,15 @@ import * as ai from './tools/ai.js';
|
|
|
16
16
|
import { HerokuREPL } from './repl/heroku-cli-repl.js';
|
|
17
17
|
const VERSION = pjson.default.version;
|
|
18
18
|
const server = new McpServer({ name: 'Heroku MCP Server', version: VERSION });
|
|
19
|
-
const
|
|
19
|
+
const requestTimeout = isNaN(Number(process.env.MCP_SERVER_REQUEST_TIMEOUT))
|
|
20
|
+
? 15_000
|
|
21
|
+
: Number(process.env.MCP_SERVER_REQUEST_TIMEOUT);
|
|
22
|
+
const herokuRepl = new HerokuREPL(requestTimeout);
|
|
23
|
+
// Listen for MCP-formatted fatal startup errors
|
|
24
|
+
herokuRepl.on('fatalError', (mcpError) => {
|
|
25
|
+
process.stderr.write(JSON.stringify(mcpError) + '\n');
|
|
26
|
+
process.exit(1);
|
|
27
|
+
});
|
|
20
28
|
// App-related tools
|
|
21
29
|
apps.registerListAppsTool(server, herokuRepl);
|
|
22
30
|
apps.registerGetAppInfoTool(server, herokuRepl);
|
|
@@ -68,26 +76,17 @@ ai.registerMakeAiInferenceTool(server, herokuRepl);
|
|
|
68
76
|
/**
|
|
69
77
|
* Run the server
|
|
70
78
|
*/
|
|
71
|
-
|
|
79
|
+
export const runServer = async () => {
|
|
72
80
|
const transport = new StdioServerTransport();
|
|
73
81
|
await server.connect(transport);
|
|
74
82
|
process.stderr.write('Heroku MCP Server running on stdio');
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
* Hook to intercept all command results before they are
|
|
86
|
-
* sent back to the LLM. This is useful for logging
|
|
87
|
-
* or modifying command results (not-implemented).
|
|
88
|
-
*/
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
90
|
-
for await (const command of herokuRepl) {
|
|
91
|
-
// do nothing until logger is implemented
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=index.js.map
|
|
83
|
+
/**
|
|
84
|
+
* Hook to intercept all command results before they are
|
|
85
|
+
* sent back to the LLM. This is useful for logging
|
|
86
|
+
* or modifying command results (not-implemented).
|
|
87
|
+
*/
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
89
|
+
for await (const command of herokuRepl) {
|
|
90
|
+
// do nothing until logger is implemented
|
|
91
|
+
}
|
|
92
|
+
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
-
import
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
4
3
|
import * as pjson from '../../package.json' with { type: 'json' };
|
|
5
|
-
|
|
6
|
-
const herokuRunPath = path.join(heroku.dir, '../', 'bin/run');
|
|
4
|
+
import { handleCliOutput } from '../utils/handle-cli-output.js';
|
|
7
5
|
const COMMAND_END_RESULTS_MESSAGE = '<<<END RESULTS>>>';
|
|
8
6
|
const READY_MESSAGE = 'heroku >';
|
|
9
7
|
const VERSION = pjson.default.version;
|
|
@@ -27,7 +25,7 @@ const VERSION = pjson.default.version;
|
|
|
27
25
|
*
|
|
28
26
|
* This maintains a single Heroku CLI process.
|
|
29
27
|
*/
|
|
30
|
-
export class HerokuREPL {
|
|
28
|
+
export class HerokuREPL extends EventEmitter {
|
|
31
29
|
static spawn = spawn;
|
|
32
30
|
isProcessingCommand = false;
|
|
33
31
|
isReady = false;
|
|
@@ -46,6 +44,7 @@ export class HerokuREPL {
|
|
|
46
44
|
* @param commandTimeout the timeout for command execution
|
|
47
45
|
*/
|
|
48
46
|
constructor(commandTimeout = 15_000) {
|
|
47
|
+
super();
|
|
49
48
|
this.commandTimeout = commandTimeout;
|
|
50
49
|
this.pauseQueue();
|
|
51
50
|
void this.initializeProcess();
|
|
@@ -74,13 +73,7 @@ export class HerokuREPL {
|
|
|
74
73
|
this.buffer = '';
|
|
75
74
|
this.isProcessingCommand = true;
|
|
76
75
|
this.process?.stdin?.write(nextCommand.command + '\n');
|
|
77
|
-
this.
|
|
78
|
-
// If a timeout occurs, we need to restart the process
|
|
79
|
-
// in case it's in a bad state or an error occurred
|
|
80
|
-
// that we can't recover from
|
|
81
|
-
void this.initializeProcess();
|
|
82
|
-
this.handleOutput(`The command failed to complete in ${this.commandTimeout}ms\n${COMMAND_END_RESULTS_MESSAGE}\n`);
|
|
83
|
-
}, this.commandTimeout);
|
|
76
|
+
this.setCommandTimeout();
|
|
84
77
|
yield nextCommand.promise;
|
|
85
78
|
}
|
|
86
79
|
}
|
|
@@ -122,20 +115,35 @@ export class HerokuREPL {
|
|
|
122
115
|
this.process.kill();
|
|
123
116
|
this.process = undefined;
|
|
124
117
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
118
|
+
try {
|
|
119
|
+
this.process = HerokuREPL.spawn('heroku', ['--repl'], {
|
|
120
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
121
|
+
signal: this.abortController.signal,
|
|
122
|
+
env: {
|
|
123
|
+
...process.env,
|
|
124
|
+
HEROKU_MCP_MODE: 'true',
|
|
125
|
+
HEROKU_MCP_SERVER_VERSION: VERSION,
|
|
126
|
+
HEROKU_HEADERS: JSON.stringify({
|
|
127
|
+
'User-Agent': this.userAgent
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
// Emit MCP error and abort
|
|
134
|
+
this.emit('fatalError', handleCliOutput(`Startup error: ${err.message}`));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
this.process.once('error', (err) => {
|
|
138
|
+
this.emit('fatalError', handleCliOutput(`Startup error: ${err.message}`));
|
|
136
139
|
});
|
|
137
140
|
this.process.stdout?.on('data', (data) => {
|
|
138
141
|
const output = data.toString();
|
|
142
|
+
// Detect old CLI warning and emit MCP error
|
|
143
|
+
if (output.includes('Warning: --repl is not a heroku command.')) {
|
|
144
|
+
this.emit('fatalError', handleCliOutput('Startup error: Your Heroku CLI version does not support --repl mode. Please upgrade to the latest Heroku CLI.'));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
139
147
|
if (output.includes(READY_MESSAGE)) {
|
|
140
148
|
this.isReady = true;
|
|
141
149
|
this.pauseIteratorResolver?.();
|
|
@@ -181,14 +189,8 @@ export class HerokuREPL {
|
|
|
181
189
|
*/
|
|
182
190
|
handleOutput(output) {
|
|
183
191
|
this.buffer += output;
|
|
184
|
-
// Reset the timeout on every output if a command is being processed
|
|
185
192
|
if (this.isProcessingCommand) {
|
|
186
|
-
|
|
187
|
-
this.commandTimeoutId = setTimeout(() => {
|
|
188
|
-
// If a timeout occurs, we need to restart the process
|
|
189
|
-
void this.initializeProcess();
|
|
190
|
-
this.handleOutput(`The command failed to complete in ${this.commandTimeout}ms\n${COMMAND_END_RESULTS_MESSAGE}\n`);
|
|
191
|
-
}, this.commandTimeout);
|
|
193
|
+
this.setCommandTimeout();
|
|
192
194
|
}
|
|
193
195
|
// Check if command execution is complete
|
|
194
196
|
if (this.buffer.includes(COMMAND_END_RESULTS_MESSAGE) && this.isProcessingCommand) {
|
|
@@ -215,6 +217,19 @@ export class HerokuREPL {
|
|
|
215
217
|
this.pauseIteratorResolver = resolve;
|
|
216
218
|
});
|
|
217
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Sets a timeout for command execution
|
|
222
|
+
*/
|
|
223
|
+
setCommandTimeout() {
|
|
224
|
+
clearTimeout(this.commandTimeoutId);
|
|
225
|
+
this.commandTimeoutId = setTimeout(() => {
|
|
226
|
+
// If a timeout occurs, we need to restart the process
|
|
227
|
+
// in case it's in a bad state or an error occurred
|
|
228
|
+
// that we can't recover from
|
|
229
|
+
void this.initializeProcess();
|
|
230
|
+
this.handleOutput(`The command failed to complete in ${this.commandTimeout}ms\n${COMMAND_END_RESULTS_MESSAGE}\n`);
|
|
231
|
+
}, this.commandTimeout);
|
|
232
|
+
}
|
|
218
233
|
/**
|
|
219
234
|
* Handles the abort event
|
|
220
235
|
*/
|
|
@@ -224,4 +239,3 @@ export class HerokuREPL {
|
|
|
224
239
|
clearTimeout(this.commandTimeoutId);
|
|
225
240
|
};
|
|
226
241
|
}
|
|
227
|
-
//# sourceMappingURL=heroku-cli-repl.js.map
|
|
@@ -109,5 +109,37 @@ describe('HerokuREPL', () => {
|
|
|
109
109
|
expect(repl['abortController'].signal.aborted).to.be.true;
|
|
110
110
|
});
|
|
111
111
|
});
|
|
112
|
+
describe('MCP startup error handling', () => {
|
|
113
|
+
it('should emit fatalError if spawn throws', () => {
|
|
114
|
+
spawnStub.restore();
|
|
115
|
+
const error = new Error('spawn failed');
|
|
116
|
+
const badSpawn = sinon.stub(HerokuREPL, 'spawn').throws(error);
|
|
117
|
+
const fatalSpy = sinon.spy();
|
|
118
|
+
const replWithError = new HerokuREPL(500);
|
|
119
|
+
replWithError.on('fatalError', fatalSpy);
|
|
120
|
+
// Force re-init to trigger error
|
|
121
|
+
replWithError['initializeProcess']();
|
|
122
|
+
expect(fatalSpy.called).to.be.true;
|
|
123
|
+
const mcpError = fatalSpy.firstCall.args[0];
|
|
124
|
+
expect(mcpError.content[0].text).to.include('Startup error: spawn failed');
|
|
125
|
+
badSpawn.restore();
|
|
126
|
+
});
|
|
127
|
+
it('should emit fatalError if process emits error', () => {
|
|
128
|
+
const fatalSpy = sinon.spy();
|
|
129
|
+
repl.on('fatalError', fatalSpy);
|
|
130
|
+
const error = new Error('process error');
|
|
131
|
+
mockProcess.emit('error', error);
|
|
132
|
+
expect(fatalSpy.called).to.be.true;
|
|
133
|
+
const mcpError = fatalSpy.firstCall.args[0];
|
|
134
|
+
expect(mcpError.content[0].text).to.include('Startup error: process error');
|
|
135
|
+
});
|
|
136
|
+
it('should emit fatalError if CLI outputs old version warning', () => {
|
|
137
|
+
const fatalSpy = sinon.spy();
|
|
138
|
+
repl.on('fatalError', fatalSpy);
|
|
139
|
+
mockProcess.stdout.emit('data', 'Warning: --repl is not a heroku command.');
|
|
140
|
+
expect(fatalSpy.called).to.be.true;
|
|
141
|
+
const mcpError = fatalSpy.firstCall.args[0];
|
|
142
|
+
expect(mcpError.content[0].text).to.include('Your Heroku CLI version does not support --repl mode');
|
|
143
|
+
});
|
|
144
|
+
});
|
|
112
145
|
});
|
|
113
|
-
//# sourceMappingURL=heroku-cli-repl.spec.js.map
|
package/dist/tools/addons.js
CHANGED
package/dist/tools/ai.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
2
4
|
import { z } from 'zod';
|
|
3
5
|
import { handleCliOutput } from '../utils/handle-cli-output.js';
|
|
4
6
|
import { CommandBuilder } from '../utils/command-builder.js';
|
|
@@ -109,33 +111,10 @@ const agentRequestSchema = z.object({
|
|
|
109
111
|
*/
|
|
110
112
|
export const aiInferenceOptionsSchema = z.object({
|
|
111
113
|
app: z.string().describe('App name/ID (required for alias)'),
|
|
112
|
-
modelResource: z
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
opts: z
|
|
117
|
-
.string()
|
|
118
|
-
.describe('JSON string with model, messages, and optional params (temp, tools, etc)')
|
|
119
|
-
.refine((val) => {
|
|
120
|
-
try {
|
|
121
|
-
const parsed = JSON.parse(val);
|
|
122
|
-
return agentRequestSchema.safeParse(parsed).success;
|
|
123
|
-
}
|
|
124
|
-
catch {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
}, {
|
|
128
|
-
message: 'Invalid JSON string or does not match AgentRequest shape'
|
|
129
|
-
}),
|
|
130
|
-
json: z
|
|
131
|
-
.boolean()
|
|
132
|
-
.optional()
|
|
133
|
-
.describe('Output as JSON')
|
|
134
|
-
.default(false),
|
|
135
|
-
output: z
|
|
136
|
-
.string()
|
|
137
|
-
.optional()
|
|
138
|
-
.describe('Output file path')
|
|
114
|
+
modelResource: z.string().describe('Model resource ID/alias (requires --app for alias)').default('heroku-inference'),
|
|
115
|
+
opts: agentRequestSchema,
|
|
116
|
+
json: z.boolean().optional().describe('Output as JSON').default(false),
|
|
117
|
+
output: z.string().optional().describe('Output file path')
|
|
139
118
|
});
|
|
140
119
|
/**
|
|
141
120
|
* Register make_ai_inference tool
|
|
@@ -145,17 +124,22 @@ export const aiInferenceOptionsSchema = z.object({
|
|
|
145
124
|
*/
|
|
146
125
|
export const registerMakeAiInferenceTool = (server, herokuRepl) => {
|
|
147
126
|
server.tool('make_ai_inference', 'Make inference request to Heroku AI API', aiInferenceOptionsSchema.shape, async (options) => {
|
|
127
|
+
// Passing a json string to the opts flag is brittle,
|
|
128
|
+
// so we write the json to a file and pass the file path instead
|
|
129
|
+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'com.heroku.mcp.ai.inference'));
|
|
130
|
+
const optsFilePath = path.join(tempDir, 'opts.json');
|
|
131
|
+
await fs.writeFile(optsFilePath, JSON.stringify(options.opts, null, 0));
|
|
148
132
|
const command = new CommandBuilder(TOOL_COMMAND_MAP.AI_AGENTS_CALL)
|
|
149
133
|
.addPositionalArguments({ modelResource: options.modelResource })
|
|
150
134
|
.addFlags({
|
|
151
135
|
app: options.app,
|
|
152
136
|
json: options.json,
|
|
153
137
|
output: options.output,
|
|
154
|
-
|
|
138
|
+
optfile: optsFilePath
|
|
155
139
|
})
|
|
156
140
|
.build();
|
|
157
141
|
const output = await herokuRepl.executeCommand(command);
|
|
142
|
+
await fs.rmdir(tempDir, { recursive: true });
|
|
158
143
|
return handleCliOutput(output);
|
|
159
144
|
});
|
|
160
145
|
};
|
|
161
|
-
//# sourceMappingURL=ai.js.map
|
package/dist/tools/ai.spec.js
CHANGED
|
@@ -2,9 +2,11 @@ import { expect } from 'chai';
|
|
|
2
2
|
import sinon from 'sinon';
|
|
3
3
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
4
|
import { HerokuREPL } from '../repl/heroku-cli-repl.js';
|
|
5
|
-
import { registerListAiAvailableModelsTool, registerProvisionAiModelTool, provisionAiModelOptionsSchema } from './ai.js';
|
|
5
|
+
import { registerListAiAvailableModelsTool, registerProvisionAiModelTool, provisionAiModelOptionsSchema, registerMakeAiInferenceTool, aiInferenceOptionsSchema } from './ai.js';
|
|
6
6
|
import { CommandBuilder } from '../utils/command-builder.js';
|
|
7
7
|
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
8
|
+
import fs from 'node:fs/promises';
|
|
9
|
+
import path from 'node:path';
|
|
8
10
|
describe('ai topic tools', () => {
|
|
9
11
|
describe('registerListAiAvailableModelsTool', () => {
|
|
10
12
|
let server;
|
|
@@ -92,5 +94,110 @@ describe('ai topic tools', () => {
|
|
|
92
94
|
});
|
|
93
95
|
});
|
|
94
96
|
});
|
|
97
|
+
describe('makeAiInferenceTool', () => {
|
|
98
|
+
let server;
|
|
99
|
+
let herokuRepl;
|
|
100
|
+
let toolCallback;
|
|
101
|
+
let mkdtempStub;
|
|
102
|
+
let writeFileStub;
|
|
103
|
+
let rmdirStub;
|
|
104
|
+
let tempDir;
|
|
105
|
+
let optsFilePath;
|
|
106
|
+
beforeEach(() => {
|
|
107
|
+
server = sinon.createStubInstance(McpServer);
|
|
108
|
+
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
109
|
+
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
110
|
+
toolCallback = callback;
|
|
111
|
+
return server;
|
|
112
|
+
});
|
|
113
|
+
tempDir = '/tmp/com.heroku.mcp.ai.inference-12345';
|
|
114
|
+
optsFilePath = path.join(tempDir, 'opts.json');
|
|
115
|
+
mkdtempStub = sinon.stub(fs, 'mkdtemp').resolves(tempDir);
|
|
116
|
+
writeFileStub = sinon.stub(fs, 'writeFile').resolves();
|
|
117
|
+
rmdirStub = sinon.stub(fs, 'rmdir').resolves();
|
|
118
|
+
registerMakeAiInferenceTool(server, herokuRepl);
|
|
119
|
+
});
|
|
120
|
+
afterEach(() => {
|
|
121
|
+
sinon.restore();
|
|
122
|
+
});
|
|
123
|
+
it('registers the tool with correct name and schema', () => {
|
|
124
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
125
|
+
const call = server.tool.getCall(0);
|
|
126
|
+
expect(call.args[0]).to.equal('make_ai_inference');
|
|
127
|
+
expect(call.args[2]).to.deep.equal(aiInferenceOptionsSchema.shape);
|
|
128
|
+
});
|
|
129
|
+
it('executes command successfully with required arguments and handles temp files', async () => {
|
|
130
|
+
const expectedOutput = 'AI inference response content';
|
|
131
|
+
const opts = {
|
|
132
|
+
model: 'claude-3-5-sonnet-latest',
|
|
133
|
+
messages: [{ role: 'user', content: 'Hello' }]
|
|
134
|
+
};
|
|
135
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.AI_AGENTS_CALL)
|
|
136
|
+
.addPositionalArguments({ modelResource: 'heroku-inference' })
|
|
137
|
+
.addFlags({
|
|
138
|
+
app: 'test-app',
|
|
139
|
+
json: false,
|
|
140
|
+
output: undefined,
|
|
141
|
+
optfile: optsFilePath
|
|
142
|
+
})
|
|
143
|
+
.build();
|
|
144
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
145
|
+
const result = await toolCallback({
|
|
146
|
+
modelResource: 'heroku-inference',
|
|
147
|
+
app: 'test-app',
|
|
148
|
+
opts
|
|
149
|
+
}, {});
|
|
150
|
+
const actualCommand = herokuRepl.executeCommand.getCall(0).args[0];
|
|
151
|
+
expect(actualCommand).to.equal(expectedCommand);
|
|
152
|
+
expect(mkdtempStub.calledOnce).to.be.true;
|
|
153
|
+
expect(mkdtempStub.firstCall.args[0]).to.include('com.heroku.mcp.ai.inference');
|
|
154
|
+
expect(writeFileStub.calledOnceWith(optsFilePath, JSON.stringify(opts, null, 0))).to.be.true;
|
|
155
|
+
expect(rmdirStub.calledOnceWith(tempDir, { recursive: true })).to.be.true;
|
|
156
|
+
expect(result).to.deep.equal({
|
|
157
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
it('executes command successfully with all optional parameters and handles temp files', async () => {
|
|
161
|
+
const expectedOutput = 'AI inference response content';
|
|
162
|
+
const opts = {
|
|
163
|
+
model: 'claude-3-5-sonnet-latest',
|
|
164
|
+
messages: [{ role: 'user', content: 'Hello' }],
|
|
165
|
+
temperature: 0.7,
|
|
166
|
+
max_tokens_per_inference_request: 1000,
|
|
167
|
+
tools: [
|
|
168
|
+
{
|
|
169
|
+
type: 'function',
|
|
170
|
+
name: 'test_tool',
|
|
171
|
+
description: 'A test tool'
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
};
|
|
175
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.AI_AGENTS_CALL)
|
|
176
|
+
.addPositionalArguments({ modelResource: 'custom-model' })
|
|
177
|
+
.addFlags({
|
|
178
|
+
app: 'test-app',
|
|
179
|
+
json: true,
|
|
180
|
+
output: 'output.json',
|
|
181
|
+
optfile: optsFilePath
|
|
182
|
+
})
|
|
183
|
+
.build();
|
|
184
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
185
|
+
const result = await toolCallback({
|
|
186
|
+
app: 'test-app',
|
|
187
|
+
modelResource: 'custom-model',
|
|
188
|
+
opts,
|
|
189
|
+
json: true,
|
|
190
|
+
output: 'output.json'
|
|
191
|
+
}, {});
|
|
192
|
+
const actualCommand = herokuRepl.executeCommand.getCall(0).args[0];
|
|
193
|
+
expect(actualCommand).to.equal(expectedCommand);
|
|
194
|
+
expect(mkdtempStub.calledOnce).to.be.true;
|
|
195
|
+
expect(mkdtempStub.firstCall.args[0]).to.include('com.heroku.mcp.ai.inference');
|
|
196
|
+
expect(writeFileStub.calledOnceWith(optsFilePath, JSON.stringify(opts, null, 0))).to.be.true;
|
|
197
|
+
expect(rmdirStub.calledOnceWith(tempDir, { recursive: true })).to.be.true;
|
|
198
|
+
expect(result).to.deep.equal({
|
|
199
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
95
203
|
});
|
|
96
|
-
//# sourceMappingURL=ai.spec.js.map
|
package/dist/tools/apps.js
CHANGED
package/dist/tools/apps.spec.js
CHANGED
package/dist/tools/data.js
CHANGED
package/dist/tools/data.spec.js
CHANGED
package/dist/tools/logs.js
CHANGED
package/dist/tools/logs.spec.js
CHANGED
package/dist/tools/pipelines.js
CHANGED
package/dist/tools/ps.js
CHANGED
package/dist/tools/ps.spec.js
CHANGED
package/dist/tools/spaces.js
CHANGED
package/dist/tools/teams.js
CHANGED
package/dist/tools/teams.spec.js
CHANGED