Skip to content

Commit e2f51dd

Browse files
authored
Merge branch 'main' into patch-1
2 parents 263789a + b2ee7cd commit e2f51dd

File tree

8 files changed

+173
-31
lines changed

8 files changed

+173
-31
lines changed

filesystem/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,16 @@ Node.js server implementing Model Context Protocol (MCP) for filesystem operatio
4141
- Features:
4242
- Line-based and multi-line content matching
4343
- Whitespace normalization with indentation preservation
44-
- Fuzzy matching with confidence scoring
4544
- Multiple simultaneous edits with correct positioning
4645
- Indentation style detection and preservation
4746
- Git-style diff output with context
4847
- Preview changes with dry run mode
49-
- Failed match debugging with confidence scores
5048
- Inputs:
5149
- `path` (string): File to edit
5250
- `edits` (array): List of edit operations
5351
- `oldText` (string): Text to search for (can be substring)
5452
- `newText` (string): Text to replace with
5553
- `dryRun` (boolean): Preview changes without applying (default: false)
56-
- `options` (object): Optional formatting settings
57-
- `preserveIndentation` (boolean): Keep existing indentation (default: true)
58-
- `normalizeWhitespace` (boolean): Normalize spaces while preserving structure (default: true)
59-
- `partialMatch` (boolean): Enable fuzzy matching (default: true)
6054
- Returns detailed diff and match information for dry runs, otherwise applies changes
6155
- Best Practice: Always use dryRun first to preview changes before applying them
6256

