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)
initialize(config)Called when the server starts up. Use this to set up connections, load configuration, etc.
shutdown()
shutdown()Called when the server is shutting down. Clean up resources here.
Data Operation Hooks
beforeCreate(vcon, context)
beforeCreate(vcon, context)Called before a vCon is created. Can modify the vCon or throw to block creation.
afterCreate(vcon, context)
afterCreate(vcon, context)Called after a vCon is successfully created.
beforeRead(uuid, context)
beforeRead(uuid, context)Called before a vCon is read. Throw an error to block access.
afterRead(vcon, context)
afterRead(vcon, context)Called after a vCon is read. Can modify the returned data (e.g., redact sensitive information).
beforeUpdate(uuid, updates, context)
beforeUpdate(uuid, updates, context)Called before a vCon is updated.
afterUpdate(vcon, context)
afterUpdate(vcon, context)Called after a vCon is updated.
beforeDelete(uuid, context)
beforeDelete(uuid, context)Called before a vCon is deleted. Throw to prevent deletion.
afterDelete(uuid, context)
afterDelete(uuid, context)Called after a vCon is deleted.
beforeSearch(criteria, context)
beforeSearch(criteria, context)Called before searching vCons. Can modify search criteria.
afterSearch(results, context)
afterSearch(results, context)Called after searching vCons. Can filter or modify results.
Tool Registration
registerTools()
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()
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
Error Handling: Always catch and properly handle errors in hooks
Performance: Keep hook execution fast - avoid slow operations
Logging: Use
console.error()for plugin logs (stdout is reserved for MCP protocol)Type Safety: Use TypeScript and proper type annotations
Documentation: Document your plugin's configuration options and behavior
Testing: Write tests for your plugin hooks
Versioning: Use semantic versioning for your plugin
Publishing Your Plugin
As npm Package
Create
package.json:
Build and publish:
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