Skip to main content
Glama

DotNet MCP Server Demo

by kasirajan22
test-api.ps14.26 kB
# MCP Demo Test Script # Run these PowerShell commands to test the API # Set the base URL $baseUrl = "http://localhost:5000" # Credentials for Basic Auth (admin:password123) $credentials = "YWRtaW46cGFzc3dvcmQxMjM=" # Base64 encoded "admin:password123" $headers = @{ "Authorization" = "Basic $credentials" "Content-Type" = "application/json" } Write-Host "=== Testing MCP Demo API ===" -ForegroundColor Green # Test 1: Health Check (no auth required) Write-Host "`n1. Testing Health Check..." -ForegroundColor Yellow try { $response = Invoke-RestMethod -Uri "$baseUrl/api/mcp/health" -Method GET Write-Host "Health Check Response:" -ForegroundColor Green $response | ConvertTo-Json -Depth 3 } catch { Write-Host "Health check failed: $_" -ForegroundColor Red } # Test 2: Get Tools (requires auth) Write-Host "`n2. Getting Available Tools..." -ForegroundColor Yellow try { $response = Invoke-RestMethod -Uri "$baseUrl/api/mcp/tools" -Method GET -Headers $headers Write-Host "Available Tools:" -ForegroundColor Green $response | ConvertTo-Json -Depth 4 } catch { Write-Host "Get tools failed: $_" -ForegroundColor Red } # Test 3: Initialize MCP Server Write-Host "`n3. Initializing MCP Server..." -ForegroundColor Yellow $initMessage = @{ jsonrpc = "2.0" id = "1" method = "initialize" params = @{ protocolVersion = "2024-11-05" capabilities = @{} clientInfo = @{ name = "Test Client" version = "1.0.0" } } } | ConvertTo-Json -Depth 4 try { $response = Invoke-RestMethod -Uri "$baseUrl/api/mcp/message" -Method POST -Body $initMessage -Headers $headers Write-Host "Initialize Response:" -ForegroundColor Green $response | ConvertTo-Json -Depth 4 } catch { Write-Host "Initialize failed: $_" -ForegroundColor Red } # Test 4: Call Echo Tool Write-Host "`n4. Calling Echo Tool..." -ForegroundColor Yellow $echoMessage = @{ jsonrpc = "2.0" id = "2" method = "tools/call" params = @{ name = "echo" arguments = @{ message = "Hello from MCP Demo!" } } } | ConvertTo-Json -Depth 4 try { $response = Invoke-RestMethod -Uri "$baseUrl/api/mcp/message" -Method POST -Body $echoMessage -Headers $headers Write-Host "Echo Tool Response:" -ForegroundColor Green $response | ConvertTo-Json -Depth 4 } catch { Write-Host "Echo tool failed: $_" -ForegroundColor Red } # Test 5: Call Calculator Tool Write-Host "`n5. Calling Calculator Tool..." -ForegroundColor Yellow $calcMessage = @{ jsonrpc = "2.0" id = "3" method = "tools/call" params = @{ name = "calculate" arguments = @{ operation = "add" a = 15 b = 27 } } } | ConvertTo-Json -Depth 4 try { $response = Invoke-RestMethod -Uri "$baseUrl/api/mcp/message" -Method POST -Body $calcMessage -Headers $headers Write-Host "Calculator Tool Response:" -ForegroundColor Green $response | ConvertTo-Json -Depth 4 } catch { Write-Host "Calculator tool failed: $_" -ForegroundColor Red } # Test 6: Call Get Time Tool Write-Host "`n6. Calling Get Time Tool..." -ForegroundColor Yellow $timeMessage = @{ jsonrpc = "2.0" id = "4" method = "tools/call" params = @{ name = "get_time" arguments = @{} } } | ConvertTo-Json -Depth 4 try { $response = Invoke-RestMethod -Uri "$baseUrl/api/mcp/message" -Method POST -Body $timeMessage -Headers $headers Write-Host "Get Time Tool Response:" -ForegroundColor Green $response | ConvertTo-Json -Depth 4 } catch { Write-Host "Get time tool failed: $_" -ForegroundColor Red } # Test 7: Get Weather (protected endpoint) Write-Host "`n7. Getting Weather Data..." -ForegroundColor Yellow try { $response = Invoke-RestMethod -Uri "$baseUrl/api/weather" -Method GET -Headers $headers Write-Host "Weather Data Response:" -ForegroundColor Green $response | ConvertTo-Json -Depth 3 } catch { Write-Host "Weather data failed: $_" -ForegroundColor Red } Write-Host "`n=== Testing Complete ===" -ForegroundColor Green Write-Host "You can also test the API using Swagger UI at: http://localhost:5000/swagger" -ForegroundColor Cyan

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kasirajan22/DotnetMCPServer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server