UCPStoreDocs
Transport

MCP

The Model Context Protocol (MCP) transport enables LLMs to interact with UCP endpoints as native tools.

Overview

MCP (Model Context Protocol) allows AI models to interact with external systems through a standardized tool interface. UCP businesses can expose their capabilities as MCP tools, enabling AI agents to browse, select, and purchase products.

MCP Server Discovery

MCP server details are declared in the business profile:

{
  "transports": {
    "mcp": {
      "server_url": "https://mcp.business.com",
      "tools_manifest": "https://mcp.business.com/tools.json",
      "protocol_version": "2024-11-05"
    }
  }
}

Tool Manifest

Businesses expose their capabilities as MCP tools:

{
  "tools": [
    {
      "name": "ucp_search_products",
      "description": "Search for products in the catalog",
      "input_schema": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string",
            "description": "Search query for products"
          },
          "category": {
            "type": "string",
            "description": "Filter by category"
          },
          "max_price": {
            "type": "number",
            "description": "Maximum price filter"
          },
          "limit": {
            "type": "integer",
            "description": "Number of results (default: 10)"
          }
        },
        "required": ["query"]
      }
    },
    {
      "name": "ucp_get_product",
      "description": "Get detailed information about a specific product",
      "input_schema": {
        "type": "object",
        "properties": {
          "product_id": {
            "type": "string",
            "description": "The product ID or SKU"
          }
        },
        "required": ["product_id"]
      }
    },
    {
      "name": "ucp_create_checkout",
      "description": "Create a new checkout session with items",
      "input_schema": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "product_id": { "type": "string" },
                "quantity": { "type": "integer" }
              },
              "required": ["product_id", "quantity"]
            }
          },
          "currency": {
            "type": "string",
            "default": "USD"
          }
        },
        "required": ["items"]
      }
    },
    {
      "name": "ucp_complete_checkout",
      "description": "Complete a checkout session with payment",
      "input_schema": {
        "type": "object",
        "properties": {
          "session_id": { "type": "string" },
          "payment_token": { "type": "string" },
          "shipping_address": {
            "type": "object",
            "properties": {
              "line1": { "type": "string" },
              "city": { "type": "string" },
              "state": { "type": "string" },
              "postal_code": { "type": "string" },
              "country": { "type": "string" }
            }
          }
        },
        "required": ["session_id", "payment_token"]
      }
    }
  ]
}

Connecting to MCP Server

import { MCPClient } from '@modelcontextprotocol/sdk';

const client = new MCPClient();

// Connect to business MCP server
await client.connect('https://mcp.business.com');

// List available tools
const tools = await client.listTools();
console.log('Available tools:', tools.map(t => t.name));

Using MCP Tools

Search Products

const results = await client.callTool('ucp_search_products', {
  query: 'wireless headphones',
  max_price: 200,
  limit: 5
});

// Response
{
  "products": [
    {
      "id": "WH-PRO-001",
      "name": "Pro Wireless Headphones",
      "price": 149.99,
      "currency": "USD",
      "availability": "in_stock",
      "rating": 4.5
    }
  ],
  "total_count": 23
}

Create Checkout

const session = await client.callTool('ucp_create_checkout', {
  items: [
    { product_id: 'WH-PRO-001', quantity: 1 }
  ],
  currency: 'USD'
});

// Response
{
  "session_id": "sess_abc123",
  "status": "open",
  "cart": {
    "items": [...],
    "total": 149.99
  },
  "expires_at": "2025-01-15T12:00:00Z"
}

Tool Response Format

MCP tools return structured responses that LLMs can understand:

{
  "content": [
    {
      "type": "text",
      "text": "Found 5 wireless headphones under $200"
    },
    {
      "type": "resource",
      "resource": {
        "uri": "ucp://products/search-results",
        "mimeType": "application/json",
        "text": "{...}"
      }
    }
  ]
}

Error Handling

{
  "content": [
    {
      "type": "text",
      "text": "Error: Product WH-PRO-001 is out of stock"
    }
  ],
  "isError": true
}

Streaming Responses

For long-running operations, MCP supports streaming:

const stream = await client.callTool('ucp_search_products', {
  query: 'electronics',
  limit: 100
}, { streaming: true });

for await (const chunk of stream) {
  console.log('Received:', chunk);
}

Authentication

MCP tools can require authentication:

// Set auth token before making calls
client.setAuthToken('Bearer eyJhbGciOiJSUzI1NiIs...');

// Or include in tool call
const session = await client.callTool('ucp_create_checkout', {
  items: [...],
  auth: {
    token: 'Bearer ...'
  }
});

Context Resources

MCP servers can expose resources for additional context:

// List available resources
const resources = await client.listResources();

// Read a resource
const catalog = await client.readResource('ucp://catalog/categories');

Integration Example

// Complete autonomous purchase flow
async function purchaseWithMCP(
  requirement: string,
  budget: number
) {
  const client = new MCPClient();
  await client.connect('https://mcp.business.com');

  // 1. Search for products
  const searchResult = await client.callTool('ucp_search_products', {
    query: requirement,
    max_price: budget
  });

  // 2. Select best product
  const product = searchResult.products[0];
  if (!product) {
    throw new Error('No products found within budget');
  }

  // 3. Create checkout
  const session = await client.callTool('ucp_create_checkout', {
    items: [{ product_id: product.id, quantity: 1 }]
  });

  // 4. Complete purchase
  const order = await client.callTool('ucp_complete_checkout', {
    session_id: session.session_id,
    payment_token: 'tok_xxx'
  });

  return order;
}

Next Steps

U

Ready to Get Started?

Join the waitlist for early access to UCPStore and start building with UCP.

Join Waitlist