main
ps1 71 lines 3.32 KB
Raw
1 [CmdletBinding()]
2 param(
3 [string]$YahooMcpBaseUrl = "http://127.0.0.1:18002",
4 [string]$McpGatewayBaseUrl = "http://127.0.0.1:18001",
5 [string]$ResearchBaseUrl = "http://127.0.0.1:18000",
6 [string]$GlobalInstrumentId = "",
7 [ValidateSet("LATEST_PRICE", "HISTORICAL_PRICE_SERIES", "VALUATION_INPUTS", "BUSINESS_QUALITY_FACTS", "GROWTH_FACTS", "BALANCE_SHEET_FACTS", "QUARTERLY_FINANCIALS", "CURRENT_NEWS", "SHAREHOLDING", "SECTOR_MACRO")]
8 [string]$Requirement = "LATEST_PRICE",
9 [string]$UserId = "",
10 [string]$UserIssuer = "aip-local-runtime-acceptance",
11 [switch]$Ensure
12 )
13
14 $ErrorActionPreference = "Stop"
15
16 function Assert-LoopbackUrl([string]$Name, [string]$Value) {
17 $uri = [Uri]$Value
18 if ($uri.Scheme -notin @("http", "https") -or $uri.Host -notin @("127.0.0.1", "localhost")) {
19 throw "$Name must target a loopback URL reached through the manually prepared LOCAL runtime."
20 }
21 }
22
23 Assert-LoopbackUrl "YahooMcpBaseUrl" $YahooMcpBaseUrl
24 Assert-LoopbackUrl "McpGatewayBaseUrl" $McpGatewayBaseUrl
25 Assert-LoopbackUrl "ResearchBaseUrl" $ResearchBaseUrl
26
27 $yahooHealth = Invoke-RestMethod -Method Get -Uri "$($YahooMcpBaseUrl.TrimEnd('/'))/health"
28 $yahooReady = Invoke-RestMethod -Method Get -Uri "$($YahooMcpBaseUrl.TrimEnd('/'))/health/ready"
29 $gatewayHealth = Invoke-RestMethod -Method Get -Uri "$($McpGatewayBaseUrl.TrimEnd('/'))/health"
30
31 [pscustomobject]@{
32 yahooHealth = $yahooHealth.status
33 yahooReady = $yahooReady.status
34 yahooRegisteredTools = $yahooHealth.registeredTools
35 gatewayHealth = $gatewayHealth.status
36 } | Format-List
37
38 $workspace = Split-Path -Parent $PSScriptRoot
39 $python = Join-Path $workspace "ai/yahoo-finance-mcp/.venv/Scripts/python.exe"
40 if (-not (Test-Path -LiteralPath $python)) {
41 throw "Create ai/yahoo-finance-mcp/.venv using the documented local setup before capability discovery."
42 }
43 & $python (Join-Path $PSScriptRoot "list_yahoo_mcp_tools.py") --url "$($YahooMcpBaseUrl.TrimEnd('/'))/mcp"
44 if ($LASTEXITCODE -ne 0) { throw "Yahoo MCP capability discovery failed." }
45
46 if (-not $GlobalInstrumentId) {
47 Write-Host "Health and capability discovery passed. Supply -GlobalInstrumentId and -UserId for readiness validation."
48 exit 0
49 }
50 if (-not $UserId) {
51 throw "UserId is required for the user-scoped readiness endpoint."
52 }
53
54 $headers = @{
55 "X-AIP-User-Id" = $UserId
56 "X-AIP-User-Issuer" = $UserIssuer
57 "X-AIP-User-Subject" = $UserId
58 "X-Correlation-ID" = "yahoo-mcp-runtime-$([Guid]::NewGuid())"
59 }
60 $readinessUri = "$($ResearchBaseUrl.TrimEnd('/'))/api/v1/research/readiness/$GlobalInstrumentId"
61 $before = Invoke-RestMethod -Method Get -Uri $readinessUri -Headers $headers
62 $beforeRequirement = $before.requirements | Where-Object { $_.requirementId -eq $Requirement } | Select-Object -First 1
63 Write-Host "Before: requirement=$Requirement status=$($beforeRequirement.status)"
64
65 if ($Ensure) {
66 $body = @{ requirements = @($Requirement) } | ConvertTo-Json -Compress
67 $after = Invoke-RestMethod -Method Post -Uri "$readinessUri/ensure" -Headers $headers -ContentType "application/json" -Body $body
68 $afterRequirement = $after.requirements | Where-Object { $_.requirementId -eq $Requirement } | Select-Object -First 1
69 $executed = @($after.ensure.executedCapabilities) -join ","
70 Write-Host "After: requirement=$Requirement status=$($afterRequirement.status) providerPath=$executed"
71 }