Skip to content

ping does not work with SSE servers #203

@esafak

Description

@esafak

Try with this file:

# tests/commands/test_ping_sse.py
"""Tests for pinging SSE servers."""
import json
import pytest
import subprocess
import time
from typer.testing import CliRunner

from mcp_cli.main import app

runner = CliRunner()

@pytest.fixture
def sse_server_config(tmp_path):
    """Create a temporary server_config.json for an SSE server."""
    config_path = tmp_path / "server_config.json"
    config = {
        "mcpServers": {
            "sse-echo": {
                "command": "uvx",
                "args": ["chuk-mcp-echo", "sse", "--port", "8081"],
                "url": "http://localhost:8081/mcp"
            }
        }
    }
    with open(config_path, "w") as f:
        json.dump(config, f)
    return config_path


def test_ping_sse_server(sse_server_config):
    """Test that 'mcp-cli ping' works with an SSE server."""
    log_file = "sse_ping_test.log"
    command = [
        ".venv/bin/mcp-cli",
        "ping",
        "--config-file",
        str(sse_server_config),
        "sse-echo",
        "--verbose",
    ]
    with open(log_file, "w") as f:
        result = subprocess.run(command, capture_output=True, text=True)

    if result.returncode != 0:
        with open(log_file, "r") as f:
            print(f.read())
        print(result.stderr)
        print(result.stdout)

    assert result.returncode == 0
    assert "✓ Online" in result.stdout
    assert "1/1 servers online" in result.stdout

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions