Skip to content

Fix audit MCP tool: add missing InputSchema for jq parameter#14442

Merged
pelikhan merged 5 commits intomainfrom
copilot/fix-jq-support-issue
Feb 8, 2026
Merged

Fix audit MCP tool: add missing InputSchema for jq parameter#14442
pelikhan merged 5 commits intomainfrom
copilot/fix-jq-support-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 8, 2026

Fix Audit Command jq Support ✅

  • Explore repository structure and relevant files
  • Examine MCP server implementation for audit tool
  • Verify audit command JSON output support
  • Review jq filtering implementation
  • Identify root cause: Missing InputSchema
  • Add InputSchema generation for audit tool
  • Create comprehensive test coverage
  • Fix linter errors (float comparison warnings)
  • Verify fix works correctly
  • Run full validation (fmt, lint, tests)
  • Address naming confusion: Rename GenerateOutputSchema to GenerateSchema

Root Cause:

The audit MCP tool had the JqFilter field defined in the args struct and the jq filtering logic fully implemented, but was missing the InputSchema definition. This caused MCP clients to reject the jq parameter as invalid because it wasn't declared in the tool's schema.

Changes Made:

1. pkg/cli/mcp_server.go:

  • Added schema generation for audit tool using GenerateSchema[auditArgs]()
  • Added InputSchema: auditSchema to the audit tool definition
  • Updated compile and logs tools to use GenerateSchema (renamed from GenerateOutputSchema)

2. pkg/cli/mcp_schema.go:

  • Renamed GenerateOutputSchema to GenerateSchema for clarity
  • The function is generic and used for both input parameters and output data
  • Kept GenerateOutputSchema as deprecated wrapper for backward compatibility
  • Updated documentation to clarify it works for both input and output schemas

3. pkg/cli/audit_jq_test.go (new file):

  • Comprehensive test coverage for jq filtering with audit output
  • Tests basic filtering (.overview, .metrics, .jobs)
  • Tests complex queries (map, select, length, field combinations)
  • Tests edge cases (empty filter, null values, invalid syntax)
  • Tests real-world scenarios with realistic audit output
  • All tests pass ✅

Naming Clarification:

The original function name GenerateOutputSchema was misleading because:

  • It was used to generate InputSchema for tool parameters (compileArgs, logsArgs, auditArgs)
  • It was also used to generate output data schemas (LogsData, AuditData) in tests
  • The new name GenerateSchema better reflects its generic, dual-purpose nature

Tool Comparison:

Tool InputSchema JqFilter Field Implementation
compile
logs
audit ✅ (fixed)

Validation Results:

  • ✅ All unit tests pass
  • ✅ All linters pass (0 issues)
  • ✅ Code formatting validated
  • ✅ Build succeeds

Example Usage (Now Works):

# Via MCP tool
agenticworkflows-audit --run-id 21784234145 --jq ".overview"
agenticworkflows-audit --run-id 21784234145 --jq ".jobs | map(.name)"
agenticworkflows-audit --run-id 21784234145 --jq "{run_id: .overview.run_id, cost: .metrics.estimated_cost}"
Original prompt

This section details on the original issue you should resolve

<issue_title>[cli-tools-test] Audit command: jq parameter not supported but should be</issue_title>
<issue_description>## Problem Description

The agenticworkflows-audit MCP tool rejects the jq parameter with an error, even though the agenticworkflows-logs tool supports it successfully. This inconsistency creates a confusing user experience.

Command/Tool

  • Tool: agenticworkflows-audit
  • MCP Server: agentic-workflows

Steps to Reproduce

  1. Call the agenticworkflows-audit MCP tool
  2. Provide a valid run ID: run_id_or_url: "21784234145"
  3. Add a jq filter: jq: ".overview"
  4. Observe the error message

Expected Behavior

The audit report should be filtered through the jq expression and return only the overview section:

