Repository navigation
Add particle MCP tool - #1415
tamohannes wants to merge 9 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a new MCP stdio server and client wrapper (ParticleTool) for PDG/name particle lookups and substring searches using the Changes
Sequence Diagram(s)sequenceDiagram
participant Client as ParticleTool (Client)
participant MCP as MCP Stdio Server
participant Lib as particle (library)
Client->>MCP: call "particle-lookup" / "particle-search" (input)
MCP->>Lib: parse as PDG ID or name / perform findall substring search
Lib-->>MCP: return particle record(s)
MCP->>Client: return formatted Markdown response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 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)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
nemo_skills/mcp/servers/particle_tool.py (1)
67-73: ⚡ Quick winNormalize and reject empty inputs before lookup/search.
Add
strip()+ empty checks so both tools fail fast with a clear message instead of relying on backend matching behavior for blank strings.Suggested patch
`@mcp.tool`(name="particle-lookup") def particle_lookup( @@ ) -> str: """Look up a particle by name or PDG ID. Returns mass, width, charge, spin, lifetime, and quantum numbers.""" + name_or_id = name_or_id.strip() + if not name_or_id: + return "Please provide a non-empty particle name or PDG ID." + from particle import InvalidParticle, Particle, ParticleNotFound @@ `@mcp.tool`(name="particle-search") def particle_search( @@ ) -> str: """Search for particles by name. Returns a list of matching particles with key properties.""" + query = query.strip() + if not query: + return "Please provide a non-empty search query." + from particle import ParticleAlso applies to: 96-100
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@nemo_skills/mcp/servers/particle_tool.py` around lines 67 - 73, Normalize the input by calling name_or_id = name_or_id.strip() at the start of particle_lookup and then immediately check for emptiness; if it is empty raise a clear ValueError (e.g. "name_or_id must not be empty") so the tool fails fast with a meaningful message instead of relying on backend behavior. Apply the same strip + empty-check + ValueError pattern to the corresponding search function (particle_search) covering the other block mentioned so both tools consistently validate and reject blank inputs.tests/test_mcp_clients.py (1)
1018-1030: ⚡ Quick winAdd one smoke execution assertion for the new tool.
list_tools()confirms discovery, but one call (e.g.,particle-lookup) would validate runtime invocation too.Proposed test enhancement
`@pytest.mark.asyncio` async def test_particle_stdio_list_tools(self): from nemo_skills.mcp.servers.particle_tool import ParticleTool tool = ParticleTool() tool.configure() try: tools = await tool.list_tools() tool_names = {t["name"] for t in tools} assert "particle-lookup" in tool_names assert "particle-search" in tool_names + lookup = await tool.execute("particle-lookup", {"name_or_id": "211"}) + assert isinstance(lookup, str) + assert "PDG ID: 211" in lookup finally: await tool.shutdown()🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/test_mcp_clients.py` around lines 1018 - 1030, The test currently verifies discovery but not runtime invocation; after calling ParticleTool.list_tools() find the tool dict with name "particle-lookup" and perform a smoke invocation using the ParticleTool.execute(...) method (or the class's run/invoke method if named differently) with minimal valid input, then assert the call returns a non-error/empty response (e.g., truthy result or expected keys). Keep configure(), list_tools(), and shutdown() usage and add the execute invocation and its assertion inside the try block after the existing name checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@nemo_skills/mcp/servers/particle_tool.py`:
- Around line 67-73: Normalize the input by calling name_or_id =
name_or_id.strip() at the start of particle_lookup and then immediately check
for emptiness; if it is empty raise a clear ValueError (e.g. "name_or_id must
not be empty") so the tool fails fast with a meaningful message instead of
relying on backend behavior. Apply the same strip + empty-check + ValueError
pattern to the corresponding search function (particle_search) covering the
other block mentioned so both tools consistently validate and reject blank
inputs.
In `@tests/test_mcp_clients.py`:
- Around line 1018-1030: The test currently verifies discovery but not runtime
invocation; after calling ParticleTool.list_tools() find the tool dict with name
"particle-lookup" and perform a smoke invocation using the
ParticleTool.execute(...) method (or the class's run/invoke method if named
differently) with minimal valid input, then assert the call returns a
non-error/empty response (e.g., truthy result or expected keys). Keep
configure(), list_tools(), and shutdown() usage and add the execute invocation
and its assertion inside the try block after the existing name checks.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 1bad1a1c-1ff6-49a7-afcb-a9a871f6c872
📒 Files selected for processing (3)
docs/agentic_inference/tool_calling.mdnemo_skills/mcp/servers/particle_tool.pytests/test_mcp_clients.py
gwarmstrong
left a comment
There was a problem hiding this comment.
Hi @tamohannes , Thank you for the contributions! I would encourage you to please switch to a tool path that avoids the MCP protocol (we have found it to cause real latency and stability issues during RL) in favor of a direct tool approach. The changes should be fairly minimal--please see the DirectPythonTool for an example.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.github/workflows/tests.yml (1)
27-33:⚠️ Potential issue | 🔴 Critical
secretsis not available in step-levelifconditions — use job-levelenvinstead.Line 27 uses
if: ${{ secrets.GHCR_PAT != '' }}in a step condition. GitHub Actions does not allow thesecretscontext at the step level, and this will fail workflow evaluation. MoveGHCR_PATto the job'senvblock and reference it viaenv.GHCR_PAT.Proposed fix
jobs: unit-tests: runs-on: ubuntu-latest + env: + GHCR_PAT: ${{ secrets.GHCR_PAT }} steps: - name: Login to GHCR - if: ${{ secrets.GHCR_PAT != '' }} + if: ${{ env.GHCR_PAT != '' }} uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} - password: ${{ secrets.GHCR_PAT }} + password: ${{ env.GHCR_PAT }} - name: Build Images - env: - GHCR_PAT: ${{ secrets.GHCR_PAT }} run: |Also applies to: 52-53
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/tests.yml around lines 27 - 33, The workflow uses secrets.GHCR_PAT in step-level if conditions (the docker/login-action step and the other step at lines ~52-53) which is invalid; move GHCR_PAT into the job-level env (e.g., add env: GHCR_PAT: ${{ secrets.GHCR_PAT }} on the job) and update the step if conditions to reference env.GHCR_PAT (e.g., if: ${{ env.GHCR_PAT != '' }}) for the docker/login-action step and the other affected steps so the condition evaluates correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In @.github/workflows/tests.yml:
- Around line 27-33: The workflow uses secrets.GHCR_PAT in step-level if
conditions (the docker/login-action step and the other step at lines ~52-53)
which is invalid; move GHCR_PAT into the job-level env (e.g., add env: GHCR_PAT:
${{ secrets.GHCR_PAT }} on the job) and update the step if conditions to
reference env.GHCR_PAT (e.g., if: ${{ env.GHCR_PAT != '' }}) for the
docker/login-action step and the other affected steps so the condition evaluates
correctly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: b0d5280b-db44-42ea-baaa-c33982109cf9
📒 Files selected for processing (1)
.github/workflows/tests.yml
Signed-off-by: tamohannes <[email protected]>
f749417 to
068c3cb
Compare
Signed-off-by: tamohannes <[email protected]>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.github/workflows/tests.yml (1)
26-33:⚠️ Potential issue | 🟠 MajorUse
env(notsecrets) in step-levelifexpressionLine 27 uses
secrets.GHCR_PATin theiffield, but thesecretscontext is not available at this location. GitHub Actions only allowsenv,github,inputs,job,matrix,needs,runner,steps,strategy, andvarscontexts in stepifexpressions. This will cause workflow validation to fail.Suggested fix
- - name: Login to GHCR - if: ${{ secrets.GHCR_PAT != '' }} + - name: Login to GHCR + env: + GHCR_PAT: ${{ secrets.GHCR_PAT }} + if: ${{ env.GHCR_PAT != '' }} uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} - password: ${{ secrets.GHCR_PAT }} + password: ${{ env.GHCR_PAT }}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/tests.yml around lines 26 - 33, The step "Login to GHCR" currently uses an invalid step-level if expression referencing secrets.GHCR_PAT; change the condition to reference env instead (e.g., if: ${{ env.GHCR_PAT != '' }}) and expose the secret via an env mapping so the secret context is available as env (add env: GHCR_PAT: ${{ secrets.GHCR_PAT }} at the job or the step containing the "Login to GHCR" step). Keep the rest of the step (uses: docker/login-action@v3, with: registry/username/password) unchanged but use env.GHCR_PAT in the if and in the password input if needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In @.github/workflows/tests.yml:
- Around line 26-33: The step "Login to GHCR" currently uses an invalid
step-level if expression referencing secrets.GHCR_PAT; change the condition to
reference env instead (e.g., if: ${{ env.GHCR_PAT != '' }}) and expose the
secret via an env mapping so the secret context is available as env (add env:
GHCR_PAT: ${{ secrets.GHCR_PAT }} at the job or the step containing the "Login
to GHCR" step). Keep the rest of the step (uses: docker/login-action@v3, with:
registry/username/password) unchanged but use env.GHCR_PAT in the if and in the
password input if needed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 2834227e-7dcf-462c-8b7f-3108c9a0f9b5
📒 Files selected for processing (4)
.github/workflows/tests.ymldocs/agentic_inference/tool_calling.mdnemo_skills/mcp/servers/particle_tool.pytests/test_mcp_clients.py
✅ Files skipped from review due to trivial changes (2)
- docs/agentic_inference/tool_calling.md
- nemo_skills/mcp/servers/particle_tool.py
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/test_mcp_clients.py
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/tests.yml:
- Around line 20-21: The GHCR_PAT secret is currently set at the job-level env
and should be scoped down; remove GHCR_PAT from the job-level env block and add
GHCR_PAT: ${{ secrets.GHCR_PAT }} only to the two steps that need it ("Login to
GHCR" and "Build Images") so other steps (install, test) cannot access the
credential; update the workflow so the step definitions for the "Login to GHCR"
and "Build Images" steps include an env section containing GHCR_PAT while the
job-level env no longer contains GHCR_PAT.
- Around line 29-34: The workflow uses github.actor as the GHCR username in the
docker/login-action step which can mismatch the GHCR_PAT owner; change the
username field in the docker/login-action@v3 step to the actual account that
owns the PAT (e.g., reference a secret like secrets.GHCR_USERNAME or hardcode
the service account username) so the credentials match the token, and ensure the
GHCR_PAT and GHCR_USERNAME secrets are set accordingly in the repository/org
secrets.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 94b773a4-2e53-4fce-a2ff-50095f18f246
📒 Files selected for processing (1)
.github/workflows/tests.yml
Signed-off-by: tamohannes <[email protected]>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Signed-off-by: tamohannes <[email protected]>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Signed-off-by: tamohannes <[email protected]>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Signed-off-by: tamohannes <[email protected]>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Signed-off-by: tamohannes <[email protected]>
|
Updated this PR to use the direct \ path instead of launching a stdio MCP server. The PR diff is now limited to the tool implementation, docs reference, and focused tests; workflow/pyproject changes were removed. @coderabbitai review |
|
Tip For best results, initiate chat on the files or code changes.
[review] |
|
Updated this PR to use the direct Tool path instead of launching a stdio MCP server. The PR diff is now limited to the tool implementation, docs reference, and focused tests; workflow/pyproject changes were removed. @coderabbitai review |
|
Tip For best results, initiate chat on the files or code changes.
[review] |
Signed-off-by: tamohannes <[email protected]>
|
Updated to the direct Tool implementation path (no stdio MCP server/client). The final diff is scoped to the tool file, docs reference, and focused tests only. @coderabbitai review |
|
Tip For best results, initiate chat on the files or code changes.
[review] |
|
The workflow changes have been removed from this PR; the current diff is scoped to docs, particle_tool.py, and tests only. @coderabbitai review |
|
Tip For best results, initiate chat on the files or code changes.
[review] |
…tool Signed-off-by: tamohannes <[email protected]>
|
Closing in favor of #1422, reopened from an internal NVIDIA-NeMo/Skills branch so CI can access repository secrets. |
Summary
Test plan
Made with Cursor
Summary by CodeRabbit
New Features
Documentation
Tests
Chores