Skip to content

feat(desktop): add outputs MCP tools#255

Merged
Whiteks1 merged 4 commits intomainfrom
codex/mcp-outputs-artifacts
Apr 4, 2026
Merged

feat(desktop): add outputs MCP tools#255
Whiteks1 merged 4 commits intomainfrom
codex/mcp-outputs-artifacts

Conversation

@Whiteks1
Copy link
Copy Markdown
Owner

@Whiteks1 Whiteks1 commented Apr 4, 2026

Summary

Add two read-only MCP tools to the local QuantLab desktop server:

  • quantlab_outputs_list to list artifacts and directories under outputs/
  • quantlab_artifact_read to read text artifacts under outputs/

Scope

This is intentionally narrow:

  • read-only access only
  • no trading logic changes
  • no submit, signing, or orchestration changes

Validation

  • node --check desktop/mcp-server.mjs
  • git diff --check

Notes

  • binary artifacts are not supported by the read tool
  • the list tool returns JSON-formatted metadata for quick inspection

Closes #254

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 4, 2026

Reviewer's Guide

Adds a local MCP server for the QuantLab desktop with two new read-only tools for browsing and reading artifacts under outputs/, wires it into the desktop package, and surfaces pretrade artifact links in the research UI alongside a small test update and agent/editor config docs.

Sequence diagram for quantlab_artifact_read MCP tool invocation

sequenceDiagram
  actor Developer
  participant CursorClient
  participant McpServer
  participant NodeFs as Fs

  Developer->>CursorClient: Request tool quantlab_artifact_read(relative_path)
  CursorClient->>McpServer: callTool quantlab_artifact_read(relative_path)

  McpServer->>McpServer: resolveOutputsPath(relative_path)
  McpServer->>Fs: stat(resolvedPath)
  Fs-->>McpServer: FileStat
  alt path_is_directory
    McpServer-->>CursorClient: isError=true, message "Expected a file under outputs/"
  else binary_extension
    McpServer-->>CursorClient: isError=true, message "Binary artifact reading is not supported"
  else text_file
    McpServer->>Fs: readFile(resolvedPath, "utf8")
    Fs-->>McpServer: content
    McpServer->>McpServer: build payload (bytes, modified_at, truncated, content)
    McpServer-->>CursorClient: content text with metadata and artifact body
  end

  CursorClient-->>Developer: Display tool result
Loading

Flow diagram for outputs/ artifact listing and reading tools

flowchart TD
  start([Start])

  subgraph list_tool[quantlab_outputs_list]
    L1{{"Tool called with optional relative_path"}}
    L1 --> L2["Resolve path under outputs/ using resolveOutputsPath"]
    L2 --> L3["fs.stat(targetPath)"]
    L3 --> L4{Is directory?}
    L4 -- No --> Lerr["Error: not a directory under outputs/"]
    L4 -- Yes --> L5["fs.readdir(targetPath, withFileTypes=true)"]
    L5 --> L6["For each entry: fs.stat(entryPath)"]
    L6 --> L7["Build metadata: name, kind, relative_path, size_bytes, size_human, modified_at"]
    L7 --> L8["Sort: directories first, then files by name"]
    L8 --> L9["Return JSON payload (root, requested_path, absolute_path, entry_count, entries)"]
  end

  subgraph read_tool[quantlab_artifact_read]
    R1{{"Tool called with relative_path"}}
    R1 --> R2["Resolve path under outputs/ using resolveOutputsPath"]
    R2 --> R3["fs.stat(targetPath)"]
    R3 --> R4{Is directory?}
    R4 -- Yes --> Rerr1["Error: expected a file under outputs/"]
    R4 -- No --> R5{Binary extension?}
    R5 -- Yes --> Rerr2["Error: binary artifact reading not supported"]
    R5 -- No --> R6["fs.readFile(targetPath, utf8)"]
    R6 --> R7["Apply truncateText to enforce MAX_OUTPUT_CHARS"]
    R7 --> R8["Build response: bytes, modified_at, truncated flag, content"]
    R8 --> R9["Return formatted text block with metadata and content"]
  end

  start --> L1
  start --> R1
Loading

File-Level Changes

Change Details Files
Expose validation and source artifact links in the pretrade panel UI.
  • Build an artifactEntries list from latest_validation/source artifact paths and hrefs, filtering out empty entries.
  • Render artifactLinks as either clickable anchors (when href present) or static rows (when only a path is available).
  • Show a fallback empty-state panel when no artifact paths are available.
  • Inject the artifact links block into the pretrade panel above rejection reasons.
