Skip to content

Agent mode sql nexus pijocoder 051526#527

Closed
nishanthini089 wants to merge 18 commits into
masterfrom
AgentMode_SQLNexus_pijocoder_051526
Closed

Agent mode sql nexus pijocoder 051526#527
nishanthini089 wants to merge 18 commits into
masterfrom
AgentMode_SQLNexus_pijocoder_051526

Conversation

@nishanthini089

Copy link
Copy Markdown

Agent created on top of the MCP Server branch with additional SQL Nexus queries as tools + diagnostic skills from SQL Nexus wiki added

hostsecret and others added 18 commits May 1, 2026 21:28
…CPServer_SQLNexus_pijocoder_050126

sh: line 1: w: command not found
…t script

- Consolidated BUILD_SUMMARY.md, GETTING_STARTED.md, HOW_TO_USE.md, and
  SETUP.md into a single README.md with setup, testing, architecture,
  MCP protocol flow diagram, and troubleshooting sections

- Added --server, --database, and --trusted-connection command-line args
  to Program.cs so connection details can be passed directly without
  relying on appsettings.json or environment variables

- Fixed stdin EOF handling in ProcessRequests() to break on null ReadLine
  (pipe close) instead of looping forever, enabling clean exit after
  piped test input

- Updated Test-McpServer.ps1:
  - Replaced hardcoded paths with script-relative paths
  - Added interactive prompts for server/database with defaults
  - Passes --server and --database args to the exe on each call
  - Implemented Invoke-McpTool helper with Format-Table output
  - Fixed while loop exit (replaced switch break with $exit flag)
…c, MCP lifecycle)

McpTypes.cs
- Added NullValueHandling.Ignore to JsonRpcResponse.Result and Error
  so responses include only result OR error, never both — fixing a
  strict JSON-RPC 2.0 spec violation that caused Copilot CLI to reject
  all responses (VS Code was tolerant; CLI was not)

Program.cs
- Notification handling: requests with null id are now treated as
  notifications and never produce a response; notifications/initialized
  is explicitly recognized as a no-op per MCP lifecycle spec
- Protocol version negotiation: initialize now echoes back the client's
  requested protocolVersion instead of hardcoding "2024-11-05"
- JSON-RPC batch support: lines starting with '[' are parsed as JArray
  and each element processed individually
- Lazy SQL initialization: DiagnosticAnalyzer is created on first tool
  call via GetAnalyzer() — server now always completes the MCP handshake
  even if SQL Server is temporarily unavailable at startup

README.md
- Updated note to include Copilot CLI alongside VS Code as a supported client
- MCP Protocol Flow diagram updated to show notifications/initialized step
  and protocol version negotiation
- Added troubleshooting entry for sqlnexus_MCP showing X in Copilot CLI

START_HERE.md
- CLI config example updated to include "type":"stdio" (required by CLI)
…d delta query stats

DiagnosticAnalyzer.cs

  AnalyzeCpuUsage() — complete rewrite:
  - Replaced wait-stats-only implementation with a single Perfmon query that
    returns per-sample rows (sample_time, sql_cpu_pct, nonsql_cpu_pct,
    system_idle_pct) from CounterData joined by RecordIndex, matching the
    Bottleneck Analysis RDL DataSet query exactly
  - SET ANSI_NULLS OFF added to match RDL behaviour: prevents the
    det.InstanceIndex = @inst_index join from silently returning zero rows
    when @inst_index is NULL
  - Falls back to tbl_SQL_CPU_HEALTH (ring buffer) when CounterData is absent
  - Aggregate summary (max, avg, count above 70%) computed in C# from the
    already-fetched rows — no second SQL round-trip
  - Consecutive high-CPU run detector: flags any run of 3+ samples above 70%
    with run_start, run_end, consecutive_samples, peak_sql_cpu_pct
  - sustained_high_cpu_detected boolean gives Copilot an immediate signal

  GetTopCpuQueries():
  - ReadTrace path: added pct_of_cpu_capacity column — % of total CPU
    capacity each query consumed during the collection window, computed as
    SUM(CPU) / (cpu_count * collection_duration_ms)
  - dm_exec_query_stats path (tbl_Hist_Top10_CPU_Queries_ByQueryHash):
    - Delta between first/last snapshot isolates CPU used only during the
      collection window (not cumulative since SQL Server startup)
    - pct_of_cpu_capacity added using tbl_RUNTIMES for the time window
    - OBJECT_ID guard on tbl_RUNTIMES prevents parse-time error when absent
    - Added avg_cpu_ms, delta_executions columns; fixed ORDER BY to DESC
  - Added ExecuteQueryToDataTable() private helper for methods that compose
    multi-section JSON from multiple queries

