Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</p>

<p align="center">
<a href="https://github.com/EcuaByte-lat/Cortex/actions/workflows/ci.yml"><img src="https://github.com/EcuaByte-lat/Cortex/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
<a href="https://github.com/EcuaByte-lat/Cortex/actions/workflows/unified.yml"><img src="https://github.com/EcuaByte-lat/Cortex/actions/workflows/unified.yml/badge.svg" alt="CI"></a>
<a href="https://codecov.io/gh/EcuaByte-lat/Cortex"><img src="https://codecov.io/gh/EcuaByte-lat/Cortex/branch/main/graph/badge.svg" alt="Coverage"></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
<a href="https://marketplace.visualstudio.com/items?itemName=EcuaByte.cortex-vscode"><img src="https://img.shields.io/visual-studio-marketplace/v/EcuaByte.cortex-vscode?label=VS%20Code&logo=visualstudiocode&color=007ACC" alt="VS Code"></a>
Expand Down Expand Up @@ -80,8 +80,8 @@ Add to your Claude Desktop or VS Code settings:
{
"mcpServers": {
"cortex": {
"command": "bun",
"args": ["run", "/path/to/Cortex/packages/mcp-server/dist/mcp-server.js"]
"command": "npx",
"args": ["-y", "@ecuabyte/cortex-mcp-server"]
}
}
}
Expand Down
60 changes: 60 additions & 0 deletions packages/mcp-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Cortex MCP Server

The **Model Context Protocol (MCP)** server for [Cortex](https://github.com/EcuaByte-lat/Cortex).

Connects your AI tools (Claude Desktop, Cursor, Zed, etc.) to your project's persistent memory.

## 🚀 Usage

### Quick Start (npx)

The easiest way to run the server is with `npx`:

```bash
npx -y @ecuabyte/cortex-mcp-server
```

### via Claude Desktop

Add this to your `claude_desktop_config.json`:

```json
{
"mcpServers": {
"cortex": {
"command": "npx",
"args": ["-y", "@ecuabyte/cortex-mcp-server"]
}
}
}
```

### via Cursor / Windsurf

1. Go to **Settings** > **MCP**
2. Add new server:
- **Type**: `command`
- **Command**: `npx`
- **Args**: `-y @ecuabyte/cortex-mcp-server`

## 🛠️ Tools

This server provides the following MCP tools to your AI agent:

- `cortex_search`: Search project memories (facts, decisions, code patterns)
- `cortex_add`: Add a new memory
- `cortex_list`: List recent memories
- `cortex_context`: Get intelligent context for a specific task
- `cortex_scan`: Scan the current project to extract context automatically

## 📦 Installation

```bash
npm install -g @ecuabyte/cortex-mcp-server
# or
bun add -g @ecuabyte/cortex-mcp-server
```

## 📄 License

MIT
2 changes: 1 addition & 1 deletion packages/mcp-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dev": "bun run --watch src/mcp-server.ts",
"start": "bun run dist/mcp-server.js",
"typecheck": "bunx tsc --noEmit",
"generate-config": "bun run scripts/generate-config.ts"
"generate-config": "bun run src/mcp-server.ts generate-config"
},
"keywords": [
"mcp",
Expand Down
71 changes: 0 additions & 71 deletions packages/mcp-server/scripts/generate-config.ts

This file was deleted.

67 changes: 67 additions & 0 deletions packages/mcp-server/src/mcp-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,73 @@ const store = new MemoryStore();
const router = new ContextRouter(store);
const guard = new ContextGuard();

// CLI Argument Handling for `generate-config`
import { parseArgs } from 'node:util';

Copilot AI Jan 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import statement for parseArgs is placed after the initial imports and right before the try-catch block. According to best practices and the project's TypeScript guidelines, all imports should be grouped at the top of the file. Move this import to line 1 or after the other imports from node modules.

Copilot uses AI. Check for mistakes.

try {
const args = process.argv.slice(2);
if (args[0] === 'generate-config') {
const { values } = parseArgs({
args: args,
options: {
target: {
type: 'string',
},
},
strict: false, // allow params we don't know yet (though we should know them)

Copilot AI Jan 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment "allow params we don't know yet (though we should know them)" suggests incomplete implementation or uncertainty about the command line interface. This should be either removed or clarified. If there are specific parameters planned for the future, document them; otherwise, set strict: true for better validation.

Suggested change
strict: false, // allow params we don't know yet (though we should know them)
strict: true, // fail on unknown params to ensure the CLI surface stays well-defined

Copilot uses AI. Check for mistakes.
});

const target = values.target as string | undefined;
const targets = ['claude', 'cursor', 'windsurf', 'goose'];

if (!target || !targets.includes(target)) {
console.error(`Usage: cortex-mcp generate-config --target <${targets.join('|')}>`);
process.exit(1);
}

const command = 'npx';
const cmdArgs = ['-y', '@ecuabyte/cortex-mcp-server'];
let config: Record<string, unknown> = {};

switch (target) {
case 'claude':
config = {
mcpServers: {
cortex: {
command,
args: cmdArgs,
},
},
};
break;
case 'cursor':
case 'windsurf':
config = {
cortex: {
type: 'command',
command,
args: cmdArgs,
},
};
break;
case 'goose':
console.log(`Run this command to configure Goose:`);
console.log(`goose configure mcp add cortex "${command} ${cmdArgs.join(' ')}"`);
process.exit(0);
}

console.log(JSON.stringify(config, null, 2));
process.exit(0);
}
} catch (e) {
// If parsing fails or other issues, just ignore and proceed to server start
// or print error if it was clearly a CLI attempt
if (process.argv[2] === 'generate-config') {
console.error('Error generating config:', e);
process.exit(1);
}
Comment on lines +76 to +81

Copilot AI Jan 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch block silently swallows errors for non-generate-config invocations. If parseArgs or the generate-config logic fails for other reasons (e.g., during normal server initialization), this will hide important errors. Consider logging the error or being more specific about which errors to ignore.

Suggested change
// If parsing fails or other issues, just ignore and proceed to server start
// or print error if it was clearly a CLI attempt
if (process.argv[2] === 'generate-config') {
console.error('Error generating config:', e);
process.exit(1);
}
// If this was a generate-config CLI invocation, report the error and exit
if (process.argv[2] === 'generate-config') {
console.error('Error generating config:', e);
process.exit(1);
}
// For all other cases, log and rethrow so startup failures are not silently swallowed
console.error('[Cortex] Failed during CLI argument handling:', e);
throw e;

Copilot uses AI. Check for mistakes.
}
Comment on lines +17 to +82

Copilot AI Jan 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generate-config logic is embedded in the main server entry point, making it execute on every server start. This adds unnecessary overhead and complexity to the main server module. Consider extracting this to a separate CLI entry point or at least moving it to a dedicated function to improve maintainability.

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +82

Copilot AI Jan 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generate-config functionality lacks test coverage. The existing test file (mcp-server.test.ts) only tests the MCP server's JSON-RPC functionality but doesn't validate the generate-config command. Consider adding tests to verify that each target (claude, cursor, windsurf, goose) generates the correct configuration format.

Copilot uses AI. Check for mistakes.

// Initialize embedding provider if available (Ollama or OpenAI)
let embeddingInitialized = false;
(async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
],
"devDependencies": {
"@types/sql.js": "^1.4.9",
"@types/vscode": "^1.85.0",
"@types/vscode": "^1.107.0",
"@vscode/vsce": "^3.7.1",
"@ecuabyte/cortex-shared": "workspace:*"
},
Expand Down
9 changes: 9 additions & 0 deletions packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setDefaultAutoSelectFamilyAttemptTimeout } from 'node:net';
import type { Memory } from '@ecuabyte/cortex-shared';
import * as vscode from 'vscode';
import { ContextObserver } from './contextObserver';
Expand All @@ -9,6 +10,14 @@ import { CortexTaskProvider } from './taskProvider';
import type { Tool } from './toolScanner';
import { ToolTreeProvider } from './toolTreeProvider';

