Plugin Development

Overview

The vCon MCP Server supports a plugin architecture that allows you to extend its functionality with custom features. This guide explains how to create your own plugins.

Plugin Interface

Plugins implement the VConPlugin interface which provides lifecycle hooks and tool registration capabilities.

Basic Plugin Structure

import { VConPlugin, RequestContext } from '@vcon/mcp-server/hooks';
import { VCon } from '@vcon/mcp-server/types';
import { Tool } from '@modelcontextprotocol/sdk/types';

export default class MyPlugin implements VConPlugin {
  name = 'my-plugin';
  version = '1.0.0';
  
  async initialize(config: any): Promise<void> {
    console.error('โœ… My Plugin initialized');
  }
  
  async shutdown(): Promise<void> {
    console.error('๐Ÿ‘‹ My Plugin shutting down');
  }
  
  // Implement hooks as needed...
}

Available Hooks

Lifecycle Hooks

initialize(config)

Called when the server starts up. Use this to set up connections, load configuration, etc.

shutdown()

Called when the server is shutting down. Clean up resources here.

Data Operation Hooks

beforeCreate(vcon, context)

Called before a vCon is created. Can modify the vCon or throw to block creation.

afterCreate(vcon, context)

Called after a vCon is successfully created.

beforeRead(uuid, context)

Called before a vCon is read. Throw an error to block access.

afterRead(vcon, context)

Called after a vCon is read. Can modify the returned data (e.g., redact sensitive information).

beforeUpdate(uuid, updates, context)

Called before a vCon is updated.

afterUpdate(vcon, context)

Called after a vCon is updated.

beforeDelete(uuid, context)

Called before a vCon is deleted. Throw to prevent deletion.

afterDelete(uuid, context)

Called after a vCon is deleted.

beforeSearch(criteria, context)

Called before searching vCons. Can modify search criteria.

afterSearch(results, context)

Called after searching vCons. Can filter or modify results.

Tool Registration

registerTools()

Register additional MCP tools that will be exposed to clients.

Note: You'll need to handle the tool execution in your plugin by registering a tool handler separately.

registerResources()

Register additional MCP resources.

Request Context

All hooks receive a RequestContext object with information about the request:

Loading Plugins

Via Environment Variable

Set the VCON_PLUGINS_PATH environment variable to load plugins:

Plugin Configuration

Plugins receive configuration from environment variables:

Access these in your plugin constructor:

Example: Simple Logging Plugin

Example: Access Control Plugin

Testing Your Plugin

Create a test file:

Best Practices

  1. Error Handling: Always catch and properly handle errors in hooks

  2. Performance: Keep hook execution fast - avoid slow operations

  3. Logging: Use console.error() for plugin logs (stdout is reserved for MCP protocol)

  4. Type Safety: Use TypeScript and proper type annotations

  5. Documentation: Document your plugin's configuration options and behavior

  6. Testing: Write tests for your plugin hooks

  7. Versioning: Use semantic versioning for your plugin

Publishing Your Plugin

As npm Package

  1. Create package.json:

  1. Build and publish:

  1. Users install with:

As Local Module

Users can load plugins from local files:

Plugin Ideas

  • Audit Logging: Log all operations to external system

  • Webhooks: Send notifications on vCon events

  • Encryption: Encrypt sensitive fields at rest

  • Multi-tenancy: Enforce tenant isolation

  • Rate Limiting: Limit operations per user

  • Caching: Cache frequently accessed vCons

  • Analytics: Collect usage statistics

  • Validation: Enforce custom business rules

  • Integration: Sync with external systems (CRM, etc.)

Support

For questions or issues with plugin development:

  • Create an issue on GitHub

  • Join our community discussions

  • Review the plugin interface source code

License

When creating plugins, ensure they comply with the MIT license of the core server, or clearly state your plugin's license.

Last updated