feat: Add get_run_logs tool to retrieve Terraform run logs#240
Open
ankitpro wants to merge 1 commit intohashicorp:mainfrom
Open
feat: Add get_run_logs tool to retrieve Terraform run logs#240ankitpro wants to merge 1 commit intohashicorp:mainfrom
ankitpro wants to merge 1 commit intohashicorp:mainfrom
Conversation
This commit adds a new MCP tool 'get_run_logs' that enables users to fetch plan and apply logs from Terraform Cloud/Enterprise runs. Features: - Retrieve plan logs, apply logs, or both from a run - Optional metadata including run status, timestamps, and version info - Proper error handling for runs without available logs - Read-only, non-destructive operation Changes: - Added pkg/tools/tfe/get_run_logs.go with main implementation - Added pkg/tools/tfe/get_run_logs_test.go with unit tests - Registered new tool in pkg/tools/dynamic_tool.go - Updated CHANGELOG.md with new feature documentation The tool uses the go-tfe library's Plans.Logs() and Applies.Logs() methods to fetch log data and returns it in a structured JSON format.
e76eced to
b565683
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new MCP tool get_run_logs that enables users to retrieve plan and apply logs from Terraform Cloud/Enterprise runs, enhancing debugging capabilities for Terraform operations.
Key changes:
- New read-only tool for fetching Terraform run logs (plan, apply, or both)
- Optional metadata support including run status, timestamps, and version information
- Comprehensive unit tests for the new functionality
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/tools/tfe/get_run_logs.go | Core implementation of the get_run_logs tool with plan/apply log fetching logic |
| pkg/tools/tfe/get_run_logs_test.go | Unit tests verifying tool creation, annotations, and schema properties |
| pkg/tools/dynamic_tool.go | Registration of the new get_run_logs tool in the dynamic tool registry |
| CHANGELOG.md | Documentation of the new get_run_logs feature |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Description
This PR adds a new MCP tool
get_run_logsthat enables users to fetch plan and apply logs from Terraform Cloud/Enterprise runs.Features
Changes
pkg/tools/tfe/get_run_logs.gowith main implementationpkg/tools/tfe/get_run_logs_test.gowith unit testspkg/tools/dynamic_tool.goCHANGELOG.mdwith new feature documentationTesting
PCI Review Checklist
I have documented a clear reason for, and description of, the change I am making.
Reason: The MCP server currently lacks the ability to read logs from Terraform runs. This feature adds a new tool
get_run_logsto retrieve plan and apply logs, enhancing debugging capabilities and providing better visibility into Terraform operations.If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.
Revert Plan: Simple revert of the PR. The feature is additive and doesn't modify existing functionality. To revert, simply revert the commit or remove the three new files and undo the registration in dynamic_tool.go.
If applicable, I've documented the impact of any changes to security controls.
Security Impact: None. The tool is read-only and uses existing TFE client authentication. It follows the same security patterns as other read-only tools like
get_run_details. No new authentication mechanisms or security controls are introduced.Related Issues
Addresses the need for log visibility when running Terraform operations through the MCP server. This is particularly useful for debugging failed plans/applies and understanding what happened during a run.