Skip to content

Commit 4737403

Browse files
yotsudaclaude
andcommitted
Simplify invoke_expression description for Claude Code
- Add API Exploration hint (Invoke-RestMethod, Add-Type for Win32) - Replace detailed file cmdlet documentation with Get-Help reference - Claude Code has built-in file editing tools, detailed docs unnecessary Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6f5fd77 commit 4737403

1 file changed

Lines changed: 4 additions & 40 deletions

File tree

PowerShell.MCP.Proxy/Tools/PowerShellTools.cs

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -110,52 +110,16 @@ public static async Task<string> GetCurrentLocation(
110110
[McpServerTool]
111111
[Description(@"Execute PowerShell cmdlets and CLI tools (e.g., git) in persistent console. Session persists: modules, variables, functions, authentication stay active—no re-authentication. Install any modules and learn them via Get-Help. Commands visible in history for user learning.
112112
113+
💡 API Exploration: Use Invoke-RestMethod to explore Web APIs and Add-Type for Win32 API testing. Verify API behavior before writing production code—get immediate feedback without compilation.
114+
113115
⚠️ CRITICAL - Variable Scope:
114116
Local variables are NOT preserved between invoke_expression calls. Use $script: or $global: scope to share variables across calls.
115117
116118
⚠️ CRITICAL - Verbose/Debug Output:
117119
Verbose and Debug streams are NOT visible to you. If you need verbose/debug information, ask the user to copy it from the console and share it with you.
118120
119-
⚠ CRITICAL - File Operations:
120-
For user-provided paths (like C:\), use PowerShell.MCP tools ONLY. Server-side tools (such as str_replace) cannot access them.
121-
When calling invoke_expression for file operations, ALWAYS use these cmdlets. NEVER use Set-Content, Get-Content, or Out-File:
122-
123-
• Show-TextFile [-Path] <string[]> [-Recurse] [-LineRange <int[]>] [-Contains <string>] [-Pattern <regex>] [-Encoding <string>]
124-
Displays file contents with line numbers. Filter by line range and/or matching text (literal or regex).
125-
Use -Recurse with -Pattern/-Contains to search subdirectories.
126-
Use negative LineRange to show tail: -LineRange -10 shows last 10 lines, -LineRange -10,-1 is equivalent.
127-
128-
• Add-LinesToFile [-Path] <string[]> [-LineNumber <int>] [-Content] <Object[]> [-Encoding <string>] [-Backup]
129-
Inserts lines at specified position or appends to end or creates new file. Accepts pipeline input for Content.
130-
131-
• Update-LinesInFile [-Path] <string[]> [[-LineRange] <int[]>] [-Content <Object[]>] [-Encoding <string>] [-Backup]
132-
Replaces ENTIRE LINES in specified range with new content. Use for replacing whole lines.
133-
Use -Content @() to delete lines. Accepts pipeline input for Content.
134-
135-
• Update-MatchInFile [-Path] <string[]> [-LineRange <int[]>] [-OldText <string>] [-Pattern <regex>] [-Replacement <string>] [-Encoding <string>] [-Backup]
136-
Replaces ONLY THE MATCHED PORTION within lines, not entire lines. Rest of line is preserved.
137-
⚠️ Use -WhatIf first to preview changes.
138-
139-
• Remove-LinesFromFile [-Path] <string[]> [-LineRange <int[]>] [-Contains <string>] [-Pattern <regex>] [-Encoding <string>] [-Backup]
140-
Removes lines matching text (literal or regex) within optional range. Use negative LineRange to remove tail (e.g., -LineRange -10).
141-
⚠️ With -Contains/-Pattern, use -WhatIf first to preview.
142-
143-
⚠️ Update-LinesInFile vs Update-MatchInFile:
144-
- Replace WHOLE LINE → Update-LinesInFile -LineRange N,N -Content 'new line'
145-
- Replace PART OF LINE → Update-MatchInFile -OldText 'old' -Replacement 'new'
146-
147-
Note: All cmdlets support -LiteralPath for exact paths and accept arrays directly (no loops needed). For LineRange, use -1 or 0 for end of file (e.g., 100,-1).
148-
149-
Examples:
150-
✅ CORRECT: invoke_expression('Add-LinesToFile -Path file.cs -Content $code')
151-
✅ CORRECT: invoke_expression('Show-TextFile file.txt -LineRange 10,20')
152-
✅ CORRECT: invoke_expression('Show-TextFile file.txt -LineRange 100,-1') # To end of file
153-
✅ CORRECT: invoke_expression('Show-TextFile file.txt -LineRange -10') # Last 10 lines
154-
✅ CORRECT: invoke_expression('Update-LinesInFile file.md -LineRange 5,5 -Content ""new line""') # Replace entire line 5
155-
✅ CORRECT: invoke_expression('Update-MatchInFile file.md -OldText ""TODO"" -Replacement ""DONE""') # Replace only ""TODO"" → ""DONE""
156-
❌ WRONG: invoke_expression('Set-Content -Path file.cs -Value $code')
157-
❌ WRONG: invoke_expression('Get-Content file.txt | Select-Object -Skip 9 -First 11')
158-
121+
📝 Text File Operations:
122+
For text file editing, use Get-Help to learn the specialized cmdlets: Show-TextFile, Add-LinesToFile, Update-LinesInFile, Update-MatchInFile, Remove-LinesFromFile.
159123
For detailed examples: invoke_expression('Get-Help <cmdlet-name> -Examples')")]
160124
public static async Task<string> InvokeExpression(
161125
IPowerShellService powerShellService,

0 commit comments

Comments
 (0)