{
  "run_id": 21784234145,
  "workflow_name": "Test Workflow",
  "status": "completed",
  "conclusion": "success",
  ...
}
```

This would be consistent with the behavior of the `logs` command, which successfully supports jq filtering.

## Actual Behavior

```
McpError: MCP error -32602: calling "tools/call": invalid jq filter expression
```

The command fails entirely, even though:
- The jq expression is valid
- The same tool signature (logs) supports jq filtering
- The audit output is JSON that would benefit from filtering

## Environment

- **Repository**: github/gh-aw
- **Run ID**: 21784347453
- **Date**: 2026-02-07
- **Testing Session**: Daily CLI tools exploratory testing

## Impact

- **Severity**: Low
- **Frequency**: Always (reproducible)
- **Workaround**: Call audit without jq, then filter the JSON in a separate step (e.g., using bash + jq)

## Why This Matters

1. **Consistency**: Users expect similar tools to have similar capabilities
2. **Token Efficiency**: Audit reports can be large; filtering reduces token usage
3. **Usability**: Being able to extract specific sections (overview, metrics, jobs) makes the tool more convenient

## Suggested Fix

Add jq filtering support to the audit command, similar to how the logs command implements it. This likely involves:
1. Accepting the `jq` parameter in the MCP tool definition
2. Passing it to the underlying `gh aw audit` command
3. Ensuring the command supports the `--jq` flag (or implementing it if missing)

## Additional Context

Working examples from the logs command:
```
agenticworkflows-logs --count 10 --jq ".summary"
agenticworkflows-logs --count 5 --jq ".runs | map({database_id, workflow_name})"
```

The audit command would benefit from similar patterns:
```
agenticworkflows-audit --run-id 123 --jq ".overview"
agenticworkflows-audit --run-id 123 --jq ".jobs"
agenticworkflows-audit --run-id 123 --jq ".key_findings"

AI generated by Daily CLI Tools Exploratory Tester

  • expires on Feb 14, 2026, 6:02 PM UTC

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


Changeset

  • Type: patch
  • Description: Add the audit MCP tool's jq parameter to the schema so the tool accepts jq filters the same way logs/compile do.

Generated by Changeset Generator

Copilot AI and others added 2 commits February 8, 2026 02:06
The audit MCP tool had the jq filter implementation but was missing
the InputSchema definition, causing MCP clients to reject the jq
parameter as invalid.

- Add GenerateOutputSchema for auditArgs
- Add InputSchema to audit tool definition
- Add comprehensive test coverage for audit jq filtering

Fixes the issue where MCP clients would return:
"MCP error -32602: invalid jq filter expression"

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Convert float64 comparisons to int64 to satisfy testifylint.
The linter prefers integer comparisons when the values represent
integer IDs or counts.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix jq parameter support in agenticworkflows-audit Fix audit MCP tool: add missing InputSchema for jq parameter Feb 8, 2026
Copilot AI requested a review from pelikhan February 8, 2026 02:17
}

// Generate schema for audit tool
auditSchema, err := GenerateOutputSchema[auditArgs]()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot is it an input or output schema?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an input schema. The function is confusingly named GenerateOutputSchema but it's actually generating a schema for the tool's input parameters (the auditArgs struct). This schema is then used as InputSchema in the MCP Tool definition (line 651), which tells MCP clients what parameters are available for the tool.

The naming confusion exists because the same function is also used to generate schemas for output data types (like LogsData, AuditData) in tests, but those aren't currently used in the actual tool definitions - only the input parameter schemas are.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot rename function to something less confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to GenerateSchema in commit 55df751. The function is now clearly documented as being used for both input parameters (InputSchema) and output data schemas. Kept the old name as a deprecated wrapper for backward compatibility.

The function was confusingly named "GenerateOutputSchema" but was used
for both input parameter schemas (InputSchema) and output data schemas.
The new name "GenerateSchema" better reflects its generic purpose.

- Renamed GenerateOutputSchema to GenerateSchema
- Updated all usages in mcp_server.go (compile, logs, audit)
- Kept GenerateOutputSchema as deprecated wrapper for compatibility
- Updated documentation to clarify dual usage (input/output schemas)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review February 8, 2026 02:43
Copilot AI review requested due to automatic review settings February 8, 2026 02:43
@pelikhan pelikhan added the smoke label Feb 8, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2026

📰 BREAKING: Smoke Copilot is now investigating this pull request. Sources say the story is developing...

@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2026

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2026

Changeset Generator completed successfully!

@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2026

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the agenticworkflows-audit MCP tool rejecting the jq argument by adding the missing InputSchema for the audit tool, and clarifies schema helper naming by introducing GenerateSchema (with a deprecated GenerateOutputSchema wrapper).

Changes:

  • Add InputSchema generation and wiring for the audit MCP tool so jq is accepted as a valid parameter.
  • Rename the schema helper to GenerateSchema and keep GenerateOutputSchema as a compatibility wrapper.
  • Add new tests intended to cover jq filtering behavior for audit-shaped JSON.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
