Skip to content

Commit 548178a

Browse files
committed
feat Adding test with MCP client for tool response
Signed-off-by: S3B4SZ17 <[email protected]>
1 parent 89b1588 commit 548178a

File tree

6 files changed

+67
-6
lines changed

6 files changed

+67
-6
lines changed

.github/workflows/test.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ jobs:
2323
runs-on: ubuntu-latest
2424
permissions:
2525
contents: read # required for actions/checkout
26+
env:
27+
SYSDIG_MCP_API_HOST: ${{ vars.SYSDIG_MCP_API_HOST }}
28+
SYSDIG_MCP_TRANSPORT: ${{ vars.SYSDIG_MCP_TRANSPORT }}
29+
SYSDIG_MCP_API_SECURE_TOKEN: ${{ secrets.SYSDIG_MCP_API_SECURE_TOKEN }}
2630
steps:
2731
- name: Check out the repo
2832
uses: actions/checkout@v4
@@ -43,5 +47,10 @@ jobs:
4347
- name: Run ruff
4448
run: make lint
4549

46-
- name: Run Unit Tests
47-
run: make test
50+
- name: Start MCP server in the background
51+
run: |
52+
make start-server-background
53+
54+
- name: Run MCP client
55+
run: |
56+
make test

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ test:
2222

2323
test-coverage:
2424
uv run pytest --cov=. --cov-report=xml
25+
26+
start-server-background:
27+
uv run main.py &
28+
sleep 5 # Wait for the server to start

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ sysdig-mcp-server = "main:main"
2525
dev-dependencies = [
2626
"pytest-cov~=6.2",
2727
"pytest~=8.4",
28-
"ruff~=0.12.1",
28+
"ruff~=0.12",
29+
"pytest-asyncio~=1.2",
2930
]
3031

3132
[build-system]

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def mock_creds():
4747
"""
4848
Fixture to set up mocked credentials.
4949
"""
50-
os.environ["SYSDIG_MCP_API_SECURE_TOKEN"] = "mocked_token"
51-
os.environ["SYSDIG_MCP_API_HOST"] = "https://us2.app.sysdig.com"
50+
os.environ["SYSDIG_MCP_API_SECURE_TOKEN"] = os.environ.get("SYSDIG_MCP_API_SECURE_TOKEN", "mocked_token")
51+
os.environ["SYSDIG_MCP_API_HOST"] = os.environ.get("SYSDIG_MCP_API_HOST", "https://us2.app.sysdig.com")
5252

5353

5454
def mock_app_config() -> AppConfig:

tests/tools_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
This is a simple test client to verify the MCP server is running and responding to requests.
3+
"""
4+
5+
from fastmcp import Client
6+
from fastmcp.client.transports import StreamableHttpTransport
7+
import os
8+
import pytest
9+
10+
11+
@pytest.mark.asyncio
12+
async def test_list_runtime_events():
13+
"""
14+
Test the list_runtime_events tool of the MCP server.
15+
This function initializes a client, calls the list_runtime_events tool,
16+
and prints the status code and total number of runtime events retrieved.
17+
"""
18+
19+
async with Client(
20+
transport=StreamableHttpTransport(
21+
url="http://localhost:8080/sysdig-mcp-server/mcp",
22+
headers={"X-Sysdig-Token": f"Bearer {os.getenv('SYSDIG_MCP_API_SECURE_TOKEN')}"},
23+
),
24+
auth="oauth", # Use "oauth" if the server is configured with OAuth authentication, otherwise use None
25+
) as client:
26+
tool_name = "list_runtime_events"
27+
result = await client.call_tool(tool_name)
28+
assert result.structured_content.get("status_code") == 200
29+
print(
30+
f"Tool {tool_name} completed with status code: {result.structured_content.get('status_code')}"
31+
f" with a total of: {result.data.get('results', {}).get('page', {}).get('total', 0)} runtime events."
32+
)

uv.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)