Examples

Find examples for using Testra MCP servers, including how to discover servers, run tests, and execute functions.


1. Search for Price Oracle Servers

Find all MCP servers tagged with price-oracle and category defi, with uptime above 99%.

curl "https://api.testra.ai/v1/servers/search?category=defi&tags=price-oracle&minUptime=99" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json"

2. Retrieve Server Details

Get metadata about a specific server by its ID (srv_price_oracle_v1):

curl "https://api.testra.ai/v1/servers/srv_price_oracle_v1" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Accept: application/json"

3. Run a Test on a Server

Run diagnostics on a server with sample input parameters:

curl -X POST "https://api.testra.ai/v1/servers/srv_price_oracle_v1/test" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
        "input": {
          "currencyFrom": "USD",
          "currencyTo": "EUR"
        }
      }'

4. Execute a Function on an MCP Server

Call the get_exchange_rate function on the srv_price_oracle_v1 server:

curl -X POST "https://api.testra.ai/v1/servers/srv_price_oracle_v1/execute" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
        "function": "get_exchange_rate",
        "input": {
          "from": "USD",
          "to": "EUR"
        }
      }'

5. JavaScript Example Using Testra SDK

import { TestraClient } from 'testra-sdk';

const client = new TestraClient({ apiKey: 'YOUR_API_KEY' });

async function getExchangeRate() {
  const response = await client.execute('srv_price_oracle_v1', 'get_exchange_rate', {
    from: 'USD',
    to: 'EUR'
  });
  console.log('Exchange Rate:', response.output.rate);
}

getExchangeRate();

6. Python Example Using Testra SDK

from testra_sdk import TestraClient

client = TestraClient(api_key='YOUR_API_KEY')

response = client.execute('srv_price_oracle_v1', 'get_exchange_rate', {
    'from': 'USD',
    'to': 'EUR'
})

print('Exchange Rate:', response['output']['rate'])

7. Handling Errors

Check HTTP status codes and handle errors in your client app:

  • 401 Unauthorized: Invalid or missing API key

  • 404 Not Found: Server or function ID not found

  • 429 Too Many Requests: Rate limit exceeded

  • 500 Internal Server Error: Server-side issue

Last updated