Skip to content

Commit 5ae6e10

Browse files
committed
Add GitHub Actions workflow and stdio tests for MCP server
1 parent 03266dd commit 5ae6e10

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

.github/workflows/tests.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Run Tests
2+
3+
on: [push]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- name: Set up Python 3.13
13+
uses: actions/setup-python@v5
14+
with:
15+
python-version: "3.13"
16+
17+
- name: Install uv
18+
run: |
19+
curl -LsSf https://astral.sh/uv/install.sh | sh
20+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
21+
22+
- name: Install dependencies
23+
run: |
24+
uv pip install -e ".[dev]"
25+
26+
- name: Run tests
27+
run: |
28+
uv run pytest tests/ -v

tests/test_stdio.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import asyncio
2+
3+
import pytest
4+
from mcp.client.session import ClientSession
5+
from mcp.client.stdio import StdioServerParameters, stdio_client
6+
7+
8+
@pytest.mark.asyncio
9+
async def test_mcp_server_tools() -> None:
10+
"""Test that we can connect to the server and list available tools."""
11+
async with stdio_client(
12+
StdioServerParameters(command="uv", args=["run", "mcp-simple-tool"])
13+
) as (read, write):
14+
async with ClientSession(read, write) as session:
15+
await session.initialize()
16+
tools = await session.list_tools()
17+
assert tools is not None, "Tools list should not be None"
18+
assert tools.tools, "Server should provide at least one tool"
19+
20+
21+
@pytest.mark.asyncio
22+
async def test_mcp_server_mood() -> None:
23+
"""Test that the mood tool works correctly."""
24+
async with stdio_client(
25+
StdioServerParameters(command="uv", args=["run", "mcp-simple-tool"])
26+
) as (read, write):
27+
async with ClientSession(read, write) as session:
28+
await session.initialize()
29+
result = await session.call_tool("mood", {"question": "How are you today?"})
30+
assert result is not None, "Mood response should not be None"
31+
assert "❤️" in str(result), "Mood response should contain a heart emoji"
32+
33+
34+
if __name__ == "__main__":
35+
asyncio.run(test_mcp_server_tools())
36+
asyncio.run(test_mcp_server_mood())

0 commit comments

Comments
 (0)