feat: FastMCP server exposing PERDA as MCP tools#33
Open
VedanshGoenka wants to merge 2 commits into
Open
Conversation
- perda/mcp_server.py: FastMCP server with 11 tools covering log management, variable search/inspection, plotting, and analysis - pyproject.toml: add mcp optional extra (fastmcp); include in full - requirements.txt: add fastmcp - README_MCP.md: install/run docs + Claude Desktop config example Tools: load_log, unload_log, list_sessions, get_summary, search_variables, get_variable_stats, get_variable_values, plot_variable, analyze_frequency, get_accel_times, get_log_metadata
integrate_variable, average_variable, get_data_slice, integrate_and_smooth, get_variable_detail_summary, plot_parametric, diff_sessions, concat_logs, plot_gps 20 tools total — covers all public Analyzer, utils, concat, plotting, and core data structure operations available in PERDA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a FastMCP server that exposes the full PERDA API as MCP tools. MCP clients (Claude Desktop, Cursor, etc.) can load local PER CSV logs and run analysis directly from an LLM conversation.
New files
perda/mcp_server.pyREADME_MCP.mdUpdated files
requirements.txtfastmcppyproject.tomlmcpoptional extra; included infullAll 20 tools
Log Management
load_log(session_id, filepath)unload_log(session_id)list_sessions()concat_logs(session_id_a, session_id_b, output_session_id, gap)perda.analyzer.concat.concat)Inspection & Search
get_summary(session_id)search_variables(session_id, query)get_variable_stats(session_id, var_name)get_variable_detail_summary(session_id, var_name)data_instance_summaryoutput including time-weighted averageget_log_metadata(session_id)Data Access
get_variable_values(session_id, var_name, ts_start, ts_end, max_points)get_data_slice(session_id, var_name, start_time, end_time)Analysis
integrate_variable(session_id, var_name, start_time, end_time)average_variable(session_id, var_name, start_time, end_time)integrate_and_smooth(session_id, var_name)analyze_frequency(session_id, var_name, expected_hz)get_accel_times(session_id)diff_sessions(session_id_a, session_id_b)Plotting
plot_variable(session_id, var_1, var_2, ts_start, ts_end, title)plot_parametric(session_id, var_x, var_y, title, square_axes)plot_gps(session_id, lat_var, lon_var, title)Usage
Claude Desktop
mcpServersconfig:{ "mcpServers": { "perda": { "command": "fastmcp", "args": ["run", "/absolute/path/to/per-data-analyzer/perda/mcp_server.py"] } } }Notes
fig.to_json()— clients can parse or render.ImportErrorfallback iffastmcpnot installed.python3 -m py_compile perda/mcp_server.py✅LiveAnalyzer(CDP/live streaming) is not included — it requires a live network connection to the car and is not suitable for an MCP tool interface.Architecture Note: Why a wrapper file, not embedded decorators?
FastMCP's
@mcp.tool()decorator works on module-level functions, not class methods. PERDA's primary API isAnalyzerinstance methods (analyzer.plot(),analyzer.search(), etc.) — decorating those directly would exposeselfas a required JSON-serializable parameter, which isn't possible over MCP.The
_analyzerssession state dict is also load-bearing: it bridges stateless MCP calls → statefulAnalyzerobjects. A client callsload_log(session_id, path)once, then all subsequent tools reference that session by ID. That mapping has to live somewhere central.For the pure utility functions (
integrate_over_time_range,data_instance_summary, etc.) that are already standalone, embedding decorators would be more natural. That would work cleanly if PERDA were redesigned as a fully functional API (noAnalyzerclass, everything takesSingleRunData/DataInstancedirectly). As-is, the wrapper file is the right seam — it keepsfastmcpas an optional dependency of the server entrypoint only, and the rest of the library stays import-clean.