Program.cs
  - Updated analyze_cpu_usage tool description to reflect new Perfmon summary
    output: max/avg SQL CPU %, samples above 70%, sustained high CPU detection
…le catalog

DiagnosticAnalyzer.cs:
- Add ListNexusTables() method exposing a curated catalog of ~70
  analytically significant SQL Nexus tables (dbo + ReadTrace schema)
- Each entry carries a plain-English description of the table's source
  DMV/query, key columns, and how to use it for analysis
- At call time, queries sys.tables to annotate each entry with
  present_in_database so the AI knows which tables were actually
  captured in this collection
- Result includes a discovery_hint pointing to INFORMATION_SCHEMA.TABLES
  so agents know the catalog is a subset and how to enumerate the rest
- Correct tbl_System_Requests description: these are internal system
  thread rows (session_id < 0) covering checkpoint, lazy writer, log
  writer and ghost cleanup — not user requests
- Correct tbl_SQL_CPU_HEALTH description: confirmed populated from the
  SQL Server ring buffer health records; used as CPU fallback when
  Perfmon CounterData is absent
- Add tbl_sqlagent_jobs entry (Agent job definitions for incident
  timeline correlation)
- Add tbl_database_options entry (per-database options snapshot)
- Add ReadTrace.tblInterestingEvents entry (deadlock graphs, attention
  events, errors)
- Fix tblErrorlog key → tbl_ERRORLOG to match actual table name
- Improve tbl_running_drivers description to call out filter drivers
  (antivirus, backup agents) explicitly

Program.cs:
- Register list_nexus_tables MCP tool in HandleListTools()
- Wire list_nexus_tables case in HandleToolCall() switch
- Tool description explicitly states it is a curated subset and embeds
  the INFORMATION_SCHEMA discovery query for AI agent awareness
…entations

- analyze_cpu_usage: remove incorrect reference to tbl_OS_WAIT_STATS /
  wait type section (SOS_SCHEDULER_YIELD, CXPACKET, CXCONSUMER); describe
  actual CounterData → tbl_SQL_CPU_HEALTH fallback, per-sample output, and
  sustained high-CPU run detection (3+ consecutive samples above 70%)
- get_top_cpu_queries: replace wrong tbl_NOTABLEACTIVEQUERIES source with
  accurate dual-path description: ReadTrace.tblBatches (primary) and
  tbl_Hist_Top10_CPU_Queries_ByQueryHash delta-snapshot (fallback);
  mention pct_of_cpu_capacity
- analyze_io_waits: add LOGBUFFER and ASYNC_IO_COMPLETION to listed wait
  types; clarify first/last snapshot delta approach
- get_collection_time_range: add caveat that it depends on
  ReadTrace.tblBatches and returns no data for non-ReadTrace collections
- AnalyzeSpinlocks: add is_high_cpu_driver column (1 if
  spins_per_millisecond_per_CPU > 20000, else 0)

- GetCollectionTimeRange: check tbl_RUNTIMES first; fall back to
  ReadTrace.tblBatches if not present
…with MCP tool workflows and skill file references
New tools in DiagnosticAnalyzer.cs + Program.cs:
- get_query_execution_details    (per-execution drill-down by HashID)
- get_wait_type_distribution     (request-level wait type frequency)
- get_wait_resource_hotspots     (hot pages/rows/keys causing contention)
- get_wait_heavy_queries         (queries with CPU < 80% of duration)
- get_statements_in_batch        (statement breakdown inside a batch)
- get_blocking_chain_tree        (recursive CTE blocking hierarchy)
- get_lock_summary_by_object     (lock contention by table/resource)
- get_queries_by_application     (queries filtered by ApplicationName)
- get_performance_by_application (aggregate perf per ApplicationName)
- get_cpu_by_database            (CPU breakdown by database)
- get_top_queries_by_reads       (I/O heavy queries, read pressure)
- get_top_queries_by_writes      (write heavy / WRITELOG pressure)
- get_sql_file_io_stats          (per-file avg read/write latency)
- get_compilation_stats          (SQL Compilations/sec from Perfmon)
- get_plan_cache_analysis        (cache composition, single-use plans)
- get_table_statistics_health    (stale stats detection)

agent.md tools list updated to include all 34 MCP tools.
…dd read+search aliases for skill file access
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.

3 participants