Skip to content

Commit 151b7f3

Browse files
Fix MCP server type annotations for resource methods
1 parent 037610b commit 151b7f3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/agents/mcp/server.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from mcp.client.streamable_http import GetSessionIdCallback, streamablehttp_client
1717
from mcp.shared.message import SessionMessage
1818
from mcp.types import (
19+
AnyUrl,
1920
CallToolResult,
2021
GetPromptResult,
2122
InitializeResult,
@@ -91,12 +92,12 @@ async def list_resources(self) -> ListResourcesResult:
9192
pass
9293

9394
@abc.abstractmethod
94-
async def read_resource(self, uri: str) -> ReadResourceResult:
95+
async def read_resource(self, uri:AnyUrl) -> ReadResourceResult:
9596
"""Read the content of a resource by URI."""
9697
pass
9798

9899
@abc.abstractmethod
99-
async def subscribe_resource(self, uri: str, **kwargs) -> AsyncIterator[SessionMessage]:
100+
async def subscribe_resource(self, uri:AnyUrl, **kwargs) -> AsyncIterator[SessionMessage]:
100101
"""Subscribe to resource updates."""
101102
pass
102103

@@ -354,19 +355,19 @@ async def list_resources(self) -> ListResourcesResult:
354355
assert session is not None
355356
return await session.list_resources()
356357

357-
async def read_resource(self, uri: str) -> ReadResourceResult:
358+
async def read_resource(self, uri: AnyUrl) -> ReadResourceResult:
358359
if not self.session:
359360
raise UserError("Server not initialized. Make sure you call `connect()` first.")
360361
session = self.session
361362
assert session is not None
362363
return await session.read_resource(uri)
363364

364-
async def subscribe_resource(self, uri: str, **kwargs) -> AsyncIterator[SessionMessage]:
365+
async def subscribe_resource(self, uri: AnyUrl, **kwargs) -> AsyncIterator[SessionMessage]:
365366
if not self.session:
366367
raise UserError("Server not initialized. Make sure you call `connect()` first.")
367368
session = self.session
368369
assert session is not None
369-
async for msg in session.subscribe_resource(uri, **kwargs):
370+
async for msg in session.subscribe_resource(uri):
370371
yield msg
371372

372373
async def list_prompts(

0 commit comments

Comments
 (0)