DEV Community

Cover image for What Is the Model Context Protocol (MCP) and Why Does It Matter for APIs?
Wanda
Wanda

Posted on • Originally published at apidog.com

What Is the Model Context Protocol (MCP) and Why Does It Matter for APIs?

TL;DR

Model Context Protocol (MCP) is a standard for connecting AI assistants to external data sources and APIs. It enables tools like Claude Desktop and Cursor to access your API securely. Modern PetstoreAPI uses MCP so AI assistants can search pets, place orders, and manage inventory using natural language.

Try Apidog today

Introduction

If you ask Claude Desktop: “Show me available cats under $300,” and it responds: “I don’t have access to pet store data,” your workflow stalls and you’re forced to copy/paste from your API.

With MCP (Model Context Protocol), Claude can access your API directly. Now, when you ask the same question, Claude queries the PetstoreAPI, filters the results, and shows you available cats under $300—no manual steps required.

Modern PetstoreAPI implements MCP, enabling AI assistants to interact with the pet store through natural language.

If you’re building APIs for AI integration, Apidog helps you test MCP implementations and validate AI assistant interactions.

What Is MCP?

MCP is a protocol created by Anthropic to connect AI assistants to external resources.

The Problem MCP Solves

AI assistants are typically isolated and cannot:

  • Access your company’s internal APIs
  • Query your database
  • Read files from your filesystem
  • Interact with external services

MCP provides a standard, secure way for AI assistants to connect to these resources.

MCP Components

  • MCP Server: Exposes resources and tools to AI assistants
  • MCP Client: The AI assistant (Claude Desktop, Cursor, etc.)
  • Resources: Data the AI can read (files, database records, API responses)
  • Tools: Actions the AI can perform (create order, update pet, search inventory)

MCP Architecture

AI Assistant (Claude Desktop)
    ↓ MCP Protocol
MCP Server (PetstoreAPI MCP Server)
    ↓ Internal APIs
PetstoreAPI Backend
    ↓
Database
Enter fullscreen mode Exit fullscreen mode

How MCP Works

1. Server Registration

Configure your AI assistant (e.g., Claude Desktop) to connect to the MCP server. Example config.json:

{
  "mcpServers": {
    "petstore": {
      "command": "node",
      "args": ["/path/to/petstore-mcp-server.js"],
      "env": {
        "PETSTORE_API_KEY": "your-api-key"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

2. Tool Discovery

AI assistant sends a request: “What tools are available?”

MCP server responds with available tools and input schemas:

{
  "tools": [
    {
      "name": "search_pets",
      "description": "Search for pets by species, status, and price",
      "inputSchema": {
        "type": "object",
        "properties": {
          "species": {"type": "string", "enum": ["CAT", "DOG"]},
          "maxPrice": {"type": "number"},
          "status": {"type": "string", "enum": ["AVAILABLE", "ADOPTED"]}
        }
      }
    },
    {
      "name": "create_order",
      "description": "Place an order for a pet",
      "inputSchema": {
        "type": "object",
        "properties": {
          "petId": {"type": "string"},
          "userId": {"type": "string"}
        },
        "required": ["petId", "userId"]
      }
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

3. Tool Execution

User: “Show me available cats under $300”

AI assistant calls the tool:

{
  "tool": "search_pets",
  "arguments": {
    "species": "CAT",
    "status": "AVAILABLE",
    "maxPrice": 300
  }
}
Enter fullscreen mode Exit fullscreen mode

MCP server executes the request:

async function search_pets({ species, status, maxPrice }) {
  const response = await fetch(
    `https://petstoreapi.com/v1/pets?species=${species}&status=${status}&maxPrice=${maxPrice}`
  );
  return await response.json();
}
Enter fullscreen mode Exit fullscreen mode

Results are returned to the AI assistant, which formats them for the user.

MCP vs Traditional APIs

Feature Traditional API MCP
Access Direct HTTP Through AI assistant
Interface REST/GraphQL Natural language
Auth API keys, OAuth MCP server handles auth
Discovery OpenAPI docs Tool schemas
Usage Code/curl Conversational
Error Handling HTTP status codes AI interprets errors

Example Comparison

Traditional API:

curl -H "Authorization: Bearer token" \
  "https://petstoreapi.com/v1/pets?species=CAT&maxPrice=300"
Enter fullscreen mode Exit fullscreen mode

MCP:

User: "Show me available cats under $300"
AI: [Calls search_pets tool, formats results]
"Here are 5 available cats under $300:
1. Fluffy - $250
2. Whiskers - $280
..."
Enter fullscreen mode Exit fullscreen mode

How Modern PetstoreAPI Implements MCP

Modern PetstoreAPI provides an MCP server that exposes a set of tools for AI assistants.

Available Tools

  • search_pets – Search pets by criteria
  • get_pet – Get pet details
  • create_order – Place an order
  • get_inventory – Check inventory
  • update_pet_status – Update pet availability

Example: Search and Order

User: “Find me a dog under $500 and place an order”

AI workflow:

1. Call search_pets({species: "DOG", maxPrice: 500})
2. Show results to user
3. User confirms: "Order the Labrador"
4. Call create_order({petId: "019b4132", userId: "user-456"})
5. Confirm order placed
Enter fullscreen mode Exit fullscreen mode

MCP Server Code Example

Set up a simple MCP server using the Model Context Protocol SDK:

import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new Server({
  name: 'petstore-mcp',
  version: '1.0.0'
}, {
  capabilities: {
    tools: {}
  }
});

server.setRequestHandler('tools/list', async () => ({
  tools: [
    {
      name: 'search_pets',
      description: 'Search for pets',
      inputSchema: {
        type: 'object',
        properties: {
          species: { type: 'string' },
          maxPrice: { type: 'number' }
        }
      }
    }
  ]
}));

server.setRequestHandler('tools/call', async (request) => {
  const { name, arguments: args } = request.params;

  if (name === 'search_pets') {
    const response = await fetch(
      `https://petstoreapi.com/v1/pets?${new URLSearchParams(args)}`
    );
    return { content: [{ type: 'text', text: JSON.stringify(await response.json()) }] };
  }
});

const transport = new StdioServerTransport();
await server.connect(transport);
Enter fullscreen mode Exit fullscreen mode

Testing MCP with Apidog

Apidog helps you test your MCP implementation:

  1. Test underlying APIs for correctness
  2. Validate tool schemas match your API contracts
  3. Test error handling scenarios
  4. Verify authentication flows

Why MCP Matters

1. AI-Native APIs

APIs become accessible via natural language, making them usable by non-technical users through AI assistants.

2. Standardization

MCP is emerging as a standard for AI-API integration. Implement once, integrate with any MCP client.

3. Security

MCP servers handle authentication. AI assistants never receive direct API credentials.

4. Composability

AI assistants can combine tools from multiple MCP servers to create workflows across services.

Conclusion

MCP bridges AI assistants and APIs. Modern PetstoreAPI implements MCP, enabling tools like Claude Desktop to interact with the pet store using natural language.

Key takeaways:

  • MCP connects AI assistants to APIs
  • Tools define the actions AI can perform
  • Natural language replaces manual API calls
  • Modern PetstoreAPI demonstrates practical MCP implementation

FAQ

Which AI assistants support MCP?

Claude Desktop, Cursor, and other Anthropic-powered tools. Support is expanding.

Is MCP secure?

Yes. MCP servers manage authentication, so AI assistants do not have access to API keys.

Can I use MCP with existing APIs?

Yes. You can build an MCP server that wraps your existing API.

Does MCP replace REST APIs?

No. MCP is for AI assistant access. REST APIs remain for direct programmatic use.

How do I test MCP tools?

Use Apidog to test the underlying APIs, then test MCP tools with Claude Desktop.

Top comments (0)