Skip to content

Add Cursor rules and local MCP server#253

Merged
Whiteks1 merged 2 commits intomainfrom
codex/cursor-mcp-integration
Apr 4, 2026
Merged

Add Cursor rules and local MCP server#253
Whiteks1 merged 2 commits intomainfrom
codex/cursor-mcp-integration

Conversation

@Whiteks1
Copy link
Copy Markdown
Owner

@Whiteks1 Whiteks1 commented Apr 4, 2026

Adds project-wide Cursor rules, a local MCP server for QuantLab validation tools, and repo guidance so agents use the same operating context.

Validation:

  • npm install in desktop/
  • node --check desktop/mcp-server.mjs
  • git status clean after commit

Summary by Sourcery

Add a local MCP server and agent guidance, and surface QuantLab validation artifacts in the research UI pretrade panel.

New Features:

  • Expose validation and source artifact links in the research UI pretrade panel when available, with a fallback empty state message.
  • Introduce a local MCP server for QuantLab with tools for health checks, version queries, run listing, paper session health, desktop smoke tests, and repository file reads.
  • Document and enforce repository-wide agent working rules and MCP usage guidance via AGENTS.md and Cursor rules.

Enhancements:

  • Extend the research UI pretrade payload and tests to include source artifact metadata for bounded handoff artifacts.

Build:

  • Add an npm script to run the MCP server and include MCP-related dependencies in the desktop package configuration.

Documentation:

  • Document the Cursor MCP server, available tools, and entrypoint in the desktop README, and add an agent guide for working with QuantLab.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 4, 2026

Reviewer's Guide

Introduces a local MCP server and Cursor configuration for QuantLab, extends the desktop app tooling, documents agent/MCP usage, and surfaces validation/source artifact links in the pre‑trade UI while tightening a related test expectation.

Sequence diagram for quantLab MCP tool invocations

sequenceDiagram
  actor Agent
  participant Cursor
  participant MCP_server_quantlab_local as quantlab_local_server
  participant PythonCLI as Python_main_py
  participant NodeSmoke as Node_smoke_script
  participant FileSystem

  Agent->>Cursor: Trigger MCP tool (e.g. quantlab_check)
  Cursor->>MCP_server_quantlab_local: JSON RPC tool call over stdio
  activate MCP_server_quantlab_local

  alt Python_based_tool
    MCP_server_quantlab_local->>PythonCLI: spawn python main.py with flags
    activate PythonCLI
    PythonCLI-->>MCP_server_quantlab_local: exitCode, stdout, stderr
    deactivate PythonCLI
  else Desktop_smoke_tool
    MCP_server_quantlab_local->>NodeSmoke: spawn node scripts/smoke.js
    activate NodeSmoke
    NodeSmoke-->>MCP_server_quantlab_local: exitCode, stdout, stderr
    deactivate NodeSmoke
  else Read_file_tool
    MCP_server_quantlab_local->>FileSystem: Resolve and read relative_path
    FileSystem-->>MCP_server_quantlab_local: File contents or error
  end

  MCP_server_quantlab_local-->>Cursor: Formatted text content (truncated if needed)
  deactivate MCP_server_quantlab_local
  Cursor-->>Agent: Display tool result in IDE
Loading

File-Level Changes

Change Details Files
Expose validation and source artifact paths in the pretrade panel UI.
  • Builds an artifactEntries list from latest_validation_* and source_artifact_* pretrade fields, filtering out empty entries.
  • Renders artifact links as either anchor tags (when href is present) or non-clickable divs showing label and path or fallback text.
  • Shows an empty-state panel when no artifact paths are available and inserts the artifact block above rejection reasons in the panel output.
research_ui/app.js
Align tests with new pretrade payload fields for source artifact metadata.
  • Extends the existing pretrade handoff payload test to assert source_artifact_path and source_artifact_href values, ensuring backend populates the new UI fields.
test/test_research_ui_server.py
Add a local MCP server for QuantLab and wire it into the desktop tooling and docs.
  • Creates mcp-server.mjs implementing a Model Context Protocol server exposing QuantLab CLI- and desktop-related tools (check, version, runs list, paper sessions health, desktop smoke, and repo-bounded file reads).
  • Implements robust child-process execution helpers with timeouts, stdout/stderr capture, and output truncation, plus path-bounded file reading using fs and path resolution.
  • Adds an npm mcp script to run the MCP server, and adds @modelcontextprotocol/sdk and zod as dev dependencies in desktop/package.json.
  • Documents the MCP server entrypoint, available tools, and how it is exposed to Cursor in desktop/README.md, and updates the lockfile accordingly.
desktop/mcp-server.mjs
desktop/package.json
desktop/README.md
desktop/package-lock.json
Introduce repository-wide agent and Cursor rules to standardize AI tooling behavior in QuantLab.
  • Adds AGENTS.md describing project context, working rules, validation preferences (favoring repo MCP tools), and quality expectations for agents working in this repo.
  • Introduces Cursor MCP configuration and rule files under .cursor/ (including desktop-electron, python-quantlab, and quantlab-core rule documents) so Cursor operates with QuantLab-specific context and tools.
  • Configures .cursor/mcp.json to point Cursor at the new quantlab-local MCP server for the defined QuantLab tools.
AGENTS.md
.cursor/mcp.json
.cursor/rules/desktop-electron.mdc
.cursor/rules/python-quantlab.mdc
.cursor/rules/quantlab-core.mdc

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 3 issues, and left some high level feedback:

  • In mcp-server.mjs, the quantlab_read_file tool’s inputSchema should be a Zod object schema (e.g., z.object({ relative_path: z.string().describe(...) })) rather than a plain object literal to match the MCP SDK’s expectations and ensure proper validation.
  • When formatting command lines in formatProcessResult (e.g., for quantlab_check, quantlab_version, etc.), consider using the PYTHON_EXECUTABLE constant instead of hardcoding python so that the reported command matches the actual executable used, especially when QUANTLAB_PYTHON is set.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `mcp-server.mjs`, the `quantlab_read_file` tool’s `inputSchema` should be a Zod object schema (e.g., `z.object({ relative_path: z.string().describe(...) })`) rather than a plain object literal to match the MCP SDK’s expectations and ensure proper validation.
