Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c6c1210fa0 | |||
| 0368512b9e |
+8
-1
@@ -165,8 +165,15 @@ export class ClaudeAgent implements Agent {
|
|||||||
*/
|
*/
|
||||||
function processJSONChunk(chunk: string, agent?: ClaudeAgent): void {
|
function processJSONChunk(chunk: string, agent?: ClaudeAgent): void {
|
||||||
try {
|
try {
|
||||||
|
// Skip debug lines that start with [DEBUG] or [debug]
|
||||||
|
const trimmedChunk = chunk.trim();
|
||||||
|
if (trimmedChunk.startsWith("[DEBUG]") || trimmedChunk.startsWith("[debug]")) {
|
||||||
|
console.log(chunk);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(chunk);
|
console.log(chunk);
|
||||||
const parsedChunk = JSON.parse(chunk.trim());
|
const parsedChunk = JSON.parse(trimmedChunk);
|
||||||
|
|
||||||
switch (parsedChunk.type) {
|
switch (parsedChunk.type) {
|
||||||
case "system":
|
case "system":
|
||||||
|
|||||||
@@ -3,4 +3,6 @@ import { mcpServerName } from "../mcp/config.ts";
|
|||||||
export const instructions = `- use the ${mcpServerName} MCP server to interact with github
|
export const instructions = `- use the ${mcpServerName} MCP server to interact with github
|
||||||
- if ${mcpServerName} is not available or doesn't include the functionality you need, describe why and bail
|
- if ${mcpServerName} is not available or doesn't include the functionality you need, describe why and bail
|
||||||
- do not under any circumstances use the gh cli
|
- do not under any circumstances use the gh cli
|
||||||
|
- if prompted by a comment to respond to create a new issue, pr or anything else, after succeeding,
|
||||||
|
also respond to the original comment with a very brief message containing a link to it
|
||||||
`;
|
`;
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
add a comment containing your best frog joke to GitHub issue https://github.com/pullfrogai/scratch/issues/2
|
create a PR implementing bogosort to https://github.com/pullfrogai/scratch/
|
||||||
|
|||||||
+15
-41
@@ -1,5 +1,5 @@
|
|||||||
import { type } from "arktype";
|
import { type } from "arktype";
|
||||||
import { getMcpContext, tool } from "./shared.ts";
|
import { contextualize, tool } from "./shared.ts";
|
||||||
|
|
||||||
export const Comment = type({
|
export const Comment = type({
|
||||||
issueNumber: type.number.describe("the issue number to comment on"),
|
issueNumber: type.number.describe("the issue number to comment on"),
|
||||||
@@ -10,45 +10,19 @@ export const CommentTool = tool({
|
|||||||
name: "create_issue_comment",
|
name: "create_issue_comment",
|
||||||
description: "Create a comment on a GitHub issue",
|
description: "Create a comment on a GitHub issue",
|
||||||
parameters: Comment,
|
parameters: Comment,
|
||||||
execute: async ({ issueNumber, body }) => {
|
execute: contextualize(async ({ issueNumber, body }, ctx) => {
|
||||||
const ctx = getMcpContext();
|
const result = await ctx.octokit.rest.issues.createComment({
|
||||||
try {
|
owner: ctx.owner,
|
||||||
const result = await ctx.octokit.rest.issues.createComment({
|
repo: ctx.name,
|
||||||
owner: ctx.owner,
|
issue_number: issueNumber,
|
||||||
repo: ctx.name,
|
body: body,
|
||||||
issue_number: issueNumber,
|
});
|
||||||
body: body,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content: [
|
success: true,
|
||||||
{
|
commentId: result.data.id,
|
||||||
type: "text",
|
url: result.data.html_url,
|
||||||
text: JSON.stringify(
|
body: result.data.body,
|
||||||
{
|
};
|
||||||
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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { type } from "arktype";
|
||||||
|
import { contextualize, tool } from "./shared.ts";
|
||||||
|
|
||||||
|
export const Issue = type({
|
||||||
|
title: type.string.describe("the title of the issue"),
|
||||||
|
body: type.string.describe("the body content of the issue"),
|
||||||
|
labels: type.string
|
||||||
|
.array()
|
||||||
|
.describe("optional array of label names to apply to the issue")
|
||||||
|
.optional(),
|
||||||
|
assignees: type.string
|
||||||
|
.array()
|
||||||
|
.describe("optional array of usernames to assign to the issue")
|
||||||
|
.optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const IssueTool = tool({
|
||||||
|
name: "create_issue",
|
||||||
|
description: "Create a new GitHub issue",
|
||||||
|
parameters: Issue,
|
||||||
|
execute: contextualize(async ({ title, body, labels, assignees }, ctx) => {
|
||||||
|
const result = await ctx.octokit.rest.issues.create({
|
||||||
|
owner: ctx.owner,
|
||||||
|
repo: ctx.name,
|
||||||
|
title: title,
|
||||||
|
body: body,
|
||||||
|
labels: labels ?? [],
|
||||||
|
assignees: assignees ?? [],
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
issueId: result.data.id,
|
||||||
|
number: result.data.number,
|
||||||
|
url: result.data.html_url,
|
||||||
|
title: result.data.title,
|
||||||
|
state: result.data.state,
|
||||||
|
labels: result.data.labels?.map((label) => (typeof label === "string" ? label : label.name)),
|
||||||
|
assignees: result.data.assignees?.map((assignee) => assignee.login),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
});
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { execSync } from "node:child_process";
|
||||||
|
import { type } from "arktype";
|
||||||
|
import { contextualize, tool } from "./shared.ts";
|
||||||
|
|
||||||
|
export const PullRequest = type({
|
||||||
|
title: type.string.describe("the title of the pull request"),
|
||||||
|
body: type.string.describe("the body content of the pull request"),
|
||||||
|
base: type.string.describe("the base branch to merge into (e.g., 'main')"),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const PullRequestTool = tool({
|
||||||
|
name: "create_pull_request",
|
||||||
|
description: "Create a pull request from the current branch",
|
||||||
|
parameters: PullRequest,
|
||||||
|
execute: contextualize(async ({ title, body, base }, ctx) => {
|
||||||
|
// Get the current branch name
|
||||||
|
const currentBranch = execSync("git rev-parse --abbrev-ref HEAD", {
|
||||||
|
encoding: "utf8",
|
||||||
|
}).trim();
|
||||||
|
|
||||||
|
console.log(`Current branch: ${currentBranch}`);
|
||||||
|
|
||||||
|
const result = await ctx.octokit.rest.pulls.create({
|
||||||
|
owner: ctx.owner,
|
||||||
|
repo: ctx.name,
|
||||||
|
title: title,
|
||||||
|
body: body,
|
||||||
|
head: currentBranch,
|
||||||
|
base: base,
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
pullRequestId: result.data.id,
|
||||||
|
number: result.data.number,
|
||||||
|
url: result.data.html_url,
|
||||||
|
title: result.data.title,
|
||||||
|
head: result.data.head.ref,
|
||||||
|
base: result.data.base.ref,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
});
|
||||||
+3
-1
@@ -2,6 +2,8 @@
|
|||||||
// Minimal GitHub Issue Comment MCP Server
|
// Minimal GitHub Issue Comment MCP Server
|
||||||
import { FastMCP } from "fastmcp";
|
import { FastMCP } from "fastmcp";
|
||||||
import { CommentTool } from "./comment.ts";
|
import { CommentTool } from "./comment.ts";
|
||||||
|
import { IssueTool } from "./issue.ts";
|
||||||
|
import { PullRequestTool } from "./pr.ts";
|
||||||
import { addTools } from "./shared.ts";
|
import { addTools } from "./shared.ts";
|
||||||
|
|
||||||
const server = new FastMCP({
|
const server = new FastMCP({
|
||||||
@@ -9,6 +11,6 @@ const server = new FastMCP({
|
|||||||
version: "0.0.1",
|
version: "0.0.1",
|
||||||
});
|
});
|
||||||
|
|
||||||
addTools(server, [CommentTool]);
|
addTools(server, [CommentTool, IssueTool, PullRequestTool]);
|
||||||
|
|
||||||
server.start();
|
server.start();
|
||||||
|
|||||||
@@ -4,6 +4,15 @@ import type { StandardSchemaV1 } from "@standard-schema/spec";
|
|||||||
import type { FastMCP, Tool } from "fastmcp";
|
import type { FastMCP, Tool } from "fastmcp";
|
||||||
import { parseRepoContext, type RepoContext } from "../utils/github.ts";
|
import { parseRepoContext, type RepoContext } from "../utils/github.ts";
|
||||||
|
|
||||||
|
export interface ToolResult {
|
||||||
|
content: {
|
||||||
|
type: "text";
|
||||||
|
text: string;
|
||||||
|
}[];
|
||||||
|
error?: string;
|
||||||
|
isError?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export const getMcpContext = cached((): McpContext => {
|
export const getMcpContext = cached((): McpContext => {
|
||||||
const githubInstallationToken = process.env.GITHUB_INSTALLATION_TOKEN;
|
const githubInstallationToken = process.env.GITHUB_INSTALLATION_TOKEN;
|
||||||
if (!githubInstallationToken) {
|
if (!githubInstallationToken) {
|
||||||
@@ -30,3 +39,40 @@ export const addTools = (server: FastMCP, tools: Tool<any, any>[]) => {
|
|||||||
}
|
}
|
||||||
return server;
|
return server;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const contextualize =
|
||||||
|
<T>(executor: (params: T, ctx: McpContext) => Promise<Record<string, any>>) =>
|
||||||
|
async (params: T): Promise<ToolResult> => {
|
||||||
|
try {
|
||||||
|
const ctx = getMcpContext();
|
||||||
|
const result = await executor(params, ctx);
|
||||||
|
return handleToolSuccess(result);
|
||||||
|
} catch (error) {
|
||||||
|
return handleToolError(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleToolSuccess = (data: Record<string, any>): ToolResult => {
|
||||||
|
return {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: JSON.stringify(data, null, 2),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleToolError = (error: unknown): ToolResult => {
|
||||||
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||||
|
return {
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: `Error: ${errorMessage}`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
error: errorMessage,
|
||||||
|
isError: true,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pullfrog/action",
|
"name": "@pullfrog/action",
|
||||||
"version": "0.0.52",
|
"version": "0.0.54",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"files": [
|
"files": [
|
||||||
"index.js",
|
"index.js",
|
||||||
|
|||||||
Reference in New Issue
Block a user