Statistics Utilities

Calculate Median

Computes the median value from a dataset with mathematical precision. Use via MCP in Cursor or Claude Code, or call GET /v1/stats/median directly. Pass an array like [1,3,5,2,4] and get back 3. Handles both odd and even-length datasets correctly, returning the middle value or average of two middle values.

API Endpoint

GET /v1/stats/median

Code Examples

curl "https://tinyfn.io/v1/stats/median" \
  -H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/stats/median', {
  headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests

response = requests.get('https://tinyfn.io/v1/stats/median',
    headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)

Use via MCP

Add to your AI agent

Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's statistics tools:

{
  "mcpServers": {
    "tinyfn-stats": {
      "url": "https://tinyfn.io/mcp/stats",
      "headers": {
        "X-API-Key": "YOUR_API_KEY"
      }
    }
  }
}

Learn more about MCP setup →

FAQ

How does median calculation work for even vs odd number of values?

For odd-length arrays, returns the middle value after sorting. For even-length arrays, returns the average of the two middle values.

What input formats does the median API accept?

Accepts numeric arrays in JSON format. Empty arrays or non-numeric values will return an error.

Can I use this median tool in AI coding assistants like Cursor?

Yes, it's available as an MCP tool in Cursor, Claude Code, GitHub Copilot, Windsurf, Cline, and other MCP-compatible editors for reliable statistical calculations.

What's the difference between mean and median for skewed data?

Median is less affected by outliers than mean. For dataset [1,2,3,100], median is 2.5 while mean is 26.5.

Does the median calculation handle decimal numbers correctly?

Yes, it processes floating-point numbers with full precision and returns exact median values, not approximations.

Try Calculate Median Now

Get your free API key and start using Calculate Median in seconds.

Get Free API Key