// Set default timeout for IPv4/IPv6 family auto-selection to avoid long delays
// This fixes: Set default auto-select family attempt timeout to 1000ms
Comment on lines +13 to +14

Copilot AI Jan 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "This fixes: Set default auto-select family attempt timeout to 1000ms" which is unclear and appears to be a copy-paste from an issue or commit message. The comment should explain WHY this timeout is being set (e.g., "Reduces connection delays when resolving IPv4/IPv6 addresses in dual-stack environments").

Suggested change
// Set default timeout for IPv4/IPv6 family auto-selection to avoid long delays
// This fixes: Set default auto-select family attempt timeout to 1000ms
// Limit IPv4/IPv6 family auto-selection to 1000ms to avoid long DNS/connection delays
// that can otherwise slow down network requests and VS Code extension activation.

Copilot uses AI. Check for mistakes.
try {
setDefaultAutoSelectFamilyAttemptTimeout(1000);
} catch (e) {
console.warn('[Cortex] Failed to set auto-select family timeout:', e);
}

export async function activate(context: vscode.ExtensionContext) {
try {
console.log('[Cortex] Extension activation started');
Expand Down
13 changes: 13 additions & 0 deletions packages/vscode-extension/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ export class MemoryStore implements IMemoryStore {
END
`);

// Fix for "no such module: fts5" error
// If the DB was created by the CLI/Core (which uses Bun:sqlite with FTS5),
// the triggers will exist but sql.js (wasm) might not support FTS5.
// We safely drop them here to allow basic CRUD operations to work.
try {
const triggers = ['memories_ai', 'memories_ad', 'memories_bu', 'memories_au'];
for (const trigger of triggers) {
this.db.run(`DROP TRIGGER IF EXISTS ${trigger}`);
}
} catch (e) {
console.warn('[Cortex] Failed to clean up FTS5 triggers:', e);
}

this.saveToFile();
} catch (error) {
console.error('[Cortex] Failed to initialize MemoryStore:', error);
Expand Down