This document outlines how to embed Cortex functionality into an existing server application like PocketBase.
Cortex is designed to be either used as a standalone server or embedded within another application. When embedded, Cortex can provide MCP (Model Context Protocol) capabilities to your existing server without requiring a separate process.
There are several ways to integrate Cortex with your existing application:
- Middleware Integration - For web frameworks that support middleware, Cortex can be added as middleware to handle MCP requests.
- Route Handler Integration - For frameworks with custom routing, Cortex handlers can be registered with your existing router.
- Plugin System Integration - For applications with plugin capabilities, Cortex can be packaged as a plugin.
To support embedding Cortex into external servers, we need to complete the following tasks:
- Create an
Embeddableinterface that defines the integration points - Implement HTTP handler adapter for easy integration with HTTP servers
- Create middleware adapters for common Go web frameworks
- Develop a dedicated PocketBase plugin implementation
- Add examples of embedding Cortex in different server types
- Create documentation with step-by-step integration guides
- Implement testing utilities for embedded integrations
PocketBase is a good example of an application where Cortex can be embedded. PocketBase provides an API and database server with authentication. By embedding Cortex, PocketBase applications can gain MCP capabilities without running a separate server.
To integrate Cortex with PocketBase, we'll implement a plugin that:
- Registers as a PocketBase plugin
- Exposes Cortex tools and resources through PocketBase's HTTP router
- Shares the application context with Cortex
- Provides authentication between PocketBase and Cortex
The following sections outline the specific tasks to implement embedding support in Cortex, starting with a minimal viable integration approach and building toward more sophisticated integration options.