Skip to content

Commit e04fbdf

Browse files
committed
checkpoint
1 parent e8b66e9 commit e04fbdf

File tree

11 files changed

+18
-37
lines changed

11 files changed

+18
-37
lines changed

README.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ async def notify_data_update(resource_uri: str, ctx: Context) -> str:
10321032
# Perform data update logic here
10331033

10341034
# Notify clients that this specific resource changed
1035-
await ctx.session.send_resource_updated(AnyUrl(resource_uri))
1035+
await ctx.session.send_resource_updated(resource_uri)
10361036

10371037
# If this affects the overall resource list, notify about that too
10381038
await ctx.session.send_resource_list_changed()
@@ -1923,8 +1923,6 @@ For servers that need to handle large datasets, the low-level server provides pa
19231923
Example of implementing pagination with MCP server decorators.
19241924
"""
19251925

1926-
from pydantic import AnyUrl
1927-
19281926
import mcp.types as types
19291927
from mcp.server.lowlevel import Server
19301928

@@ -1949,7 +1947,7 @@ async def list_resources_paginated(request: types.ListResourcesRequest) -> types
19491947

19501948
# Get page of resources
19511949
page_items = [
1952-
types.Resource(uri=AnyUrl(f"resource://items/{item}"), name=item, description=f"Description for {item}")
1950+
types.Resource(uri=f"resource://items/{item}", name=item, description=f"Description for {item}")
19531951
for item in ITEMS[start:end]
19541952
]
19551953

@@ -2035,8 +2033,6 @@ cd to the `examples/snippets/clients` directory and run:
20352033
import asyncio
20362034
import os
20372035

2038-
from pydantic import AnyUrl
2039-
20402036
from mcp import ClientSession, StdioServerParameters, types
20412037
from mcp.client.stdio import stdio_client
20422038
from mcp.shared.context import RequestContext
@@ -2089,7 +2085,7 @@ async def run():
20892085
print(f"Available tools: {[t.name for t in tools.tools]}")
20902086

20912087
# Read a resource (greeting resource from fastmcp_quickstart)
2092-
resource_content = await session.read_resource(AnyUrl("greeting://World"))
2088+
resource_content = await session.read_resource("greeting://World")
20932089
content_block = resource_content.contents[0]
20942090
if isinstance(content_block, types.TextContent):
20952091
print(f"Resource content: {content_block.text}")
@@ -2256,8 +2252,6 @@ cd to the `examples/snippets` directory and run:
22562252
import asyncio
22572253
from urllib.parse import parse_qs, urlparse
22582254

2259-
from pydantic import AnyUrl
2260-
22612255
from mcp import ClientSession
22622256
from mcp.client.auth import OAuthClientProvider, TokenStorage
22632257
from mcp.client.streamable_http import streamablehttp_client
@@ -2304,7 +2298,7 @@ async def main():
23042298
server_url="http://localhost:8001",
23052299
client_metadata=OAuthClientMetadata(
23062300
client_name="Example MCP Client",
2307-
redirect_uris=[AnyUrl("http://localhost:3000/callback")],
2301+
redirect_uris=["http://localhost:3000/callback"],
23082302
grant_types=["authorization_code", "refresh_token"],
23092303
response_types=["code"],
23102304
scope="user",

examples/servers/simple-pagination/mcp_simple_pagination/server.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import click
1212
import mcp.types as types
1313
from mcp.server.lowlevel import Server
14-
from pydantic import AnyUrl
1514
from starlette.requests import Request
1615

1716
# Sample data - in real scenarios, this might come from a database
@@ -160,7 +159,7 @@ async def call_tool(name: str, arguments: dict[str, Any]) -> list[types.ContentB
160159

161160
# Implement read_resource handler
162161
@app.read_resource()
163-
async def read_resource(uri: AnyUrl) -> str:
162+
async def read_resource(uri: str) -> str:
164163
# Find the resource in our sample data
165164
resource = next((r for r in SAMPLE_RESOURCES if r.uri == uri), None)
166165
if not resource:

examples/servers/simple-resource/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Using the MCP client, you can retrieve resources like this using the STDIO trans
2222

2323
```python
2424
import asyncio
25-
from mcp.types import AnyUrl
2625
from mcp.client.session import ClientSession
2726
from mcp.client.stdio import StdioServerParameters, stdio_client
2827

@@ -39,7 +38,7 @@ async def main():
3938
print(resources)
4039

4140
# Get a specific resource
42-
resource = await session.read_resource(AnyUrl("file:///greeting.txt"))
41+
resource = await session.read_resource("file:///greeting.txt")
4342
print(resource)
4443

4544

examples/servers/simple-resource/mcp_simple_resource/server.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import mcp.types as types
44
from mcp.server.lowlevel import Server
55
from mcp.server.lowlevel.helper_types import ReadResourceContents
6-
from pydantic import AnyUrl, FileUrl
76
from starlette.requests import Request
87

98
SAMPLE_RESOURCES = {
@@ -47,7 +46,7 @@ async def list_resources() -> list[types.Resource]:
4746
]
4847

4948
@app.read_resource()
50-
async def read_resource(uri: AnyUrl):
49+
async def read_resource(uri: str):
5150
if uri.path is None:
5251
raise ValueError(f"Invalid resource path: {uri}")
5352
name = uri.path.replace(".txt", "").lstrip("/")

examples/servers/simple-streamablehttp/mcp_simple_streamablehttp/server.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import mcp.types as types
99
from mcp.server.lowlevel import Server
1010
from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
11-
from pydantic import AnyUrl
1211
from starlette.applications import Starlette
1312
from starlette.middleware.cors import CORSMiddleware
1413
from starlette.routing import Mount
@@ -74,7 +73,7 @@ async def call_tool(name: str, arguments: dict[str, Any]) -> list[types.ContentB
7473

7574
# This will send a resource notificaiton though standalone SSE
7675
# established by GET request
77-
await ctx.session.send_resource_updated(uri=AnyUrl("http:///test_resource"))
76+
await ctx.session.send_resource_updated(uri="http:///test_resource")
7877
return [
7978
types.TextContent(
8079
type="text",

examples/snippets/clients/oauth_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import asyncio
1111
from urllib.parse import parse_qs, urlparse
1212

13-
from pydantic import AnyUrl
14-
1513
from mcp import ClientSession
1614
from mcp.client.auth import OAuthClientProvider, TokenStorage
1715
from mcp.client.streamable_http import streamablehttp_client
@@ -58,7 +56,7 @@ async def main():
5856
server_url="http://localhost:8001",
5957
client_metadata=OAuthClientMetadata(
6058
client_name="Example MCP Client",
61-
redirect_uris=[AnyUrl("http://localhost:3000/callback")],
59+
redirect_uris=["http://localhost:3000/callback"],
6260
grant_types=["authorization_code", "refresh_token"],
6361
response_types=["code"],
6462
scope="user",

examples/snippets/clients/stdio_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import asyncio
77
import os
88

9-
from pydantic import AnyUrl
10-
119
from mcp import ClientSession, StdioServerParameters, types
1210
from mcp.client.stdio import stdio_client
1311
from mcp.shared.context import RequestContext
@@ -60,7 +58,7 @@ async def run():
6058
print(f"Available tools: {[t.name for t in tools.tools]}")
6159

6260
# Read a resource (greeting resource from fastmcp_quickstart)
63-
resource_content = await session.read_resource(AnyUrl("greeting://World"))
61+
resource_content = await session.read_resource("greeting://World")
6462
content_block = resource_content.contents[0]
6563
if isinstance(content_block, types.TextContent):
6664
print(f"Resource content: {content_block.text}")

examples/snippets/servers/pagination_example.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Example of implementing pagination with MCP server decorators.
33
"""
44