research_ui/app.js
Add a local MCP server for QuantLab desktop with tools for health checks, repo file reads, and outputs/ browsing/reading.
  • Introduce mcp-server.mjs that sets up an MCP server over stdio with tools wrapping QuantLab Python CLI commands and a desktop smoke test.
  • Implement secure path resolution helpers for repository and outputs/ paths, including directory traversal guards.
  • Add utilities for truncating output, formatting process results, and humanizing byte sizes.
  • Add quantlab_outputs_list to return JSON metadata for entries under outputs/ and quantlab_artifact_read to read non-binary artifacts with truncation metadata.
desktop/mcp-server.mjs
Wire MCP server into the desktop package and document available tools and agent rules.
  • Add an npm mcp script to run the MCP server and declare @modelcontextprotocol/sdk and zod as devDependencies.
  • Document available MCP tools and server entrypoint in desktop/README.md.
  • Add AGENTS.md plus Cursor MCP and rules files to guide agents and editor behavior.
desktop/package.json
desktop/README.md
AGENTS.md
.cursor/mcp.json
.cursor/rules/desktop-electron.mdc
.cursor/rules/python-quantlab.mdc
.cursor/rules/quantlab-core.mdc
Extend pretrade payload expectations in tests to cover source artifact metadata.
  • Update the pretrade handoff payload test to assert source_artifact_path and source_artifact_href fields for the newer handoff artifact.
test/test_research_ui_server.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The MCP tool inputSchema definitions in mcp-server.mjs are currently plain objects containing z.string() etc.; consider wrapping these in z.object({...}) so they match the expected Zod schema shape used by the MCP SDK and can validate inputs correctly.
  • The new assertion in test_build_pretrade_handoff_payload_selects_latest_validation_artifact hardcodes a Windows-specific absolute path string, which will be brittle on non-Windows environments; consider deriving this expected value from the tmp_path/fixtures instead of embedding a platform-specific path.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The MCP tool `inputSchema` definitions in `mcp-server.mjs` are currently plain objects containing `z.string()` etc.; consider wrapping these in `z.object({...})` so they match the expected Zod schema shape used by the MCP SDK and can validate inputs correctly.
- The new assertion in `test_build_pretrade_handoff_payload_selects_latest_validation_artifact` hardcodes a Windows-specific absolute path string, which will be brittle on non-Windows environments; consider deriving this expected value from the tmp_path/fixtures instead of embedding a platform-specific path.

## Individual Comments

### Comment 1
<location path="test/test_research_ui_server.py" line_range="514-515" />
<code_context>
     assert payload["handoff_id"] == "handoff-newer"
     assert payload["latest_validation_path"] == str(newer)
     assert payload["latest_validation_href"] == "/outputs/pretrade_handoff/newer/pretrade_handoff_validation.json"
+    assert payload["source_artifact_path"] == "C:\\Users\\marce\\Documents\\meta_trade\\tests\\fixtures\\expected_quantlab_handoff.json"
+    assert payload["source_artifact_href"] is None


</code_context>
<issue_to_address>
**issue (testing):** Avoid hard‑coding an absolute Windows path in the test to keep it portable and robust.

The test will only pass on your local Windows setup and may break if the fixture is moved. Instead of hard‑coding the full path, derive `source_artifact_path` from the same fixture/tmp directory used in setup (e.g., using `Path` joins or a helper) so the test remains portable and still verifies the field correctly.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +514 to +515
assert payload["source_artifact_path"] == "C:\\Users\\marce\\Documents\\meta_trade\\tests\\fixtures\\expected_quantlab_handoff.json"
assert payload["source_artifact_href"] is None
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (testing): Avoid hard‑coding an absolute Windows path in the test to keep it portable and robust.

The test will only pass on your local Windows setup and may break if the fixture is moved. Instead of hard‑coding the full path, derive source_artifact_path from the same fixture/tmp directory used in setup (e.g., using Path joins or a helper) so the test remains portable and still verifies the field correctly.

@Whiteks1 Whiteks1 merged commit 461a969 into main Apr 4, 2026
2 checks passed
@Whiteks1 Whiteks1 deleted the codex/mcp-outputs-artifacts branch April 4, 2026 18:53
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.

feat(desktop): add outputs MCP tools

1 participant