pkg/cli/mcp_server.go Switch compile/logs to GenerateSchema and add audit tool InputSchema so jq is a declared MCP parameter.
pkg/cli/mcp_schema.go Introduce GenerateSchema and keep GenerateOutputSchema as a deprecated wrapper; update documentation/comments.
pkg/cli/audit_jq_test.go Adds tests for applying jq filters to representative audit JSON payloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +23
func TestAuditJqFilter_BasicFiltering(t *testing.T) {
// Create sample audit JSON output
auditJSON := `{
"overview": {
"run_id": 123456,
"workflow_name": "test-workflow",
"status": "completed",
"conclusion": "success"
},
"metrics": {
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new test file doesn’t exercise the actual regression fixed by the PR (the audit MCP tool missing InputSchema for the jq parameter). It only tests ApplyJqFilter on sample JSON, which was already covered by jq_test.go. Add a test that verifies the audit tool’s MCP schema (via ListTools) includes a jq property / that a CallTool request with a jq argument is accepted (i.e., doesn’t fail schema validation with “invalid params”).

Copilot uses AI. Check for mistakes.
Comment on lines +38 to +41
// GenerateOutputSchema is deprecated. Use GenerateSchema instead.
// This function is kept for backward compatibility but will be removed in a future version.
func GenerateOutputSchema[T any]() (*jsonschema.Schema, error) {
return GenerateSchema[T]()
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go tooling (and this repo elsewhere) recognizes deprecations only when the doc comment starts with Deprecated:. Consider changing this to // Deprecated: Use GenerateSchema instead. so callers get proper deprecation signals in editors and staticcheck.

Copilot uses AI. Check for mistakes.
@@ -19,21 +20,27 @@ import (
// - PropertyOrder maintains deterministic field ordering (v0.4.0+)
//
// MCP Requirements:
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “Tool input/output schemas must be objects” note is misleading in this generic helper: GenerateSchema can produce array/primitive schemas (and the repo even tests array schemas). It’d be clearer to scope this requirement to MCP Tool.InputSchema (and Tool.OutputSchema, if/when used) rather than implying GenerateSchema always returns an object schema.

Suggested change
// MCP Requirements:
// MCP Tool Requirements (when using this helper for Tool.InputSchema/Tool.OutputSchema):

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +12
import (
"encoding/json"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests call ApplyJqFilter(), which depends on an external jq binary. Unlike pkg/cli/jq_test.go, this file does not skip when jq isn’t available, so unit test runs in environments without jq will fail. Add an exec.LookPath("jq") guard (or a shared helper) to t.Skip at the start of these tests when jq is missing.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2026

PRs checked: #14435 Standardize error wrapping in compiler to preserve error chains; #14425 Fix plugin installation format from marketplace URL to GitHub repository path
GitHub MCP: ✅
Serena MCP (activate+find_symbol): ✅
Playwright (GitHub title contains "GitHub"): ✅
File write+cat: ✅
Build (make build): ✅
Overall: PASS

AI generated by Smoke Codex

@github-actions github-actions bot added smoke-codex and removed smoke labels Feb 8, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2026

Agent Container Tool Check

Tool Status Version
bash 5.2.21
sh POSIX shell
git 2.52.0
jq 1.7
yq 4.52.2
curl 8.5.0
gh 2.86.0
node 20.20.0
python3 3.12.3
go 1.24.12
java ⚠️ binary present (corrupted shell output)
dotnet ⚠️ binary present (execution error)

Result: 10/12 tools verified ✅, 2/12 tools present but malfunctioning ⚠️


Critical Issue Detected

Java and .NET binaries exist as valid ELF executables at:

  • /opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/21.0.10-7/x64/bin/java
  • /usr/share/dotnet/dotnet

However, executing these commands returns:

  • java -version → Outputs bash version instead of Java version
  • dotnet --version → Error: "cannot execute dotnet when renamed to bash"

This indicates a system-level process execution issue, possibly:

  • Container environment misconfiguration
  • Shell command interception or hijacking
  • Library/loader corruption affecting process spawning

Impact: While 10/12 critical development tools work correctly, Java and .NET workflows will fail. This needs investigation before releasing workflows that depend on these runtimes.

AI generated by Agent Container Smoke Test

@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2026

Smoke Test Results

Overall: PARTIAL PASS (Serena MCP connection issue)

@pelikhan @Copilot

AI generated by Smoke Copilot

@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2026

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@pelikhan pelikhan merged commit 9fdee51 into main Feb 8, 2026
1 check passed
@pelikhan pelikhan deleted the copilot/fix-jq-support-issue branch February 8, 2026 02:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cli-tools-test] Audit command: jq parameter not supported but should be

2 participants