Skip to content

Commit 0dc738a

Browse files
committed
fix(pc):
1 parent 47ca656 commit 0dc738a

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

agentic_security/mcp/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
)
1212

1313

14-
async def run()-> None:
14+
async def run() -> None:
1515
async with stdio_client(server_params) as (read, write):
1616
async with ClientSession(read, write) as session:
17-
# Initialize the connection --> connection doesnt work
17+
# Initialize the connection --> connection does not work
1818
await session.initialize()
1919

20-
# List available prompts, resources, and tools --> no avalialbe tools
20+
# List available prompts, resources, and tools --> no avalialbe tools
2121
prompts = await session.list_prompts()
2222
print(f"Available prompts: {prompts}")
2323

@@ -27,7 +27,7 @@ async def run()-> None:
2727
tools = await session.list_tools()
2828
print(f"Available tools: {tools}")
2929

30-
# Call the echo tool --> echo tool iisue
30+
# Call the echo tool --> echo tool iisue
3131
echo_result = await session.call_tool(
3232
"echo_tool", arguments={"message": "Hello from client!"}
3333
)

agentic_security/mcp/main.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ async def verify_llm(spec: str) -> dict:
1717
"""
1818
Verify an LLM model specification using the FastAPI server
1919
20-
Returns:
21-
dict: containing the verification result form the FastAPI server
22-
20+
Returns:
21+
dict: containing the verification result form the FastAPI server
22+
2323
Args: spect(str): The specification of the LLM model to verify.
24-
24+
2525
"""
2626
url = f"{AGENTIC_SECURITY}/verify"
2727
async with httpx.AsyncClient() as client:
@@ -40,13 +40,13 @@ async def start_scan(
4040
Start an LLM security scan via the FastAPI server.
4141
Returns:
4242
dict: The scan initiation result from the FastAPI server.
43-
44-
Args:
43+
44+
Args:
4545
llmSpec (str): The specification of the LLM model.
4646
maxBudget (int): The maximum budget for the scan.
4747
optimize (bool, optional): Whether to enable optimization during scanning. Defaults to False.
48-
enableMultiStepAttack (bool, optional): Whether to enable multi-step attack
49-
48+
enableMultiStepAttack (bool, optional): Whether to enable multi-step attack
49+
5050
"""
5151
url = f"{AGENTIC_SECURITY}/scan"
5252
payload = {

tests/test_client.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,84 @@
1-
import pytest
21
import asyncio
32
from unittest.mock import AsyncMock, patch
3+
4+
import pytest
5+
46
from agentic_security.mcp import ClientSession
7+
58
from ..agentic_security.mcp.client import run
69

7-
# Fixtures
10+
11+
# Fixtures
812
@pytest.fixture(scope="session")
913
def event_loop():
1014
"""Create an instance of the default event loop for each test case."""
1115
loop = asyncio.get_event_loop_policy().new_event_loop()
1216
yield loop
1317
loop.close()
1418

19+
1520
@pytest.fixture
1621
async def mock_session():
17-
with patch('mcp.client.stdio.stdio_client') as mock_client:
18-
22+
with patch("mcp.client.stdio.stdio_client") as mock_client:
1923
mock_read = AsyncMock()
2024
mock_write = AsyncMock()
21-
22-
# Configures mock client such that mock responses are returned
25+
26+
# Configures mock client such that mock responses are returned
2327
mock_client.return_value.__aenter__.return_value = (mock_read, mock_write)
24-
28+
2529
# Creates a mock session
2630
mock_session = AsyncMock(spec=ClientSession)
27-
31+
2832
# Expected responses
2933
mock_session.initialize = AsyncMock()
3034
mock_session.list_prompts = AsyncMock(return_value=["test_prompt"])
3135
mock_session.list_resources = AsyncMock(return_value=["test_resource"])
3236
mock_session.list_tools = AsyncMock(return_value=["echo_tool"])
3337
mock_session.call_tool = AsyncMock(return_value="Hello from client!")
34-
35-
with patch('mcp.ClientSession', return_value=mock_session):
38+
39+
with patch("mcp.ClientSession", return_value=mock_session):
3640
yield mock_session
3741

38-
# Tests
42+
43+
# Tests
44+
3945

4046
@pytest.mark.asyncio
4147
async def test_initialization(mock_session):
4248
"""Test initialization success and failure cases"""
43-
# Test initialization success case
49+
# Test initialization success case
4450
await run()
4551
mock_session.initialize.assert_called_once()
46-
47-
# Resetting the mock to test for failure case
52+
53+
# Resetting the mock to test for failure case
4854
mock_session.initialize.reset_mock()
4955
mock_session.initialize.side_effect = ConnectionError("Failed to connect")
50-
56+
5157
# Test connection error
5258
with pytest.raises(ConnectionError):
5359
await run()
5460

61+
5562
@pytest.mark.asyncio
5663
async def test_list_resources(mock_session):
5764
"""Test listing available resources"""
5865
await run()
5966
mock_session.list_resources.assert_called_once()
6067
assert await mock_session.list_resources() == ["test_resource"]
6168

69+
6270
@pytest.mark.asyncio
6371
async def test_list_tools(mock_session):
6472
"""Test listing available tools"""
6573
await run()
6674
mock_session.list_tools.assert_called_once()
6775
assert await mock_session.list_tools() == ["echo_tool"]
6876

77+
6978
@pytest.mark.asyncio
7079
async def test_echo_tool(mock_session):
7180
"""Test the echo tool functionality"""
7281
await run()
7382
mock_session.call_tool.assert_called_once_with(
74-
"echo_tool",
75-
arguments={"message": "Hello from client!"}
76-
)
83+
"echo_tool", arguments={"message": "Hello from client!"}
84+
)

0 commit comments

Comments
 (0)