TL;DR
Model Context Protocol (MCP) is a standard for connecting AI assistants to external data sources and APIs. It lets Claude Desktop, Cursor, and other AI tools access your API securely. Modern PetstoreAPI implements MCP so AI assistants can search pets, place orders, and manage inventory through natural language.
Introduction
Imagine asking Claude Desktop:
Show me available cats under $300.
Without API access, Claude might respond that it cannot access your pet store data. You would then need to query the API manually and paste the results into the conversation.
With MCP, Claude can call your API through an MCP server. The same request becomes an automated workflow:
- Claude identifies the required tool.
- It calls
search_petswith the appropriate filters. - The MCP server queries PetstoreAPI.
- Claude formats the response for the user.
Modern PetstoreAPI implements MCP, allowing 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 for connecting AI assistants to external resources and tools.
The Problem MCP Solves
AI assistants are powerful but isolated. Without an integration layer, they cannot:
- Access your company’s internal APIs
- Query your database
- Read files from your filesystem
- Interact with external services
MCP provides a standard way for AI assistants to connect to these resources while keeping authentication and API access in the MCP server.
MCP Components
- MCP server — Exposes resources and tools to AI assistants.
- MCP client — The AI assistant, such as Claude Desktop or Cursor.
- Resources — Data the AI can read, including files, database records, and API responses.
- Tools — Actions the AI can perform, such as creating an order, updating a pet, or searching inventory.
MCP Architecture
AI Assistant (Claude Desktop)
↓ MCP Protocol
MCP Server (PetstoreAPI MCP Server)
↓ Internal APIs
PetstoreAPI Backend
↓
Database
How MCP Works
An MCP integration typically follows three steps:
- Register the MCP server with the AI client.
- Expose the available tools and their input schemas.
- Execute a tool when the assistant determines that it is needed.
1. Register the MCP Server
For example, configure Claude Desktop to start a local MCP server:
{
"mcpServers": {
"petstore": {
"command": "node",
"args": ["/path/to/petstore-mcp-server.js"],
"env": {
"PETSTORE_API_KEY": "your-api-key"
}
}
}
}
The configuration tells the client:
- Which command starts the server
- Where the server entry point is located
- Which environment variables the server needs
Keep credentials in environment variables rather than hard-coding them in the server source.
2. Expose Tools and Schemas
The AI client can discover the tools exposed by the server:
{
"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"]
}
}
]
}
The tool schema is important because it tells the assistant:
- Which operations are available
- What each tool does
- Which arguments it accepts
- Which arguments are required
- Which values are valid for enum fields
Keep descriptions specific. A clear description helps the assistant select the correct tool and construct valid arguments.
3. Execute a Tool Call
When the user asks:
Show me available cats under $300.
The assistant can translate that request into a tool call:
{
"tool": "search_pets",
"arguments": {
"species": "CAT",
"status": "AVAILABLE",
"maxPrice": 300
}
}
The MCP server then maps the tool arguments to the underlying API request:
async function search_pets({ species, status, maxPrice }) {
const params = new URLSearchParams({
species,
status,
maxPrice: String(maxPrice)
});
const response = await fetch(
`https://petstoreapi.com/v1/pets?${params}`
);
return await response.json();
}
The server returns the API response to the assistant, which formats the results for the user.
MCP vs. Traditional APIs
| Feature | Traditional API | MCP |
|---|---|---|
| Access | Direct HTTP | Through an AI assistant |
| Interface | REST or GraphQL | Natural language |
| Authentication | API keys or OAuth | MCP server handles authentication |
| Discovery | OpenAPI documentation | Tool schemas |
| Usage | Code or curl
|
Conversational requests |
| Error handling | HTTP status codes | AI interprets and presents errors |
MCP does not replace the underlying API. It adds an AI-oriented interface on top of it.
Example Comparison
A direct API request might look like this:
curl -H "Authorization: Bearer token" \
"https://petstoreapi.com/v1/pets?species=CAT&maxPrice=300"
The equivalent MCP interaction is conversational:
User: Show me available cats under $300
AI: Calls search_pets with:
species = CAT
status = AVAILABLE
maxPrice = 300
AI: Here are 5 available cats under $300:
1. Fluffy - $250
2. Whiskers - $280
...
The API still performs the search. MCP provides the discovery and interaction layer that allows the assistant to invoke it.
How Modern PetstoreAPI Implements MCP
Modern PetstoreAPI provides an MCP server that exposes pet-store operations as tools.
Available Tools
The available tools include:
-
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
A request such as:
Find me a dog under $500 and place an order
should be handled as a multi-step workflow:
- Call
search_pets({ species: "DOG", maxPrice: 500 }). - Show the matching results to the user.
- Wait for confirmation, such as:
Order the Labrador. - Call
create_order({ petId: "019b4132", userId: "user-456" }). - Confirm that the order was placed.
Separating search from order creation gives the user an opportunity to review and confirm the selected pet before an action is performed.
MCP Server Code
The following server uses the MCP SDK and a standard input/output transport:
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);
The implementation has two important handlers:
-
tools/listpublishes the tools and their schemas. -
tools/callexecutes the selected tool and returns the result.
For a production implementation, add validation for tool names and arguments, and map API failures to clear tool responses.
Testing MCP with Apidog
Use Apidog to test the API and MCP integration in separate stages.
Test the Underlying API
First verify that the API endpoints work independently:
- Search pets with valid filters.
- Retrieve pet details.
- Create orders with valid identifiers.
- Test invalid query parameters.
- Confirm authentication behavior.
- Check response formats and error status codes.
Validate the MCP Layer
Then verify that the MCP server correctly exposes and invokes those operations:
- Confirm every expected operation appears in
tools/list. - Check that tool names and descriptions are accurate.
- Validate required and optional input fields.
- Confirm enum values match the API contract.
- Verify tool arguments map to the correct API parameters.
- Test authentication failures.
- Test API errors and malformed tool input.
- Confirm returned data is formatted as valid tool content.
Testing both layers makes it easier to determine whether a failure comes from the API contract, the MCP schema, or the tool execution logic.
Why MCP Matters
1. AI-Native APIs
APIs become accessible through natural language. Non-technical users can interact with your API through supported AI assistants.
2. Standardization
MCP provides a standard approach to AI and API integration. You can expose your operations through MCP instead of building a separate custom integration for every AI client.
3. Security
MCP servers handle authentication. AI assistants do not need direct access to the API keys used by the underlying service.
The MCP server should still validate inputs, enforce authorization, and apply the same security controls as any other API integration.
4. Composability
AI assistants can combine multiple MCP servers to create workflows across services.
For example, an assistant could search a pet inventory service, retrieve customer information from another service, and then create an order through the PetstoreAPI MCP server.
Conclusion
MCP bridges AI assistants and APIs. Modern PetstoreAPI implements MCP, allowing Claude Desktop and other AI tools to interact with the pet store through natural language.
To implement a similar integration:
- Identify the API operations the assistant should access.
- Wrap those operations as MCP tools.
- Define accurate input schemas.
- Register the MCP server with an AI client.
- Validate authentication, input handling, and error responses.
- Test both the underlying API and MCP tool calls.
Key takeaways:
- MCP connects AI assistants to APIs.
- Tools define what the AI can do.
- Tool schemas describe valid inputs.
- Natural language requests can trigger API calls.
- MCP servers can wrap existing REST APIs.
- Modern PetstoreAPI demonstrates an MCP-based implementation.
FAQ
Which AI assistants support MCP?
Claude Desktop, Cursor, and other Anthropic-powered tools support MCP. Support is growing across AI clients.
Is MCP secure?
MCP servers handle authentication, so AI assistants do not need to see the API keys used by the underlying service. You should still validate inputs and enforce authorization in the MCP server and API.
Can I use MCP with existing APIs?
Yes. Build an MCP server that wraps your existing API. Each MCP tool can translate structured tool arguments into requests to your REST or GraphQL endpoints.
Does MCP replace REST APIs?
No. MCP is an interface for AI assistant access. REST APIs remain useful for direct programmatic access, integrations, and clients that do not use MCP.
How do I test MCP tools?
Use Apidog to test the underlying APIs and contracts, then connect the MCP server to an MCP-compatible client such as Claude Desktop to test tool discovery and execution.
Top comments (0)