5-
from pydantic import AnyUrl
6-
75
import mcp.types as types
86
from mcp.server.lowlevel import Server
97

src/mcp/server/auth/handlers/authorize.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from dataclasses import dataclass
33
from typing import Any, Literal
44

5-
from pydantic import AnyUrl, BaseModel, Field, RootModel, ValidationError
5+
from pydantic import BaseModel, Field, RootModel, ValidationError
66
from starlette.datastructures import FormData, QueryParams
77
from starlette.requests import Request
88
from starlette.responses import RedirectResponse, Response
@@ -24,7 +24,7 @@
2424
class AuthorizationRequest(BaseModel):
2525
# See https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1
2626
client_id: str = Field(..., description="The client ID")
27-
redirect_uri: AnyUrl | None = Field(None, description="URL to redirect to after authorization")
27+
redirect_uri: str | None = Field(None, description="URL to redirect to after authorization")
2828

2929
# see OAuthClientMetadata; we only support `code`
3030
response_type: Literal["code"] = Field(..., description="Must be 'code' for authorization code flow")
@@ -44,7 +44,7 @@ class AuthorizationRequest(BaseModel):
4444
class AuthorizationErrorResponse(BaseModel):
4545
error: AuthorizationErrorCode
4646
error_description: str | None
47-
error_uri: AnyUrl | None = None
47+
error_uri: str | None = None
4848
# must be set if provided in the request
4949
state: str | None = None
5050

@@ -106,9 +106,7 @@ async def error_response(
106106
if params is not None and "redirect_uri" not in params:
107107
raw_redirect_uri = None
108108
else:
109-
raw_redirect_uri = AnyUrlModel.model_validate(
110-
best_effort_extract_string("redirect_uri", params)
111-
).root
109+
raw_redirect_uri = best_effort_extract_string("redirect_uri", params)
112110
redirect_uri = client.validate_redirect_uri(raw_redirect_uri)
113111
except (ValidationError, InvalidRedirectUriError):
114112
# if the redirect URI is invalid, ignore it & just return the

src/mcp/server/auth/provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Generic, Literal, Protocol, TypeVar
33
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse
44

5-
from pydantic import AnyUrl, BaseModel
5+
from pydantic import BaseModel
66

77
from mcp.shared.auth import OAuthClientInformationFull, OAuthToken
88

@@ -11,7 +11,7 @@ class AuthorizationParams(BaseModel):
1111
state: str | None
1212
scopes: list[str] | None
1313
code_challenge: str
14-
redirect_uri: AnyUrl
14+
redirect_uri: str
1515
redirect_uri_provided_explicitly: bool
1616
resource: str | None = None # RFC 8707 resource indicator
1717

@@ -22,7 +22,7 @@ class AuthorizationCode(BaseModel):
2222
expires_at: float
2323
client_id: str
2424
code_challenge: str
25-
redirect_uri: AnyUrl
25+
redirect_uri: str
2626
redirect_uri_provided_explicitly: bool
2727
resource: str | None = None # RFC 8707 resource indicator
2828

0 commit comments

Comments
 (0)