Feature Request: Expose Backtest Results as MCP Resources

Open
#49 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
api, backend

Research direction

Start by tracing the existing read_backtest, read_backtest_orders, read_backtest_chart, and related Tool implementations to understand their API integration. Read the MCP Resources specification alongside the proposed qc:// URI patterns and capability declarations. Done means resources can be discovered and selectively read for the proposed backtest data while existing Tools remain unchanged.

Written by the indexing model from the issue text.

Description

Feature Request: Expose Backtest Results as MCP Resources

Summary

Expose backtest (and live algorithm) results as MCP Resources in addition to the existing Tools, enabling application-controlled, lazy-loaded access to result data via URIs.

Motivation

The current MCP server provides excellent Tool-based access to backtest results via read_backtest, read_backtest_chart, read_backtest_orders, etc. These work well but have a limitation in LLM-driven workflows: Tools return full JSON responses directly into the context window, which can be problematic for large backtests with extensive order histories or chart data.

The MCP specification explicitly distinguishes between:

  • Tools: Model-controlled, data returned inline, ideal for actions and small responses
  • Resources: Application-controlled, lazy-loaded via URI, ideal for "large reference materials that shouldn't be automatically loaded but should be available on demand"

Backtest results fit the Resource pattern well. A multi-year backtest might generate thousands of orders, megabytes of chart data, and extensive logs—but an LLM workflow often only needs specific slices of this data at any given time.

Proposed Design

Current Flow (Tools only)
create_backtest → backtestId
read_backtest → full JSON in context
read_backtest_orders → full order list in context
Proposed Flow (Resources + Tools)
create_backtest → backtestId

# Resources become discoverable:
resources/list → [
  qc://backtest/{id}/summary,
  qc://backtest/{id}/orders,
  qc://backtest/{id}/chart,
  ...
]

# User/client selects which to load:
resources/read(uri) → only requested data fetched
Suggested Resource URIs

Using a custom qc:// URI scheme per RFC 3986:

Resource URI Pattern Description
Summary qc://backtest/{id}/summary High-level stats: Sharpe, drawdown, total trades, net P&L, CAGR
Orders qc://backtest/{id}/orders Full order history (paginated via query params if needed)
Chart qc://backtest/{id}/chart/{name} Specific chart data series (e.g., "Strategy Equity")
Logs qc://backtest/{id}/logs Algorithm debug/info logs
Insights qc://backtest/{id}/insights Alpha model insights (if applicable)
Errors qc://backtest/{id}/errors Runtime errors and stack traces

The same pattern could extend to live algorithms:

Resource URI Pattern
Portfolio qc://live/{projectId}/portfolio
Orders qc://live/{projectId}/orders
Logs qc://live/{projectId}/logs
Resource Templates

Per the MCP spec, these could be exposed as resource templates for dynamic discovery:

{
  "resourceTemplates": [
    {
      "uriTemplate": "qc://backtest/{backtestId}/summary",
      "name": "Backtest Summary",
      "description": "High-level performance statistics for a backtest",
      "mimeType": "application/json"
    },
    {
      "uriTemplate": "qc://backtest/{backtestId}/orders",
      "name": "Backtest Orders",
      "description": "Complete order history from a backtest",
      "mimeType": "application/json"
    }
  ]
}
Capability Declaration
{
  "capabilities": {
    "resources": {
      "subscribe": true,
      "listChanged": true
    }
  }
}

The listChanged capability would allow the server to notify clients when new backtests complete, making resources available dynamically.

Benefits

  1. Context window efficiency: LLMs can request only what they need (e.g., just the summary to decide if orders are worth examining)

  2. Client-controlled loading: Host applications (Claude Desktop, custom agents) can present resources in a picker UI, letting users decide what context to include

  3. Progressive disclosure: Start with summary → drill into orders if needed → examine specific chart if anomalies detected

  4. Subscription support: Clients could subscribe to live algorithm resources for real-time updates during trading

  5. Spec alignment: Follows MCP's intended separation between model-controlled actions (Tools) and application-controlled context (Resources)

Backwards Compatibility

This is purely additive—existing Tools would continue to work unchanged. Resources provide an alternative access pattern for clients that support them.

Implementation Notes

The existing Tool implementations (read_backtest, read_backtest_orders, etc.) already contain the API integration logic. Resources would largely wrap the same underlying API calls, just exposed through the Resources protocol instead of Tools.

References

Dominant language
Python
Stars
77
Forks
33
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from QuantConnect/mcp-server

All issues in QuantConnect/mcp-server

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.