# MCP Server Test Script
# Tests the MCP endpoint exposed through Azure API Management
param(
[string]$ApimUrl = "https://apimmcp-apim-dev.azure-api.net",
[string]$SubscriptionKey = "80b6a6a2a02147b5b5c2f06c92bbd096"
)
$headers = @{
"Ocp-Apim-Subscription-Key" = $SubscriptionKey
"Content-Type" = "application/json"
}
$mcpEndpoint = "$ApimUrl/mcp"
function Invoke-McpRequest {
param(
[string]$Method,
[hashtable]$Params = @{},
[int]$Id
)
$body = @{
jsonrpc = "2.0"
method = $Method
id = $Id
params = $Params
} | ConvertTo-Json -Depth 10 -Compress
try {
$response = Invoke-RestMethod -Uri $mcpEndpoint -Method POST -Headers $headers -Body $body
return $response
} catch {
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
return $null
}
}
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " MCP Server Test Suite" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Endpoint: $mcpEndpoint" -ForegroundColor Gray
Write-Host ""
# Test 1: Initialize
Write-Host "1. Testing initialize..." -ForegroundColor Yellow
$initParams = @{
protocolVersion = "2024-11-05"
capabilities = @{}
clientInfo = @{ name = "test-client"; version = "1.0.0" }
}
$result = Invoke-McpRequest -Method "initialize" -Params $initParams -Id 1
if ($result) {
Write-Host " Server: $($result.result.serverInfo.name) v$($result.result.serverInfo.version)" -ForegroundColor Green
Write-Host " Protocol: $($result.result.protocolVersion)" -ForegroundColor Green
} else {
Write-Host " FAILED" -ForegroundColor Red
}
Write-Host ""
# Test 2: List Tools
Write-Host "2. Testing tools/list..." -ForegroundColor Yellow
$result = Invoke-McpRequest -Method "tools/list" -Id 2
if ($result) {
$tools = $result.result.tools
Write-Host " Found $($tools.Count) tools:" -ForegroundColor Green
foreach ($tool in $tools) {
Write-Host " - $($tool.name): $($tool.description)" -ForegroundColor Gray
}
} else {
Write-Host " FAILED" -ForegroundColor Red
}
Write-Host ""
# Test 3: Get Products
Write-Host "3. Testing tools/call (get_products)..." -ForegroundColor Yellow
$result = Invoke-McpRequest -Method "tools/call" -Params @{ name = "get_products" } -Id 3
if ($result -and $result.result.content) {
$products = $result.result.content[0].text | ConvertFrom-Json
Write-Host " Found $($products.Count) products:" -ForegroundColor Green
foreach ($product in $products[0..2]) {
Write-Host " - $($product.name): `$$($product.price)" -ForegroundColor Gray
}
if ($products.Count -gt 3) {
Write-Host " ... and $($products.Count - 3) more" -ForegroundColor Gray
}
} else {
Write-Host " FAILED" -ForegroundColor Red
}
Write-Host ""
# Test 4: Search Products
Write-Host "4. Testing tools/call (search_products)..." -ForegroundColor Yellow
$result = Invoke-McpRequest -Method "tools/call" -Params @{ name = "search_products"; arguments = @{ query = "smart" } } -Id 4
if ($result -and $result.result.content) {
$products = $result.result.content[0].text | ConvertFrom-Json
Write-Host " Found $($products.Count) products matching 'smart':" -ForegroundColor Green
foreach ($product in $products) {
Write-Host " - $($product.name)" -ForegroundColor Gray
}
} else {
Write-Host " FAILED" -ForegroundColor Red
}
Write-Host ""
# Test 5: Get Product By ID
Write-Host "5. Testing tools/call (get_product_by_id)..." -ForegroundColor Yellow
$result = Invoke-McpRequest -Method "tools/call" -Params @{ name = "get_product_by_id"; arguments = @{ id = "prod-001" } } -Id 5
if ($result -and $result.result.content) {
$product = $result.result.content[0].text | ConvertFrom-Json
Write-Host " Product: $($product.name)" -ForegroundColor Green
Write-Host " Price: `$$($product.price)" -ForegroundColor Gray
Write-Host " Stock: $($product.stock)" -ForegroundColor Gray
Write-Host " Category: $($product.category)" -ForegroundColor Gray
} else {
Write-Host " FAILED" -ForegroundColor Red
}
Write-Host ""
# Test 6: Create Order
Write-Host "6. Testing tools/call (create_order)..." -ForegroundColor Yellow
$result = Invoke-McpRequest -Method "tools/call" -Params @{ name = "create_order"; arguments = @{ productId = "prod-001"; quantity = 2 } } -Id 6
if ($result -and $result.result.content) {
$order = $result.result.content[0].text | ConvertFrom-Json
Write-Host " Order Created: $($order.orderId)" -ForegroundColor Green
Write-Host " Product: $($order.productName)" -ForegroundColor Gray
Write-Host " Quantity: $($order.quantity)" -ForegroundColor Gray
Write-Host " Total: `$$($order.totalPrice)" -ForegroundColor Gray
} else {
Write-Host " FAILED" -ForegroundColor Red
}
Write-Host ""
# Test 7: Get Orders
Write-Host "7. Testing tools/call (get_orders)..." -ForegroundColor Yellow
$result = Invoke-McpRequest -Method "tools/call" -Params @{ name = "get_orders" } -Id 7
if ($result -and $result.result.content) {
$orders = $result.result.content[0].text | ConvertFrom-Json
Write-Host " Found $($orders.Count) orders" -ForegroundColor Green
} else {
Write-Host " FAILED" -ForegroundColor Red
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Test Suite Complete" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan