Skip to content

Commit 77545ec

Browse files
committed
clean up stdio for mcp server, remove emojis from logging, clarify docs
1 parent 3778e3e commit 77545ec

File tree

12 files changed

+45
-39
lines changed

12 files changed

+45
-39
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ GITHUB_APP_PRIVATE_KEY=your_github_app_private_key_base64_encoded
66
GITHUB_APP_PRIVATE_KEY_PATH=./private-key.pem
77
GITHUB_WEBHOOK_SECRET=your_webhook_secret
88
GITHUB_BASE_URL=https://github.com
9+
# Working directory where the app runs
910
GITHUB_APP_CWD=/Users/username/project/your-repo
1011

1112
# Server Configuration

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ A GitHub App for automated code reviews using Hono.js and Amp.
1111
- **Check Runs**: Integration with GitHub's check runs API for status reporting
1212
- **MCP Server**: Model Context Protocol server for AI agent integration
1313

14+
**Requirements**: Amp account with API key required for code reviews.
15+
1416
## Quick Start
1517

1618
### Local Development
@@ -75,6 +77,7 @@ A GitHub App for automated code reviews using Hono.js and Amp.
7577
- Repository: Checks (Write)
7678
- Repository: Contents (Read)
7779
- Repository: Metadata (Read)
80+
- Repository: Webhooks (Write)
7881
3. **Configure webhook settings:**
7982
- Webhook URL: `https://your-domain.com/github/webhook` (use your APP_BASE_URL)
8083
- Subscribe to: Pull request events and Installation events
@@ -94,14 +97,16 @@ The GitHub App requires a private key for authentication. You have two options:
9497
3. Set `GITHUB_APP_PRIVATE_KEY_PATH=./private-key.pem`
9598
4. Add `*.pem` to your `.gitignore` to avoid committing the key
9699

97-
#### Option 2: Environment Variable (Recommended for production)
100+
#### Option 2: Environment Variable (Recommended for production/Docker)
98101
1. Convert your private key to base64:
99102
```bash
100103
cat private-key.pem | base64 -w 0
101104
```
102105
2. Set the result as `GITHUB_APP_PRIVATE_KEY` in your environment
103106
3. The application will automatically decode and format the key
104107

108+
**Note**: Docker setup requires the base64 encoded key in `.env` - private key files are not accessible in containers.
109+
105110
### Configuration File (config.yml)
106111

107112
Contains GitHub settings, queue configuration, server settings, Amp integration, and the AI review prompt. Environment variables are interpolated using `${VARIABLE_NAME}` syntax.

config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ amp:
3131
command: "sh"
3232
args:
3333
- "-c"
34-
- "cd ${GITHUB_APP_CWD} && node dist/mcp/server.js 2>&1 | tee /tmp/mcp-server.log"
34+
- "cd ${GITHUB_APP_CWD} && node dist/mcp/server.js 2>/tmp/mcp-server.log"
3535
env:
3636
GITHUB_APP_CWD: "${GITHUB_APP_CWD}"
3737
GITHUB_APP_ID: "${GITHUB_APP_ID}"

