@heroku/mcp-server 1.0.4 → 1.0.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/README.md +44 -0
- package/dist/index.js +6 -1
- package/dist/repl/heroku-cli-repl.js +18 -8
- package/dist/tools/ai.js +145 -0
- package/dist/tools/ai.spec.js +203 -0
- package/dist/utils/tool-commands.js +5 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
# heroku-mcp-server
|
|
2
2
|
|
|
3
|
+
[](https://smithery.ai/server/@heroku/heroku-mcp-server)
|
|
4
|
+
|
|
3
5
|
> The Heroku Platform MCP Server works on Common Runtime, Cedar Private and Shield Spaces, and Fir Private Spaces.
|
|
4
6
|
|
|
7
|
+
## Deploy on Heroku
|
|
8
|
+
|
|
9
|
+
[](https://www.heroku.com/deploy?template=https://github.com/heroku/heroku-mcp-server)
|
|
10
|
+
|
|
5
11
|
## Overview
|
|
6
12
|
|
|
7
13
|
The Heroku Platform MCP Server is a specialized Model Context Protocol (MCP) implementation designed to facilitate
|
|
@@ -380,3 +386,41 @@ To set up local debugging with breakpoints:
|
|
|
380
386
|
5. Press F5 or use the **`Run and Debug`** sidebar.
|
|
381
387
|
|
|
382
388
|
Note: the debugger automatically builds your TypeScript files before launching.
|
|
389
|
+
|
|
390
|
+
### Installing via Smithery
|
|
391
|
+
|
|
392
|
+
To install Heroku Platform MCP Server for Claude Desktop automatically via
|
|
393
|
+
[Smithery](https://smithery.ai/server/@heroku/heroku-mcp-server):
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
npx -y @smithery/cli install @heroku/heroku-mcp-server --client claude
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
## Environment Variables
|
|
400
|
+
|
|
401
|
+
The Heroku Platform MCP Server supports the following environment variables:
|
|
402
|
+
|
|
403
|
+
### `HEROKU_API_KEY`
|
|
404
|
+
|
|
405
|
+
Your Heroku authorization token. Required for authentication with the Heroku Platform.
|
|
406
|
+
|
|
407
|
+
### `MCP_SERVER_REQUEST_TIMEOUT`
|
|
408
|
+
|
|
409
|
+
Timeout in milliseconds for command execution. Defaults to 15000 (15 seconds) if not set.
|
|
410
|
+
|
|
411
|
+
Example configuration with custom timeout:
|
|
412
|
+
|
|
413
|
+
```json
|
|
414
|
+
{
|
|
415
|
+
"mcpServers": {
|
|
416
|
+
"heroku": {
|
|
417
|
+
"command": "npx",
|
|
418
|
+
"args": ["-y", "@heroku/mcp-server"],
|
|
419
|
+
"env": {
|
|
420
|
+
"HEROKU_API_KEY": "<YOUR_HEROKU_AUTH_TOKEN>",
|
|
421
|
+
"MCP_SERVER_REQUEST_TIMEOUT": "30000"
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -12,10 +12,11 @@ import * as ps from './tools/ps.js';
|
|
|
12
12
|
import * as pipelines from './tools/pipelines.js';
|
|
13
13
|
import * as deployToHeroku from './tools/deploy-to-heroku.js';
|
|
14
14
|
import * as logs from './tools/logs.js';
|
|
15
|
+
import * as ai from './tools/ai.js';
|
|
15
16
|
import { HerokuREPL } from './repl/heroku-cli-repl.js';
|
|
16
17
|
const VERSION = pjson.default.version;
|
|
17
18
|
const server = new McpServer({ name: 'Heroku MCP Server', version: VERSION });
|
|
18
|
-
const herokuRepl = new HerokuREPL();
|
|
19
|
+
const herokuRepl = new HerokuREPL(isNaN(Number(process.env.MCP_SERVER_REQUEST_TIMEOUT)) ? 15_000 : Number(process.env.MCP_SERVER_REQUEST_TIMEOUT));
|
|
19
20
|
// App-related tools
|
|
20
21
|
apps.registerListAppsTool(server, herokuRepl);
|
|
21
22
|
apps.registerGetAppInfoTool(server, herokuRepl);
|
|
@@ -60,6 +61,10 @@ pipelines.registerPipelinesInfoTool(server, herokuRepl);
|
|
|
60
61
|
// Deploy-to-Heroku tool
|
|
61
62
|
deployToHeroku.registerDeployToHerokuTool(server);
|
|
62
63
|
deployToHeroku.registerDeployOneOffDynoTool(server);
|
|
64
|
+
// AI-related tools
|
|
65
|
+
ai.registerListAiAvailableModelsTool(server, herokuRepl);
|
|
66
|
+
ai.registerProvisionAiModelTool(server, herokuRepl);
|
|
67
|
+
ai.registerMakeAiInferenceTool(server, herokuRepl);
|
|
63
68
|
/**
|
|
64
69
|
* Run the server
|
|
65
70
|
*/
|
|
@@ -3,7 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import * as pjson from '../../package.json' with { type: 'json' };
|
|
5
5
|
const heroku = path.parse(path.relative(process.cwd(), fileURLToPath(import.meta.resolve('heroku', import.meta.url))));
|
|
6
|
-
const herokuRunPath = path.join(heroku.dir, '
|
|
6
|
+
const herokuRunPath = path.join(heroku.dir, '..', 'bin', 'run');
|
|
7
7
|
const COMMAND_END_RESULTS_MESSAGE = '<<<END RESULTS>>>';
|
|
8
8
|
const READY_MESSAGE = 'heroku >';
|
|
9
9
|
const VERSION = pjson.default.version;
|
|
@@ -74,13 +74,7 @@ export class HerokuREPL {
|
|
|
74
74
|
this.buffer = '';
|
|
75
75
|
this.isProcessingCommand = true;
|
|
76
76
|
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);
|
|
77
|
+
this.setCommandTimeout();
|
|
84
78
|
yield nextCommand.promise;
|
|
85
79
|
}
|
|
86
80
|
}
|
|
@@ -181,6 +175,9 @@ export class HerokuREPL {
|
|
|
181
175
|
*/
|
|
182
176
|
handleOutput(output) {
|
|
183
177
|
this.buffer += output;
|
|
178
|
+
if (this.isProcessingCommand) {
|
|
179
|
+
this.setCommandTimeout();
|
|
180
|
+
}
|
|
184
181
|
// Check if command execution is complete
|
|
185
182
|
if (this.buffer.includes(COMMAND_END_RESULTS_MESSAGE) && this.isProcessingCommand) {
|
|
186
183
|
const result = this.buffer.trim();
|
|
@@ -206,6 +203,19 @@ export class HerokuREPL {
|
|
|
206
203
|
this.pauseIteratorResolver = resolve;
|
|
207
204
|
});
|
|
208
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Sets a timeout for command execution
|
|
208
|
+
*/
|
|
209
|
+
setCommandTimeout() {
|
|
210
|
+
clearTimeout(this.commandTimeoutId);
|
|
211
|
+
this.commandTimeoutId = setTimeout(() => {
|
|
212
|
+
// If a timeout occurs, we need to restart the process
|
|
213
|
+
// in case it's in a bad state or an error occurred
|
|
214
|
+
// that we can't recover from
|
|
215
|
+
void this.initializeProcess();
|
|
216
|
+
this.handleOutput(`The command failed to complete in ${this.commandTimeout}ms\n${COMMAND_END_RESULTS_MESSAGE}\n`);
|
|
217
|
+
}, this.commandTimeout);
|
|
218
|
+
}
|
|
209
219
|
/**
|
|
210
220
|
* Handles the abort event
|
|
211
221
|
*/
|
package/dist/tools/ai.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { handleCliOutput } from '../utils/handle-cli-output.js';
|
|
6
|
+
import { CommandBuilder } from '../utils/command-builder.js';
|
|
7
|
+
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
8
|
+
/**
|
|
9
|
+
* Register list_ai_available_models tool
|
|
10
|
+
*
|
|
11
|
+
* @param server MCP server instance
|
|
12
|
+
* @param herokuRepl Heroku REPL instance
|
|
13
|
+
*/
|
|
14
|
+
export const registerListAiAvailableModelsTool = (server, herokuRepl) => {
|
|
15
|
+
server.tool('list_ai_available_models', 'List available AI inference models', z.object({}).shape, async () => {
|
|
16
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.LIST_AI_AVAILABLE_MODELS).build();
|
|
17
|
+
const output = await herokuRepl.executeCommand(command);
|
|
18
|
+
return handleCliOutput(output);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Schema for provisioning an AI model
|
|
23
|
+
*/
|
|
24
|
+
export const provisionAiModelOptionsSchema = z.object({
|
|
25
|
+
app: z.string().describe('Target app name for AI model access provisioning'),
|
|
26
|
+
modelName: z
|
|
27
|
+
.string()
|
|
28
|
+
.describe('Name of the AI model to provision access for. Valid model names can be found with tool "list_ai_available_models"'),
|
|
29
|
+
as: z
|
|
30
|
+
.string()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe('Alias for the model resource when attaching to the app. Randomly generated if not provided.')
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Register create_app tool
|
|
36
|
+
*
|
|
37
|
+
* @param server MCP server instance
|
|
38
|
+
* @param herokuRepl Heroku REPL instance
|
|
39
|
+
*/
|
|
40
|
+
export const registerProvisionAiModelTool = (server, herokuRepl) => {
|
|
41
|
+
server.tool('provision_ai_model', 'Provision AI model access for app', provisionAiModelOptionsSchema.shape, async (options) => {
|
|
42
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.PROVISION_AI_MODEL)
|
|
43
|
+
.addPositionalArguments({ modelName: options.modelName })
|
|
44
|
+
.addFlags({
|
|
45
|
+
app: options.app,
|
|
46
|
+
as: options.as
|
|
47
|
+
})
|
|
48
|
+
.build();
|
|
49
|
+
const output = await herokuRepl.executeCommand(command);
|
|
50
|
+
return handleCliOutput(output);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Schema for agent message
|
|
55
|
+
*/
|
|
56
|
+
const agentMessageSchema = z.object({
|
|
57
|
+
role: z.string(),
|
|
58
|
+
content: z.string()
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Schema for agent tool parameters
|
|
62
|
+
*/
|
|
63
|
+
const agentToolParametersSchema = z.object({
|
|
64
|
+
type: z.string(),
|
|
65
|
+
properties: z.record(z.unknown()),
|
|
66
|
+
required: z.array(z.string())
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Schema for agent tool params
|
|
70
|
+
*/
|
|
71
|
+
const agentToolParamsSchema = z.object({
|
|
72
|
+
cmd: z.string().optional(),
|
|
73
|
+
description: z.string().optional(),
|
|
74
|
+
parameters: agentToolParametersSchema.optional()
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Schema for agent runtime params
|
|
78
|
+
*/
|
|
79
|
+
const agentRuntimeParamsSchema = z.object({
|
|
80
|
+
// eslint-disable-next-line camelcase
|
|
81
|
+
target_app_name: z.string().optional(),
|
|
82
|
+
// eslint-disable-next-line camelcase
|
|
83
|
+
tool_params: agentToolParamsSchema.optional()
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Schema for agent tool
|
|
87
|
+
*/
|
|
88
|
+
const agentToolSchema = z.object({
|
|
89
|
+
type: z.string(),
|
|
90
|
+
name: z.string(),
|
|
91
|
+
description: z.string().optional(),
|
|
92
|
+
// eslint-disable-next-line camelcase
|
|
93
|
+
runtime_params: agentRuntimeParamsSchema.optional()
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Schema for agent request
|
|
97
|
+
*/
|
|
98
|
+
const agentRequestSchema = z.object({
|
|
99
|
+
model: z.string(),
|
|
100
|
+
messages: z.array(agentMessageSchema),
|
|
101
|
+
// eslint-disable-next-line camelcase
|
|
102
|
+
max_tokens_per_inference_request: z.number().optional(),
|
|
103
|
+
stop: z.array(z.string()).optional(),
|
|
104
|
+
temperature: z.number().optional(),
|
|
105
|
+
tools: z.array(agentToolSchema).optional(),
|
|
106
|
+
// eslint-disable-next-line camelcase
|
|
107
|
+
top_p: z.number().optional()
|
|
108
|
+
});
|
|
109
|
+
/**
|
|
110
|
+
* Schema for making an AI inference request
|
|
111
|
+
*/
|
|
112
|
+
export const aiInferenceOptionsSchema = z.object({
|
|
113
|
+
app: z.string().describe('App name/ID (required for alias)'),
|
|
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')
|
|
118
|
+
});
|
|
119
|
+
/**
|
|
120
|
+
* Register make_ai_inference tool
|
|
121
|
+
*
|
|
122
|
+
* @param server MCP server instance
|
|
123
|
+
* @param herokuRepl Heroku REPL instance
|
|
124
|
+
*/
|
|
125
|
+
export const registerMakeAiInferenceTool = (server, herokuRepl) => {
|
|
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));
|
|
132
|
+
const command = new CommandBuilder(TOOL_COMMAND_MAP.AI_AGENTS_CALL)
|
|
133
|
+
.addPositionalArguments({ modelResource: options.modelResource })
|
|
134
|
+
.addFlags({
|
|
135
|
+
app: options.app,
|
|
136
|
+
json: options.json,
|
|
137
|
+
output: options.output,
|
|
138
|
+
optfile: optsFilePath
|
|
139
|
+
})
|
|
140
|
+
.build();
|
|
141
|
+
const output = await herokuRepl.executeCommand(command);
|
|
142
|
+
await fs.rmdir(tempDir, { recursive: true });
|
|
143
|
+
return handleCliOutput(output);
|
|
144
|
+
});
|
|
145
|
+
};
|
|
@@ -0,0 +1,203 @@
|
|
|
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 { registerListAiAvailableModelsTool, registerProvisionAiModelTool, provisionAiModelOptionsSchema, registerMakeAiInferenceTool, aiInferenceOptionsSchema } from './ai.js';
|
|
6
|
+
import { CommandBuilder } from '../utils/command-builder.js';
|
|
7
|
+
import { TOOL_COMMAND_MAP } from '../utils/tool-commands.js';
|
|
8
|
+
import fs from 'node:fs/promises';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
describe('ai topic tools', () => {
|
|
11
|
+
describe('registerListAiAvailableModelsTool', () => {
|
|
12
|
+
let server;
|
|
13
|
+
let herokuRepl;
|
|
14
|
+
let toolCallback;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
server = sinon.createStubInstance(McpServer);
|
|
17
|
+
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
18
|
+
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
19
|
+
toolCallback = callback;
|
|
20
|
+
return server;
|
|
21
|
+
});
|
|
22
|
+
registerListAiAvailableModelsTool(server, herokuRepl);
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
sinon.restore();
|
|
26
|
+
});
|
|
27
|
+
it('registers the tool with correct name', () => {
|
|
28
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
29
|
+
const call = server.tool.getCall(0);
|
|
30
|
+
expect(call.args[0]).to.equal('list_ai_available_models');
|
|
31
|
+
});
|
|
32
|
+
it('executes command successfully', async () => {
|
|
33
|
+
const expectedOutput = ' Model Type Supported regions \n' +
|
|
34
|
+
' ───────────────────────── ───────────────── ───────────────── \n' +
|
|
35
|
+
' claude-3-5-haiku text-to-text us \n' +
|
|
36
|
+
' claude-3-5-sonnet-latest text-to-text us \n';
|
|
37
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.LIST_AI_AVAILABLE_MODELS).build();
|
|
38
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
39
|
+
const result = await toolCallback({}, {});
|
|
40
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
41
|
+
expect(result).to.deep.equal({
|
|
42
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe('provisionAiModelTool', () => {
|
|
47
|
+
let server;
|
|
48
|
+
let herokuRepl;
|
|
49
|
+
let toolCallback;
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
server = sinon.createStubInstance(McpServer);
|
|
52
|
+
herokuRepl = sinon.createStubInstance(HerokuREPL);
|
|
53
|
+
server.tool.callsFake((_name, _description, _schema, callback) => {
|
|
54
|
+
toolCallback = callback;
|
|
55
|
+
return server;
|
|
56
|
+
});
|
|
57
|
+
registerProvisionAiModelTool(server, herokuRepl);
|
|
58
|
+
});
|
|
59
|
+
afterEach(() => {
|
|
60
|
+
sinon.restore();
|
|
61
|
+
});
|
|
62
|
+
it('registers the tool with correct name and schema', () => {
|
|
63
|
+
expect(server.tool.calledOnce).to.be.true;
|
|
64
|
+
const call = server.tool.getCall(0);
|
|
65
|
+
expect(call.args[0]).to.equal('provision_ai_model');
|
|
66
|
+
expect(call.args[2]).to.deep.equal(provisionAiModelOptionsSchema.shape);
|
|
67
|
+
});
|
|
68
|
+
it('executes command successfully with required arguments', async () => {
|
|
69
|
+
const expectedOutput = 'Provisioning access to claude-3-5-sonnet-latest for app test-app... done\n' +
|
|
70
|
+
'Created claude-3-5-sonnet-latest as INFERENCE on test-app';
|
|
71
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.PROVISION_AI_MODEL)
|
|
72
|
+
.addPositionalArguments({ modelName: 'claude-3-5-sonnet-latest' })
|
|
73
|
+
.addFlags({ app: 'test-app' })
|
|
74
|
+
.build();
|
|
75
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
76
|
+
const result = await toolCallback({ app: 'test-app', modelName: 'claude-3-5-sonnet-latest' }, {});
|
|
77
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
78
|
+
expect(result).to.deep.equal({
|
|
79
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
it('executes command successfully with optional "--as" parameter', async () => {
|
|
83
|
+
const expectedOutput = 'Provisioning access to claude-3-5-sonnet-latest for app test-app as MY_MODEL... done\n' +
|
|
84
|
+
'Created claude-3-5-sonnet-latest as MY_MODEL on test-app';
|
|
85
|
+
const expectedCommand = new CommandBuilder(TOOL_COMMAND_MAP.PROVISION_AI_MODEL)
|
|
86
|
+
.addPositionalArguments({ modelName: 'claude-3-5-sonnet-latest' })
|
|
87
|
+
.addFlags({ app: 'test-app', as: 'MY_MODEL' })
|
|
88
|
+
.build();
|
|
89
|
+
herokuRepl.executeCommand.resolves(expectedOutput);
|
|
90
|
+
const result = await toolCallback({ app: 'test-app', modelName: 'claude-3-5-sonnet-latest', as: 'MY_MODEL' }, {});
|
|
91
|
+
expect(herokuRepl.executeCommand.calledOnceWith(expectedCommand)).to.be.true;
|
|
92
|
+
expect(result).to.deep.equal({
|
|
93
|
+
content: [{ type: 'text', text: expectedOutput }]
|
|
94
|
+
});
|
|
95
|
+
});
|
|
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
|
+
});
|
|
203
|
+
});
|
|
@@ -43,5 +43,9 @@ export const TOOL_COMMAND_MAP = {
|
|
|
43
43
|
PIPELINES_PROMOTE: 'pipelines:promote',
|
|
44
44
|
PIPELINES_INFO: 'pipelines:info',
|
|
45
45
|
// Logs commands
|
|
46
|
-
LOGS: 'logs'
|
|
46
|
+
LOGS: 'logs',
|
|
47
|
+
// AI commands
|
|
48
|
+
LIST_AI_AVAILABLE_MODELS: 'ai:models:list',
|
|
49
|
+
PROVISION_AI_MODEL: 'ai:models:create',
|
|
50
|
+
AI_AGENTS_CALL: 'ai:agents:call'
|
|
47
51
|
};
|
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.0.
|
|
4
|
+
"version": "1.0.6",
|
|
5
5
|
"author": "Heroku",
|
|
6
6
|
"bugs": "https://github.com/heroku/heroku-mcp-server/issues",
|
|
7
7
|
"bin": {
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"dependencies": {
|
|
12
|
+
"@heroku/plugin-ai": "^1.0.1",
|
|
12
13
|
"@modelcontextprotocol/sdk": "^1.8.0",
|
|
13
|
-
"heroku": "10.
|
|
14
|
+
"heroku": "10.8.0-alpha.0",
|
|
14
15
|
"jsonschema": "^1.5.0",
|
|
15
16
|
"tar-stream": "^3.1.7",
|
|
16
17
|
"zod": "^3.24.2",
|
|
@@ -72,7 +73,8 @@
|
|
|
72
73
|
"build": "rm -rf dist && tsc -p tsconfig.json && npm run exec-perms",
|
|
73
74
|
"build:dev": "rm -rf dist && tsc --sourceMap -p tsconfig.json && npm run exec-perms",
|
|
74
75
|
"build:watch": "tsc --sourceMap -p tsconfig.json -w",
|
|
75
|
-
"start": "npm run build:dev && npm link && npx @modelcontextprotocol/inspector heroku-mcp-server",
|
|
76
|
+
"start:dev": "npm run build:dev && npm link && npx @modelcontextprotocol/inspector heroku-mcp-server",
|
|
77
|
+
"start": "node dist/index.js",
|
|
76
78
|
"format": "prettier . --write --config ./.prettier.mjs",
|
|
77
79
|
"lint": "cd src && eslint ./",
|
|
78
80
|
"posttest": "npm run lint",
|