Merge pull request #39 from anthropics/fix-mcp-undefined-error
Fix MCP file operations server errors
This commit is contained in:
@@ -434,9 +434,27 @@ ${
|
|||||||
eventData.eventName === "pull_request_review_comment"
|
eventData.eventName === "pull_request_review_comment"
|
||||||
? `<comment_tool_info>
|
? `<comment_tool_info>
|
||||||
IMPORTANT: For this inline PR review comment, you have been provided with ONLY the mcp__github__update_pull_request_comment tool to update this specific review comment.
|
IMPORTANT: For this inline PR review comment, you have been provided with ONLY the mcp__github__update_pull_request_comment tool to update this specific review comment.
|
||||||
|
|
||||||
|
Tool usage example for mcp__github__update_pull_request_comment:
|
||||||
|
{
|
||||||
|
"owner": "${context.repository.split("/")[0]}",
|
||||||
|
"repo": "${context.repository.split("/")[1]}",
|
||||||
|
"commentId": ${eventData.commentId || context.claudeCommentId},
|
||||||
|
"body": "Your comment text here"
|
||||||
|
}
|
||||||
|
All four parameters (owner, repo, commentId, body) are required.
|
||||||
</comment_tool_info>`
|
</comment_tool_info>`
|
||||||
: `<comment_tool_info>
|
: `<comment_tool_info>
|
||||||
IMPORTANT: For this event type, you have been provided with ONLY the mcp__github__update_issue_comment tool to update comments.
|
IMPORTANT: For this event type, you have been provided with ONLY the mcp__github__update_issue_comment tool to update comments.
|
||||||
|
|
||||||
|
Tool usage example for mcp__github__update_issue_comment:
|
||||||
|
{
|
||||||
|
"owner": "${context.repository.split("/")[0]}",
|
||||||
|
"repo": "${context.repository.split("/")[1]}",
|
||||||
|
"commentId": ${context.claudeCommentId},
|
||||||
|
"body": "Your comment text here"
|
||||||
|
}
|
||||||
|
All four parameters (owner, repo, commentId, body) are required.
|
||||||
</comment_tool_info>`
|
</comment_tool_info>`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,6 +565,9 @@ Important Notes:
|
|||||||
- Use this spinner HTML when work is in progress: <img src="https://github.com/user-attachments/assets/5ac382c7-e004-429b-8e35-7feb3e8f9c6f" width="14px" height="14px" style="vertical-align: middle; margin-left: 4px;" />
|
- Use this spinner HTML when work is in progress: <img src="https://github.com/user-attachments/assets/5ac382c7-e004-429b-8e35-7feb3e8f9c6f" width="14px" height="14px" style="vertical-align: middle; margin-left: 4px;" />
|
||||||
${eventData.isPR && !eventData.claudeBranch ? `- Always push to the existing branch when triggered on a PR.` : `- IMPORTANT: You are already on the correct branch (${eventData.claudeBranch || "the created branch"}). Never create new branches when triggered on issues or closed/merged PRs.`}
|
${eventData.isPR && !eventData.claudeBranch ? `- Always push to the existing branch when triggered on a PR.` : `- IMPORTANT: You are already on the correct branch (${eventData.claudeBranch || "the created branch"}). Never create new branches when triggered on issues or closed/merged PRs.`}
|
||||||
- Use mcp__github_file_ops__commit_files for making commits (works for both new and existing files, single or multiple). Use mcp__github_file_ops__delete_files for deleting files (supports deleting single or multiple files atomically), or mcp__github__delete_file for deleting a single file. Edit files locally, and the tool will read the content from the same path on disk.
|
- Use mcp__github_file_ops__commit_files for making commits (works for both new and existing files, single or multiple). Use mcp__github_file_ops__delete_files for deleting files (supports deleting single or multiple files atomically), or mcp__github__delete_file for deleting a single file. Edit files locally, and the tool will read the content from the same path on disk.
|
||||||
|
Tool usage examples:
|
||||||
|
- mcp__github_file_ops__commit_files: {"files": ["path/to/file1.js", "path/to/file2.py"], "message": "feat: add new feature"}
|
||||||
|
- mcp__github_file_ops__delete_files: {"files": ["path/to/old.js"], "message": "chore: remove deprecated file"}
|
||||||
- Display the todo list as a checklist in the GitHub comment and mark things off as you go.
|
- Display the todo list as a checklist in the GitHub comment and mark things off as you go.
|
||||||
- REPOSITORY SETUP INSTRUCTIONS: The repository's CLAUDE.md file(s) contain critical repo-specific setup instructions, development guidelines, and preferences. Always read and follow these files, particularly the root CLAUDE.md, as they provide essential context for working with the codebase effectively.
|
- REPOSITORY SETUP INSTRUCTIONS: The repository's CLAUDE.md file(s) contain critical repo-specific setup instructions, development guidelines, and preferences. Always read and follow these files, particularly the root CLAUDE.md, as they provide essential context for working with the codebase effectively.
|
||||||
- Use h3 headers (###) for section titles in your comments, not h1 headers (#).
|
- Use h3 headers (###) for section titles in your comments, not h1 headers (#).
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { readFile } from "fs/promises";
|
import { readFile } from "fs/promises";
|
||||||
|
import { join } from "path";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import { GITHUB_API_URL } from "../github/api/config";
|
import { GITHUB_API_URL } from "../github/api/config";
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ type GitHubNewCommit = {
|
|||||||
const REPO_OWNER = process.env.REPO_OWNER;
|
const REPO_OWNER = process.env.REPO_OWNER;
|
||||||
const REPO_NAME = process.env.REPO_NAME;
|
const REPO_NAME = process.env.REPO_NAME;
|
||||||
const BRANCH_NAME = process.env.BRANCH_NAME;
|
const BRANCH_NAME = process.env.BRANCH_NAME;
|
||||||
|
const REPO_DIR = process.env.REPO_DIR || process.cwd();
|
||||||
|
|
||||||
if (!REPO_OWNER || !REPO_NAME || !BRANCH_NAME) {
|
if (!REPO_OWNER || !REPO_NAME || !BRANCH_NAME) {
|
||||||
console.error(
|
console.error(
|
||||||
@@ -71,18 +73,9 @@ server.tool(
|
|||||||
throw new Error("GITHUB_TOKEN environment variable is required");
|
throw new Error("GITHUB_TOKEN environment variable is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert absolute paths to relative if they match CWD
|
|
||||||
const cwd = process.cwd();
|
|
||||||
const processedFiles = files.map((filePath) => {
|
const processedFiles = files.map((filePath) => {
|
||||||
if (filePath.startsWith("/")) {
|
if (filePath.startsWith("/")) {
|
||||||
if (filePath.startsWith(cwd)) {
|
return filePath.slice(1);
|
||||||
// Strip CWD from absolute path
|
|
||||||
return filePath.slice(cwd.length + 1);
|
|
||||||
} else {
|
|
||||||
throw new Error(
|
|
||||||
`Path '${filePath}' must be relative to repository root or within current working directory`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
});
|
});
|
||||||
@@ -126,7 +119,11 @@ server.tool(
|
|||||||
// 3. Create tree entries for all files
|
// 3. Create tree entries for all files
|
||||||
const treeEntries = await Promise.all(
|
const treeEntries = await Promise.all(
|
||||||
processedFiles.map(async (filePath) => {
|
processedFiles.map(async (filePath) => {
|
||||||
const content = await readFile(filePath, "utf-8");
|
const fullPath = filePath.startsWith("/")
|
||||||
|
? filePath
|
||||||
|
: join(REPO_DIR, filePath);
|
||||||
|
|
||||||
|
const content = await readFile(fullPath, "utf-8");
|
||||||
return {
|
return {
|
||||||
path: filePath,
|
path: filePath,
|
||||||
mode: "100644",
|
mode: "100644",
|
||||||
@@ -232,13 +229,16 @@ server.tool(
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const errorMessage =
|
||||||
|
error instanceof Error ? error.message : String(error);
|
||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
type: "text",
|
type: "text",
|
||||||
text: `Error: ${error instanceof Error ? error.message : String(error)}`,
|
text: `Error: ${errorMessage}`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
error: errorMessage,
|
||||||
isError: true,
|
isError: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -423,13 +423,16 @@ server.tool(
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const errorMessage =
|
||||||
|
error instanceof Error ? error.message : String(error);
|
||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
type: "text",
|
type: "text",
|
||||||
text: `Error: ${error instanceof Error ? error.message : String(error)}`,
|
text: `Error: ${errorMessage}`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
error: errorMessage,
|
||||||
isError: true,
|
isError: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ export async function prepareMcpConfig(
|
|||||||
REPO_OWNER: owner,
|
REPO_OWNER: owner,
|
||||||
REPO_NAME: repo,
|
REPO_NAME: repo,
|
||||||
BRANCH_NAME: branch,
|
BRANCH_NAME: branch,
|
||||||
|
REPO_DIR: process.env.GITHUB_WORKSPACE || process.cwd(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user