Skip to content

Add particle MCP tool - #1415

Closed
tamohannes wants to merge 9 commits into
NVIDIA-NeMo:mainfrom
tamohannes:feat/particle-mcp-tool
Closed

tamohannes wants to merge 9 commits into
NVIDIA-NeMo:mainfrom
tamohannes:feat/particle-mcp-tool

Conversation

@tamohannes

@tamohannes tamohannes commented May 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add a built-in particle MCP tool for PDG particle lookup and search.
  • Document the new built-in tool in the agentic inference tool-calling guide.
  • Add MCP client tests for tool configuration and stdio tool listing.

Test plan

  • python -m py_compile nemo_skills/mcp/servers/particle_tool.py
  • python -m pytest tests/test_mcp_clients.py::TestParticleTool -q --tb=short
  • python -m pytest tests/test_mcp_clients.py -q --tb=short

Made with Cursor

Summary by CodeRabbit

  • New Features

    • Added a particle-physics lookup tool (PDG ID and name resolution) and a particle search tool (substring queries, up to 10 matches).
  • Documentation

    • Updated built-in tools reference to include the ParticleTool and a note about the particle dependency.
  • Tests

    • Added tests verifying ParticleTool configuration and basic integration, with ensured teardown.
  • Chores

    • CI: conditional registry caching and GHCR login, tightened test selection, and a fork-safe path for MCP tests.

@coderabbitai

coderabbitai Bot commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new MCP stdio server and client wrapper (ParticleTool) for PDG/name particle lookups and substring searches using the particle package, updates docs, adds tests for tool discovery, and conditions CI to optionally use GHCR and install tooling extras.

Changes

Cohort / File(s) Summary
MCP Particle Server Implementation
nemo_skills/mcp/servers/particle_tool.py
New MCP stdio server exposing particle-lookup and particle-search, formatter for particle records, main() entrypoint, and ParticleTool MCP client wrapper using MCPStdioClient.
Tool Documentation
docs/agentic_inference/tool_calling.md
Added ParticleTool to built-in tools list with GitHub link and note about requiring the particle dependency.
Tests
tests/test_mcp_clients.py
Added tests verifying ParticleTool client configuration and async tool discovery (particle-lookup, particle-search), ensuring client shutdown in teardown.
CI workflow
.github/workflows/tests.yml
Conditional GHCR login and Docker cache gated on GHCR_PAT; retry wrapper for Docker builds; test marker narrowed to not gpu and not live; when GHCR credentials absent, runs fork-safe MCP tests step.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add particle MCP tool' clearly and concisely describes the main change: introduction of a new particle physics lookup tool using the MCP (Model Context Protocol) framework.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
nemo_skills/mcp/servers/particle_tool.py (1)

67-73: ⚡ Quick win

Normalize 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 Particle

Also 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 win

Add 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7dcb0a6 and 56a7d8b.

📒 Files selected for processing (3)
  • docs/agentic_inference/tool_calling.md
  • nemo_skills/mcp/servers/particle_tool.py
  • tests/test_mcp_clients.py

@gwarmstrong gwarmstrong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

secrets is not available in step-level if conditions — use job-level env instead.

Line 27 uses if: ${{ secrets.GHCR_PAT != '' }} in a step condition. GitHub Actions does not allow the secrets context at the step level, and this will fail workflow evaluation. Move GHCR_PAT to the job's env block and reference it via env.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

📥 Commits

Reviewing files that changed from the base of the PR and between 56a7d8b and f749417.

📒 Files selected for processing (1)
  • .github/workflows/tests.yml

Signed-off-by: tamohannes <[email protected]>
@tamohannes
tamohannes force-pushed the feat/particle-mcp-tool branch from f749417 to 068c3cb Compare May 1, 2026 19:03

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🟠 Major

Use env (not secrets) in step-level if expression

Line 27 uses secrets.GHCR_PAT in the if field, but the secrets context is not available at this location. GitHub Actions only allows env, github, inputs, job, matrix, needs, runner, steps, strategy, and vars contexts in step if expressions. 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

📥 Commits

Reviewing files that changed from the base of the PR and between f749417 and 068c3cb.

📒 Files selected for processing (4)
  • .github/workflows/tests.yml
  • docs/agentic_inference/tool_calling.md
  • nemo_skills/mcp/servers/particle_tool.py
  • tests/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

@tamohannes

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 068c3cb and b0cf452.

📒 Files selected for processing (1)
  • .github/workflows/tests.yml

Comment thread .github/workflows/tests.yml Resolved
Comment thread .github/workflows/tests.yml Resolved
@tamohannes

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tamohannes

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tamohannes

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tamohannes

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tamohannes

Copy link
Copy Markdown
Collaborator Author

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

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@tamohannes: Thanks for the update! Triggering a review of the revised PR now — I'll review the tool implementation, docs reference, and focused tests.

[review]

@tamohannes

Copy link
Copy Markdown
Collaborator Author

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

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@tamohannes: Thanks for the update! Triggering a review of the revised PR now — I'll review the tool implementation, docs reference, and focused tests.

[review]

@tamohannes

Copy link
Copy Markdown
Collaborator Author

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

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@tamohannes: Thanks for the update! Triggering a review of the revised PR now — I'll review the direct Tool implementation, docs reference, and focused tests.

[review]

@tamohannes

Copy link
Copy Markdown
Collaborator Author

The workflow changes have been removed from this PR; the current diff is scoped to docs, particle_tool.py, and tests only. @coderabbitai review

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@tamohannes: Thanks for the update — triggering a review of the scoped diff now (docs, particle_tool.py, and tests only).

[review]

@tamohannes

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #1422, reopened from an internal NVIDIA-NeMo/Skills branch so CI can access repository secrets.

@tamohannes tamohannes closed this May 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants