Skip to main content

Validation Layers: MCP, Protobuf, API-first

HAPI server applies multiple layers of validation to every gRPC request and response, ensuring your system is robust, secure, and always in sync with your protobuf contract.

Validation Layers in HAPI (gRPC)

  1. Schema Validation: All data is validated against your protobuf message definitions (types, enums, etc.).
  2. Security Validation: Authentication and authorization are enforced using MCP context and gRPC metadata.
  3. Context Validation: MCP context is checked for required fields and permissions.
  4. Custom Validation: Add hooks for business logic or additional checks as needed.
tip

Use protobuf field options and enums for strong schema validation. Combine with MCP context checks for full coverage.

Example: Request Validation

rpc CreateUser (User) returns (UserResponse);

Example: Security Validation

// Use gRPC metadata for API keys or tokens
caution

If your schema and implementation drift, validation errors will occur. Always update your protobuf definitions when making changes to your API.

Best Practices

  • Use tools like protoc to validate your schema.
  • Test all RPCs with valid and invalid data.
  • Use descriptive error messages for validation failures.

Further Reading