Second Brain AI Agent is a personal knowledge management AI agent project designed to help users cope with the large amount of information collected daily, such as Markdown files, videos, web pages, and PDFs. The project is inspired by Tiago Forte's Second Brain concept, which is not only about recording ideas but also about building a tool that enhances learning and creativity.
Main capabilities:
- Automatic indexing: Automatically index the content of Markdown files and the links they contain (PDF documents, YouTube videos, web pages), with no manual organization required.
- MCP-driven retrieval: Use the built-in Model Context Protocol (MCP) server to extract the most relevant context from notes and connect it to the LLM or workflow of the user's choice.
- Seamless integration: Whether or not you follow the Second Brain method, the system can adapt to your personal note-taking style.
- Improved efficiency: Reduce organization time and access information faster.
The system is built on the LangChain framework and ChromaDB vector storage. The input is a directory containing Markdown notes (for example, notes taken using Obsidian), and the system automatically handles file changes. The process is as follows:
- transform_md.py extracts text from Markdown files and extracts PDFs, URLs, and YouTube videos from the links within them and converts them to text. Supported link formats include: local PDFs (such as ~/Documents/report.pdf or /home/user/papers/research.pdf), remote PDFs (such as https://arxiv.org/pdf/2305.04091.pdf)、网页(如 https://example.com/article)、YouTube videos (such as https://www.youtube.com/watch?v=VIDEO_ID)、文件 URLs (such as file:///path/to/document.pdf).
- Support for extracting historical data: If a ## History section exists or the filename contains History, the file is split into multiple sections in the <day> <month> <year> format (such as ### 10 Sep 2023).
- transform_txt.py chunks text files, creates vector embeddings, and stores them in the vector database.
Naming conventions: Files whose names contain History, Journal, or StatusReport are treated as logs, with entries in the format ## 02 Dec 2024; other files may contain a ## History section, with entries in the format ### 02 Dec 2024. Document classification uses the concept of a "domain": the domain metadata is obtained by removing numbers and the strings At, Journal, Project, Notes, and History from the filename. For example, the domain of WorkoutHistory202412.md is Workout. Use the SBA_ORG_DOC variable in the .env file to specify a special document (defaulting to SecondBrainOrganization.md) to define domain mappings, which can be used to distinguish between work and personal activities.
MCP server features: Provides programmatic access to the vector database and document retrieval system.
- Retrieve Context: Use search_documents to stream the most relevant note snippets.
- Search Documents: Perform semantic search across documents, with support for metadata filtering.
- Document Management: Get document counts and metadata, and list available domains.
- Domain-based Search: Search within a specific domain (work, personal, etc.).
- Recent Documents: Retrieve recently accessed documents.
Usage:
- Install the MCP server: uv add fastmcp
- Run the MCP server: uv run python mcp_server.py
- Test the server: make test
- Configure the MCP client (mcp_config.json): { "mcpServers" : { "second-brain-agent" : { "command" : " /your/path/to/second-brain-agent/mcp-server.sh " } } }
Available MCP tools:
- search_documents: Search documents using semantic similarity
- get_document_count: Get the total number of documents
- get_domains: List all available domains
- get_recent_documents: Get recently accessed documents
Environment requirements: Requires a Python 3 interpreter, uv, and inotify-tools. Tested on a Fedora Linux 42 laptop and on Ubuntu latest in a CI workflow.
Installation steps:
- Get the source code
- Copy the example .env file and edit it as needed
- Install dependencies using uv
- Note: chromadb is intentionally not installed via uv. This repository loads the Python package directly from the sibling checkout directory ../chroma/chromadb, so that local development can reuse the Chroma Python source code without building the native package. The actual Chroma server still runs in Docker.
- The Chroma container persists the database at /chroma/chroma, so compose.yaml bind-mounts $DSTDIR/Db to that location. If the mount target changes, sba-txt will rebuild the vector database on the next startup.
- Activate the virtual environment
systemd services:
- Use the command to install the systemd services to automatically manage the scripts at operating system startup (requires sudo privileges)
- View the output of the md and txt services
Using the MCP server:
- The MCP server is now the single interface for exploring the second brain. After configuring the environment, you can experiment.
- The repository comes with a small helper script that lets you experiment without a dedicated MCP client, demonstrating how to call the exposed tools (document search, count, domains, and recent documents), and prints example results in the terminal; the output includes an MCP client configuration snippet that can be pasted into Cursor or other MCP-compatible tools.
Command-line helper tools:
- If you prefer fast terminal searches, you can use the CLI wrapper, which prints the top matches and their sources and jumps directly to the relevant files.
Testing:
- Install the test dependencies using uv, then run the tests. Note: integration tests require a running vector database and are automatically excluded in the pre-commit hook. Unit tests require no external dependencies and are suitable for CI/CD pipelines.
Full integration testing:
- Comprehensively test the entire system (including the vector database and MCP server): set up a complete test environment including ChromaDB, process test documents through the system, run pytest integration tests to verify MCP server functionality, test the document lifecycle (creation, modification, deletion), and provide end-to-end verification. Note: requires docker-compose/podman-compose and will create temporary test data.
Before submitting a PR, make sure pre-commit is activated.
Applicable scenarios: professionals (streamline workflows and quickly find what they need), students (access and understand notes more efficiently), researchers (dig deeper without getting lost in information overload), creative workers (easily organize thoughts and ideas).