- When formatting command lines in `formatProcessResult` (e.g., for `quantlab_check`, `quantlab_version`, etc.), consider using the `PYTHON_EXECUTABLE` constant instead of hardcoding `python` so that the reported command matches the actual executable used, especially when `QUANTLAB_PYTHON` is set.

## Individual Comments

### Comment 1
<location path="desktop/mcp-server.mjs" line_range="146-151" />
<code_context>
+    return formatProcessResult("quantlab_desktop_smoke", result, "node scripts/smoke.js");
+  });
+
+  server.registerTool("quantlab_read_file", {
+    description: "Read a text file within the QuantLab repository.",
+    inputSchema: {
+      relative_path: z.string().describe("Path relative to the QuantLab repository root"),
+    },
+  }, async ({ relative_path }) => {
+    const resolvedPath = path.resolve(PROJECT_ROOT, relative_path);
+    const relative = path.relative(PROJECT_ROOT, resolvedPath);
</code_context>
<issue_to_address>
**issue (bug_risk):** `inputSchema` for `quantlab_read_file` is not a Zod schema object, which may break validation and tool metadata.

Here `inputSchema` is a plain object instead of a Zod schema, so the MCP SDK may not treat it as a valid schema (breaking validation or metadata). This should be wrapped in `z.object(...)`, e.g.

```ts
inputSchema: z.object({
  relative_path: z
    .string()
    .describe("Path relative to the QuantLab repository root"),
}),
```

and the handler signature adjusted if the SDK now passes an object matching that schema shape.
</issue_to_address>

### Comment 2
<location path="desktop/mcp-server.mjs" line_range="107-108" />
<code_context>
+  server.registerTool("quantlab_check", {
+    description: "Run the standard QuantLab health check.",
+  }, async () => {
+    const result = await runPythonCli(["--check"], 120000);
+    return formatProcessResult("quantlab_check", result, "python main.py --check");
+  });
+
</code_context>
<issue_to_address>
**nitpick:** The command string passed to `formatProcessResult` is hardcoded to `python` and can diverge from `PYTHON_EXECUTABLE`.

Because the display string is hardcoded as `"python main.py --check"` while the actual executable comes from `PYTHON_EXECUTABLE`, the shown command can differ from what was run (e.g. when `QUANTLAB_PYTHON` points to another interpreter). To keep them aligned, construct the display command from `PYTHON_EXECUTABLE`, e.g.:

```js
const commandLine = `${PYTHON_EXECUTABLE} main.py --check`;
const result = await runPythonCli(["--check"], 120000);
return formatProcessResult("quantlab_check", result, commandLine);
```

You can apply the same approach to the other `quantlab_*` tools.
</issue_to_address>

### Comment 3
<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-coded, machine-specific absolute path in test assertion

`source_artifact_path` is asserted against a Windows-specific absolute path (with a username and local directory layout), which will fail on other machines/CI and on non-Windows platforms. Please build the expected path from the same test/fixture base (e.g., `tmp_path`, `Path`, or a fixture helper) and compare against that, or relax the check (e.g., `endswith`/`in`) to keep the test portable.
</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 +146 to +151
server.registerTool("quantlab_read_file", {
description: "Read a text file within the QuantLab repository.",
inputSchema: {
relative_path: z.string().describe("Path relative to the QuantLab repository root"),
},
}, async ({ relative_path }) => {
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 (bug_risk): inputSchema for quantlab_read_file is not a Zod schema object, which may break validation and tool metadata.

Here inputSchema is a plain object instead of a Zod schema, so the MCP SDK may not treat it as a valid schema (breaking validation or metadata). This should be wrapped in z.object(...), e.g.

inputSchema: z.object({
  relative_path: z
    .string()
    .describe("Path relative to the QuantLab repository root"),
}),

and the handler signature adjusted if the SDK now passes an object matching that schema shape.

Comment on lines +107 to +108
const result = await runPythonCli(["--check"], 120000);
return formatProcessResult("quantlab_check", result, "python main.py --check");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nitpick: The command string passed to formatProcessResult is hardcoded to python and can diverge from PYTHON_EXECUTABLE.

Because the display string is hardcoded as "python main.py --check" while the actual executable comes from PYTHON_EXECUTABLE, the shown command can differ from what was run (e.g. when QUANTLAB_PYTHON points to another interpreter). To keep them aligned, construct the display command from PYTHON_EXECUTABLE, e.g.:

const commandLine = `${PYTHON_EXECUTABLE} main.py --check`;
const result = await runPythonCli(["--check"], 120000);
return formatProcessResult("quantlab_check", result, commandLine);

You can apply the same approach to the other quantlab_* tools.

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-coded, machine-specific absolute path in test assertion

source_artifact_path is asserted against a Windows-specific absolute path (with a username and local directory layout), which will fail on other machines/CI and on non-Windows platforms. Please build the expected path from the same test/fixture base (e.g., tmp_path, Path, or a fixture helper) and compare against that, or relax the check (e.g., endswith/in) to keep the test portable.

@Whiteks1 Whiteks1 merged commit 0eb7364 into main Apr 4, 2026
2 checks passed
@Whiteks1 Whiteks1 deleted the codex/cursor-mcp-integration branch April 4, 2026 17:22
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.

1 participant