|
37 | 37 | ProgressNotification, |
38 | 38 | PromptReference, |
39 | 39 | ReadResourceResult, |
| 40 | + ResourceLink, |
40 | 41 | ResourceListChangedNotification, |
41 | 42 | ResourceTemplateReference, |
42 | 43 | SamplingMessage, |
@@ -147,6 +148,25 @@ async def tool_with_progress(message: str, ctx: Context, steps: int = 3) -> str: |
147 | 148 | def echo(message: str) -> str: |
148 | 149 | return f"Echo: {message}" |
149 | 150 |
|
| 151 | + # Tool that returns ResourceLinks |
| 152 | + @mcp.tool(description="Lists files and returns resource links", title="List Files Tool") |
| 153 | + def list_files() -> list[ResourceLink]: |
| 154 | + """Returns a list of resource links for files matching the pattern.""" |
| 155 | + |
| 156 | + # Mock some file resources for testing |
| 157 | + file_resources = [ |
| 158 | + { |
| 159 | + "type": "resource_link", |
| 160 | + "uri": "file:///project/README.md", |
| 161 | + "name": "README.md", |
| 162 | + "mimeType": "text/markdown", |
| 163 | + } |
| 164 | + ] |
| 165 | + |
| 166 | + result: list[ResourceLink] = [ResourceLink.model_validate(file_json) for file_json in file_resources] |
| 167 | + |
| 168 | + return result |
| 169 | + |
150 | 170 | # Tool with sampling capability |
151 | 171 | @mcp.tool(description="A tool that uses sampling to generate content", title="Sampling Tool") |
152 | 172 | async def sampling_tool(prompt: str, ctx: Context) -> str: |
@@ -753,7 +773,17 @@ async def call_all_mcp_features(session: ClientSession, collector: NotificationC |
753 | 773 | assert isinstance(tool_result.content[0], TextContent) |
754 | 774 | assert tool_result.content[0].text == "Echo: hello" |
755 | 775 |
|
756 | | - # 2. Tool with context (logging and progress) |
| 776 | + # 2. Test tool that returns ResourceLinks |
| 777 | + list_files_result = await session.call_tool("list_files") |
| 778 | + assert len(list_files_result.content) == 1 |
| 779 | + |
| 780 | + # Rest should be ResourceLinks |
| 781 | + content = list_files_result.content[0] |
| 782 | + assert isinstance(content, ResourceLink) |
| 783 | + assert str(content.uri).startswith("file:///") |
| 784 | + assert content.name is not None |
| 785 | + assert content.mimeType is not None |
| 786 | + |
757 | 787 | # Test progress callback functionality |
758 | 788 | progress_updates = [] |
759 | 789 |
|
|
0 commit comments