Skip to content

New MCP tool for retrieving user audit trails from Harness #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

abhishek-singh0710
Copy link

@abhishek-singh0710 abhishek-singh0710 commented Jul 4, 2025

This PR adds a new MCP tool for retrieving user audit trails from Harness

Features

  • Retrieves the complete audit trail for a specified user within Harness
  • Supports filtering by organization, project, and module(s)
  • Allows time-bounded queries using start and end time (in milliseconds)
  • Includes pagination support for large audit result sets
  • Returns detailed audit event information, including resource, action, timestamp, and module

Required Parameters

  • user_id: The user ID for whom to retrieve the audit trail

Optional Parameters

  • start_time: Start time for audit events (milliseconds since epoch, default: 0)
  • end_time: End time for audit events (milliseconds since epoch, default: current time)
  • org_id, project_id: Scope filters for organization and project
  • Pagination parameters: page, size

Testing

  • Verified audit retrieval for a variety of users, organizations, and projects
  • Tested filtering by module and time range
  • Confirmed pagination returns expected results for large audit sets

@CLAassistant
Copy link

CLAassistant commented Jul 4, 2025

CLA assistant check
All committers have signed the CLA.

@abhishek-singh0710 abhishek-singh0710 changed the title This PR adds a new MCP tool for retrieving user audit trails from Harness New MCP tool for retrieving user audit trails from Harness Jul 4, 2025
Updated the function identifier.
Updated function identifier.
client/audit.go Outdated
}

params := make(map[string]string)
params["routingId"] = scope.AccountID

Choose a reason for hiding this comment

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

its best to standardize routingId, accountIdentifier etc as consts across all clients

Copy link
Author

@abhishek-singh0710 abhishek-singh0710 Jul 7, 2025

Choose a reason for hiding this comment

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

Following the other code files, I've kept this separate in the audit file.

client/audit.go Outdated
addScope(scope, params)

// Required fields
opts.FilterType = "Audit"

Choose a reason for hiding this comment

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

what purpose does this filtertype serve ?

Copy link
Author

Choose a reason for hiding this comment

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

That was a field as mentioned in the API Documentation.

FilterType string `json:"filterType,omitempty"`
StartTime int64 `json:"startTime,omitempty"`
EndTime int64 `json:"endTime,omitempty"`
Modules []string `json:"modules,omitempty"`

Choose a reason for hiding this comment

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

Please make sure to match terminology in UI . e.g. Modules is not clear to end user
Indent properly

Copy link
Author

Choose a reason for hiding this comment

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

I have removed that since post-filtering is being done.


type AuditListItem struct {
AuditID string `json:"auditId,omitempty"`
InsertId string `json:"insertId,omitempty"`

Choose a reason for hiding this comment

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

what is insertId ?

Copy link
Author

Choose a reason for hiding this comment

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

This entire struct has been removed.

maxSize = 100
)

func maxMin(val, min, max int) int {

Choose a reason for hiding this comment

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

see if math package can solve your requirements

Copy link
Author

Choose a reason for hiding this comment

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

I have used the math package to clamp the values.

Copy link
Contributor

@thisrohangupta thisrohangupta left a comment

Choose a reason for hiding this comment

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

We need to review this

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.

4 participants