Skip to content

feat: support MCP client roots feature#1945

Open
OrKoN wants to merge 1 commit intomainfrom
orkon/igotnoroots
Open

feat: support MCP client roots feature#1945
OrKoN wants to merge 1 commit intomainfrom
orkon/igotnoroots

Conversation

@OrKoN
Copy link
Copy Markdown
Collaborator

@OrKoN OrKoN commented Apr 23, 2026

This PR implements https://modelcontextprotocol.io/specification/2025-11-25/client/roots If client specifies roots, all reads and writes to the file system originating in tool calls will denied (including tmp files). The client specified empty list of roots, all filesystem access will be restricted.

Closes #1860

@OrKoN OrKoN force-pushed the orkon/igotnoroots branch 3 times, most recently from eba7359 to 51e3291 Compare April 23, 2026 11:30
@OrKoN OrKoN changed the title feat: support client roots feature feat: support MCP client roots feature Apr 23, 2026
@OrKoN OrKoN requested a review from wolfib April 23, 2026 11:38
Comment thread src/McpContext.ts Outdated
@OrKoN OrKoN force-pushed the orkon/igotnoroots branch 2 times, most recently from a11f796 to abf7160 Compare April 23, 2026 13:55
@OrKoN
Copy link
Copy Markdown
Collaborator Author

OrKoN commented Apr 23, 2026

I realized I might have had a bug in index.ts. PT(another)L.

@OrKoN OrKoN requested a review from wolfib April 23, 2026 13:56
@OrKoN OrKoN force-pushed the orkon/igotnoroots branch 3 times, most recently from 4823288 to 314d91d Compare April 23, 2026 15:10
@OrKoN
Copy link
Copy Markdown
Collaborator Author

OrKoN commented Apr 23, 2026

Sorry, I realised again that we should treat empty roots differently from undefined roots (rejecting any file access with empty roots). PTAL

@OrKoN OrKoN requested a review from wolfib April 23, 2026 15:10
@OrKoN OrKoN force-pushed the orkon/igotnoroots branch from 314d91d to d910a7a Compare April 23, 2026 15:18
Comment thread src/McpContext.ts
Comment on lines +677 to +679
const filepath = await getTempFilePath(filename);
this.validatePath(filepath);
await fs.writeFile(filepath, data);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be wrapped in a try..catch?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no, why would it need a try/catch?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fs.writeFile might throw an exception. Maybe it's already caught elsewhere, but it's not obvious.

The previous saveTemporaryFile did catch exceptions too.

* Only add methods used by tools/*.
*/
export type Context = Readonly<{
validatePath(filePath: string): void;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be

Suggested change
validatePath(filePath: string): void;
validatePath(filePath?: string): void;

So we can ignore some if statements?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, let me re-visit this next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support the roots feature from the MCP spec

3 participants