Skip to content

MCP App: Progressive tool discovery and inline image output for anomaly plots#16

Open
MatthewKhouzam wants to merge 7 commits intoeclipse-tmll:mainfrom
MatthewKhouzam:mcp-app
Open

MCP App: Progressive tool discovery and inline image output for anomaly plots#16
MatthewKhouzam wants to merge 7 commits intoeclipse-tmll:mainfrom
MatthewKhouzam:mcp-app

Conversation

@MatthewKhouzam
Copy link
Copy Markdown

@MatthewKhouzam MatthewKhouzam commented Apr 7, 2026

What it does

This PR reworks the MCP server in two commits to improve context
efficiency and enable richer AI output.

Progressive MCP tool discovery (99b7fcb)

Migrates from the low-level Server API (with manual list_tools/call_tool
dispatching) to FastMCP with decorated @mcp.tool() functions. This
eliminates the monolithic tool schema that was sent upfront in every
conversation, replacing it with progressive discovery where the AI only
loads tool definitions as needed.

  • Removes ~80 net lines from server.py (209 deletions, 128 insertions) —
    less code to maintain and less context consumed per MCP session
  • Each tool is now a standalone typed Python function instead of a branch
    in a giant if/elif chain
  • Adds --resample-freq and --min-size CLI flags for anomaly detection
  • Fixes fetch_data CSV export to handle nested TREE_TIME_XY series
    properly

MCP App with image output (ff6b48a)

Adds plot_xy_with_anomalies — a new tool that returns ImageContent
directly in the MCP response, allowing the AI to embed annotated anomaly-
detection charts inline in its output rather than just returning text
summaries.

  • Uses matplotlib to generate per-output plots with anomaly periods shaded
    and outlier points marked
  • Returns base64-encoded PNG images via MCP's ImageContent type alongside
    a text summary
  • Adds ensure_server tool to auto-download and start the Trace Compass
    server if not running
  • Adds cluster_data tool for kmeans/dbscan/hierarchical clustering
  • Refactors base_module.py to properly handle TREE_TIME_XY dict-of-series
    data via a new _add_dataframe helper
  • Adds stdout protection (_protect_stdout) and debug logging to stderr to
    prevent stray prints from corrupting the MCP stdio transport

Context savings: The old server shipped all 11 tool schemas in a single
list_tools response on every connection. With FastMCP's progressive
discovery, the client only resolves schemas for tools it actually invokes,
reducing per-session context overhead — particularly valuable when the AI
has a limited context window and every token counts.

How to test

Load in an AI ide and ask to plot an XY graph

tc-mcp-app.mp4

Follow-ups

  • Add interactivity and xy-charts.
  • Add gantt charts

Review checklist

  • As an author, I have thoroughly tested my changes and carefully followed the instructions in this template

Implement tmll_cli.py with commands for experiment management and ML analysis:
- Experiment operations: create, list, delete, list-outputs, fetch-data
- Anomaly detection: anomaly, memory-leak
- Performance analysis: changepoint, correlation
- Resource optimization: idle-resources, capacity planning
- Clustering analysis

Note: this code was created with the assistance of claude sonnet 4.5

Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Add the following MCP

mcp.json
{
  "mcpServers": {
    "tmll": {
      "command": "/usr/bin/python3",
      "args": "path-to/tmll/mcp_server_cli.py"],
      "env": {
        "PYTHONPATH": "path-to/tmll"
      }
    }
  }
}

This code creation was assisted by claude-sonnet-4.5

Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
- Fix experiment.UUID -> experiment.uuid
- Add None check for experiment in create_experiment
- Fix MemoryLeakDetection: remove outputs param, use analyze_memory_leaks()
- Fix ChangePointAnalysis: method -> methods (list of analysis modes)
- Fix CorrelationAnalysis: analyze_correlation -> analyze_correlations,
  plot_correlation -> plot_correlation_matrix
- Fix IdleResourceDetection: single threshold -> per-resource thresholds
- Fix CapacityPlanning: plan_capacity -> forecast_capacity(forecast_steps=)
- Remove clustering command (module not meaningful)
- Fix help text: 'UUID or name' -> 'UUID'
- Handle nested dict data in fetch_data_cmd
- Move scripts to tmll/mcp package
- Fix MCP server CLI_PATH to use Path(__file__) for reliable resolution
- Make MCP call_tool arguments Optional[dict] with None guard
- Add mcp==1.27.0 to requirements.txt
When the trace server returns a non-200 status for both datatree and
timegraph tree endpoints, response.model is None. Accessing .model on
None caused an AttributeError, failing CI tests.
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Allow less context usage

Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
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