@giantswarm-io/pro 1.11.0 → 1.11.2
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/package.json +1 -1
- package/src/lib/mcp/http.js +11 -5
- package/src/lib/mcp/tools.js +41 -7
package/package.json
CHANGED
package/src/lib/mcp/http.js
CHANGED
|
@@ -51,11 +51,15 @@ const sessions = {};
|
|
|
51
51
|
* @param {Object} options
|
|
52
52
|
* @param {number} options.port - Port to listen on (default: 8080; 0 picks a free port)
|
|
53
53
|
* @param {string} options.endpoint - MCP endpoint path (default: /mcp)
|
|
54
|
+
* @param {number} options.sessionTtlMs - Idle time after which a session is evicted (default: 30 minutes)
|
|
55
|
+
* @param {number} options.sessionSweepIntervalMs - How often idle sessions are swept (default: 5 minutes)
|
|
54
56
|
* @returns {Promise<import('http').Server>} the listening server
|
|
55
57
|
*/
|
|
56
58
|
export async function startHTTPServer(options = {}) {
|
|
57
59
|
const port = options.port ?? (parseInt(process.env.HTTP_PORT, 10) || DEFAULT_PORT);
|
|
58
60
|
const endpoint = options.endpoint || DEFAULT_ENDPOINT;
|
|
61
|
+
const sessionTtlMs = options.sessionTtlMs ?? SESSION_TTL_MS;
|
|
62
|
+
const sessionSweepIntervalMs = options.sessionSweepIntervalMs ?? SESSION_SWEEP_INTERVAL_MS;
|
|
59
63
|
|
|
60
64
|
const app = express();
|
|
61
65
|
// Trust exactly 1 proxy hop (Envoy Gateway). express-rate-limit requires
|
|
@@ -208,11 +212,13 @@ export async function startHTTPServer(options = {}) {
|
|
|
208
212
|
await transport.handleRequest(req, res, req.body);
|
|
209
213
|
return;
|
|
210
214
|
} else if (sessionId) {
|
|
211
|
-
// Session ID provided but not found — expired or invalid
|
|
212
|
-
|
|
215
|
+
// Session ID provided but not found — expired or invalid. The MCP
|
|
216
|
+
// spec (Streamable HTTP, session management) requires 404 here: it is
|
|
217
|
+
// the client's signal to start a new session with a fresh initialize.
|
|
218
|
+
res.status(404).json({
|
|
213
219
|
jsonrpc: '2.0',
|
|
214
220
|
error: {
|
|
215
|
-
code: -
|
|
221
|
+
code: -32001,
|
|
216
222
|
message: 'Session not found or expired'
|
|
217
223
|
},
|
|
218
224
|
id: null
|
|
@@ -246,7 +252,7 @@ export async function startHTTPServer(options = {}) {
|
|
|
246
252
|
const sweepInterval = setInterval(() => {
|
|
247
253
|
const now = Date.now();
|
|
248
254
|
for (const sessionId in sessions) {
|
|
249
|
-
if (now - sessions[sessionId].lastActivity >
|
|
255
|
+
if (now - sessions[sessionId].lastActivity > sessionTtlMs) {
|
|
250
256
|
logger.info(`Evicting idle session: ${sessionId}`);
|
|
251
257
|
try {
|
|
252
258
|
sessions[sessionId].transport.close();
|
|
@@ -256,7 +262,7 @@ export async function startHTTPServer(options = {}) {
|
|
|
256
262
|
delete sessions[sessionId];
|
|
257
263
|
}
|
|
258
264
|
}
|
|
259
|
-
},
|
|
265
|
+
}, sessionSweepIntervalMs);
|
|
260
266
|
sweepInterval.unref();
|
|
261
267
|
|
|
262
268
|
// Start listening
|
package/src/lib/mcp/tools.js
CHANGED
|
@@ -388,7 +388,7 @@ export async function handleUpdateIssueField(args, extra) {
|
|
|
388
388
|
export const createIssueInProjectTool = {
|
|
389
389
|
name: 'create_issue_in_project',
|
|
390
390
|
annotations: additiveWrite(),
|
|
391
|
-
description: 'Create a new GitHub Issue in a specified repository and add it to a project board. Supports optional initial status, assignees, and labels. For public repos, only create sanitized, non-customer-specific content. If applying labels fails after the issue has already been created and added to the board, the issue is NOT rolled back -- the response reports success with a `warning` explaining that labels were not applied.',
|
|
391
|
+
description: 'Create a new GitHub Issue in a specified repository and add it to a project board. Supports optional initial status, assignees, and labels. For public repos, only create sanitized, non-customer-specific content. If applying labels fails after the issue has already been created and added to the board, the issue is NOT rolled back -- the response reports success with a `warning` explaining that labels were not applied. If GitHub refuses the creation (the token lacks issues:write on the repository, e.g. a GitHub App token outside its installation), the error names the repository and the missing permission and no issue is created.',
|
|
392
392
|
inputSchema: {
|
|
393
393
|
type: 'object',
|
|
394
394
|
properties: {
|
|
@@ -432,6 +432,31 @@ export const createIssueInProjectTool = {
|
|
|
432
432
|
}
|
|
433
433
|
};
|
|
434
434
|
|
|
435
|
+
/**
|
|
436
|
+
* Whether a GitHub API error is a permission refusal: GraphQL reports it as a
|
|
437
|
+
* FORBIDDEN error ("Resource not accessible by integration" for a GitHub App
|
|
438
|
+
* token outside its installation's repositories or permissions), REST as 403.
|
|
439
|
+
* @param {Error} error
|
|
440
|
+
* @returns {boolean}
|
|
441
|
+
*/
|
|
442
|
+
export function isPermissionRefusal(error) {
|
|
443
|
+
return error?.status === 403 ||
|
|
444
|
+
(Array.isArray(error?.errors) && error.errors.some(e => e?.type === 'FORBIDDEN')) ||
|
|
445
|
+
/Resource not accessible by integration/i.test(error?.message || '');
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* The error returned when GitHub refuses to create an issue in a repository.
|
|
450
|
+
* @param {string} owner
|
|
451
|
+
* @param {string} repo
|
|
452
|
+
* @returns {string}
|
|
453
|
+
*/
|
|
454
|
+
export function issueCreationRefusedMessage(owner, repo) {
|
|
455
|
+
return `No issue was created: GitHub refused to create an issue in ${owner}/${repo} because the token lacks the issues:write permission there. ` +
|
|
456
|
+
'A token issued by a GitHub App (for example through muster\'s GitHub sign-in) can only write to the repositories the App\'s installation covers; ' +
|
|
457
|
+
`ask an organization owner to add ${owner}/${repo} to that installation, or create the issue elsewhere and use add_existing_issue.`;
|
|
458
|
+
}
|
|
459
|
+
|
|
435
460
|
export async function handleCreateIssueInProject(args, extra) {
|
|
436
461
|
try {
|
|
437
462
|
const token = extractToken(extra);
|
|
@@ -494,12 +519,21 @@ export async function handleCreateIssueInProject(args, extra) {
|
|
|
494
519
|
}
|
|
495
520
|
|
|
496
521
|
// Create the issue
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
522
|
+
let createResult;
|
|
523
|
+
try {
|
|
524
|
+
createResult = await graphQLWithAuth(CREATE_ISSUE_MUTATION, {
|
|
525
|
+
repositoryId,
|
|
526
|
+
title: args.title,
|
|
527
|
+
body: args.body || '',
|
|
528
|
+
assigneeIds: assigneeIds.length > 0 ? assigneeIds : undefined
|
|
529
|
+
}, token);
|
|
530
|
+
} catch (error) {
|
|
531
|
+
if (isPermissionRefusal(error)) {
|
|
532
|
+
logger.error('MCP: Issue creation refused', { repository: `${owner}/${repo}`, error: error.message });
|
|
533
|
+
return { error: issueCreationRefusedMessage(owner, repo) };
|
|
534
|
+
}
|
|
535
|
+
throw error;
|
|
536
|
+
}
|
|
503
537
|
|
|
504
538
|
const issue = createResult.createIssue.issue;
|
|
505
539
|
|