93 lines
2.4 KiB
JavaScript
93 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
// Minimal GitHub Issue Comment MCP Server
|
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
import { Octokit } from "@octokit/rest";
|
|
import { type } from "arktype";
|
|
import { z } from "zod";
|
|
import { resolveRepoContext } from "../utils/repo-context.ts";
|
|
|
|
const server = new McpServer({
|
|
name: "Minimal GitHub Issue Comment Server",
|
|
version: "0.0.1",
|
|
});
|
|
|
|
// Define the schema for creating issue comments
|
|
const Comment = type({
|
|
issueNumber: type.number.describe("the issue number to comment on"),
|
|
body: type.string.describe("the comment body content"),
|
|
});
|
|
|
|
server.tool(
|
|
"create_issue_comment",
|
|
"Create a comment on a GitHub issue",
|
|
{
|
|
issueNumber: z.number().describe("the issue number to comment on"),
|
|
body: z.string().describe("the comment body content"),
|
|
},
|
|
async ({ issueNumber, body }) => {
|
|
try {
|
|
Comment.assert({ issueNumber, body });
|
|
|
|
const githubInstallationToken = process.env.GITHUB_INSTALLATION_TOKEN;
|
|
if (!githubInstallationToken) {
|
|
throw new Error("GITHUB_INSTALLATION_TOKEN environment variable is required");
|
|
}
|
|
|
|
// Resolve repository context from environment
|
|
const repoContext = resolveRepoContext();
|
|
|
|
const octokit = new Octokit({
|
|
auth: githubInstallationToken,
|
|
});
|
|
|
|
const result = await octokit.rest.issues.createComment({
|
|
owner: repoContext.owner,
|
|
repo: repoContext.name,
|
|
issue_number: issueNumber,
|
|
body: body,
|
|
});
|
|
|
|
return {
|
|
content: [
|
|
{
|
|
type: "text",
|
|
text: JSON.stringify(
|
|
{
|
|
success: true,
|
|
commentId: result.data.id,
|
|
url: result.data.html_url,
|
|
body: result.data.body,
|
|
},
|
|
null,
|
|
2
|
|
),
|
|
},
|
|
],
|
|
};
|
|
} catch (error) {
|
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
return {
|
|
content: [
|
|
{
|
|
type: "text",
|
|
text: `Error creating comment: ${errorMessage}`,
|
|
},
|
|
],
|
|
error: errorMessage,
|
|
isError: true,
|
|
};
|
|
}
|
|
}
|
|
);
|
|
|
|
async function runServer() {
|
|
const transport = new StdioServerTransport();
|
|
await server.connect(transport);
|
|
process.on("exit", () => {
|
|
server.close();
|
|
});
|
|
}
|
|
|
|
await runServer();
|