|
12 | 12 | ) |
13 | 13 | from mcp.types import Tool as MCPTool |
14 | 14 |
|
| 15 | +from langchain_mcp_adapters.client import MultiServerMCPClient |
15 | 16 | from langchain_mcp_adapters.tools import ( |
16 | 17 | _convert_call_tool_result, |
17 | 18 | convert_mcp_tool_to_langchain_tool, |
18 | 19 | load_mcp_tools, |
19 | 20 | ) |
| 21 | +from tests.utils import run_streamable_http |
20 | 22 |
|
21 | 23 |
|
22 | 24 | def test_convert_empty_text_content(): |
@@ -207,3 +209,44 @@ async def mock_call_tool(tool_name, arguments): |
207 | 209 | assert result2 == ToolMessage( |
208 | 210 | content="tool2 result with {'param1': 'test2', 'param2': 2}", name="tool2", tool_call_id="2" |
209 | 211 | ) |
| 212 | + |
| 213 | + |
| 214 | +@pytest.mark.asyncio |
| 215 | +async def test_load_mcp_tools_with_annotations( |
| 216 | + socket_enabled, |
| 217 | +) -> None: |
| 218 | + """Test load mcp tools with annotations.""" |
| 219 | + from mcp.server import FastMCP |
| 220 | + from mcp.types import ToolAnnotations |
| 221 | + |
| 222 | + server = FastMCP(port=8181) |
| 223 | + |
| 224 | + @server.tool( |
| 225 | + annotations=ToolAnnotations(title="Get Time", readOnlyHint=True, idempotentHint=False) |
| 226 | + ) |
| 227 | + def get_time() -> str: |
| 228 | + """Get current time""" |
| 229 | + return "5:20:00 PM EST" |
| 230 | + |
| 231 | + async with run_streamable_http(server): |
| 232 | + # Initialize client without initial connections |
| 233 | + client = MultiServerMCPClient( |
| 234 | + { |
| 235 | + "time": { |
| 236 | + "url": "http://localhost:8181/mcp/", |
| 237 | + "transport": "streamable_http", |
| 238 | + }, |
| 239 | + } |
| 240 | + ) |
| 241 | + # pass |
| 242 | + tools = await client.get_tools(server_name="time") |
| 243 | + assert len(tools) == 1 |
| 244 | + tool = tools[0] |
| 245 | + assert tool.name == "get_time" |
| 246 | + assert tool.metadata == { |
| 247 | + "title": "Get Time", |
| 248 | + "readOnlyHint": True, |
| 249 | + "idempotentHint": False, |
| 250 | + "destructiveHint": None, |
| 251 | + "openWorldHint": None, |
| 252 | + } |
0 commit comments