MCP Integration Usage Examples
MCP Integration Usage Examples
Section titled “MCP Integration Usage Examples”This document demonstrates how LLMs will interact with your multi-protocol API platform through the MCP integration.
Example 1: Simple API Query
Section titled “Example 1: Simple API Query”LLM Prompt
Section titled “LLM Prompt”“Get all active sessions for user ‘john.doe@example.com‘“
MCP Tool Call
Section titled “MCP Tool Call”{ "tool": "execute-api", "arguments": { "protocol": "rest", "operation": { "method": "GET", "endpoint": "/api/v1/sessions", "params": { "userId": "john.doe@example.com" } }, "auth": { "type": "apikey", "credentials": "sk-..." } }}
Response
Section titled “Response”{ "content": [ { "type": "text", "text": "[{\"id\":\"session-123\",\"userId\":\"john.doe@example.com\",\"createdAt\":\"2024-01-01T10:00:00Z\",\"status\":\"active\"}]" } ]}
Example 2: Complex Workflow - Web Scraping
Section titled “Example 2: Complex Workflow - Web Scraping”LLM Prompt
Section titled “LLM Prompt”“I need to scrape product prices from https://example-shop.com/products. Create a browser session, navigate to the page, and extract all prices.”
Step 1: Create Session
Section titled “Step 1: Create Session”{ "tool": "create-session", "arguments": { "username": "scraper-bot", "password": "secure-password" }}
Step 2: Create Browser Context
Section titled “Step 2: Create Browser Context”{ "tool": "create-browser-context", "arguments": { "sessionId": "session-456", "options": { "headless": true, "viewport": { "width": 1920, "height": 1080 } } }}
Step 3: Navigate to Page
Section titled “Step 3: Navigate to Page”{ "tool": "execute-in-context", "arguments": { "contextId": "context-789", "command": "navigate", "parameters": { "url": "https://example-shop.com/products", "waitUntil": "networkidle2" } }}
Step 4: Extract Prices
Section titled “Step 4: Extract Prices”{ "tool": "execute-in-context", "arguments": { "contextId": "context-789", "command": "evaluate", "parameters": { "script": "Array.from(document.querySelectorAll('.price')).map(el => el.textContent)" } }}
Example 3: Real-time Monitoring
Section titled “Example 3: Real-time Monitoring”LLM Prompt
Section titled “LLM Prompt”“Monitor all context updates for the next 5 minutes and alert me if any context fails”
MCP Tool Calls
Section titled “MCP Tool Calls”Subscribe to Updates
Section titled “Subscribe to Updates”{ "tool": "execute-api", "arguments": { "protocol": "websocket", "operation": { "action": "subscribe", "topic": "context-updates", "filter": { "status": "failed" }, "duration": 300000 }, "auth": { "type": "jwt", "credentials": "eyJ..." } }}
Process Updates (LLM handles streaming responses)
Section titled “Process Updates (LLM handles streaming responses)”// LLM receives real-time updates:{ "type": "context-update", "contextId": "context-abc", "status": "failed", "error": "Navigation timeout", "timestamp": "2024-01-01T10:05:23Z"}
Example 4: Multi-Protocol Orchestration
Section titled “Example 4: Multi-Protocol Orchestration”LLM Prompt
Section titled “LLM Prompt”“Create a workflow that: 1) Creates a user session via REST, 2) Starts a browser context via gRPC, 3) Monitors the context via WebSocket”
LLM Orchestration
Section titled “LLM Orchestration”# LLM generates this workflow:
# Step 1: REST API - Create Sessionsession = await mcp.call_tool("execute-api", { "protocol": "rest", "operation": { "method": "POST", "endpoint": "/api/v1/sessions", "body": { "username": "workflow-user", "metadata": {"purpose": "automated-testing"} } }})
# Step 2: gRPC - Create Contextcontext = await mcp.call_tool("execute-api", { "protocol": "grpc", "operation": { "service": "ContextService", "method": "CreateContext", "request": { "sessionId": session.id, "type": "puppeteer", "config": {"headless": true} } }})
# Step 3: WebSocket - Monitorsubscription = await mcp.call_tool("execute-api", { "protocol": "websocket", "operation": { "action": "subscribe", "topic": "context-updates", "filter": {"contextId": context.id} }})
Example 5: API Discovery and Learning
Section titled “Example 5: API Discovery and Learning”LLM Prompt
Section titled “LLM Prompt”“What APIs are available for session management?”
MCP Resource Query
Section titled “MCP Resource Query”{ "resource": "api://catalog"}
LLM Processes Catalog
Section titled “LLM Processes Catalog”{ "rest": { "endpoints": [ { "path": "/sessions", "methods": ["GET", "POST", "DELETE"], "description": "Session management" } ] }, "grpc": { "services": [ { "name": "SessionService", "methods": ["CreateSession", "GetSession", "DeleteSession", "ListSessions"] } ] }}
LLM Follow-up
Section titled “LLM Follow-up”“Show me the schema for creating a session via gRPC”
{ "resource": "api://schemas/SessionService/CreateSession"}
Example 6: Error Handling and Recovery
Section titled “Example 6: Error Handling and Recovery”Scenario: LLM encounters an error
Section titled “Scenario: LLM encounters an error”{ "tool": "execute-in-context", "arguments": { "contextId": "expired-context", "command": "navigate", "parameters": { "url": "https://example.com" } }}
Error Response
Section titled “Error Response”{ "error": { "code": "CONTEXT_NOT_FOUND", "message": "Context expired-context not found or has expired" }}
LLM Recovery Strategy
Section titled “LLM Recovery Strategy”- Check if session is still valid
- Create new context if needed
- Retry the operation
{ "tool": "create-browser-context", "arguments": { "sessionId": "session-456", "options": { "headless": true } }}
Example 7: Batch Operations
Section titled “Example 7: Batch Operations”LLM Prompt
Section titled “LLM Prompt”“Check the status of 10 different URLs and return which ones are accessible”
LLM Generates Parallel Execution
Section titled “LLM Generates Parallel Execution”const urls = [ 'https://site1.com', 'https://site2.com', // ... 8 more URLs];
const contexts = await Promise.all( urls.map(async (url, index) => { const ctx = await mcp.call_tool('create-browser-context', { sessionId: sessionId, options: { name: `checker-${index}` }, }); return ctx.contextId; }),);
const results = await Promise.all( contexts.map(async (contextId, index) => { try { const response = await mcp.call_tool('execute-in-context', { contextId: contextId, command: 'navigate', parameters: { url: urls[index], timeout: 5000, }, }); return { url: urls[index], status: 'accessible' }; } catch (error) { return { url: urls[index], status: 'failed', error: error.message }; } }),);
Security Examples
Section titled “Security Examples”Example 8: Permission-based Access
Section titled “Example 8: Permission-based Access”Scenario 1: Limited Permissions
Section titled “Scenario 1: Limited Permissions”{ "tool": "execute-api", "arguments": { "protocol": "rest", "operation": { "method": "DELETE", "endpoint": "/api/v1/sessions/all" }, "auth": { "type": "apikey", "credentials": "sk-readonly-key" } }}
Response:
{ "error": { "code": "PERMISSION_DENIED", "message": "API key lacks 'session:delete' permission" }}
Scenario 2: Scoped Access
Section titled “Scenario 2: Scoped Access”{ "tool": "list-sessions", "arguments": { "userId": "other-user@example.com" }, "auth": { "type": "jwt", "credentials": "user-specific-token" }}
Response:
{ "error": { "code": "FORBIDDEN", "message": "Cannot list sessions for other users" }}
Advanced Use Cases
Section titled “Advanced Use Cases”Example 9: AI-Powered Testing
Section titled “Example 9: AI-Powered Testing”The LLM generates comprehensive API tests:
// LLM generates test scenariosconst testScenarios = [ { name: 'Valid session creation', tool: 'create-session', input: { username: 'test-user', password: 'valid-pass' }, expectedStatus: 'success', }, { name: 'Invalid credentials', tool: 'create-session', input: { username: 'test-user', password: 'wrong-pass' }, expectedError: 'INVALID_CREDENTIALS', }, { name: 'Session expiration', tool: 'execute-api', input: { protocol: 'rest', operation: { method: 'GET', endpoint: '/api/v1/protected' }, auth: { type: 'session', credentials: 'expired-session-id' }, }, expectedError: 'SESSION_EXPIRED', },];
// Execute all testsfor (const scenario of testScenarios) { const result = await mcp.call_tool(scenario.tool, scenario.input); // LLM validates results against expectations}
Example 10: Natural Language API Interface
Section titled “Example 10: Natural Language API Interface”User: “I want to see all failed browser contexts from the last hour”
LLM Translation:
{ "tool": "execute-api", "arguments": { "protocol": "rest", "operation": { "method": "GET", "endpoint": "/api/v1/contexts", "params": { "status": "failed", "since": "2024-01-01T09:00:00Z" } } }}
LLM Response to User: “I found 3 failed browser contexts in the last hour:
- Context ‘price-scraper’ failed at 09:15 - Navigation timeout
- Context ‘form-filler’ failed at 09:32 - Page crash
- Context ‘screenshot-bot’ failed at 09:45 - Memory limit exceeded”
Benefits Summary
Section titled “Benefits Summary”- Unified Interface: LLMs interact with all protocols through one consistent interface
- Intelligent Orchestration: LLMs can combine multiple protocols for complex workflows
- Self-Discovery: LLMs can explore and learn about available APIs
- Error Recovery: LLMs can implement sophisticated error handling strategies
- Natural Language: Users interact with APIs using plain language
- Security Maintained: All existing security measures remain in effect
- Monitoring & Debugging: Full audit trail of LLM interactions
This MCP integration transforms your platform into an AI-native API gateway that can be seamlessly integrated into any LLM-powered application.