Skip to main content

Serve and Consume APIs with the HAPI Stack for MCP

This guide walks you through the typical flow of serving and consuming APIs using the HAPI Stack for MCP. It covers the steps from defining your API contract to consuming it in a MCP client compliant application, all while adhering to API-first principles and the Model Context Protocol (MCP).


runMCP FlowArchitecture SequenceProviderMCP Server ProviderConsumerchatMCP UserrunMCP PortalHAPI CPDNSMCP ServerMCP ToolsBackend APIchatMCPOAS1. Provides Swagger(OAS v3) fileAPI2. Forward OASto control planeπŸŽ›οΈ3. Deploy MCP Serverwith OAS configuration4. Configure DNSfor traffic routing🌐😁 HAPIServer5. Load MCP Toolsbased on OASπŸ› οΈ6. Connect toBackend APIs7. Consumer accesseschatMCP8. Connect to MCP Tools9. Multi-agent collaborationA1A2A310. Consumer interaction with agentsContinuous managementLifecycle managementrunMCP

Typical Workflow Overview​

  1. Design β†’ 2. Register β†’ 3. Serve β†’ 4. Consume β†’ 5. Monitor & Iterate ♻️

The above flow ensures a contract-driven, API-first development process, reducing integration friction and enabling rapid iteration.


Step 1: Define Your API (OpenAPI Spec)​

  openapi: 3.1.0
info:
title: Example API for MCP
version: 1.0.0
paths:
/hello:
get:
summary: Greet the AI world
responses:
'200':
description: Success

Step 2: Register API with runMCP​

  • Upload or link your OpenAPI spec in the runMCP dashboard.
  • runMCP validates and registers your API, generating interactive API testing UI and MCP endpoint.
  • Forward the spec to the HAPI Control Plane for serving.

Step 3: Serve the API​

  • The HAPI Control Plane handles serving your API based on the registered OpenAPI spec.
    • Instantiate the HAPI server with your OpenAPI spec.
    • Configure the routing engine registering subdomains to your API endpoints.
  • The instance of HAPI Server will:
    • Serve your API endpoints dynamically based on the OpenAPI spec.
    • Generate endpoints dynamically based on your OpenAPI spec.
    • Validate incoming requests against the spec.
    • Secure access using OpenAPI security schemes (OAuth2, API keys, etc.).
  • The HAPI Control Plane dynamically configures the Routing Engine to expose your API endpoints.
Extensions 🧩

Extensions can be used to add custom metadata for advanced HAPI-specific features or MCP context. Features like throttling, rate limiting, and caching can be configured as needed.

Step 4: Consume the API​

  • chatMCP can discover and consume the MCP Tools via runMCP’s catalog.
  • Also, you can use any MCP client compliant application to consume the API.

Step 5: Monitor & Iterate​

  • Monitor usage, logs, and health via runMCP, with all metrics and events tracked as code artifacts.
  • Manage your OpenAPI spec and API configurations in version control (Git), enabling automated change tracking and auditability.
  • Use GitOps workflows to update, version, and redeploy your APIβ€”every change is declarative and reproducible.
  • Automatically trigger redeployment and re-registration of your API when changes are merged, keeping consumers in sync and ensuring continuous delivery.
  • Integrate with CI/CD pipelines for automated testing, validation, and rollout of API updates.

Further Reading​