From 6a7b54e0081bbdf3d1bcd0288b594f99c0506594 Mon Sep 17 00:00:00 2001 From: Tapan Chugh Date: Thu, 2 Oct 2025 12:53:22 -0700 Subject: [PATCH 1/2] Allow non-file URI schemes for Root resources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements SEP-1573 to enable Roots with any URI scheme (https://, s3://, git://, etc.) instead of only file:// URIs. This allows servers to work with remote resources while maintaining full backward compatibility. Changes: - Update RootSchema to accept any URI scheme - Add tests validating both file:// and https:// URIs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/types.test.ts | 33 ++++++++++++++++++++++++++++++++- src/types.ts | 5 +++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/types.test.ts b/src/types.test.ts index cd8cc0711..c8a0466b3 100644 --- a/src/types.test.ts +++ b/src/types.test.ts @@ -5,7 +5,8 @@ import { ContentBlockSchema, PromptMessageSchema, CallToolResultSchema, - CompleteRequestSchema + CompleteRequestSchema, + RootSchema } from './types.js'; describe('Types', () => { @@ -311,4 +312,34 @@ describe('Types', () => { } }); }); + + describe('Root', () => { + test('should validate roots with file:// URIs', () => { + const root = { + uri: 'file:///users/test/project', + name: 'Test Root' + }; + + const result = RootSchema.safeParse(root); + expect(result.success).toBe(true); + if (result.success) { + expect(result.data.uri).toBe('file:///users/test/project'); + expect(result.data.name).toBe('Test Root'); + } + }); + + test('should validate roots with non-file URI schemes', () => { + const root = { + uri: 'https://github.com/owner/repo', + name: 'GitHub Repo' + }; + + const result = RootSchema.safeParse(root); + expect(result.success).toBe(true); + if (result.success) { + expect(result.data.uri).toBe('https://github.com/owner/repo'); + expect(result.data.name).toBe('GitHub Repo'); + } + }); + }); }); diff --git a/src/types.ts b/src/types.ts index e6d3fe46e..ac047a5a1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1365,9 +1365,10 @@ export const CompleteResultSchema = ResultSchema.extend({ export const RootSchema = z .object({ /** - * The URI identifying the root. This *must* start with file:// for now. + * The URI identifying the root. Can be any valid URI scheme (e.g., file://, https://, s3://, git://). + * Servers should document which URI schemes they support and handle unsupported schemes gracefully. */ - uri: z.string().startsWith('file://'), + uri: z.string(), /** * An optional name for the root. */ From c9777c992bbbbb26d3c3bb0e83a45832b47c10de Mon Sep 17 00:00:00 2001 From: Tapan Chugh Date: Mon, 6 Oct 2025 00:39:09 -0700 Subject: [PATCH 2/2] Add proper URI validation to RootSchema using z.string().url() --- src/types.test.ts | 10 ++++++++++ src/types.ts | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/types.test.ts b/src/types.test.ts index c8a0466b3..031f455b8 100644 --- a/src/types.test.ts +++ b/src/types.test.ts @@ -341,5 +341,15 @@ describe('Types', () => { expect(result.data.name).toBe('GitHub Repo'); } }); + + test('should reject invalid URIs', () => { + const invalidRoot = { + uri: '/home/modelcontextprotocol/project', + name: 'Invalid Root' + }; + + const result = RootSchema.safeParse(invalidRoot); + expect(result.success).toBe(false); + }); }); }); diff --git a/src/types.ts b/src/types.ts index ac047a5a1..a4d6702ce 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1368,7 +1368,7 @@ export const RootSchema = z * The URI identifying the root. Can be any valid URI scheme (e.g., file://, https://, s3://, git://). * Servers should document which URI schemes they support and handle unsupported schemes gracefully. */ - uri: z.string(), + uri: z.string().url(), /** * An optional name for the root. */