[codex] Add Bocha Search MCP example - #697
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a complete Bocha Search MCP agent example: YAML config, a runnable async Python example that reads BOCHA env vars, discovers and invokes the bocha_web_search tool via MCP with error detection and cleanup, tests covering config and error cases, and a README with setup and run instructions. ChangesBocha Search MCP Agent Example
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
tests/examples/test_bocha_search_mcp_agent_example.py (1)
38-55: ⚡ Quick winAdd negative-path env tests for required variables.
This test only covers the happy path. Add cases where
BOCHA_API_KEYorBOCHA_SEARCH_MCP_DIRis missing to lock the RuntimeError contract.Proposed test additions
+import pytest @@ def test_bocha_example_reads_server_config_from_process_env(monkeypatch): @@ assert env == {"BOCHA_API_KEY": "test-key"} + + +def test_bocha_example_server_config_requires_api_key(monkeypatch): + from examples.usecases.bocha_search_mcp_agent.main import bocha_server_config_from_process + + monkeypatch.delenv("BOCHA_API_KEY", raising=False) + monkeypatch.setenv("BOCHA_SEARCH_MCP_DIR", "D:/bocha-search-mcp") + + with pytest.raises(RuntimeError, match="BOCHA_API_KEY is required"): + bocha_server_config_from_process() + + +def test_bocha_example_server_config_requires_search_dir(monkeypatch): + from examples.usecases.bocha_search_mcp_agent.main import bocha_server_config_from_process + + monkeypatch.setenv("BOCHA_API_KEY", "test-key") + monkeypatch.delenv("BOCHA_SEARCH_MCP_DIR", raising=False) + + with pytest.raises(RuntimeError, match="BOCHA_SEARCH_MCP_DIR is required"): + bocha_server_config_from_process()🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/examples/test_bocha_search_mcp_agent_example.py` around lines 38 - 55, The test only covers the happy path for bocha_server_config_from_process; add negative-path tests that unset BOCHA_API_KEY and BOCHA_SEARCH_MCP_DIR (use monkeypatch.delenv or monkeypatch.setenv with None) and assert bocha_server_config_from_process raises a RuntimeError when either required env var is missing, referencing the function name bocha_server_config_from_process and the environment variable names BOCHA_API_KEY and BOCHA_SEARCH_MCP_DIR in the assertions to ensure the RuntimeError contract is enforced.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@examples/usecases/bocha_search_mcp_agent/main.py`:
- Around line 14-24: The code checks BOCHA_SEARCH_MCP_DIR exists as an env var
but does not verify the path points to an actual directory before returning
server args; update the logic around server_dir (the value from
os.environ.get("BOCHA_SEARCH_MCP_DIR")) to construct a Path(server_dir) and
verify path.exists() and path.is_dir(), and if not raise a RuntimeError with a
clear message including the invalid path value so the function that returns
(["--directory", str(Path(server_dir)), "run", "bocha-search-mcp"],
{"BOCHA_API_KEY": api_key}) fails fast with useful context.
- Around line 52-54: The current expression that finds the search tool using
next(name for name in tool_names if name.endswith("bocha_web_search")) can raise
a raw StopIteration; modify the lookup to handle missing tools and raise a clear
RuntimeError including tool_names instead. Replace that next(...) call (where
search_tool and tool_names are used) with a safe lookup (e.g., next(..., None)
or a try/except around next) and if no match is found raise RuntimeError(f"No
'bocha_web_search' tool found; available tools: {tool_names}") so the async
function surfaces a clear, targeted error.
In `@examples/usecases/bocha_search_mcp_agent/README.md`:
- Around line 28-32: Update the README.md example command to avoid a “file not
found” error by explicitly specifying the examples directory or adding a cd step
before running main.py; mention the examples/usecases/bocha_search_mcp_agent
path and either prepend cd examples/usecases/bocha_search_mcp_agent then run uv
run --project ... python main.py, or run uv run --project ... python
examples/usecases/bocha_search_mcp_agent/main.py so that the reference to
main.py is repo-root-safe and unambiguous.
---
Nitpick comments:
In `@tests/examples/test_bocha_search_mcp_agent_example.py`:
- Around line 38-55: The test only covers the happy path for
bocha_server_config_from_process; add negative-path tests that unset
BOCHA_API_KEY and BOCHA_SEARCH_MCP_DIR (use monkeypatch.delenv or
monkeypatch.setenv with None) and assert bocha_server_config_from_process raises
a RuntimeError when either required env var is missing, referencing the function
name bocha_server_config_from_process and the environment variable names
BOCHA_API_KEY and BOCHA_SEARCH_MCP_DIR in the assertions to ensure the
RuntimeError contract is enforced.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cdd9c151-7fdc-42ff-a168-42b122e209b6
📒 Files selected for processing (4)
examples/usecases/bocha_search_mcp_agent/README.mdexamples/usecases/bocha_search_mcp_agent/main.pyexamples/usecases/bocha_search_mcp_agent/mcp_agent.config.yamltests/examples/test_bocha_search_mcp_agent_example.py
Summary
BochaAI/bocha-search-mcpover stdioBOCHA_API_KEYandBOCHA_SEARCH_MCP_DIRfrom the runtime environment so secrets and local paths are not stored in configValidation
uv run pytest tests/examples/test_bocha_search_mcp_agent_example.py -q-> 3 passedBOCHA_API_KEYandBOCHA_SEARCH_MCP_DIRset -> discoveredbocha_bocha_web_search/bocha_bocha_ai_searchand completedbocha_web_searchwith HTTP 200Notes
BOCHA_SEARCH_MCP_DIR.Summary by CodeRabbit
Documentation
New Features
Tests