Skip to main content

MCP Server Access

Integrate AI tools into your applications using the Model Context Protocol

What is MCP?

MCP (Model Context Protocol) is an open protocol developed by Anthropic that standardizes how AI applications connect to external data sources and tools. It enables AI assistants like Claude to seamlessly access services through a unified JSON-RPC interface.

  • Standardized: Works with any MCP-compatible AI client or application.
  • Pay-per-use: Lightning Network micropayments for each service call.
  • No Accounts: Privacy-focused access without signup or KYC.
  • Interoperable: Designed for AI-to-service communication.

By integrating MCP, Sats4AI provides a standardized way for AI agents and applications to access powerful AI services with Bitcoin payments.Learn more about MCP

API Endpoint

HTTP/JSON-RPC: https://sats4ai.com/api/mcp

Content-Type: application/json

Protocol Version: 2024-11-05

Payment Flow

  1. 1create_payment → Get Lightning invoice & paymentId
  2. 2Pay invoice → Using any Lightning wallet
  3. 3check_payment_status → Verify payment received (optional)
  4. 4Execute tool → Pass paymentId with your request

Step-by-Step Guide

Step 1: Initialize Connection

First, initialize the MCP connection. This establishes the protocol version and client capabilities.

curl -X POST https://sats4ai.com/api/mcp \
-H "Content-Type: application/json" \
-d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "protocolVersion": "2024-11-05",
    "capabilities": {},
    "clientInfo": { "name": "my-client", "version": "1.0.0" }
  }
}'

Step 2: List Available Tools (Optional)

You can list all available tools to see what services are offered and their parameters.

curl -X POST https://sats4ai.com/api/mcp \
-H "Content-Type: application/json" \
-d '{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/list",
  "params": {}
}'

Step 3: Create Payment

Before using a paid service, create a payment to get a Lightning invoice. Specify the tool you want to use and the model ID.

curl -X POST https://sats4ai.com/api/mcp \
-H "Content-Type: application/json" \
-d '{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "create_payment",
    "arguments": {
      "toolName": "generate_image",
      "modelId": 1,
      "quantity": 1
    }
  }
}'

Response:

{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "content": [{
      "type": "text",
      "text": "{
        \"paymentId\": \"abc123\",
        \"lightningInvoice\": \"lnbc...<LIGHTNING_INVOICE>\",
        \"amountSats\": 50,
        \"expiresAt\": \"2024-01-01T12:00:00Z\"
      }"
    }]
  }
}

Save the paymentId and pay the lightningInvoice using any Lightning wallet.

Step 4: Pay the Lightning Invoice

Copy the lightningInvoice and pay it using any Lightning-enabled Bitcoin wallet (Phoenix, Muun, Wallet of Satoshi, etc.).

You can optionally verify the payment was received:

curl -X POST https://sats4ai.com/api/mcp \
-H "Content-Type: application/json" \
-d '{
  "jsonrpc": "2.0",
  "id": 5,
  "method": "tools/call",
  "params": {
    "name": "check_payment_status",
    "arguments": {
      "paymentId": "abc123"
    }
  }
}'

Step 5: Execute the Service

Once payment is confirmed, call the service tool with your paymentId.

curl -X POST https://sats4ai.com/api/mcp \
-H "Content-Type: application/json" \
-d '{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "tools/call",
  "params": {
    "name": "generate_image",
    "arguments": {
      "paymentId": "abc123",
      "prompt": "A futuristic Bitcoin-powered robot",
      "modelId": "black-forest-labs/flux-schnell",
      "amount": 1
    }
  }
}'

Successful Response:

{
  "jsonrpc": "2.0",
  "id": 4,
  "result": {
    "content": [{
      "type": "text",
      "text": "{\"images\": [\"https://...\"]}",
    }]
  }
}

Available Tools

ToolDescriptionPaymentAsync
create_paymentCreate Lightning invoice for a serviceNoNo
check_payment_statusCheck if payment has been receivedNoNo
generate_imageGenerate images from text promptsYesNo
generate_textAI text generation and chatYesNo
generate_videoGenerate videos from text promptsYesYes
analyze_imageAI vision and image analysisYesNo
list_modelsList all available AI modelsNoNo
get_model_pricingGet pricing for a specific modelNoNo
check_job_statusCheck status of async jobsNoNo
get_job_resultGet result of completed async jobsNoNo

Tool Schemas

create_payment

{
  "toolName": "generate_image",  // Tool to pay for
  "modelId": 1,                  // AI model database ID
  "quantity": 1,                 // Number of outputs
  "additionalCharge": 0          // Extra sats (optional)
}

generate_image

{
  "paymentId": "abc123",
  "prompt": "A futuristic city at sunset",
  "modelId": "black-forest-labs/flux-schnell",
  "amount": 1,
  "imageBase64": "..."  // Optional, for img2img
}

generate_text

{
  "paymentId": "abc123",
  "prompt": "Explain Bitcoin in simple terms",
  "modelId": 2,
  "systemPrompt": "You are a helpful assistant",  // Optional
  "maxTokens": 2048  // Optional
}

generate_video

{
  "paymentId": "abc123",
  "prompt": "A rocket launching into space",
  "modelId": 5,
  "duration": "5",       // "5" or "10" seconds
  "cameraFixed": false   // Optional
}

Async Operations

Some operations like video generation are asynchronous. They return a requestId immediately, and you need to poll for the result.

// Step 1: Generate video (returns requestId)
const videoJob = await mcpRequest('tools/call', {
  name: 'generate_video',
  arguments: {
    paymentId: 'abc123',
    prompt: 'A rocket launching into space',
    modelId: 5,
    duration: '5'
  }
});
// Returns: { requestId: 'xyz789', status: 'IN_PROGRESS' }

// Step 2: Poll status until complete
let status;
do {
  await sleep(5000);
  status = await mcpRequest('tools/call', {
    name: 'check_job_status',
    arguments: { requestId: 'xyz789', jobType: 'video' }
  });
} while (status.status === 'IN_PROGRESS');

// Step 3: Get the result
const result = await mcpRequest('tools/call', {
  name: 'get_job_result',
  arguments: { requestId: 'xyz789', jobType: 'video' }
});
// Returns: { videoUrl: 'https://...' }

Note: Async operations include: generate_video, generate_video_from_image, and generate_3d_model. Use check_job_status and get_job_result to handle these.

Error Handling

Errors are returned in standard JSON-RPC format:

{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32603,
    "message": "Payment has not been received yet"
  }
}

Common Error Codes

CodeMeaning
-32700Parse error - Invalid JSON
-32600Invalid request - Missing required fields
-32601Method not found
-32602Invalid params - Wrong parameter types
-32603Internal error - Service execution failure

MCP Resources

The MCP server also exposes resources that can be read by MCP clients:

URIDescription
sats4ai://modelsList of all available AI models with specs and pricing
sats4ai://pricingPricing information for all services

Need Help?

If you have questions or run into issues, visit our contact page or check out the official MCP documentation.