Conversation
Reviewer's GuideIntroduces 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 invocationssequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues, and left some high level feedback:
- In
mcp-server.mjs, thequantlab_read_filetool’sinputSchemashould 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., forquantlab_check,quantlab_version, etc.), consider using thePYTHON_EXECUTABLEconstant instead of hardcodingpythonso that the reported command matches the actual executable used, especially whenQUANTLAB_PYTHONis 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| 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 }) => { |
There was a problem hiding this comment.
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.
| const result = await runPythonCli(["--check"], 120000); | ||
| return formatProcessResult("quantlab_check", result, "python main.py --check"); |
There was a problem hiding this comment.
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.
| assert payload["source_artifact_path"] == "C:\\Users\\marce\\Documents\\meta_trade\\tests\\fixtures\\expected_quantlab_handoff.json" | ||
| assert payload["source_artifact_href"] is None |
There was a problem hiding this comment.
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.
Adds project-wide Cursor rules, a local MCP server for QuantLab validation tools, and repo guidance so agents use the same operating context.
Validation:
Summary by Sourcery
Add a local MCP server and agent guidance, and surface QuantLab validation artifacts in the research UI pretrade panel.
New Features:
Enhancements:
Build:
Documentation: