Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Public/Invoke-HandleRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ function Invoke-HandleRequest {

$result = & $toolName @targetArgs

$resultText = if ($null -eq $result) {
""
}
elseif ($result -is [string]) {
$result
}
elseif ($result -is [ValueType]) {
$result.ToString()
}
else {
$result | ConvertTo-Json -Depth 100
}
Comment on lines +86 to +108
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

There are Pester tests for other public entry points (e.g., Register-MCPTool), but none cover Invoke-HandleRequest's tools/call result formatting. Adding tests around this new $resultText branching (null, scalar string, string[], value types, complex objects serialized to JSON) would help prevent MCP response regressions.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +89 to +108
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

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

$result -is [string] only matches a scalar string. If a tool writes multiple strings (common in PowerShell), $result becomes string[] and will fall into the JSON branch, so the client receives a literal JSON array string (e.g. ["a","b"]) instead of readable text lines. Consider detecting an enumerable of strings (or value types) and joining with newlines / Out-String for those cases, reserving ConvertTo-Json for non-text objects.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback


# Log structured data
Write-Log -LogEntry @{
RequestId = $request.id
Expand All @@ -63,7 +76,7 @@ function Invoke-HandleRequest {
content = @(
[ordered]@{
type = "text"
text = $result | Out-String
text = $resultText
}
)
isError = $false
Expand Down