Skip to content

Commit 28d8e8a

Browse files
author
Tapan Chugh
committed
Allow non-file URI schemes for Root resources
Changed Root.uri from FileUrl to AnyUrl to support various URI schemes (https://, git://, s3://, etc.) in addition to file:// URLs.
1 parent ca34666 commit 28d8e8a

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/mcp/types.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections.abc import Callable
22
from typing import Annotated, Any, Generic, Literal, TypeAlias, TypeVar
33

4-
from pydantic import BaseModel, ConfigDict, Field, FileUrl, RootModel
4+
from pydantic import BaseModel, ConfigDict, Field, RootModel
55
from pydantic.networks import AnyUrl, UrlConstraints
66
from typing_extensions import deprecated
77

@@ -1151,11 +1151,10 @@ class ListRootsRequest(Request[RequestParams | None, Literal["roots/list"]]):
11511151
class Root(BaseModel):
11521152
"""Represents a root directory or file that the server can operate on."""
11531153

1154-
uri: FileUrl
1154+
uri: AnyUrl
11551155
"""
1156-
The URI identifying the root. This *must* start with file:// for now.
1157-
This restriction may be relaxed in future versions of the protocol to allow
1158-
other URI schemes.
1156+
The URI identifying the root. Can be any valid URI scheme (e.g., file://, https://,
1157+
git://, s3://, etc.). Servers should document which URI schemes they support.
11591158
"""
11601159
name: str | None = None
11611160
"""

tests/client/test_list_roots_callback.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from pydantic import FileUrl
2+
from pydantic import AnyUrl
33

44
from mcp.client.session import ClientSession
55
from mcp.server.fastmcp.server import Context
@@ -20,11 +20,11 @@ async def test_list_roots_callback():
2020
callback_return = ListRootsResult(
2121
roots=[
2222
Root(
23-
uri=FileUrl("file://users/fake/test"),
23+
uri=AnyUrl("file://users/fake/test"),
2424
name="Test Root 1",
2525
),
2626
Root(
27-
uri=FileUrl("file://users/fake/test/2"),
27+
uri=AnyUrl("https://github.com/user/repo"), # Non-file URL also works
2828
name="Test Root 2",
2929
),
3030
]

0 commit comments

Comments
 (0)