# Skill: Use the APIHub MCP Server

> Connect your agent to APIHub via Model Context Protocol. Discover, search, and call paid APIs through MCP tools.

## What is MCP?

MCP (Model Context Protocol) is a standard for connecting AI agents to external tools and data sources. APIHub exposes its full marketplace as an MCP server, so any MCP-compatible agent can discover and use paid APIs.

## Prerequisites

- An APIHub API key (see https://apihub.io/skills/register.md)
- An MCP-compatible client (Claude Desktop, Claude Code, Cursor, custom agent, etc.)

## Configuration

Add this to your MCP configuration:

```json
{
  "mcpServers": {
    "apihub": {
      "url": "https://mcp.apihub.io/mcp",
      "headers": {
        "Authorization": "Bearer ahk_your_api_key"
      }
    }
  }
}
```

Transport: Streamable HTTP (the standard for remote MCP servers).

**Easier setup**: `npx @apihubio/cli install` auto-detects Claude Desktop / Cursor / Codex / Claude Code and writes the config for you.

## Available tools

### apihub_search

Search for APIs by capability, category, or price.

```json
{
  "tool": "apihub_search",
  "arguments": {
    "query": "weather forecast",
    "category": "data",
    "max_price": 10000
  }
}
```

Parameters:
- `query` (string, required) -- what you are looking for
- `category` (string, optional) -- filter by category: ai, data, search, finance, media, infra, communication, content, travel, other
- `max_price` (number, optional) -- maximum price in microdollars per request

### apihub_list_services

Browse all available services with their endpoints and pricing.

```json
{
  "tool": "apihub_list_services",
  "arguments": {}
}
```

No parameters required. Returns all active services.

### apihub_get_service

Get full details for a specific service including input/output schemas.

```json
{
  "tool": "apihub_get_service",
  "arguments": {
    "slug": "weather"
  }
}
```

Parameters:
- `slug` (string, required) -- the service slug from search or list results

### apihub_call

Make a paid API call to an onboarded APIHub service. This is the main tool for consuming APIs. Debits the endpoint's price from your credit balance and forwards the request to the upstream provider.

```json
{
  "tool": "apihub_call",
  "arguments": {
    "service_slug": "weather",
    "endpoint_path": "/current?city=NYC",
    "method": "GET"
  }
}
```

Parameters:
- `service_slug` (string, required) -- service slug from apihub_search or apihub_list_services
- `endpoint_path` (string, required) -- endpoint path including any query string, e.g. `/latest/USD` or `/forecast?lat=51.5`
- `method` (string, optional) -- one of GET, POST, PUT, DELETE. Defaults to GET. Must match the method declared on the endpoint.
- `body` (string, optional) -- request body as a JSON string for POST/PUT. Sent verbatim with Content-Type: application/json.

Returns the upstream response body, HTTP status, and credits charged. Payment is handled automatically. If your balance is insufficient, the call returns a 402 with payment requirements (use `apihub_topup` to add credits, or configure x402 wallet payment).

### apihub_search_external

Search external x402 services in the marketplace (APIs from providers outside APIHub, discovered via on-chain activity).

```json
{
  "tool": "apihub_search_external",
  "arguments": {
    "query": "ai",
    "category": "finance",
    "limit": 10
  }
}
```

Parameters:
- `query` (string, optional) -- search text matched against name/description
- `category` (string, optional) -- one of: ai, search, finance, media, other
- `limit` (number, optional) -- max results (default 10, max 50)

Returns listings ordered by 24h transaction count, with endpoint count, min price, and detail URL.

### apihub_call_external

Call any external x402-protected URL. APIHub pays the provider from the platform wallet; your credit balance is debited for the exact amount. No wallet or gas required.

```json
{
  "tool": "apihub_call_external",
  "arguments": {
    "url": "https://enrichx402.com/api/apollo/org-enrich",
    "method": "POST",
    "body": { "domain": "example.com" }
  }
}
```

Parameters:
- `url` (string, required) -- full URL of the x402 endpoint
- `method` (string, optional) -- HTTP method, defaults to POST
- `body` (object or string, optional) -- request body
- `headers` (object, optional) -- extra request headers (Authorization and X-PAYMENT are handled automatically)

### apihub_read_content

Read web content through a paid content gateway.

```json
{
  "tool": "apihub_read_content",
  "arguments": {
    "service": "news-content",
    "url": "https://example.com/article"
  }
}
```

Parameters:
- `service` (string, required) -- content gateway service slug
- `url` (string, required) -- the URL to read

Returns structured content: title, text, headings, and metadata.

### apihub_topup

Purchase APIHub credits via x402 (USDC on Base). Returns payment instructions for browser, CLI, or direct x402 signing. Credits are added instantly once payment confirms on-chain.

```json
{
  "tool": "apihub_topup",
  "arguments": {
    "amount_dollars": 10
  }
}
```

Parameters:
- `amount_dollars` (number, required) -- amount to top up in USD. Minimum $5.00, maximum $10,000 per call.

Returns three payment methods:
- **browser** -- URL to open in a browser and pay via connected wallet or Stripe
- **cli** -- shell command to run: `npx @apihubio/cli topup <amount>`
- **x402_direct** -- raw x402 requirements (endpoint, network, USDC contract, platform wallet, amount) for agents with wallet capability

### apihub_balance

Check your credit balance, total spending, and rate limit usage.

```json
{
  "tool": "apihub_balance",
  "arguments": {}
}
```

No parameters required. Returns:
- Credit balance in microdollars and display format
- Total spent
- Total requests made
- Current rate limit usage

## Example workflow

A typical agent workflow through MCP:

1. **Search** -- `apihub_search` to find relevant APIs
2. **Inspect** -- `apihub_get_service` to check schemas and pricing
3. **Check balance** -- `apihub_balance` to confirm sufficient credits
4. **Top up if needed** -- `apihub_topup` with the shortfall amount, follow one of the returned payment methods
5. **Call** -- `apihub_call` to make the API request
6. **Use result** -- parse the response and continue your task

## Discovery endpoints

These URLs help agents discover the MCP server:

| URL | Purpose |
|-----|---------|
| https://apihub.io/.well-known/mcp.json | MCP server metadata and tool list |
| https://apihub.io/.well-known/agent.json | Full agent card with all capabilities |
| https://apihub.io/.well-known/agent-skills/index.json | Skills discovery index |

## Related skills

- Register to get an API key: https://apihub.io/skills/register.md
- Purchase credits: https://apihub.io/skills/purchase-credits.md
- Make calls via REST instead: https://apihub.io/skills/make-api-call.md
