@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.
Files changed (87) hide show
  1. package/README.md +37 -0
  2. package/bin/heroku-mcp-server.mjs +9 -0
  3. package/dist/index.js +20 -21
  4. package/dist/repl/heroku-cli-repl.js +45 -31
  5. package/dist/repl/heroku-cli-repl.spec.js +33 -1
  6. package/dist/services/app-service.js +0 -1
  7. package/dist/services/app-setup-service.js +0 -1
  8. package/dist/services/build-service.js +0 -1
  9. package/dist/services/dyno-service.js +0 -1
  10. package/dist/services/rendezvous.js +0 -1
  11. package/dist/services/source-service.js +0 -1
  12. package/dist/tools/addons.js +0 -1
  13. package/dist/tools/addons.spec.js +0 -1
  14. package/dist/tools/ai.js +14 -30
  15. package/dist/tools/ai.spec.js +109 -2
  16. package/dist/tools/apps.js +0 -1
  17. package/dist/tools/apps.spec.js +0 -1
  18. package/dist/tools/data.js +0 -1
  19. package/dist/tools/data.spec.js +0 -1
  20. package/dist/tools/deploy-to-heroku.js +0 -1
  21. package/dist/tools/deploy-to-heroku.spec.js +0 -1
  22. package/dist/tools/logs.js +0 -1
  23. package/dist/tools/logs.spec.js +0 -1
  24. package/dist/tools/maintenance.js +0 -1
  25. package/dist/tools/maintenance.spec.js +0 -1
  26. package/dist/tools/pipelines.js +0 -1
  27. package/dist/tools/pipelines.spec.js +0 -1
  28. package/dist/tools/ps.js +0 -1
  29. package/dist/tools/ps.spec.js +0 -1
  30. package/dist/tools/spaces.js +0 -1
  31. package/dist/tools/spaces.spec.js +0 -1
  32. package/dist/tools/teams.js +0 -1
  33. package/dist/tools/teams.spec.js +0 -1
  34. package/dist/utils/command-builder.js +0 -1
  35. package/dist/utils/command-builder.spec.js +0 -1
  36. package/dist/utils/generate-request-init.js +0 -1
  37. package/dist/utils/handle-cli-output.js +0 -1
  38. package/dist/utils/handle-cli-output.spec.js +0 -1
  39. package/dist/utils/mcp-tool-response.js +0 -1
  40. package/dist/utils/read-app-json.js +0 -1
  41. package/dist/utils/read-app-json.spec.js +0 -1
  42. package/dist/utils/tarball.js +0 -1
  43. package/dist/utils/tarball.spec.js +0 -1
  44. package/dist/utils/tool-commands.js +0 -1
  45. package/package.json +9 -6
  46. package/dist/index.js.map +0 -1
  47. package/dist/repl/heroku-cli-repl.js.map +0 -1
  48. package/dist/repl/heroku-cli-repl.spec.js.map +0 -1
  49. package/dist/services/app-service.js.map +0 -1
  50. package/dist/services/app-setup-service.js.map +0 -1
  51. package/dist/services/build-service.js.map +0 -1
  52. package/dist/services/dyno-service.js.map +0 -1
  53. package/dist/services/rendezvous.js.map +0 -1
  54. package/dist/services/source-service.js.map +0 -1
  55. package/dist/tools/addons.js.map +0 -1
  56. package/dist/tools/addons.spec.js.map +0 -1
  57. package/dist/tools/ai.js.map +0 -1
  58. package/dist/tools/ai.spec.js.map +0 -1
  59. package/dist/tools/apps.js.map +0 -1
  60. package/dist/tools/apps.spec.js.map +0 -1
  61. package/dist/tools/data.js.map +0 -1
  62. package/dist/tools/data.spec.js.map +0 -1
  63. package/dist/tools/deploy-to-heroku.js.map +0 -1
  64. package/dist/tools/deploy-to-heroku.spec.js.map +0 -1
  65. package/dist/tools/logs.js.map +0 -1
  66. package/dist/tools/logs.spec.js.map +0 -1
  67. package/dist/tools/maintenance.js.map +0 -1
  68. package/dist/tools/maintenance.spec.js.map +0 -1
  69. package/dist/tools/pipelines.js.map +0 -1
  70. package/dist/tools/pipelines.spec.js.map +0 -1
  71. package/dist/tools/ps.js.map +0 -1
  72. package/dist/tools/ps.spec.js.map +0 -1
  73. package/dist/tools/spaces.js.map +0 -1
  74. package/dist/tools/spaces.spec.js.map +0 -1
  75. package/dist/tools/teams.js.map +0 -1
  76. package/dist/tools/teams.spec.js.map +0 -1
  77. package/dist/utils/command-builder.js.map +0 -1
  78. package/dist/utils/command-builder.spec.js.map +0 -1
  79. package/dist/utils/generate-request-init.js.map +0 -1
  80. package/dist/utils/handle-cli-output.js.map +0 -1
  81. package/dist/utils/handle-cli-output.spec.js.map +0 -1
  82. package/dist/utils/mcp-tool-response.js.map +0 -1
  83. package/dist/utils/read-app-json.js.map +0 -1
  84. package/dist/utils/read-app-json.spec.js.map +0 -1
  85. package/dist/utils/tarball.js.map +0 -1
  86. package/dist/utils/tarball.spec.js.map +0 -1
  87. 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
  [![Deploy](https://www.herokucdn.com/deploy/button.svg)](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
+ ```
@@ -0,0 +1,9 @@
1
+ /* global process */
2
+ try {
3
+ const { runServer } = await import('../dist/index.js');
4
+ await runServer();
5
+ } catch (error) {
6
+ const { message } = error;
7
+ process.stderr.write(`Fatal error in main(): ${message}`);
8
+ process.exit(1);
9
+ }
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 herokuRepl = new HerokuREPL();
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
- async function runServer() {
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
- try {
77
- await runServer();
78
- }
79
- catch (error) {
80
- const { message } = error;
81
- process.stderr.write(`Fatal error in main():, ${message}`);
82
- process.exit(1);
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 path from 'node:path';
3
- import { fileURLToPath } from 'node:url';
2
+ import { EventEmitter } from 'node:events';
4
3
  import * as pjson from '../../package.json' with { type: 'json' };
5
- const heroku = path.parse(path.relative(process.cwd(), fileURLToPath(import.meta.resolve('heroku', import.meta.url))));
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.commandTimeoutId = setTimeout(() => {
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
- this.process = HerokuREPL.spawn(herokuRunPath, [], {
126
- stdio: ['pipe', 'pipe', 'pipe'],
127
- signal: this.abortController.signal,
128
- env: {
129
- ...process.env,
130
- HEROKU_MCP_MODE: 'true',
131
- HEROKU_MCP_SERVER_VERSION: VERSION,
132
- HEROKU_HEADERS: JSON.stringify({
133
- 'User-Agent': this.userAgent
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
- clearTimeout(this.commandTimeoutId);
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
@@ -40,4 +40,3 @@ export default class AppService {
40
40
  throw new Error(`${response.status}: ${message}`, { cause: response });
41
41
  }
42
42
  }
43
- //# sourceMappingURL=app-service.js.map
@@ -70,4 +70,3 @@ export default class AppSetupService {
70
70
  throw new Error(`${response.status}: ${message}`, { cause: response });
71
71
  }
72
72
  }
73
- //# sourceMappingURL=app-setup-service.js.map
@@ -147,4 +147,3 @@ export default class BuildService {
147
147
  throw new Error(`${response.status}: ${message}`, { cause: response });
148
148
  }
149
149
  }
150
- //# sourceMappingURL=build-service.js.map
@@ -250,4 +250,3 @@ export default class DynoService {
250
250
  throw new Error(`${response.status}: ${message}`, { cause: response });
251
251
  }
252
252
  }
253
- //# sourceMappingURL=dyno-service.js.map
@@ -138,4 +138,3 @@ export class RendezvousConnection {
138
138
  }
139
139
  }
140
140
  }
141
- //# sourceMappingURL=rendezvous.js.map
@@ -40,4 +40,3 @@ export default class SourceService {
40
40
  throw new Error(`${response.status}: ${message}`, { cause: response });
41
41
  }
42
42
  }
43
- //# sourceMappingURL=source-service.js.map
@@ -139,4 +139,3 @@ export const registerListAddonPlansTool = (server, herokuRepl) => {
139
139
  return handleCliOutput(output);
140
140
  });
141
141
  };
142
- //# sourceMappingURL=addons.js.map
@@ -296,4 +296,3 @@ describe('addons topic tools', () => {
296
296
  });
297
297
  });
298
298
  });
299
- //# sourceMappingURL=addons.spec.js.map
package/dist/tools/ai.js CHANGED
@@ -1,4 +1,6 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
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
- .string()
114
- .describe('Model resource ID/alias (requires --app for alias)')
115
- .default('heroku-inference'),
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
- opts: options.opts
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
@@ -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
@@ -131,4 +131,3 @@ export const registerTransferAppTool = (server, herokuRepl) => {
131
131
  return handleCliOutput(output);
132
132
  });
133
133
  };
134
- //# sourceMappingURL=apps.js.map
@@ -320,4 +320,3 @@ describe('apps topic tools', () => {
320
320
  });
321
321
  });
322
322
  });
323
- //# sourceMappingURL=apps.spec.js.map
@@ -303,4 +303,3 @@ export const registerPgUpgradeTool = (server, herokuRepl) => {
303
303
  return handleCliOutput(output);
304
304
  });
305
305
  };
306
- //# sourceMappingURL=data.js.map
@@ -298,4 +298,3 @@ describe('PostgreSQL Tools', () => {
298
298
  });
299
299
  });
300
300
  });
301
- //# sourceMappingURL=data.spec.js.map
@@ -602,4 +602,3 @@ export const registerDeployOneOffDynoTool = (server) => {
602
602
  };
603
603
  });
604
604
  };
605
- //# sourceMappingURL=deploy-to-heroku.js.map
@@ -205,4 +205,3 @@ describe('DeployToHeroku', () => {
205
205
  });
206
206
  });
207
207
  });
208
- //# sourceMappingURL=deploy-to-heroku.spec.js.map
@@ -31,4 +31,3 @@ export const registerGetAppLogsTool = (server, herokuRepl) => {
31
31
  return handleCliOutput(output);
32
32
  });
33
33
  };
34
- //# sourceMappingURL=logs.js.map
@@ -110,4 +110,3 @@ describe('logs topic tools', () => {
110
110
  });
111
111
  });
112
112
  });
113
- //# sourceMappingURL=logs.spec.js.map
@@ -45,4 +45,3 @@ export const registerMaintenanceOffTool = (server, herokuRepl) => {
45
45
  return handleCliOutput(output);
46
46
  });
47
47
  };
48
- //# sourceMappingURL=maintenance.js.map
@@ -113,4 +113,3 @@ describe('Maintenance Tools', () => {
113
113
  });
114
114
  });
115
115
  });
116
- //# sourceMappingURL=maintenance.spec.js.map
@@ -127,4 +127,3 @@ export const registerPipelinesTool = (server, herokuRepl) => {
127
127
  return handleCliOutput(output);
128
128
  });
129
129
  };
130
- //# sourceMappingURL=pipelines.js.map
@@ -181,4 +181,3 @@ describe('Pipeline Tools', () => {
181
181
  });
182
182
  });
183
183
  });
184
- //# sourceMappingURL=pipelines.spec.js.map
package/dist/tools/ps.js CHANGED
@@ -85,4 +85,3 @@ export const registerPsRestartTool = (server, herokuRepl) => {
85
85
  return handleCliOutput(output);
86
86
  });
87
87
  };
88
- //# sourceMappingURL=ps.js.map
@@ -125,4 +125,3 @@ describe('Process Management Tools', () => {
125
125
  });
126
126
  });
127
127
  });
128
- //# sourceMappingURL=ps.spec.js.map
@@ -24,4 +24,3 @@ export const registerListPrivateSpacesTool = (server, herokuRepl) => {
24
24
  return handleCliOutput(output);
25
25
  });
26
26
  };
27
- //# sourceMappingURL=spaces.js.map
@@ -69,4 +69,3 @@ describe('spaces topic tools', () => {
69
69
  });
70
70
  });
71
71
  });
72
- //# sourceMappingURL=spaces.spec.js.map
@@ -30,4 +30,3 @@ export const registerListTeamsTool = (server, herokuRepl) => {
30
30
  return handleCliOutput(output);
31
31
  });
32
32
  };
33
- //# sourceMappingURL=teams.js.map
@@ -67,4 +67,3 @@ describe('teams', () => {
67
67
  });
68
68
  });
69
69
  });
70
- //# sourceMappingURL=teams.spec.js.map
@@ -59,4 +59,3 @@ export class CommandBuilder {
59
59
  return command;
60
60
  }
61
61
  }
62
- //# sourceMappingURL=command-builder.js.map