src/github/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class GitHubClient {
4949
'Authorization': `Bearer ${token}`,
5050
};
5151
} catch (error) {
52-
console.error('Failed to get installation token:', error);
52+
console.error('Failed to get installation token:', error);
5353
throw error;
5454
}
5555
} else {

src/github/process-review.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export async function processReview(
8282

8383
if (fs.existsSync(commentsFilePath)) {
8484
try {
85-
console.log(`📖 Reading collected comments from ${commentsFilePath}`);
85+
console.log(`Reading collected comments from ${commentsFilePath}`);
8686
const fileContent = fs.readFileSync(commentsFilePath, 'utf8').trim();
8787

8888
if (fileContent) {
@@ -94,7 +94,7 @@ export async function processReview(
9494

9595
// TODO(sayans): GitHub API allows <= 30 comments per review, so we need to add splitting logic if there are > 30 comments
9696

97-
console.log(`📝 Collected ${inlineComments.length} inline comments and ${generalComments.length} general comments`);
97+
console.log(`Collected ${inlineComments.length} inline comments and ${generalComments.length} general comments`);
9898

9999
// Create review summary from general comments
100100
let reviewSummary = generalComments.length > 0
@@ -108,7 +108,7 @@ export async function processReview(
108108
}
109109

110110
// Post aggregated review
111-
console.log('📋 Posting aggregated PR review...');
111+
console.log('Posting aggregated PR review...');
112112
await githubClient.createPRReview(
113113
owner,
114114
repo,
@@ -123,20 +123,20 @@ export async function processReview(
123123
: comment.message
124124
}))
125125
);
126-
console.log('PR review posted successfully');
126+
console.log('PR review posted successfully');
127127
} else {
128-
console.log('📝 No comments collected, skipping review creation');
128+
console.log('No comments collected, skipping review creation');
129129
}
130130

131131
// Clean up the comments file
132132
fs.unlinkSync(commentsFilePath);
133-
console.log('🗑️ Cleaned up comments file');
133+
console.log('Cleaned up comments file');
134134

135135
} catch (error) {
136-
console.error('Failed to read or process comments file:', error);
136+
console.error('Failed to read or process comments file:', error);
137137
}
138138
} else {
139-
console.log('📝 No comments file found, skipping review creation');
139+
console.log('No comments file found, skipping review creation');
140140
}
141141

142142
// Update check run with success (simplified since review details are now in PR review)

src/mcp/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ amp:
4444
amp.mcpServers:
4545
github:
4646
command: "sh"
47-
args: ["-c", "cd ${GITHUB_APP_CWD} && pnpm run mcp"]
47+
args: ["-c", "cd ${GITHUB_APP_CWD} && node dist/mcp/server.js"]
4848
env:
4949
GITHUB_APP_CWD: "${GITHUB_APP_CWD}"
5050
GITHUB_APP_ID: "${GITHUB_APP_ID}"

src/mcp/comment-collector.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ export function initializeCollector(): FileBasedCommentCollector | null {
5151
const commentsFile = process.env.COMMENTS_FILE;
5252

5353
if (!commentsFile) {
54-
console.log('📝 No COMMENTS_FILE environment variable, collector not initialized');
54+
console.error('No COMMENTS_FILE environment variable, collector not initialized');
5555
return null;
5656
}
5757

5858
try {
5959
globalCollector = new FileBasedCommentCollector(commentsFile);
60-
console.log('📝 Comment collector initialized with file:', commentsFile);
60+
console.error('Comment collector initialized with file:', commentsFile);
6161
return globalCollector;
6262
} catch (error) {
63-
console.error('Failed to initialize comment collector:', error);
63+
console.error('Failed to initialize comment collector:', error);
6464
return null;
6565
}
6666
}

src/mcp/server.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class GitHubMCPServer {
2626
private config: Config;
2727

2828
constructor() {
29-
console.log('🚀 Initializing GitHub MCP Server...');
29+
console.error('Initializing GitHub MCP Server...');
3030
this.server = new Server(
3131
{
3232
name: 'github-cra',
@@ -45,9 +45,9 @@ class GitHubMCPServer {
4545
}
4646

4747
private setupToolHandlers(): void {
48-
console.log('🔨 Setting up tool handlers...');
48+
console.error('Setting up tool handlers...');
4949
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
50-
console.log('📋 ListTools request received - returning available tools');
50+
console.error('ListTools request received - returning available tools');
5151
return {
5252
tools: [
5353
{
@@ -118,17 +118,17 @@ class GitHubMCPServer {
118118

119119
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
120120
const { name, arguments: args } = request.params;
121-
console.log(`🔧 MCP Tool called: ${name}`);
122-
console.log(`📝 Tool arguments:`, JSON.stringify(args, null, 2));
121+
console.error(`MCP Tool called: ${name}`);
122+
console.error(`Tool arguments:`, JSON.stringify(args, null, 2));
123123
const startTime = Date.now();
124124

125125
try {
126126
switch (name) {
127127
case 'leave_general_comment': {
128-
console.log(`🗨️ Executing leave_general_comment...`);
128+
console.error(`Executing leave_general_comment...`);
129129
const validatedArgs = validateLeaveGeneralCommentArgs(args);
130130
const result = await leaveGeneralComment(validatedArgs);
131-
console.log(`✅ leave_general_comment completed in ${Date.now() - startTime}ms`);
131+
console.error(`leave_general_comment completed in ${Date.now() - startTime}ms`);
132132
return {
133133
content: [
134134
{
@@ -140,10 +140,10 @@ class GitHubMCPServer {
140140
}
141141

142142
case 'leave_inline_comment': {
143-
console.log(`📝 Executing leave_inline_comment...`);
143+
console.error(`Executing leave_inline_comment...`);
144144
const validatedArgs = validateLeaveInlineCommentArgs(args);
145145
const result = await leaveInlineComment(validatedArgs);
146-
console.log(`✅ leave_inline_comment completed in ${Date.now() - startTime}ms`);
146+
console.error(`leave_inline_comment completed in ${Date.now() - startTime}ms`);
147147
return {
148148
content: [
149149
{
@@ -156,13 +156,13 @@ class GitHubMCPServer {
156156

157157

158158
case 'get_pr_comments': {
159-
console.log(`💬 Executing get_pr_comments...`);
159+
console.error(`Executing get_pr_comments...`);
160160
const validatedArgs = validateGetPRCommentsArgs(args);
161161
const result = await getPRComments(
162162
validatedArgs,
163163
this.config
164164
);
165-
console.log(`✅ get_pr_comments completed in ${Date.now() - startTime}ms`);
165+
console.error(`get_pr_comments completed in ${Date.now() - startTime}ms`);
166166
return {
167167
content: [
168168
{
@@ -174,14 +174,14 @@ class GitHubMCPServer {
174174
}
175175

176176
default:
177-
console.log(`❌ Unknown tool requested: ${name}`);
177+
console.error(`Unknown tool requested: ${name}`);
178178
throw new McpError(
179179
ErrorCode.MethodNotFound,
180180
`Unknown tool: ${name}`
181181
);
182182
}
183183
} catch (error) {
184-
console.log(`❌ Tool execution failed for ${name} after ${Date.now() - startTime}ms:`, error);
184+
console.error(`Tool execution failed for ${name} after ${Date.now() - startTime}ms:`, error);
185185
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
186186
throw new McpError(
187187
ErrorCode.InternalError,
@@ -192,12 +192,12 @@ class GitHubMCPServer {
192192
}
193193

194194
async run(): Promise<void> {
195-
console.log('🔌 Starting MCP server connection...');
196-
console.log('📡 Creating stdio transport...');
195+
console.error('Starting MCP server connection...');
196+
console.error('Creating stdio transport...');
197197
const transport = new StdioServerTransport();
198-
console.log('🔗 Connecting to transport...');
198+
console.error('Connecting to transport...');
199199
await this.server.connect(transport);
200-
console.error('🟢 GitHub MCP server running on stdio - ready to receive requests');
200+
console.error('GitHub MCP server running on stdio - ready to receive requests');
201201
}
202202
}
203203

src/mcp/tools/leave_general_comment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export async function leaveGeneralComment(
1010
try {
1111
const { message } = args;
1212

13-
console.log('📝 Collecting general comment for later review');
13+
console.error('Collecting general comment for later review');
1414

1515
const collector = getCollector();
1616
if (collector) {
1717
collector.addGeneralComment(message);
1818
} else {
19-
console.log('⚠️ No collector available, comment will be skipped');
19+
console.error('No collector available, comment will be skipped');
2020
}
2121

2222
return {

src/mcp/tools/leave_inline_comment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ export async function leaveInlineComment(
1313
try {
1414
const { message, path, line, suggested_fix } = args;
1515

16-
console.log('📝 Collecting inline comment for later review:', { path, line, hasSuggestion: !!suggested_fix });
16+
console.error('Collecting inline comment for later review:', { path, line, hasSuggestion: !!suggested_fix });
1717

1818
const collector = getCollector();
1919
if (collector) {
2020
collector.addInlineComment(path, line, message, suggested_fix);
2121
} else {
22-
console.log('⚠️ No collector available, comment will be skipped');
22+
console.error('No collector available, comment will be skipped');
2323
}
2424

2525
return {

0 commit comments

Comments
 (0)