Skip to content

Commit 6a7b54e

Browse files
Tapan Chughclaude
andcommitted
Allow non-file URI schemes for Root resources
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 <[email protected]>
1 parent 29b65b0 commit 6a7b54e

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/types.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
ContentBlockSchema,
66
PromptMessageSchema,
77
CallToolResultSchema,
8-
CompleteRequestSchema
8+
CompleteRequestSchema,
9+
RootSchema
910
} from './types.js';
1011

1112
describe('Types', () => {
@@ -311,4 +312,34 @@ describe('Types', () => {
311312
}
312313
});
313314
});
315+
316+
describe('Root', () => {
317+
test('should validate roots with file:// URIs', () => {
318+
const root = {
319+
uri: 'file:///users/test/project',
320+
name: 'Test Root'
321+
};
322+
323+
const result = RootSchema.safeParse(root);
324+
expect(result.success).toBe(true);
325+
if (result.success) {
326+
expect(result.data.uri).toBe('file:///users/test/project');
327+
expect(result.data.name).toBe('Test Root');
328+
}
329+
});
330+
331+
test('should validate roots with non-file URI schemes', () => {
332+
const root = {
333+
uri: 'https://github.com/owner/repo',
334+
name: 'GitHub Repo'
335+
};
336+
337+
const result = RootSchema.safeParse(root);
338+
expect(result.success).toBe(true);
339+
if (result.success) {
340+
expect(result.data.uri).toBe('https://github.com/owner/repo');
341+
expect(result.data.name).toBe('GitHub Repo');
342+
}
343+
});
344+
});
314345
});

src/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,9 +1365,10 @@ export const CompleteResultSchema = ResultSchema.extend({
13651365
export const RootSchema = z
13661366
.object({
13671367
/**
1368-
* The URI identifying the root. This *must* start with file:// for now.
1368+
* The URI identifying the root. Can be any valid URI scheme (e.g., file://, https://, s3://, git://).
1369+
* Servers should document which URI schemes they support and handle unsupported schemes gracefully.
13691370
*/
1370-
uri: z.string().startsWith('file://'),
1371+
uri: z.string(),
13711372
/**
13721373
* An optional name for the root.
13731374
*/

0 commit comments

Comments
 (0)