Second Brain MCP Server
Captures and organizes structured markdown notes from Claude Code sessions with automatic pattern detection, complexity analysis, advanced search, and weekly reports. Everything runs locally without external dependencies.
README
Second Brain MCP Server
An MCP (Model Context Protocol) server that helps you create structured markdown notes from your Claude Code sessions. Capture commands executed, file changes, conversation summaries, and code snippets, then organize everything into a searchable second brain.
Features
Session Capture & Analysis
- Pattern Detection: Automatically identifies session type (🆕 New Feature, 🐛 Bug Fix, ♻️ Refactoring, 📝 Documentation, ⚙️ Configuration, ✅ Testing)
- Complexity Analysis: Simple file count-based classification (🟢 Simple: <3 files, 🟡 Moderate: 3-7 files, 🔴 Complex: 8+ files)
- Automatic Organization: Notes organized by project into subdirectories
- Rich Metadata: Captures commands, file changes, code snippets, and summaries with structured metadata
- Clean Markdown: Readable format with emoji indicators and Key Changes bullets
Search & Discovery
- Advanced Search: Multi-criteria filters (project, tags, pattern, complexity, date range, text query) with relevance scoring
- Similarity Search: Find related sessions using Jaccard similarity across tags, patterns, and projects
- Unified Search Tool: Single
search_notestool handles both text search and similarity search
Weekly Reports
- Comprehensive Summaries: Statistics on sessions, files changed, and commands executed
- Pattern & Complexity Distribution: Visual breakdown of work patterns and complexity levels
- Project Breakdown: Sessions grouped by project
- Session List: Chronological list of all sessions with summaries
Technical
- No External Dependencies: Everything runs locally without API keys or external services
- Metadata Caching: Fast queries with JSON metadata files
- Flexible Configuration: Customize where notes are stored
- TypeScript: Full type safety with comprehensive test coverage
Installation
- Clone or download this repository
- Install dependencies:
pnpm install
- Build the TypeScript code:
pnpm run build
Configuration
Add the MCP server to your Claude Code configuration file (~/.claude/settings.local.json):
{
"mcpServers": {
"second-brain": {
"command": "node",
"args": ["/absolute/path/to/second_brain_mcp/build/index.js"]
}
}
}
Replace /absolute/path/to/second_brain_mcp with the actual path to this project.
Notes Directory Configuration
By default, notes are saved to ~/notes (your home directory). You can customize this in two ways:
Option 1: Environment Variable (Recommended)
Set the SECOND_BRAIN_NOTES_DIR environment variable:
export SECOND_BRAIN_NOTES_DIR=~/Documents/my-notes
Or add it to your MCP server configuration:
{
"mcpServers": {
"second-brain": {
"command": "node",
"args": ["/absolute/path/to/second_brain_mcp/build/index.js"],
"env": {
"SECOND_BRAIN_NOTES_DIR": "/home/username/Documents/my-notes"
}
}
}
}
Option 2: Per-Tool Parameter
Pass notesDirectory parameter when calling any tool (overrides environment variable):
Please capture this session with notesDirectory: "/path/to/custom/notes"
Priority: Tool parameter > Environment variable > Default (~/notes)
Available Tools
This MCP server provides 3 focused tools for managing your session notes:
| Tool | Purpose |
|---|---|
capture_session_note |
Capture and save detailed session notes with automatic pattern and complexity analysis |
search_notes |
Search notes with advanced filters, text search, and similarity-based discovery |
generate_weekly_report |
Generate comprehensive weekly summary reports |
Usage
Once configured, you can use these tools in your Claude Code conversations:
Basic Example
Please capture this session with the summary:
"Implemented user authentication with JWT tokens"
Full Example with All Fields
Please capture this session note:
Summary: "Implemented user authentication system with JWT tokens and refresh token rotation"
Project: "my-web-app"
Topic: "authentication"
Commands executed:
- npm install jsonwebtoken bcrypt
- npm run test
File changes:
- Created: src/auth/jwt.ts - JWT token generation and validation
- Modified: src/server.ts - Added authentication middleware
- Created: src/auth/routes.ts - Login and registration endpoints
Code snippets:
- The JWT validation middleware (from src/auth/middleware.ts)
- The token generation function (from src/auth/jwt.ts)
Tags: authentication, security, jwt, backend
Working directory: /home/user/projects/my-web-app
Searching Notes
Search for notes about "authentication"
Search for bug-fix sessions with complex complexity
Find all notes tagged with "typescript" from the last month
Find sessions similar to ~/notes/my-project/2025-01-15_14-30-22_my-project-authentication.md
Weekly Reports
Generate a weekly report of my coding sessions
Tool Reference
capture_session_note
Capture and save a markdown note from a Claude Code session with automatic analysis.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
summary |
string | Yes | High-level summary of what was accomplished |
projectName |
string | No | Project name (used for organizing into subdirectories) |
topic |
string | No | Specific topic or feature being worked on |
commands |
array | No | List of commands executed with descriptions |
fileChanges |
array | No | Files created, modified, or deleted |
codeSnippets |
array | No | Important code snippets from the session |
tags |
array | No | Tags for categorizing the note |
workingDirectory |
string | No | Working directory (defaults to current directory) |
notesDirectory |
string | No | Custom notes directory (defaults to ~/notes or $SECOND_BRAIN_NOTES_DIR) |
Command Object:
{
command: string; // The command that was executed
description?: string; // What the command does
output?: string; // Command output (optional)
timestamp?: string; // When it was executed (ISO format)
}
File Change Object:
{
path: string; // File path
type: 'created' | 'modified' | 'deleted';
description?: string; // What changed
diff?: string; // Git-style diff (optional)
}
Code Snippet Object:
{
language: string; // Programming language for syntax highlighting
code: string; // The code snippet
description?: string; // What the code does
filePath?: string; // Where the code is from
}
search_notes
Search session notes with advanced filters, text search, and similarity-based discovery.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
query |
string | No | Text to search for in notes |
projectName |
string | No | Filter by project name |
tags |
array | No | Filter by tags (notes must have at least one) |
pattern |
string | No | Filter by session pattern (new-feature, bug-fix, refactoring, documentation, configuration, testing, mixed) |
complexity |
string | No | Filter by complexity level (simple, moderate, complex) |
startDate |
string | No | Filter by start date (ISO format) |
endDate |
string | No | Filter by end date (ISO format) |
similarTo |
string | No | Path to note for similarity search. Results ranked by similarity to this note. |
notesDirectory |
string | No | Custom notes directory (defaults to ~/notes or $SECOND_BRAIN_NOTES_DIR) |
Text Search Examples:
Search for notes about "authentication"
Search for bug-fix sessions with complex complexity
Find all notes tagged with "typescript" from the last month
Similarity Search Examples:
Find sessions related to ~/notes/my-project/2025-01-15_14-30-22_my-project-authentication.md
Find similar sessions to my last authentication work
Combined Search:
Search for "database" sessions similar to ~/notes/my-project/2025-01-10_migration.md
Similarity is calculated using weighted Jaccard similarity:
- Tags (40% weight)
- Pattern matching (30% weight)
- Project name (30% weight)
Results are sorted by relevance score (combined text relevance and similarity if applicable) and include project, summary, date, tags, matched tags, and file path.
generate_weekly_report
Generate a comprehensive weekly summary of all sessions.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
notesDirectory |
string | No | Custom notes directory (defaults to ~/notes or $SECOND_BRAIN_NOTES_DIR) |
Example:
Generate a weekly report of my coding sessions
The report includes:
- Total sessions, files changed, commands executed
- Project breakdown
- Work patterns distribution (🆕 New Feature, 🐛 Bug Fix, etc.)
- Complexity distribution (🟢 Simple, 🟡 Moderate, 🔴 Complex)
- List of all sessions with date, time, and summaries
Note Organization
Notes are saved to a centralized location (~/notes by default) and organized by project:
~/notes/
├── my-web-app/
│ ├── 2025-01-15_14-30-22_my-web-app-authentication.md
│ └── 2025-01-15_16-45-10_my-web-app-database-setup.md
├── cli-tool/
│ └── 2025-01-14_10-15-33_cli-tool-refactoring.md
└── second-brain-mcp/
└── 2025-01-13_09-20-15_second-brain-mcp.md
Organization structure:
- All notes are in one centralized directory (easier to search and backup)
- Each project gets its own subdirectory
- Filenames include date, time, project name, and topic
- Notes without a project name go into a
session/folder
Benefits of centralized storage:
- Easy to search across all projects
- Simple to backup (one directory)
- Works well with version control
- Can be synced to cloud storage
Output Format
Generated notes include:
- Header: Project name and topic
- Metadata: Date, working directory, tags, Pattern (🆕/🐛/♻️/etc.), Complexity (🟢/🟡/🔴 with file count)
- Summary: High-level description
- Key Changes: 2-3 concise bullet points summarizing main changes
- Commands Executed: All commands with outputs (collapsible)
- File Changes: Organized by created/modified/deleted with descriptions
- Code Snippets: With syntax highlighting and context
Example Note
# my-web-app
## Authentication
---
**Date**: 15/01/2025, 14:30:22
**Working Directory**: `/home/user/projects/my-web-app`
**Tags**: #authentication, #security, #jwt
**Pattern**: 🆕 New Feature
**Complexity**: 🟡 Moderate (3 files)
---
## Summary
Implemented user authentication system with JWT tokens and refresh token rotation
## Key Changes
- Created JWT token generation and validation
- Added authentication middleware
- Implemented login and registration endpoints
## Commands Executed
### Install authentication dependencies
```bash
npm install jsonwebtoken bcrypt
Run tests
npm run test
File Changes
Created Files
src/auth/jwt.ts- JWT token generation and validationsrc/auth/routes.ts- Login and registration endpoints
Modified Files
src/server.ts- Added authentication middleware
Code Snippets
JWT validation middleware
From: src/auth/middleware.ts
export const authMiddleware = async (req, res, next) => {
const token = req.headers.authorization?.split(' ')[1];
if (!token) return res.status(401).json({ error: 'No token provided' });
try {
const decoded = jwt.verify(token, process.env.JWT_SECRET);
req.user = decoded;
next();
} catch (error) {
res.status(401).json({ error: 'Invalid token' });
}
};
## Development
### Build
```bash
pnpm run build
Watch Mode
pnpm run watch
Run Locally
pnpm run dev
Testing
# Run tests
pnpm run test
# Run tests in watch mode
pnpm run test:watch
# Run tests with coverage
pnpm run test:coverage
The project has comprehensive test coverage (95%+) covering all services and utilities.
Tips
- End of Session: Call the capture tool at the end of your coding session to document your work
- Consistent Project Names: Use the same project name across sessions for better organization
- Meaningful Summaries: Write clear summaries that you can search for later
- Use Tags: Add relevant tags to make notes easier to find
- Include Context: Add code snippets and file changes to provide context for future reference
- File Descriptions: Add descriptions to file changes - they become Key Changes bullets in your notes
Contributing
Contributions are welcome! Please read our Contributing Guide for details on:
- Setting up the development environment
- Code style and conventions
- Commit message format (we use Conventional Commits)
- Pull request process
- Running tests
Quick Start for Contributors
# Fork and clone the repository
git clone https://github.com/VoCoufi/second_brain_mcp.git
cd second_brain_mcp
# Install dependencies
pnpm install
# Run tests
pnpm run test
# Build the project
pnpm run build
Versioning
This project uses Semantic Versioning and automated releases via semantic-release. Version numbers and changelog entries are automatically generated based on commit messages.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。