Skip to content

Commit 9bd9f74

Browse files
chore: updating formatting + linting (#325)
Just getting to know the repo, drive by improvements
1 parent 368e52d commit 9bd9f74

File tree

6 files changed

+559
-374
lines changed

6 files changed

+559
-374
lines changed

langchain_mcp_adapters/sessions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ async def _create_websocket_session(
339339
ImportError: If websockets package is not installed.
340340
"""
341341
try:
342-
from mcp.client.websocket import websocket_client
342+
from mcp.client.websocket import websocket_client # noqa: PLC0415
343343
except ImportError:
344344
msg = (
345345
"Could not import websocket_client. "

langchain_mcp_adapters/tools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,13 @@ async def call_tool(
137137
call_tool_result = await session.call_tool(tool.name, arguments)
138138

139139
if call_tool_result is None:
140-
raise RuntimeError(
140+
msg = (
141141
"Tool call failed: no result returned from the underlying MCP SDK. "
142142
"This may indicate that an exception was handled or suppressed "
143143
"by the MCP SDK (e.g., client disconnection, network issue, "
144144
"or other execution error)."
145145
)
146+
raise RuntimeError(msg)
146147

147148
return _convert_call_tool_result(call_tool_result)
148149

tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from collections.abc import Generator
55

66
import pytest
7+
import pytest_socket
78

89
from tests.utils import run_server
910

@@ -55,8 +56,6 @@ def websocket_server(websocket_server_port: int) -> Generator[None, None, None]:
5556
def socket_enabled():
5657
"""Temporarily enable socket connections for websocket tests."""
5758
try:
58-
import pytest_socket
59-
6059
pytest_socket.enable_socket()
6160
previous_state = pytest_socket.socket_allow_hosts()
6261
# Only allow connections to localhost

tests/test_import.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
def test_import() -> None:
22
"""Test that the code can be imported"""
3-
from langchain_mcp_adapters import client, prompts, resources, tools # noqa: F401
3+
from langchain_mcp_adapters import ( # noqa: F401, PLC0415
4+
client,
5+
prompts,
6+
resources,
7+
tools,
8+
)

tests/test_tools.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from typing import Annotated
22
from unittest.mock import AsyncMock, MagicMock
33

4+
import httpx
45
import pytest
56
from langchain_core.callbacks import CallbackManagerForToolRun
67
from langchain_core.messages import ToolMessage
78
from langchain_core.tools import BaseTool, InjectedToolArg, ToolException, tool
9+
from mcp.server import FastMCP
810
from mcp.types import (
911
CallToolResult,
1012
EmbeddedResource,
@@ -223,9 +225,6 @@ async def mock_call_tool(tool_name, arguments):
223225

224226

225227
def _create_annotations_server():
226-
from mcp.server import FastMCP
227-
from mcp.types import ToolAnnotations
228-
229228
server = FastMCP(port=8181)
230229

231230
@server.tool(
@@ -356,8 +355,6 @@ def test_convert_langchain_tool_to_fastmcp_tool_with_injection():
356355

357356

358357
def _create_status_server():
359-
from mcp.server import FastMCP
360-
361358
server = FastMCP(port=8182)
362359

363360
@server.tool()
@@ -372,7 +369,6 @@ def get_status() -> str:
372369
@pytest.mark.asyncio
373370
async def test_load_mcp_tools_with_custom_httpx_client_factory(socket_enabled) -> None:
374371
"""Test load mcp tools with custom httpx client factory."""
375-
import httpx
376372

377373
# Custom httpx client factory
378374
def custom_httpx_client_factory(
@@ -412,8 +408,6 @@ def custom_httpx_client_factory(
412408

413409

414410
def _create_info_server():
415-
from mcp.server import FastMCP
416-
417411
server = FastMCP(port=8183)
418412

419413
@server.tool()
@@ -429,7 +423,6 @@ async def test_load_mcp_tools_with_custom_httpx_client_factory_sse(
429423
socket_enabled,
430424
) -> None:
431425
"""Test load mcp tools with custom httpx client factory using SSE transport."""
432-
import httpx
433426

434427
# Custom httpx client factory
435428
def custom_httpx_client_factory(

0 commit comments

Comments
 (0)