Repository navigation
feat(search): prepare explicitly selected import evidence (5/6) - #590
Open
sowju-hashicorp wants to merge 1 commit into
Open
sowju-hashicorp wants to merge 1 commit into
sowju-hashicorp wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Managed-type prefix inference rejects valid provider/resource combinations despite matching selection and locked-provider evidence.
2 open issues
What changed in this PR
Adds read-only prepare_import to both MCP SDKs, extending Terraform Search from result summaries to explicitly selected import evidence. Plan verification remains deferred to PR 6.
Changes:
- Adds independent target confirmation, exact locked-provider validation, and destination eligibility checks.
- Validates complete QueryRun evidence while returning only selected observations, HCL drafts, and stateless import context.
- Registers the tool across both SDKs and adds workflow documentation, logging checks, and integration coverage.
| File | Description |
|---|---|
| README.md | Documents selected-only preparation and its boundaries. |
| pkg/toolsets/search.go | Adds credential-gated preparation metadata. |
| pkg/toolsets/search_test.go | Updates toolset and credential-gating expectations. |
| pkg/tools/search/scope.go | Adds independent import-target scope resolution. |
| pkg/tools/search/scope_test.go | Covers target defaults and confirmation guidance. |
| pkg/tools/search/prepare_import.go | Implements preparation, evidence selection, and import context. |
| pkg/tools/search/prepare_collector_test.go | Checks selected-only evidence retention. |
| pkg/tools/search/import_tools.go | Adds the legacy SDK adapter and tool contract. |
| pkg/tools/search/import_tools_test.go | Covers preparation inputs, results, and legacy transport. |
| pkg/tools/search/import_preflight_test.go | Tests validation and blocked-state guidance. |
| pkg/tools/search/diagnostic_codes.go | Defines preparation diagnostic codes. |
| pkg/tools/search/descriptions_test.go | Checks preparation contract wording. |
| pkg/tools/factories.go | Registers the legacy preparation tool. |
| pkg/tools/factories_test.go | Tests credential-aware registration. |
| pkg/mcp-official/tools/tools.go | Registers the official SDK preparation tool. |
| pkg/mcp-official/tools/tools_test.go | Updates registration and credential tests. |
| pkg/mcp-official/tools/search/search.go | Adds the official SDK schema and handler. |
| pkg/mcp-official/tools/search/search_test.go | Tests official schemas, validation, and scope interaction. |
| pkg/mcp-official/tools/prepare_test.go | Tests cross-SDK parity, preflight, and disclosure boundaries. |
| pkg/mcp-official/tools/middleware/tool_logging_test.go | Checks preparation argument and error logging protections. |
| pkg/instructions/instructions.md | Adds import preparation workflow guidance. |
| pkg/instructions/instructions_test.go | Checks preparation instructions and stopping boundaries. |
| pkg/client/tool_logging_middleware_test.go | Checks legacy preparation argument logging protections. |
| CHANGELOG.md | Records preparation support and remaining limitations. |
Review effort: Balanced
| // The list type is not necessarily a plural of the managed type. | ||
| // Keep the caller-proposed managed type and Search list type separate; | ||
| // the optional target schema and finished Plan supply target-side checks. | ||
| if !ok || len(found.Provider.Source) > 256 || !providerSourcePattern.MatchString(found.Provider.Source) || !exactLockedVersion.MatchString(found.Provider.Version) || !strings.HasPrefix(selection.ManagedType, strings.Split(found.Provider.Source, "/")[2]+"_") { |
| case "/api/v2/workspaces/ws-source": | ||
| _, _ = fmt.Fprint(w, `{"data":{"type":"workspaces","id":"ws-source","attributes":{"name":"source"},"relationships":{"organization":{"data":{"type":"organizations","id":"org"}}}}}`) | ||
| case "/api/v2/search/no-code-query/ncqry-test": | ||
| _, _ = fmt.Fprintf(w, `{"data":{"id":"ncqry-test","attributes":{"no-code-query-providers":[{"namespace":"hashicorp","name":"aws","version":"6.66.0","no-code-query-resources":[{"body":{"resource_type":%q}}]}]},"relationships":{"workspace":{"data":{"id":"ws-source"}}}}}`, listType) |
mjyocca
added this pull request to stack #593
October 22, 2026 16:45
mjyocca
force-pushed
the
sowju/search-05-prepare-import
branch
from
October 22, 2026 18:54
1075e6d to
561a510
Compare
This branch has not been deployed
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.


Summary
PR 5 of 6 in the Terraform Search stack.
Branch:
sowju/search-05-prepare-importBase:
sowju/search-04-resultsAdds read-only
prepare_importon both MCP SDKs to prepare explicitly selected Search results for a separately confirmed import destination.Changes
query_result_markerselections, caller-proposed managed resource types, and exact target provider versions reported from the local lockfile.import_contextfor later Plan verification.Security and data handling
TF_MCP_QUERY_WORKSPACEas an import-target default. Target resolution uses explicit arguments, thenTF_MCP_IMPORT_WORKSPACE, thenTF_WORKSPACE.resource_objectdata.import_context.The server does not read local files or attest the caller-reported lockfile. Historical schema evidence does not prove compatibility with the locally locked provider release or validate final authored HCL.
Read-only boundary
prepare_importdoes not:terraform import, write state, or apply changes.Local inspection and configuration authoring remain separate agent/user activities. Any speculative Plan requires separate approval.
Validation
Reviewer focus
Stack scope
Depends on PR 4 for validated summaries, markers, streaming evidence processing, and generated-HCL parsing. Set this PR's base to
sowju/search-04-resultsso the diff shows only import preparation.Exact speculative Run and Plan verification remains deferred to PR 6. This layer ends at prepared evidence and reviewed local changes; it does not establish import or apply safety.
Next branch:
sowju/search-06-verify-plan, based on this branch.Rollback
Revert this PR before PR 6 merges. If PR 6 has merged, coordinate its rollback first.
Reverting removes preparation support but leaves the Search-only workflow intact. The tool performs no remote mutations, so no infrastructure rollback is required. Any separately authored local configuration must be reviewed and reverted independently if needed.
PCI review checklist
I have documented a clear reason for, and description of, the change I am making.
If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.
If applicable, I've documented the impact of any changes to security controls.
Examples of changes to security controls include using new access control methods, adding or removing logging pipelines, etc.