|
38 | 38 | ProgressNotification,
|
39 | 39 | PromptReference,
|
40 | 40 | ReadResourceResult,
|
| 41 | + ResourceLink, |
41 | 42 | ResourceListChangedNotification,
|
42 | 43 | ResourceTemplateReference,
|
43 | 44 | SamplingMessage,
|
@@ -152,6 +153,25 @@ async def tool_with_progress(message: str, ctx: Context, steps: int = 3) -> str:
|
152 | 153 | def echo(message: str) -> str:
|
153 | 154 | return f"Echo: {message}"
|
154 | 155 |
|
| 156 | + # Tool that returns ResourceLinks |
| 157 | + @mcp.tool(description="Lists files and returns resource links", title="List Files Tool") |
| 158 | + def list_files() -> list[ResourceLink]: |
| 159 | + """Returns a list of resource links for files matching the pattern.""" |
| 160 | + |
| 161 | + # Mock some file resources for testing |
| 162 | + file_resources = [ |
| 163 | + { |
| 164 | + "type": "resource_link", |
| 165 | + "uri": "file:///project/README.md", |
| 166 | + "name": "README.md", |
| 167 | + "mimeType": "text/markdown", |
| 168 | + } |
| 169 | + ] |
| 170 | + |
| 171 | + result: list[ResourceLink] = [ResourceLink.model_validate(file_json) for file_json in file_resources] |
| 172 | + |
| 173 | + return result |
| 174 | + |
155 | 175 | # Tool with sampling capability
|
156 | 176 | @mcp.tool(description="A tool that uses sampling to generate content", title="Sampling Tool")
|
157 | 177 | async def sampling_tool(prompt: str, ctx: Context) -> str:
|
@@ -762,7 +782,17 @@ async def call_all_mcp_features(session: ClientSession, collector: NotificationC
|
762 | 782 | assert isinstance(tool_result.content[0], TextContent)
|
763 | 783 | assert tool_result.content[0].text == "Echo: hello"
|
764 | 784 |
|
765 |
| - # 2. Tool with context (logging and progress) |
| 785 | + # 2. Test tool that returns ResourceLinks |
| 786 | + list_files_result = await session.call_tool("list_files") |
| 787 | + assert len(list_files_result.content) == 1 |
| 788 | + |
| 789 | + # Rest should be ResourceLinks |
| 790 | + content = list_files_result.content[0] |
| 791 | + assert isinstance(content, ResourceLink) |
| 792 | + assert str(content.uri).startswith("file:///") |
| 793 | + assert content.name is not None |
| 794 | + assert content.mimeType is not None |
| 795 | + |
766 | 796 | # Test progress callback functionality
|
767 | 797 | progress_updates = []
|
768 | 798 |
|
|
0 commit comments