Skip to main content
This guide walks you through creating a FrontMCP plugin from scratch. We’ll build a real-world example: a site authorization plugin that validates user access to site-scoped tools.

Plugin Architecture

A FrontMCP plugin can:
  1. Register providers - Services available to the plugin and optionally exported to the host app
  2. Contribute tools - Add tools that become available when the plugin is attached
  3. Intercept flows via hooks - Run code before/after specific stages (caching, validation, logging)
  4. Accept configuration - Via init() for runtime customization
  5. Extend metadata - Add custom fields to tool metadata for plugin-specific behavior

Step 1: Create the Plugin Structure

Step 2: Define Types

Start by defining your plugin’s options and any metadata extensions.
site-authorization.types.ts

Step 3: Create the Plugin Class

Simple Plugin (No Required Options)

For plugins that work without configuration:
site-authorization.plugin.ts

Usage

Step 4: Add Dynamic Providers

For plugins that need to create providers based on configuration:
cache.plugin.ts

Step 5: Type-Safe Options with Zod

For plugins with complex options and defaults, use Zod:
my-plugin.types.ts
my-plugin.plugin.ts

Step 6: Using Factory Pattern

For async initialization or injecting other providers:

Step 7: Export the Plugin

index.ts

Hook Reference

Available Hooks

Hook Timing

Priority

Lower numbers run first. Common conventions:

FlowCtxOf State

Access flow state in hooks:

Error Handling in Hooks

Hooks should handle errors gracefully, especially in non-critical paths:
Guidelines:
  • Authorization hooks - Throw errors to block execution
  • Caching/logging hooks - Catch errors and continue gracefully
  • Cleanup hooks (Did) - Always wrap in try/catch to avoid breaking the response

Best Practices

  1. Use descriptive names - Plugin name should be lowercase with hyphens
  2. Provider naming - Use plugin-name:provider-name format
  3. Default options - Always provide sensible defaults
  4. Guard hooks early - Check for required state before processing
  5. Don’t throw in cleanup - Wrap finalize hooks in try/catch
  6. Document metadata extensions - If extending ExtendFrontMcpToolMetadata
  7. Export types - Export options types for consumers
  8. Type-safe authInfo access - Use helper methods to safely extract user data

Complete Example

See the built-in plugins for complete examples:
  • CachePlugin - Caching with Redis/memory, hooks, dynamic providers
  • CodeCallPlugin - Complex plugin with tools, multiple providers, Zod validation
  • SiteAuthorizationPlugin - Simple authorization plugin with hooks

Next Steps

Cache Plugin

Study the built-in cache plugin implementation

Remember Plugin

See session memory plugin patterns

Customize Flow Stages

Deep dive into hook types and priorities

Plugin Reference

Full plugin decorator documentation