Public/Get-MCPServer.ps1
|
<#
.SYNOPSIS Retrieves a list of MCP servers from the registry. .DESCRIPTION The Get-MCPServer function queries the MCP server registry to retrieve a list of available servers. It supports filtering by name, description, or repository URL. The function returns custom objects with server details including name, description, repository URL, and version. Use the -Raw switch to return the full server records from the API. .PARAMETER Filter A string to filter the servers. The filter applies to the server's name, description, or repository URL using wildcard matching. .PARAMETER Limit The maximum number of servers to retrieve per request. Default is 100. .PARAMETER Raw A switch to return the full server records from the API instead of the custom objects. .EXAMPLE Get-MCPServer Retrieves the first 100 servers from the registry. .EXAMPLE Get-MCPServer -Raw Retrieves the first 100 servers as full API records. .NOTES This function requires the $Script:BaseUrl variable to be set to the base URL of the MCP registry API. Errors during the REST API call are caught and reported via Write-Error. .LINK https://github.com/dfinke/PowerShellMCPRegistry #> function Get-MCPServer { [CmdletBinding()] param ( [string]$Filter, [int]$Limit = 100, [switch]$Raw ) $uri = "$Script:BaseUrl/servers?limit=$Limit" try { $response = Invoke-RestMethod -Uri $uri -Method Get $servers = $response.servers $filtered = $servers.server | Where-Object { -not $Filter -or ($_.name -like "*$Filter*" -or $_.description -like "*$Filter*" -or $_.repository.url -like "*$Filter*") } if ($Raw) { $filtered } else { $filtered | ForEach-Object { [PSCustomObject]@{ Name = $_.name Description = $_.description Repository = $_.repository.url Version = $_.version } } } } catch { Write-Error "Failed to retrieve servers: $_" } } |