nsys-mcp

nsys-mcp

Enables GPU profiling and performance analysis via NVIDIA Nsight Systems, allowing agents to profile binaries and aggregate statistics for kernels, memory copies, and NVTX ranges. It supports advanced analysis through interval tree construction and structural queries on profiling reports.

Category
访问服务器

README

<p align="center"> <img src="assets/nvidia-nsight-systems-icon-gbp-shaded-256.png" alt="Nsight Systems logo" width="128"> </p>

<h3 align="center">nsys MCP Server</h3>

<p align="center"> <code>MCP</code> · <code>GPU Profiling</code> · <code>NVIDIA Nsight Systems</code> · <code>LLM Agents</code> </p>


nsys-mcp is an MCP (Model Context Protocol) server that provides GPU profiling capabilities through NVIDIA Nsight Systems (nsys). It lets an LLM agent profile binaries, parse reports, compute statistics, and analyze interval trees — all via standard MCP tool calls.

Prerequisites

Installation

pip install -e .

For development (tests):

pip install -e ".[dev]"

Running the Server

The server communicates over stdio (the default MCP transport):

python -m nsys_mcp.server

Cursor / VS Code MCP configuration

Add to your MCP settings (e.g. .cursor/mcp.json):

{
  "mcpServers": {
    "nsys-profiler": {
      "command": "python",
      "args": ["-m", "nsys_mcp.server"]
    }
  }
}

Available Tools

The server exposes 10 tools:

# Tool Description
1 check_nsys Verify that nsys is installed and return its version
2 profile_binary Profile a binary with full CUDA, NVTX, and GPU metrics collection
3 load_report Load a pre-existing .nsys-rep or NDJSON .json file
4 list_reports List all cached profiling reports with metadata
5 get_event_summary Breakdown of event types and counts for a report
6 get_kernel_stats Aggregate GPU kernel statistics grouped by kernel name
7 get_nvtx_stats Aggregate NVTX range durations grouped by annotation text
8 get_memcpy_stats Aggregate memory copy statistics grouped by direction
9 build_interval_tree Construct an interval tree from profiling events
10 query_interval_tree Run structural queries against an interval tree

profile_binary

Profile a binary with full CUDA, NVTX, and GPU metrics collection. Results are cached so repeated calls with the same arguments skip re-profiling.

Parameter Type Description
binary str Path to the executable
args list[str] Command-line arguments (optional)
env dict[str, str] Extra environment variables (optional)
cwd str Working directory (optional)
duration int Max profiling duration in seconds (optional)
extra_nsys_flags list[str] Additional nsys flags (optional)

Returns report_id, event_counts, and time_span_ns.

load_report

Load a pre-existing .nsys-rep or NDJSON .json file without re-profiling.

Parameter Type Description
path str Path to .nsys-rep or .json file

get_event_summary

Get a breakdown of event types and counts for a report.

Parameter Type Description
report_id str ID from profile_binary or load_report

get_kernel_stats

Aggregate GPU kernel statistics grouped by kernel name. Includes duration statistics (mean, std, min, max, median, count, total) and GPU metrics (grid/block size, shared memory, registers).

Parameter Type Description
report_id str Report identifier
top_n int Limit to top N kernels (optional)
sort_by str total_ns, count, mean_ns, or max_ns (default: total_ns)

get_nvtx_stats

Aggregate NVTX range durations grouped by annotation text.

Parameter Type Description
report_id str Report identifier
domain_id int Filter by NVTX domain (optional)

get_memcpy_stats

Aggregate memory copy statistics grouped by copy direction (HtoD, DtoH, DtoD, etc.). Includes duration stats, total bytes, and bandwidth estimates.

Parameter Type Description
report_id str Report identifier

build_interval_tree

Construct an interval tree from profiling events. If multiple disjoint trees exist (a forest), they can be merged under a synthetic root.

Parameter Type Description
report_id str Report identifier
event_types list[str] Subset of ["kernel", "nvtx", "trace", "memcpy", "sync"] (default: all)
reduce_forest bool Merge forest into single tree (default: true)
thread_id int Filter by thread/stream ID (optional)

query_interval_tree

Run structural queries against a previously built interval tree.

Parameter Type Description
report_id str Report identifier
query_type str One of the query types below
event_name str Event name for count_calls
subtree_root_name str Scope query to a named subtree (optional)
max_depth int Limit traversal depth (optional)

Query types:

Type Description
most_time_consuming Find the longest-duration event in a subtree
top_level List top-level interval names
count_calls Count occurrences of a named event in a subtree
subtree_summary Aggregated stats for a named subtree

Typical Workflow

1. check_nsys()                              — verify nsys is available
2. profile_binary(binary="/app/solver", ...) — profile and get report_id
3. get_kernel_stats(report_id, top_n=10)     — see top 10 kernels
4. get_nvtx_stats(report_id)                 — see NVTX annotation timings
5. get_memcpy_stats(report_id)               — see memory transfer stats
6. build_interval_tree(report_id)            — build the tree
7. query_interval_tree(report_id,            — find bottleneck
       query_type="most_time_consuming")
8. query_interval_tree(report_id,            — count specific kernel calls
       query_type="count_calls",
       event_name="cub::DeviceReduce")

Caching

Profiling results are cached in two tiers:

  • In-memory LRU — fast access for the current session (up to 8 reports).
  • Disk — persists across server restarts at ~/.nsys_mcp/cache/.

Cache keys are derived from the binary path and arguments, so identical profiling runs reuse cached results automatically.

Testing

pip install -e ".[dev]"
pytest

Project Structure

src/nsys_mcp/
├── server.py           # FastMCP server, tool definitions, lifespan
├── nsys_runner.py      # nsys CLI wrapper (profile, export, version)
├── report_parser.py    # NDJSON streaming parser, string-table resolution
├── models.py           # Pydantic models for events, stats, configs
├── aggregator.py       # Group-by aggregation (mean, std, min, max, count)
├── interval_tree.py    # Interval tree/forest construction + queries
└── cache.py            # Two-tier cache (memory LRU + disk pickle)

Links

License

nsys-mcp is licensed under the MIT License.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选