Skip to content
Merged
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
56 changes: 56 additions & 0 deletions .github/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import subprocess
import sys
from pathlib import Path

import pytest
from dotenv import dotenv_values

REFERENCE_SCRIPTS = [
("binance_mcp_reference_implementation/binance_mcp.py", []),
("binance_mcp_reference_implementation/binance_mcp_w_prompt.py", []),
("binance_mcp_reference_implementation/binance_mcp_w_resource.py", []),
("binance_mcp/binance_mcp.py", []),
("langgraph/price_graph.py", []),
("ref_openai_mcp/function_calling.py", ["openai"]),
("ref_openai_mcp/mcp_with_openai_agent.py", ["openai"]),
("ref_openai_mcp/mcp_with_responses_api.py", ["openai"]),
]

# Load .env only for missing env vars
if Path(".env").exists():
env_config = dotenv_values(".env")
for k, v in env_config.items():
if k not in os.environ:
os.environ[k] = v


def run_script(script_path):
result = subprocess.run(
[sys.executable, script_path], capture_output=True, text=True
)
print(f"\n--- Output of {script_path} ---\n{result.stdout}")
if result.returncode != 0:
print(f"--- Error output of {script_path} ---\n{result.stderr}")
return result.returncode


def install_dependency_groups(groups):
if not groups:
return
for g in groups:
cmd = f"uv sync --group {g}"
# Use bash to support process substitution
result = subprocess.run(cmd, shell=True, executable="/bin/bash")
if result.returncode != 0:
raise RuntimeError(f"Failed to install dependency groups: {groups}")


@pytest.mark.parametrize("script_path,groups", REFERENCE_SCRIPTS)
def test_reference_script(script_path, groups):
install_dependency_groups(groups)
assert run_script(script_path) == 0


if __name__ == "__main__":
sys.exit(pytest.main([__file__]))
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install dependencies with uv
run: |
uv venv
source .venv/bin/activate
uv pip install -e .
uv pip install -r <(uv pip compile --extra ci pyproject.toml)

- name: Run tests
run: |
source .venv/bin/activate
pytest test.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ typescript_mcp/node_modules/
# Courseware dev
/dev
/.archive
!.github/
5 changes: 3 additions & 2 deletions langgraph/price_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@


async def get_crypto_prices():
async with MultiServerMCPClient(mcp_config) as client:
tools = client.get_tools()
client = MultiServerMCPClient(mcp_config)
async with client.session("binance") as session:
tools = await client.get_tools()

agent = create_react_agent(model, tools)

Expand Down
17 changes: 11 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ description = "MCP Course projects"
requires-python = ">=3.10"
dependencies = [
# From binance-mcp
"mcp[cli]==1.6.0",
"mcp[cli]==1.9.2",
"requests==2.32.3", # Also for llm-tool-use
# From llm-tool-use
"python-dotenv==1.1.0",
"google-generativeai==0.8.5",
# Jupyter support
"ipykernel>=6.29.5",
"ipywidgets>=8.1.6",
"langchain==0.3.25",
"langchain-openai==0.3.16",
"langchain-core==0.3.59",
"langchain-mcp-adapters==0.0.9",
"langgraph==0.4.3",
"langchain==0.3.26",
"langchain-openai==0.3.27",
"langchain-core==0.3.68",
"langchain-mcp-adapters==0.1.9",
"langgraph==0.5.2",
"langchain-google-genai==2.0.10",
"black>=25.1.0",
]
Expand All @@ -43,3 +43,8 @@ openai = [
"openai",
"openai-agents",
]

ci = [
"pytest",
"pytest-dotenv",
]
Loading
Loading