Refactor MCP server responses and harden docs path handling#391
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
et3 | e7300c0 | Commit Preview URL Branch Preview URL |
Jan 13 2026, 08:30 PM |
Summary of ChangesHello @zz-plant, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on improving the robustness, consistency, and maintainability of the MCP server tools. It centralizes response handling to streamline output, significantly enhances the security of documentation access by preventing path traversal, and refines TypeScript typings and code formatting for better developer experience. These changes are primarily internal quality improvements and do not alter the functional output of the tools, only their internal implementation and error handling. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively refactors the MCP server tool responses by introducing textResponse and errorResponse helpers, which significantly reduces boilerplate and improves consistency. The security hardening in the read_docs tool, by switching to path.resolve and improving the path validation, is a crucial improvement against directory traversal vulnerabilities. The code is now cleaner and more robust.
I've added a few suggestions to further improve the code by using more modern JavaScript features for conciseness and by parallelizing file system operations for better performance. Overall, these are great changes.
| const files: string[] = []; | ||
| for await (const file of glob.scan({ cwd: componentsDir })) { | ||
| files.push(file); | ||
| } |
There was a problem hiding this comment.
For conciseness and better readability, you can use Array.fromAsync to collect the results of the async iterator from glob.scan() into an array directly. This avoids the manual loop and files.push().
| const files: string[] = []; | |
| for await (const file of glob.scan({ cwd: componentsDir })) { | |
| files.push(file); | |
| } | |
| const files = await Array.fromAsync(glob.scan({ cwd: componentsDir })); |
| const files: string[] = []; | ||
|
|
||
| for await (const file of glob.scan({ cwd: pagesDir })) { | ||
| files.push(file); | ||
| } |
There was a problem hiding this comment.
For conciseness and better readability, you can use Array.fromAsync to collect the results of the async iterator from glob.scan() into an array directly. This avoids the manual loop and files.push().
| const files: string[] = []; | |
| for await (const file of glob.scan({ cwd: pagesDir })) { | |
| files.push(file); | |
| } | |
| const files = await Array.fromAsync(glob.scan({ cwd: pagesDir })); |
Motivation
read_docstool.Description
textResponseanderrorResponsehelpers and replaced repeated inline response objects with those helpers inscripts/mcp-server.ts.resolveand validating paths withsepto prevent directory traversal in theread_docstool.resolveandsep, addedtype: "text" as constto satisfy TypeScript, and cleaned up formatting/iteration in the component/project/dist listing tools.Testing
bun run check(which runs lint, unit tests, typecheck,astro:check,validate-json, andvalidate-glossary) and it completed successfully.17tests run across7files with14pass,3skipped, and0failed.tsctypecheck and other automated checks passed, andbunx prettier --writewas applied toscripts/mcp-server.ts.Codex Task