Skip to content

Commit c9777c9

Browse files
author
Tapan Chugh
committed
Add proper URI validation to RootSchema using z.string().url()
1 parent 6a7b54e commit c9777c9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/types.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,5 +341,15 @@ describe('Types', () => {
341341
expect(result.data.name).toBe('GitHub Repo');
342342
}
343343
});
344+
345+
test('should reject invalid URIs', () => {
346+
const invalidRoot = {
347+
uri: '/home/modelcontextprotocol/project',
348+
name: 'Invalid Root'
349+
};
350+
351+
const result = RootSchema.safeParse(invalidRoot);
352+
expect(result.success).toBe(false);
353+
});
344354
});
345355
});

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ export const RootSchema = z
13681368
* The URI identifying the root. Can be any valid URI scheme (e.g., file://, https://, s3://, git://).
13691369
* Servers should document which URI schemes they support and handle unsupported schemes gracefully.
13701370
*/
1371-
uri: z.string(),
1371+
uri: z.string().url(),
13721372
/**
13731373
* An optional name for the root.
13741374
*/

0 commit comments

Comments
 (0)