filesystem/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const allowedDirectories = args.map(dir =>
4242
// Validate that all directories exist and are accessible
4343
await Promise.all(args.map(async (dir) => {
4444
try {
45-
const stats = await fs.stat(dir);
45+
const stats = await fs.stat(expandHome(dir));
4646
if (!stats.isDirectory()) {
4747
console.error(`Error: ${dir} is not a directory`);
4848
process.exit(1);

git/uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/common/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export const GitHubLabelSchema = z.object({
157157
name: z.string(),
158158
color: z.string(),
159159
default: z.boolean(),
160-
description: z.string().optional(),
160+
description: z.string().nullable().optional(),
161161
});
162162

163163
export const GitHubMilestoneSchema = z.object({

github/index.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "@modelcontextprotocol/sdk/types.js";
88
import { z } from 'zod';
99
import { zodToJsonSchema } from 'zod-to-json-schema';
10+
import fetch, { Request, Response } from 'node-fetch';
1011

1112
import * as repository from './operations/repository.js';
1213
import * as files from './operations/files.js';
@@ -27,6 +28,11 @@ import {
2728
} from './common/errors.js';
2829
import { VERSION } from "./common/version.js";
2930

31+
// If fetch doesn't exist in global scope, add it
32+
if (!globalThis.fetch) {
33+
globalThis.fetch = fetch as unknown as typeof global.fetch;
34+
}
35+
3036
const server = new Server(
3137
{
3238
name: "github-mcp-server",
@@ -293,10 +299,39 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
293299
case "create_issue": {
294300
const args = issues.CreateIssueSchema.parse(request.params.arguments);
295301
const { owner, repo, ...options } = args;
296-
const issue = await issues.createIssue(owner, repo, options);
297-
return {
298-
content: [{ type: "text", text: JSON.stringify(issue, null, 2) }],
299-
};
302+
303+
try {
304+
console.error(`[DEBUG] Attempting to create issue in ${owner}/${repo}`);
305+
console.error(`[DEBUG] Issue options:`, JSON.stringify(options, null, 2));
306+
307+
const issue = await issues.createIssue(owner, repo, options);
308+
309+
console.error(`[DEBUG] Issue created successfully`);
310+
return {
311+
content: [{ type: "text", text: JSON.stringify(issue, null, 2) }],
312+
};
313+
} catch (err) {
314+
// Type guard for Error objects
315+
const error = err instanceof Error ? err : new Error(String(err));
316+
317+
console.error(`[ERROR] Failed to create issue:`, error);
318+
319+
if (error instanceof GitHubResourceNotFoundError) {
320+
throw new Error(
321+
`Repository '${owner}/${repo}' not found. Please verify:\n` +
322+
`1. The repository exists\n` +
323+
`2. You have correct access permissions\n` +
324+
`3. The owner and repository names are spelled correctly`
325+
);
326+
}
327+
328+
// Safely access error properties
329+
throw new Error(
330+
`Failed to create issue: ${error.message}${
331+
error.stack ? `\nStack: ${error.stack}` : ''
332+
}`
333+
);
334+
}
300335
}
301336

302337
case "create_pull_request": {

gitlab/schemas.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ export const GitLabRepositorySchema = z.object({
2222
name: z.string(),
2323
path_with_namespace: z.string(), // Changed from full_name to match GitLab API
2424
visibility: z.string(), // Changed from private to match GitLab API
25-
owner: GitLabOwnerSchema,
25+
owner: GitLabOwnerSchema.optional(),
2626
web_url: z.string(), // Changed from html_url to match GitLab API
2727
description: z.string().nullable(),
28-
fork: z.boolean(),
28+
fork: z.boolean().optional(),
2929
ssh_url_to_repo: z.string(), // Changed from ssh_url to match GitLab API
3030
http_url_to_repo: z.string(), // Changed from clone_url to match GitLab API
3131
created_at: z.string(),
@@ -218,12 +218,12 @@ export const GitLabMergeRequestSchema = z.object({
218218
title: z.string(),
219219
description: z.string(), // Changed from body to match GitLab API
220220
state: z.string(),
221-
merged: z.boolean(),
221+
merged: z.boolean().optional(),
222222
author: GitLabUserSchema,
223223
assignees: z.array(GitLabUserSchema),
224224
source_branch: z.string(), // Changed from head to match GitLab API
225225
target_branch: z.string(), // Changed from base to match GitLab API
226-
diff_refs: GitLabMergeRequestDiffRefSchema,
226+
diff_refs: GitLabMergeRequestDiffRefSchema.nullable(),
227227
web_url: z.string(), // Changed from html_url to match GitLab API
228228
created_at: z.string(),
229229
updated_at: z.string(),

puppeteer/README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ A Model Context Protocol server that provides browser automation capabilities us
88

99
- **puppeteer_navigate**
1010
- Navigate to any URL in the browser
11-
- Input: `url` (string)
11+
- Inputs:
12+
- `url` (string, required): URL to navigate to
13+
- `launchOptions` (object, optional): PuppeteerJS LaunchOptions. Default null. If changed and not null, browser restarts. Example: `{ headless: true, args: ['--user-data-dir="C:/Data"'] }`
14+
- `allowDangerous` (boolean, optional): Allow dangerous LaunchOptions that reduce security. When false, dangerous args like `--no-sandbox`, `--disable-web-security` will throw errors. Default false.
1215

1316
- **puppeteer_screenshot**
1417
- Capture screenshots of the entire page or specific elements
@@ -61,6 +64,7 @@ The server provides access to two types of resources:
6164
- Screenshot capabilities
6265
- JavaScript execution
6366
- Basic web interaction (navigation, clicking, form filling)
67+
- Customizable Puppeteer launch options
6468

6569
## Configuration to use Puppeteer Server
6670
Here's the Claude Desktop configuration to use the Puppeter server:
@@ -93,6 +97,39 @@ Here's the Claude Desktop configuration to use the Puppeter server:
9397
}
9498
```
9599

100+
### Launch Options
101+
102+
You can customize Puppeteer's browser behavior in two ways:
103+
104+
1. **Environment Variable**: Set `PUPPETEER_LAUNCH_OPTIONS` with a JSON-encoded string in the MCP configuration's `env` parameter:
105+
106+
```json
107+
{
108+
"mcpServers": {
109+
"mcp-puppeteer": {
110+
"command": "npx",
111+
"args": ["-y", "@modelcontextprotocol/server-puppeteer"]
112+
"env": {
113+
"PUPPETEER_LAUNCH_OPTIONS": "{ \"headless\": false, \"executablePath\": \"C:/Program Files/Google/Chrome/Application/chrome.exe\", \"args\": [] }",
114+
"ALLOW_DANGEROUS": "true"
115+
}
116+
}
117+
}
118+
}
119+
```
120+
121+
2. **Tool Call Arguments**: Pass `launchOptions` and `allowDangerous` parameters to the `puppeteer_navigate` tool:
122+
123+
```json
124+
{
125+
"url": "https://example.com",
126+
"launchOptions": {
127+
"headless": false,
128+
"defaultViewport": {"width": 1280, "height": 720}
129+
}
130+
}
131+
```
132+
96133
## Build
97134

98135
Docker build:
@@ -103,4 +140,4 @@ docker build -t mcp/puppeteer -f src/puppeteer/Dockerfile .
103140

104141
## License
105142

106-
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.
143+
This MCP server is licensed under the MIT License. This means you are free to use, modify, and distribute the software, subject to the terms and conditions of the MIT License. For more details, please see the LICENSE file in the project repository.

puppeteer/index.ts

Lines changed: 87 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ const TOOLS: Tool[] = [
2222
inputSchema: {
2323
type: "object",
2424
properties: {
25-
url: { type: "string" },
25+
url: { type: "string", description: "URL to navigate to" },
26+
launchOptions: { type: "object", description: "PuppeteerJS LaunchOptions. Default null. If changed and not null, browser restarts. Example: { headless: true, args: ['--no-sandbox'] }" },
27+
allowDangerous: { type: "boolean", description: "Allow dangerous LaunchOptions that reduce security. When false, dangerous args like --no-sandbox will throw errors. Default false." },
2628
},
2729
required: ["url"],
2830
},
@@ -101,16 +103,65 @@ const TOOLS: Tool[] = [
101103
];
102104

103105
// Global state
104-
let browser: Browser | undefined;
105-
let page: Page | undefined;
106+
let browser: Browser | null;
107+
let page: Page | null;
106108
const consoleLogs: string[] = [];
107109
const screenshots = new Map<string, string>();
110+
let previousLaunchOptions: any = null;
111+
112+
async function ensureBrowser({ launchOptions, allowDangerous }: any) {
113+
114+
const DANGEROUS_ARGS = [
115+
'--no-sandbox',
116+
'--disable-setuid-sandbox',
117+
'--single-process',
118+
'--disable-web-security',
119+
'--ignore-certificate-errors',
120+
'--disable-features=IsolateOrigins',
121+
'--disable-site-isolation-trials',
122+
'--allow-running-insecure-content'
123+
];
124+
125+
// Parse environment config safely
126+
let envConfig = {};
127+
try {
128+
envConfig = JSON.parse(process.env.PUPPETEER_LAUNCH_OPTIONS || '{}');
129+
} catch (error: any) {
130+
console.warn('Failed to parse PUPPETEER_LAUNCH_OPTIONS:', error?.message || error);
131+
}
132+
133+
// Deep merge environment config with user-provided options
134+
const mergedConfig = deepMerge(envConfig, launchOptions || {});
135+
136+
// Security validation for merged config
137+
if (mergedConfig?.args) {
138+
const dangerousArgs = mergedConfig.args?.filter?.((arg: string) => DANGEROUS_ARGS.some((dangerousArg: string) => arg.startsWith(dangerousArg)));
139+
if (dangerousArgs?.length > 0 && !(allowDangerous || (process.env.ALLOW_DANGEROUS === 'true'))) {
140+
throw new Error(`Dangerous browser arguments detected: ${dangerousArgs.join(', ')}. Fround from environment variable and tool call argument. ` +
141+
'Set allowDangerous: true in the tool call arguments to override.');
142+
}
143+
}
144+
145+
try {
146+
if ((browser && !browser.connected) ||
147+
(launchOptions && (JSON.stringify(launchOptions) != JSON.stringify(previousLaunchOptions)))) {
148+
await browser?.close();
149+
browser = null;
150+
}
151+
}
152+
catch (error) {
153+
browser = null;
154+
}
155+
156+
previousLaunchOptions = launchOptions;
108157

109-
async function ensureBrowser() {
110158
if (!browser) {
111159
const npx_args = { headless: false }
112160
const docker_args = { headless: true, args: ["--no-sandbox", "--single-process", "--no-zygote"] }
113-
browser = await puppeteer.launch(process.env.DOCKER_CONTAINER ? docker_args : npx_args);
161+
browser = await puppeteer.launch(deepMerge(
162+
process.env.DOCKER_CONTAINER ? docker_args : npx_args,
163+
mergedConfig
164+
));
114165
const pages = await browser.pages();
115166
page = pages[0];
116167

@@ -126,6 +177,31 @@ async function ensureBrowser() {
126177
return page!;
127178
}
128179

180+
// Deep merge utility function
181+
function deepMerge(target: any, source: any): any {
182+
const output = Object.assign({}, target);
183+
if (typeof target !== 'object' || typeof source !== 'object') return source;
184+
185+
for (const key of Object.keys(source)) {
186+
const targetVal = target[key];
187+
const sourceVal = source[key];
188+
if (Array.isArray(targetVal) && Array.isArray(sourceVal)) {
189+
// Deduplicate args/ignoreDefaultArgs, prefer source values
190+
output[key] = [...new Set([
191+
...(key === 'args' || key === 'ignoreDefaultArgs' ?
192+
targetVal.filter((arg: string) => !sourceVal.some((launchArg: string) => arg.startsWith('--') && launchArg.startsWith(arg.split('=')[0]))) :
193+
targetVal),
194+
...sourceVal
195+
])];
196+
} else if (sourceVal instanceof Object && key in target) {
197+
output[key] = deepMerge(targetVal, sourceVal);
198+
} else {
199+
output[key] = sourceVal;
200+
}
201+
}
202+
return output;
203+
}
204+
129205
declare global {
130206
interface Window {
131207
mcpHelper: {
@@ -136,7 +212,7 @@ declare global {
136212
}
137213

138214
async function handleToolCall(name: string, args: any): Promise<CallToolResult> {
139-
const page = await ensureBrowser();
215+
const page = await ensureBrowser(args);
140216

141217
switch (name) {
142218
case "puppeteer_navigate":
@@ -285,15 +361,15 @@ async function handleToolCall(name: string, args: any): Promise<CallToolResult>
285361
window.mcpHelper.logs.push(`[${method}] ${args.join(' ')}`);
286362
(window.mcpHelper.originalConsole as any)[method](...args);
287363
};
288-
} );
289-
} );
364+
});
365+
});
290366

291-
const result = await page.evaluate( args.script );
367+
const result = await page.evaluate(args.script);
292368

293369
const logs = await page.evaluate(() => {
294370
Object.assign(console, window.mcpHelper.originalConsole);
295371
const logs = window.mcpHelper.logs;
296-
delete ( window as any).mcpHelper;
372+
delete (window as any).mcpHelper;
297373
return logs;
298374
});
299375

@@ -405,4 +481,4 @@ runServer().catch(console.error);
405481
process.stdin.on("close", () => {
406482
console.error("Puppeteer MCP Server closed");
407483
server.close();
408-
});
484+
});

0 commit comments

Comments
 (0)