Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion src/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
ContentBlockSchema,
PromptMessageSchema,
CallToolResultSchema,
CompleteRequestSchema
CompleteRequestSchema,
RootSchema
} from './types.js';

describe('Types', () => {
Expand Down Expand Up @@ -311,4 +312,44 @@ 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');
}
});

test('should reject invalid URIs', () => {
const invalidRoot = {
uri: '/home/modelcontextprotocol/project',
name: 'Invalid Root'
};

const result = RootSchema.safeParse(invalidRoot);
expect(result.success).toBe(false);
});
});
});
5 changes: 3 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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().url(),
/**
* An optional name for the root.
*/
Expand Down