Documentation

ExMCP Extension Development

ThinkCode's extension system is powered by ExMCP (Extended Machine Cognition Protocol), a flexible framework that allows developers to add new capabilities or enhance existing ones. This guide will walk you through the process of creating your own extensions to customize ThinkCode for your team's specific needs.

ExMCP Protocol Overview

The Extended Machine Cognition Protocol (ExMCP) is the foundation of ThinkCode's extensibility. It enables seamless communication between different components of the system and custom extensions.

Key Concepts

  • ExMCP Context: The shared state and context that extensions can access and modify
  • Context Providers: Components that supply contextual information to the AI system
  • Extension Points: Specific locations in the system where custom functionality can be inserted
  • Message Types: Standardized formats for communication between components

Architecture

ExMCP follows a modular architecture with clearly defined interfaces:

  1. Core System: The base ThinkCode environment
  2. Extension API: The interface that extensions interact with
  3. Context Registry: A central repository of contextual information
  4. Event System: A publish-subscribe mechanism for communication

Creating Custom Extensions

Prerequisites

Before you begin developing extensions, ensure you have:

  • ThinkCode Enterprise or Professional Edition (v1.2+)
  • Node.js (v16+) and npm/yarn installed
  • TypeScript knowledge (recommended)
  • Basic understanding of VSCode extension development

Setting Up Your Development Environment

  1. Install the ThinkCode Extension Development Kit:
npm install -g thinkcode-extension-cli
  1. Create a new extension project:
thinkcode-ext create my-extension
cd my-extension
  1. Install dependencies:
npm install

Extension Structure

A typical ThinkCode extension has the following structure:

my-extension/
├── package.json         # Extension metadata and dependencies
├── tsconfig.json        # TypeScript configuration
├── src/
│   ├── extension.ts     # Main extension entry point
│   ├── providers/       # Context providers
│   ├── commands/        # Custom commands
│   └── views/           # UI components
└── README.md            # Documentation

Developing Your First Extension

Here's a simple example of an extension that adds a new context provider:

import { registerExtension, ContextProvider } from 'thinkcode-extension-api';
 
// Define a custom context provider
class MyContextProvider implements ContextProvider {
  id = 'my.custom.provider';
  
  async getContext(params: any) {
    return {
      type: 'custom',
      data: {
        // Custom data your extension provides
        timestamp: Date.now(),
        customInfo: 'This is from my custom extension'
      }
    };
  }
}
 
// Register the extension
export function activate(context: any) {
  registerExtension({
    id: 'my.custom.extension',
    name: 'My Custom Extension',
    version: '1.0.0',
    providers: [new MyContextProvider()]
  });
  
  console.log('My extension is now active!');
}
 
// Clean up when deactivated
export function deactivate() {
  console.log('My extension is deactivated');
}

Testing Extensions

ThinkCode provides a sandbox environment for testing extensions:

  1. Start the extension development server:
npm run dev
  1. In ThinkCode, open the Extension Development Host:

    • Press Ctrl+Shift+P (or Cmd+Shift+P on macOS)
    • Select "ThinkCode: Open Extension Development Host"
    • Choose your extension folder
  2. Debug your extension using the built-in tools

API Reference

The ExMCP API provides several key interfaces for extension development:

Core Interfaces

  • ContextProvider: For supplying context to the AI system
  • CommandProvider: For registering custom commands
  • ViewProvider: For creating custom UI elements
  • ModelAdapter: For integrating custom AI models

Event API

Subscribe to and publish events within the ThinkCode system:

import { events } from 'thinkcode-extension-api';
 
// Subscribe to an event
events.on('context.updated', (data) => {
  console.log('Context was updated:', data);
});
 
// Publish an event
events.emit('my.custom.event', { message: 'Hello from my extension' });

Storage API

Persist extension data between sessions:

import { storage } from 'thinkcode-extension-api';
 
// Save data
await storage.set('my.extension.settings', { enabled: true });
 
// Retrieve data
const settings = await storage.get('my.extension.settings');

Best Practices

When developing ExMCP extensions, follow these guidelines:

  • Contextual Relevance: Ensure your extension provides relevant context to the AI system
  • Performance: Minimize the performance impact of your extension
  • Security: Handle sensitive data appropriately
  • User Experience: Integrate seamlessly with the existing ThinkCode UI
  • Documentation: Provide clear documentation for your extension

Troubleshooting

Common issues and their solutions:

  • Extension Not Loading: Check for console errors and ensure your package.json is correctly configured
  • Context Not Appearing: Verify that your context provider is properly registered
  • Performance Issues: Profile your extension using the built-in tools

Resources

Next Steps

After mastering extension development, consider exploring: