MCP Integration
Connect libragen to Claude, Cursor, VS Code, and other AI tools
Libragen includes an MCP server that lets AI assistants query your libraries directly. Once configured, your AI can search documentation without you copying and pasting.
Quick Setup
Install the libragen MCP server with one command:
npx -y install-mcp @libragen/mcpThat’s it! This automatically detects and configures your AI tool (Claude Desktop, Cursor, Windsurf, etc.).
Library Discovery
The MCP server automatically discovers libraries from multiple locations:
- Project-local libraries: If your workspace has a
.libragen/libraries/directory, those libraries are discovered automatically - Global libraries: Platform-specific global directory (e.g.,
~/Library/Application Support/libragen/libraries/on macOS)
Project-local libraries take priority over global libraries with the same name. This means you can have project-specific versions of libraries that shadow global ones.
How It Works
When used in VS Code, Windsurf, Cursor, or other IDEs that support MCP roots:
- The server requests workspace roots from the IDE
- For each workspace root, it checks for
.libragen/libraries/ - Project libraries are searched first, then global libraries
- No configuration needed—just open your project!
Supported Tools
The install-mcp package automatically configures:
- Claude Desktop - Adds to
claude_desktop_config.json - Cursor - Adds to Cursor’s MCP settings
- Windsurf - Adds to Windsurf’s MCP configuration
- VS Code - Adds to Copilot’s MCP servers
After installation, restart your AI tool to load the server.
Manual Configuration
If you prefer manual setup or need custom options, add this to your tool’s MCP configuration:
{ "mcpServers": { "libragen": { "command": "npx", "args": ["-y", "@libragen/mcp"] } }}See install-mcp documentation for config file locations by tool.
Available Tools
The MCP server provides 8 tools for managing and querying libraries:
libragen_search
Search libraries for relevant content using hybrid semantic + keyword search.
Inputs:
query(string, required) - Natural language search querylibraries(string[], optional) - Specific libraries to search (searches all if omitted)contentVersion(string, optional) - Filter by content versiontopK(number, default: 10) - Number of resultshybridAlpha(number, default: 0.5) - Balance between vector (1) and keyword (0) searchcontextBefore(number, default: 1) - Chunks to include before each resultcontextAfter(number, default: 1) - Chunks to include after each resultrerank(boolean, default: false) - Apply cross-encoder reranking for better relevance
Example prompt:
“Search my react-docs library for information about useEffect cleanup”
libragen_list
List available libraries with metadata, descriptions, and usage guidance.
Example prompt:
“What libragen libraries do I have installed?”
libragen_build
Build a searchable library from source files or git repositories.
This tool uses an async pattern to avoid timeouts on long-running builds. Builds run in worker threads (up to n-1 CPU cores) to avoid blocking the MCP server.
Actions:
start(default) - Start a new build, returns ataskIdimmediatelystatus- Check build progress (requirestaskId)cancel- Cancel a running or queued build (requirestaskId)
Workflow:
- Call with
action='start'andsourceto begin a build - Poll with
action='status'andtaskIdto check progress - When
status='completed', theresultfield contains the build output
Inputs:
action(string, default: “start”) - Action to perform:start,status, orcanceltaskId(string, for status/cancel) - Task ID returned from start actionsource(string, for start) - Directory, file path, or git URL to indexname(string, optional) - Library nameoutput(string, optional) - Output path for the .libragen fileversion(string, default: “0.1.0”) - Library versioncontentVersion(string, optional) - Version of source contentdescription(string, optional) - Short descriptionagentDescription(string, optional) - Guidance for AI agentsexampleQueries(string[], optional) - Example querieskeywords(string[], optional) - Searchable tagsprogrammingLanguages(string[], optional) - Languages coveredframeworks(string[], optional) - Frameworks coveredchunkSize(number, default: 1000) - Target chunk sizechunkOverlap(number, default: 100) - Chunk overlapinclude(string[], optional) - Glob patterns to includeexclude(string[], optional) - Glob patterns to excludegitRef(string, optional) - Git branch/tag/commitgitRepoAuthToken(string, optional) - Auth token for private reposinstall(boolean, default: false) - Install after building
Response fields:
taskId- Unique identifier for the build taskstatus- Task status:queued,running,completed,failed,cancelledprogress- Progress percentage (0-100)currentStep- Description of current build stepresult- Build output (when completed)error- Error message (when failed)queuePosition- Position in queue (when queued)estimatedTotalSeconds- Estimated total build time (system-aware)estimatedRemainingSeconds- Estimated seconds until completionelapsedSeconds- How long the build has been running
Example prompts:
“Build a library from https://github.com/vercel/next.js/tree/main/docs”
“Check the status of build task abc-123”
libragen_install
Install a library or collection to make it available for searching.
Inputs:
source(string, required) - Library file (.libragen), collection (.json), or URLforce(boolean, default: false) - Overwrite existing librariesincludeOptional(boolean, default: false) - Include optional libraries from collections
Example prompt:
“Install the library from ./my-docs.libragen”
libragen_uninstall
Remove an installed library.
Inputs:
name(string, required) - Name of the library to uninstall
Example prompt:
“Uninstall the react-docs library”
libragen_update
Update installed libraries to newer versions from collections.
Inputs:
name(string, optional) - Library to update (updates all if omitted)force(boolean, default: false) - Force update even if versions matchdryRun(boolean, default: false) - Show what would be updated without applying
Example prompt:
“Check for updates to my installed libraries”
libragen_collection
Create a collection file that bundles multiple libraries together.
Inputs:
output(string, required) - Output file path (.json)name(string, optional) - Collection namedescription(string, optional) - Collection descriptionversion(string, default: “1.0.0”) - Collection versionlibraries(string[], optional) - Required library sourcesoptionalLibraries(string[], optional) - Optional library sourcescollections(string[], optional) - Nested collection sources
Example prompt:
“Create a collection called team-docs with my api-docs and guides libraries”
libragen_config
Get libragen configuration including paths, version, and discovered project directories.
Returns:
version- libragen versionpaths- Default paths (home, libraries, models)discoveredPaths- All library paths being searched (includes project-local)pathsInitialized- Whether paths have been discovered from workspace rootsenvironment- Active environment variable overrides
Example prompt:
“Show me the libragen configuration and where libraries are stored”
Custom Library Directory
To use libraries from a custom location, set the LIBRAGEN_HOME environment variable:
# Install with custom library pathLIBRAGEN_HOME=/path/to/your/libragen npx -y install-mcp @libragen/mcpOr add it manually to your MCP config:
{ "mcpServers": { "libragen": { "command": "npx", "args": ["-y", "@libragen/mcp"], "env": { "LIBRAGEN_HOME": "/path/to/your/libragen" } } }}Tips for Best Results
-
Be specific - “Search react-docs for useEffect dependency arrays” works better than “how does useEffect work”
-
Name your libraries clearly - The AI uses library names to understand what’s available
-
Add descriptions - When building libraries, include descriptions so the AI knows what each library contains
-
Version your content - Use
--content-versionwhen building so you can reference specific versions
Troubleshooting
Server not loading
- Verify the MCP config syntax is valid JSON
- Check that
npxis in your PATH - Restart your AI tool completely
No libraries found
- Check that libraries exist in the default location
- Verify with
libragen listin your terminal - Try setting
LIBRAGEN_HOMEexplicitly
Slow first query
The first query downloads the embedding model (~50MB). Subsequent queries are fast.