Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read # required for actions/checkout
env:
SYSDIG_MCP_API_HOST: ${{ vars.SYSDIG_MCP_API_HOST }}
SYSDIG_MCP_TRANSPORT: ${{ vars.SYSDIG_MCP_TRANSPORT }}
SYSDIG_MCP_API_SECURE_TOKEN: ${{ secrets.SYSDIG_MCP_API_SECURE_TOKEN }}
steps:
- name: Check out the repo
uses: actions/checkout@v4
Expand All @@ -43,5 +47,10 @@ jobs:
- name: Run ruff
run: make lint

- name: Run Unit Tests
run: make test
- name: Start MCP server in the background
run: |
make start-server-background

- name: Run MCP client
run: |
make test
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ test:

test-coverage:
uv run pytest --cov=. --cov-report=xml

start-server-background:
uv run main.py &
sleep 5 # Wait for the server to start
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ sysdig-mcp-server = "main:main"
dev-dependencies = [
"pytest-cov~=6.2",
"pytest~=8.4",
"ruff~=0.12.1",
"ruff~=0.12",
"pytest-asyncio~=1.2",
]

[build-system]
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def mock_creds():
"""
Fixture to set up mocked credentials.
"""
os.environ["SYSDIG_MCP_API_SECURE_TOKEN"] = "mocked_token"
os.environ["SYSDIG_MCP_API_HOST"] = "https://us2.app.sysdig.com"
os.environ["SYSDIG_MCP_API_SECURE_TOKEN"] = os.environ.get("SYSDIG_MCP_API_SECURE_TOKEN", "mocked_token")
os.environ["SYSDIG_MCP_API_HOST"] = os.environ.get("SYSDIG_MCP_API_HOST", "https://us2.app.sysdig.com")


def mock_app_config() -> AppConfig:
Expand Down
32 changes: 32 additions & 0 deletions tests/tools_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
This is a simple test client to verify the MCP server is running and responding to requests.
"""

from fastmcp import Client
from fastmcp.client.transports import StreamableHttpTransport
import os
import pytest


@pytest.mark.asyncio
async def test_list_runtime_events():
"""
Test the list_runtime_events tool of the MCP server.
This function initializes a client, calls the list_runtime_events tool,
and prints the status code and total number of runtime events retrieved.
"""

async with Client(
transport=StreamableHttpTransport(
url="http://localhost:8080/sysdig-mcp-server/mcp",
headers={"X-Sysdig-Token": f"Bearer {os.getenv('SYSDIG_MCP_API_SECURE_TOKEN')}"},
),
auth="oauth", # Use "oauth" if the server is configured with OAuth authentication, otherwise use None
) as client:
tool_name = "list_runtime_events"
result = await client.call_tool(tool_name)
assert result.structured_content.get("status_code") == 200
print(
f"Tool {tool_name} completed with status code: {result.structured_content.get('status_code')}"
f" with a total of: {result.data.get('results', {}).get('page', {}).get('total', 0)} runtime events."
)
17 changes: 16 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.