|
1 | 1 | from datetime import timedelta
|
2 | 2 |
|
3 | 3 | from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
|
4 |
| -from pydantic import AnyUrl |
| 4 | +from pydantic import AnyUrl, FileUrl |
5 | 5 |
|
6 | 6 | from mcp_python.shared.session import BaseSession
|
7 | 7 | from mcp_python.shared.version import SUPPORTED_PROTOCOL_VERSIONS
|
|
12 | 12 | ClientNotification,
|
13 | 13 | ClientRequest,
|
14 | 14 | ClientResult,
|
| 15 | + CompleteResult, |
15 | 16 | EmptyResult,
|
| 17 | + GetPromptResult, |
16 | 18 | Implementation,
|
17 | 19 | InitializedNotification,
|
18 | 20 | InitializeResult,
|
19 | 21 | JSONRPCMessage,
|
| 22 | + ListPromptsResult, |
20 | 23 | ListResourcesResult,
|
| 24 | + ListRootsResult, |
| 25 | + ListToolsResult, |
21 | 26 | LoggingLevel,
|
| 27 | + PromptReference, |
22 | 28 | ReadResourceResult,
|
| 29 | + ResourceReference, |
23 | 30 | ServerNotification,
|
24 | 31 | ServerRequest,
|
25 | 32 | )
|
@@ -61,7 +68,12 @@ async def initialize(self) -> InitializeResult:
|
61 | 68 | params=InitializeRequestParams(
|
62 | 69 | protocolVersion=LATEST_PROTOCOL_VERSION,
|
63 | 70 | capabilities=ClientCapabilities(
|
64 |
| - sampling=None, experimental=None |
| 71 | + sampling=None, |
| 72 | + experimental=None, |
| 73 | + roots={ |
| 74 | + # TODO: Should this be based on whether we _will_ send notifications, or only whether they're supported? |
| 75 | + "listChanged": True |
| 76 | + } |
65 | 77 | ),
|
66 | 78 | clientInfo=Implementation(name="mcp_python", version="0.1.0"),
|
67 | 79 | ),
|
@@ -220,3 +232,72 @@ async def call_tool(
|
220 | 232 | ),
|
221 | 233 | CallToolResult,
|
222 | 234 | )
|
| 235 | + |
| 236 | + async def list_prompts(self) -> ListPromptsResult: |
| 237 | + """Send a prompts/list request.""" |
| 238 | + from mcp_python.types import ListPromptsRequest |
| 239 | + |
| 240 | + return await self.send_request( |
| 241 | + ClientRequest( |
| 242 | + ListPromptsRequest( |
| 243 | + method="prompts/list", |
| 244 | + ) |
| 245 | + ), |
| 246 | + ListPromptsResult, |
| 247 | + ) |
| 248 | + |
| 249 | + async def get_prompt(self, name: str, arguments: dict[str, str] | None = None) -> GetPromptResult: |
| 250 | + """Send a prompts/get request.""" |
| 251 | + from mcp_python.types import GetPromptRequest, GetPromptRequestParams |
| 252 | + |
| 253 | + return await self.send_request( |
| 254 | + ClientRequest( |
| 255 | + GetPromptRequest( |
| 256 | + method="prompts/get", |
| 257 | + params=GetPromptRequestParams(name=name, arguments=arguments), |
| 258 | + ) |
| 259 | + ), |
| 260 | + GetPromptResult, |
| 261 | + ) |
| 262 | + |
| 263 | + async def complete(self, ref: ResourceReference | PromptReference, argument: dict) -> CompleteResult: |
| 264 | + """Send a completion/complete request.""" |
| 265 | + from mcp_python.types import CompleteRequest, CompleteRequestParams, CompletionArgument |
| 266 | + |
| 267 | + return await self.send_request( |
| 268 | + ClientRequest( |
| 269 | + CompleteRequest( |
| 270 | + method="completion/complete", |
| 271 | + params=CompleteRequestParams( |
| 272 | + ref=ref, |
| 273 | + argument=CompletionArgument(**argument), |
| 274 | + ), |
| 275 | + ) |
| 276 | + ), |
| 277 | + CompleteResult, |
| 278 | + ) |
| 279 | + |
| 280 | + async def list_tools(self) -> ListToolsResult: |
| 281 | + """Send a tools/list request.""" |
| 282 | + from mcp_python.types import ListToolsRequest |
| 283 | + |
| 284 | + return await self.send_request( |
| 285 | + ClientRequest( |
| 286 | + ListToolsRequest( |
| 287 | + method="tools/list", |
| 288 | + ) |
| 289 | + ), |
| 290 | + ListToolsResult, |
| 291 | + ) |
| 292 | + |
| 293 | + async def send_roots_list_changed(self) -> None: |
| 294 | + """Send a roots/list_changed notification.""" |
| 295 | + from mcp_python.types import RootsListChangedNotification |
| 296 | + |
| 297 | + await self.send_notification( |
| 298 | + ClientNotification( |
| 299 | + RootsListChangedNotification( |
| 300 | + method="notifications/roots/list_changed", |
| 301 | + ) |
| 302 | + ) |
| 303 | + ) |
0 commit comments