secondbrainos-mcp-server
v1.10.0
Published
Second Brain OS MCP Server for Claude Desktop
Maintainers
Readme
Second Brain OS MCP Server
This package provides a Model Context Protocol (MCP) server for integrating Second Brain OS with Claude Desktop and Claude Code.
Prerequisites
- Node.js v16 or higher
- Claude Desktop application and/or Claude Code CLI
- A valid Second Brain OS account with the Claude MCP feature enabled
Installation
npm install -g secondbrainos-mcp-serverUsage
After installation, run the setup command with your USER_ID and USER_SECRET:
secondbrainos-mcp USER_ID USER_SECRETThis will:
- Verify your account credentials
- Confirm you have access to the Claude MCP feature
- Store credentials securely at
~/.secondbrainos/credentials.json - Configure Claude Desktop and Claude Code to use
servemode (credentials read from file, not embedded in config)
Claude Code
To add the server to Claude Code:
claude mcp add secondbrainos-mcp-server -- npx secondbrainos-mcp-serverOr add it to your project's .mcp.json file.
Features
Enhanced OpenAPI Support
The server uses @samchon/openapi library for robust OpenAPI handling, providing:
- Support for all OpenAPI/Swagger versions (v2.0, v3.0, v3.1)
- Automatic schema conversion to a standardized format
- Better handling of complex schemas including references, nullable properties, and union types
Improved Function Execution
- Type-safe function execution with built-in error handling
- Automatic request formatting based on OpenAPI specifications
- Support for complex parameters and nested objects
Prompts
The server exposes four types of MCP prompts, available as slash commands (e.g. /secondbrainos:agent_my_agent):
Start (start_secondbrainos)
- Returns a context document with SBOS terminology, agent architecture, and an index of all available agents and skills with their slash commands
- This is the zero-cost discovery mechanism — Claude can read this prompt to learn what agents and skills are available without calling
getAIAgentsSchemaorrunPromptChainas MCP tools (which would be billed). All discovery data comes from the in-memory cache populated at session init - Useful for orienting Claude at the start of a session
Skills (Workflows)
- Discovered via
runPromptChainon firstListPromptscall, then cached for the session - Each skill appears with a
[Skill]prefix and returns a structured document withskill_id,name,description, and an ordered list of prompts (metadata only, no instructions) - Supports an optional
user_inputargument to provide additional context
Agents
- Discovered via
getAIAgentsSchemaon firstListPromptscall, then cached for the session - Each agent appears with an
[Agent]prefix and returns a structured document containingagent_id,name,description,behaviour_and_instructions,searchMyKnowledge_collection_id,actions(with id, name, description, body_parameters), andworkflows(with prompt order and description) - Supports an optional
user_inputargument
Features
- Extracted from the
featuresarray in theschema.secondbrainos.comresponse at startup, then cached - Each feature appears with a
[Feature]prefix and returns itsguidelinestext - Features have consistent guidelines for all users (not user-specific)
- Supports an optional
user_inputargument
Knowledge Bases
- Aggregates all
searchMyKnowledge_collection_idvalues from your agents - Appears as a single
[Knowledge Bases]prompt returning an array of collection IDs
Better Error Handling
- Detailed error messages for debugging
- Proper handling of authentication failures, bad requests, and service errors
- Graceful fallback for unexpected errors
Development
Setup
- Clone the repository:
git clone https://github.com/your-username/secondbrainos-mcp-server.git
cd secondbrainos-mcp-server- Install dependencies:
npm install- Create a
.envfile from the example:
cp .env.example .env
# Edit .env with your actual USER_ID and USER_SECRETTesting the Schema Conversion
To see how your OpenAPI schema is converted to MCP tools:
npm run test-conversionThis will:
- Fetch your OpenAPI schema from Second Brain OS
- Convert it to LLM function calling format
- Display all available functions and their schemas
- Show any conversion errors
- Demonstrate the MCP tool format
Development Scripts
npm run build- Compile TypeScript to JavaScriptnpm run dev- Run the MCP server in development modenpm run test-conversion- Test the OpenAPI to MCP conversionnpm start- Run the compiled server
Project Structure
secondbrainos-mcp-server/
├── src/
│ ├── index.ts # Main MCP server implementation
│ └── test-conversion.ts # Schema conversion testing utility
├── build/ # Compiled JavaScript (git-ignored)
├── bin/
│ └── cli.js # CLI setup script
├── .env.example # Environment variables template
├── package.json # Package configuration
├── tsconfig.json # TypeScript configuration
└── README.md # This fileCredentials
Credentials are stored securely at ~/.secondbrainos/credentials.json (created during setup with mode 0o600). The server reads from this file in serve mode. Environment variables USER_ID, USER_SECRET, and API_BASE_URL can override the stored credentials if set.
How It Works
Startup & Session Init
- Schema Fetching (0 credits): On startup, the server POSTs your
user_idtoschema.secondbrainos.comand receives your personalized OpenAPI spec along with afeaturesarray (consistent guidelines for all users) - Schema Conversion: The
@samchon/openapilibrary converts the spec to LLM function calling format. Each API endpoint becomes an MCP tool. Three service paths are discovered from the spec for internal use:runPromptChain— fetches workflows/skillsgetAIAgentsSchema— fetches agentsgenerateFileUploadGoogleCloudStorageURL— used only when a tool argument contains a local file path
- MCP server connects via stdio — no API calls yet, no credits spent
Cache Population (on first connection)
- ListPrompts trigger: Claude Code automatically calls
ListPromptson connect. This is when the first credits are spent:runPromptChainis called with{}→ returns all user workflows with prompt metadata (name, order, description)getAIAgentsSchemais called with{include_sensitive_config: true}→ returns all user agents with behaviour, knowledge collection ID, actions, and workflows
- In-memory cache: Both responses are normalized (consistent field names, defaults applied) and sorted (prompts ordered by
orderfield), then stored in memory ascachedWorkflows,cachedAgents, and name-to-ID lookup maps - Slash commands exposed: The cached data is surfaced as MCP prompts —
/secondbrainos:feature_*,/secondbrainos:skill_*,/secondbrainos:agent_*,/secondbrainos:start_secondbrainos, and/secondbrainos:knowledge_bases
During the Session
- Slash commands (0 credits): When a user runs a slash command (e.g.
/secondbrainos:agent_my_agent), the server returns the full agent/skill definition from cache — no API calls start_secondbrainos(0 credits): Builds a context document from cached agents and workflows — an index of all available slash commands with descriptions, enabling Claude to discover and invoke agents/skills autonomously- Tool calls (billed per call): When Claude calls an MCP tool (e.g.
runPromptChainwith a specific entity/entity_id to fetch prompt instructions, orsearchMyKnowledge), the server executes the API call viaapi.secondbrainos.comwith authentication - File upload: If a tool argument contains a local file path (e.g.
addToMyKnowledgewithfile_path), the server validates the extension (.txt,.md,.png,.jpg,.jpeg,.gif,.webp,.pdf), uploads the file to GCS viagenerateFileUploadGoogleCloudStorageURLwith the correct MIME type, and replaces the path with the GCS URI before forwarding the API call
Credit Cost
| Event | Credits |
|-------|---------|
| Schema fetch | 0 |
| Session init (ListPrompts) | n workflows + n agents |
| Slash commands | 0 (cached) |
| start_secondbrainos | 0 (cached) |
| Tool calls | Billed per call via service router |
See docs/architecture.md for detailed diagrams.
Troubleshooting
Client doesn't see the server
- Claude Desktop: Ensure it's completely quit before running setup. Check the configuration file was created at the correct location.
- Claude Code: Run
claude mcp addor check your.mcp.jsonconfiguration. - Review the logs at the platform-specific location mentioned during setup
Authentication errors
- Verify your USER_ID and USER_SECRET are correct
- Ensure your account has the Claude MCP feature enabled
- Check that your credentials haven't expired
Schema conversion errors
- Run
npm run test-conversionto see detailed error messages - Some complex OpenAPI features may not be supported by LLM function calling
- Check the console output for specific endpoints that failed conversion
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
MIT
