kogral/docs/book/apps/mcp-quickguide.html
2026-01-23 16:11:07 +00:00

562 lines
25 KiB
HTML

<!DOCTYPE HTML>
<html lang="en" class="rust sidebar-visible" dir="ltr">
<head>
<!-- Book generated using mdBook -->
<meta charset="UTF-8">
<title>MCP Quick Guide - KOGRAL Documentation</title>
<!-- Custom HTML head -->
<meta name="description" content="Complete documentation for KOGRAL - Git-native knowledge graphs for developer teams">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#ffffff">
<link rel="icon" href="../favicon.svg">
<link rel="shortcut icon" href="../favicon.png">
<link rel="stylesheet" href="../css/variables.css">
<link rel="stylesheet" href="../css/general.css">
<link rel="stylesheet" href="../css/chrome.css">
<link rel="stylesheet" href="../css/print.css" media="print">
<!-- Fonts -->
<link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
<link rel="stylesheet" href="../fonts/fonts.css">
<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" id="highlight-css" href="../highlight.css">
<link rel="stylesheet" id="tomorrow-night-css" href="../tomorrow-night.css">
<link rel="stylesheet" id="ayu-highlight-css" href="../ayu-highlight.css">
<!-- Custom theme stylesheets -->
<!-- Provide site root and default themes to javascript -->
<script>
const path_to_root = "../";
const default_light_theme = "rust";
const default_dark_theme = "navy";
</script>
<!-- Start loading toc.js asap -->
<script src="../toc.js"></script>
</head>
<body>
<div id="mdbook-help-container">
<div id="mdbook-help-popup">
<h2 class="mdbook-help-title">Keyboard shortcuts</h2>
<div>
<p>Press <kbd></kbd> or <kbd></kbd> to navigate between chapters</p>
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
<p>Press <kbd>?</kbd> to show this help</p>
<p>Press <kbd>Esc</kbd> to hide this help</p>
</div>
</div>
</div>
<div id="body-container">
<!-- Work around some values being stored in localStorage wrapped in quotes -->
<script>
try {
let theme = localStorage.getItem('mdbook-theme');
let sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') && theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
</script>
<!-- Set the theme before any content is loaded, prevents flash -->
<script>
const default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? default_dark_theme : default_light_theme;
let theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
const html = document.documentElement;
html.classList.remove('rust')
html.classList.add(theme);
html.classList.add("js");
</script>
<input type="checkbox" id="sidebar-toggle-anchor" class="hidden">
<!-- Hide / unhide sidebar before it is displayed -->
<script>
let sidebar = null;
const sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
} else {
sidebar = 'hidden';
}
sidebar_toggle.checked = sidebar === 'visible';
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
</script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
<!-- populated by js -->
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
<noscript>
<iframe class="sidebar-iframe-outer" src="../toc.html"></iframe>
</noscript>
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
<div class="sidebar-resize-indicator"></div>
</div>
</nav>
<div id="page-wrapper" class="page-wrapper">
<div class="page">
<div id="menu-bar-hover-placeholder"></div>
<div id="menu-bar" class="menu-bar sticky">
<div class="left-buttons">
<label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
<i class="fa fa-bars"></i>
</label>
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
<i class="fa fa-paint-brush"></i>
</button>
<ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
<li role="none"><button role="menuitem" class="theme" id="default_theme">Auto</button></li>
<li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
<li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
<li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
<li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
<li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
</ul>
<button id="search-toggle" class="icon-button" type="button" title="Search (`/`)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="/ s" aria-controls="searchbar">
<i class="fa fa-search"></i>
</button>
</div>
<h1 class="menu-title">KOGRAL Documentation</h1>
<div class="right-buttons">
<a href="../print.html" title="Print this book" aria-label="Print this book">
<i id="print-button" class="fa fa-print"></i>
</a>
<a href="https://github.com/your-org/knowledge-base" title="Git repository" aria-label="Git repository">
<i id="git-repository-button" class="fa fa-github"></i>
</a>
<a href="https://github.com/your-org/knowledge-base/edit/main/docs/./apps/mcp-quickguide.md" title="Suggest an edit" aria-label="Suggest an edit">
<i id="git-edit-button" class="fa fa-edit"></i>
</a>
</div>
</div>
<div id="search-wrapper" class="hidden">
<form id="searchbar-outer" class="searchbar-outer">
<input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
</form>
<div id="searchresults-outer" class="searchresults-outer hidden">
<div id="searchresults-header" class="searchresults-header"></div>
<ul id="searchresults">
</ul>
</div>
</div>
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
<script>
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
});
</script>
<div id="content" class="content">
<main>
<h1 id="mcp-quick-guide"><a class="header" href="#mcp-quick-guide">MCP Quick Guide</a></h1>
<p>Fast-track guide to integrating KOGRAL with Claude Code via the Model Context Protocol (MCP).</p>
<h2 id="what-is-mcp"><a class="header" href="#what-is-mcp">What is MCP?</a></h2>
<p>MCP (Model Context Protocol) is a protocol that allows Claude Code to interact with external tools and data sources. The kogral-mcp server exposes your KOGRAL knowledge base to Claude Code for AI-assisted knowledge management.</p>
<h2 id="quick-setup-5-minutes"><a class="header" href="#quick-setup-5-minutes">Quick Setup (5 Minutes)</a></h2>
<h3 id="step-1-build-mcp-server"><a class="header" href="#step-1-build-mcp-server">Step 1: Build MCP Server</a></h3>
<pre><code class="language-bash"># Build kogral-mcp server
cargo build --package kb-mcp --release
# Verify binary
ls -lh target/release/kb-mcp
</code></pre>
<h3 id="step-2-configure-claude-code"><a class="header" href="#step-2-configure-claude-code">Step 2: Configure Claude Code</a></h3>
<p>Add to <code>~/.config/claude/config.json</code>:</p>
<pre><code class="language-json">{
"mcpServers": {
"kogral-mcp": {
"command": "/path/to/knowledge-base/target/release/kb-mcp",
"args": ["serve"],
"env": {
"KOGRAL_DIR": "/path/to/your/project/.kogral"
}
}
}
}
</code></pre>
<p>Replace <code>/path/to/knowledge-base</code> and <code>/path/to/your/project/.kogral</code> with your actual paths.</p>
<h3 id="step-3-initialize-kogral"><a class="header" href="#step-3-initialize-kogral">Step 3: Initialize KOGRAL</a></h3>
<pre><code class="language-bash"># Navigate to your project
cd /path/to/your/project
# Initialize .kb directory
kb init
</code></pre>
<h3 id="step-4-start-claude-code"><a class="header" href="#step-4-start-claude-code">Step 4: Start Claude Code</a></h3>
<pre><code class="language-bash"># Start Claude Code (will auto-connect to kb-mcp)
claude-code
</code></pre>
<h3 id="step-5-test-connection"><a class="header" href="#step-5-test-connection">Step 5: Test Connection</a></h3>
<p>In Claude Code, try:</p>
<pre><code>Search for "error handling"
</code></pre>
<p>Claude will use the <code>kogral/search</code> tool to query your knowledge base.</p>
<hr />
<h2 id="essential-commands"><a class="header" href="#essential-commands">Essential Commands</a></h2>
<h3 id="search-knowledge-base"><a class="header" href="#search-knowledge-base">Search Knowledge Base</a></h3>
<p><strong>Natural language</strong>:</p>
<pre><code>Find notes about Rust error handling
</code></pre>
<p><strong>Claude translates to</strong>:</p>
<pre><code class="language-json">{
"tool": "kogral/search",
"params": {
"query": "error handling",
"type": "note",
"semantic": true
}
}
</code></pre>
<h3 id="add-note"><a class="header" href="#add-note">Add Note</a></h3>
<p><strong>Natural language</strong>:</p>
<pre><code>Add a note about async Rust patterns with tags rust, async, patterns
</code></pre>
<p><strong>Claude translates to</strong>:</p>
<pre><code class="language-json">{
"tool": "kogral/add_note",
"params": {
"title": "Async Rust Patterns",
"content": "...",
"tags": ["rust", "async", "patterns"]
}
}
</code></pre>
<h3 id="add-decision"><a class="header" href="#add-decision">Add Decision</a></h3>
<p><strong>Natural language</strong>:</p>
<pre><code>Document decision to use SurrealDB for storage
</code></pre>
<p><strong>Claude translates to</strong>:</p>
<pre><code class="language-json">{
"tool": "kogral/add_decision",
"params": {
"title": "Use SurrealDB for Storage",
"context": "Need scalable graph database",
"decision": "Adopt SurrealDB as primary storage backend",
"consequences": ["Better query performance", "Additional infrastructure"]
}
}
</code></pre>
<h3 id="get-guidelines"><a class="header" href="#get-guidelines">Get Guidelines</a></h3>
<p><strong>Natural language</strong>:</p>
<pre><code>What are our Rust error handling guidelines?
</code></pre>
<p><strong>Claude translates to</strong>:</p>
<pre><code class="language-json">{
"tool": "kogral/get_guidelines",
"params": {
"language": "rust",
"category": "error-handling"
}
}
</code></pre>
<h3 id="link-concepts"><a class="header" href="#link-concepts">Link Concepts</a></h3>
<p><strong>Natural language</strong>:</p>
<pre><code>Link note-async-patterns to decision-use-tokio as implements
</code></pre>
<p><strong>Claude translates to</strong>:</p>
<pre><code class="language-json">{
"tool": "kogral/link",
"params": {
"from": "note-async-patterns",
"to": "decision-use-tokio",
"relation": "implements"
}
}
</code></pre>
<hr />
<h2 id="common-workflows"><a class="header" href="#common-workflows">Common Workflows</a></h2>
<h3 id="capture-meeting-notes"><a class="header" href="#capture-meeting-notes">Capture Meeting Notes</a></h3>
<p><strong>You</strong>:</p>
<pre><code>We just decided in our meeting to migrate from REST to GraphQL.
Context: current REST API is too chatty, requires multiple round trips.
Consequences: better client performance, but team needs to learn GraphQL.
Create a decision record.
</code></pre>
<p><strong>Claude</strong> (uses <code>kb/add_decision</code>):</p>
<pre><code>Created decision: decision-migrate-to-graphql
Status: proposed
Context: Current REST API requires multiple round trips (chatty)
Decision: Migrate from REST to GraphQL API
Consequences:
- ✅ Better client performance
- ❌ Team learning curve for GraphQL
</code></pre>
<h3 id="find-related-knowledge"><a class="header" href="#find-related-knowledge">Find Related Knowledge</a></h3>
<p><strong>You</strong>:</p>
<pre><code>I'm working on error handling. What related notes and patterns do we have?
</code></pre>
<p><strong>Claude</strong> (uses <code>kogral/search</code> with semantic=true):</p>
<pre><code>Found 5 related items:
1. **Error Handling with thiserror** (pattern)
Tags: rust, error-handling
Created: 2026-01-15
2. **Result Type Best Practices** (guideline)
Tags: rust, error-handling, best-practices
Created: 2026-01-10
3. **Decision: Use anyhow for Application Errors** (decision)
Status: accepted
Created: 2026-01-08
4. **Custom Error Types** (note)
Tags: rust, error-handling
Created: 2026-01-05
5. **Error Propagation Patterns** (pattern)
Tags: rust, error-handling
Created: 2026-01-03
Would you like me to link your current work to any of these?
</code></pre>
<h3 id="document-implementation"><a class="header" href="#document-implementation">Document Implementation</a></h3>
<p><strong>You</strong>:</p>
<pre><code>I just implemented the user authentication module following our security guidelines.
Add a note and link it to our security guideline.
</code></pre>
<p><strong>Claude</strong> (uses <code>kb/add_note</code> + <code>kb/link</code>):</p>
<pre><code>Created note: note-user-auth-implementation
Tags: security, authentication, implementation
Linked:
note-user-auth-implementation --[implements]--&gt; guideline-security-practices
Done! Your implementation is now documented and connected to our guidelines.
</code></pre>
<h3 id="review-project-knowledge"><a class="header" href="#review-project-knowledge">Review Project Knowledge</a></h3>
<p><strong>You</strong>:</p>
<pre><code>Summarize our project knowledge: what decisions have we made, what patterns are we using?
</code></pre>
<p><strong>Claude</strong> (uses <code>kb/summarize_project</code> prompt):</p>
<pre><code># Project Knowledge Summary
**Total Nodes**: 42
## Recent Decisions (5)
- Use SurrealDB for Storage (accepted, 2 days ago)
- Adopt MCP for AI Integration (accepted, 5 days ago)
- Nickel for Configuration (accepted, 1 week ago)
## Active Patterns (8)
- Error Handling with thiserror
- Repository Pattern for DB
- Builder Pattern for Complex Objects
- ...
## Top Tags
1. rust (23 nodes)
2. architecture (12 nodes)
3. error-handling (8 nodes)
4. patterns (7 nodes)
## Guideline Coverage
- Rust: 5 guidelines
- Testing: 3 guidelines
- Security: 2 guidelines
</code></pre>
<hr />
<h2 id="advanced-usage"><a class="header" href="#advanced-usage">Advanced Usage</a></h2>
<h3 id="conditional-queries"><a class="header" href="#conditional-queries">Conditional Queries</a></h3>
<p><strong>You</strong>:</p>
<pre><code>Find all decisions made in the last week that are still proposed (not accepted)
</code></pre>
<p><strong>Claude</strong> (combines <code>kogral/search</code> with filtering):</p>
<pre><code>Found 2 proposed decisions from last week:
1. **Migrate to GraphQL** (proposed)
Created: 3 days ago
Context: REST API is too chatty...
2. **Add Redis Caching** (proposed)
Created: 5 days ago
Context: Database queries are slow...
Would you like to review these and update their status?
</code></pre>
<h3 id="cross-reference-check"><a class="header" href="#cross-reference-check">Cross-Reference Check</a></h3>
<p><strong>You</strong>:</p>
<pre><code>Before I implement X, check if we have any decisions or guidelines about it
</code></pre>
<p><strong>Claude</strong> (uses <code>kogral/search</code> + <code>kogral/get_guidelines</code>):</p>
<pre><code>Checking existing knowledge about X...
**Decisions**: None found
**Guidelines**: 1 relevant guideline found
- guideline-module-structure: "Keep modules focused and small"
**Related Notes**: 2 notes mention similar topics
- note-module-design-patterns
- note-separation-of-concerns
Recommendation: Your implementation of X looks aligned with our guidelines.
Consider linking it to guideline-module-structure when done.
</code></pre>
<h3 id="export-for-sharing"><a class="header" href="#export-for-sharing">Export for Sharing</a></h3>
<p><strong>You</strong>:</p>
<pre><code>Export our architectural decisions to Logseq so I can review them visually
</code></pre>
<p><strong>Claude</strong> (uses <code>kb/export</code>):</p>
<pre><code>Exporting to Logseq format...
✓ Exported 12 decisions to /Users/akasha/logseq-export/
- 12 decision records
- Preserved wikilinks
- Added Logseq properties
You can now open /Users/akasha/logseq-export/ in Logseq to visualize the decision graph.
</code></pre>
<hr />
<h2 id="tips-and-tricks"><a class="header" href="#tips-and-tricks">Tips and Tricks</a></h2>
<h3 id="1-use-natural-language"><a class="header" href="#1-use-natural-language">1. Use Natural Language</a></h3>
<p>Don't worry about exact tool syntax. Claude understands:</p>
<p><strong>Don't say</strong>: "Use kb/search with query='rust' and type='pattern'"
<strong>Do say</strong>: "Find Rust patterns in KOGRAL"</p>
<h3 id="2-be-specific-with-tags"><a class="header" href="#2-be-specific-with-tags">2. Be Specific with Tags</a></h3>
<p>When adding notes, use consistent tags:</p>
<p><strong>Good</strong>: <code>tags: rust, error-handling, pattern</code>
<strong>Bad</strong>: <code>tags: Rust, ErrorHandling, patterns</code></p>
<h3 id="3-link-as-you-go"><a class="header" href="#3-link-as-you-go">3. Link as You Go</a></h3>
<p>After creating notes, ask Claude to link them:</p>
<pre><code>Link this note to our error handling guideline as 'implements'
</code></pre>
<h3 id="4-review-regularly"><a class="header" href="#4-review-regularly">4. Review Regularly</a></h3>
<p>Ask Claude for summaries:</p>
<pre><code>What have we documented this week?
</code></pre>
<h3 id="5-use-semantic-search"><a class="header" href="#5-use-semantic-search">5. Use Semantic Search</a></h3>
<p>For conceptual queries:</p>
<pre><code>Find anything related to "making code maintainable"
</code></pre>
<p>Not just keyword "maintainable", but concepts like refactoring, clean code, patterns, etc.</p>
<hr />
<h2 id="troubleshooting"><a class="header" href="#troubleshooting">Troubleshooting</a></h2>
<h3 id="mcp-server-not-responding"><a class="header" href="#mcp-server-not-responding">"MCP server not responding"</a></h3>
<pre><code class="language-bash"># Check kb-mcp is built
ls target/release/kb-mcp
# Test manually
echo '{"jsonrpc":"2.0","id":1,"method":"kogral/search","params":{"query":"test"}}' \
| target/release/kb-mcp serve
</code></pre>
<h3 id="kb-directory-not-found"><a class="header" href="#kb-directory-not-found">"KB directory not found"</a></h3>
<pre><code class="language-bash"># Verify .kb exists
ls -la /path/to/project/.kogral
# Initialize if missing
cd /path/to/project
kb init
</code></pre>
<h3 id="permission-denied"><a class="header" href="#permission-denied">"Permission denied"</a></h3>
<pre><code class="language-bash"># Make binary executable
chmod +x target/release/kb-mcp
# Check environment variable
echo $KOGRAL_DIR
</code></pre>
<h3 id="empty-search-results"><a class="header" href="#empty-search-results">"Empty search results"</a></h3>
<pre><code class="language-bash"># Add some test content
kb add note "Test Note" --content "Test content"
# Try search again in Claude Code
</code></pre>
<hr />
<h2 id="next-steps"><a class="header" href="#next-steps">Next Steps</a></h2>
<ul>
<li><strong>Read</strong>: <a href="../api/mcp-tools.html">MCP Tools API Reference</a> for all available tools</li>
<li><strong>Explore</strong>: <a href="../guides/use-cases.html">Use Cases</a> for more examples</li>
<li><strong>Configure</strong>: <a href="../config/overview.html">Configuration Reference</a> to customize behavior</li>
<li><strong>Integrate</strong>: <a href="claude-code.html">Claude Code Integration</a> for advanced setup</li>
</ul>
<hr />
<h2 id="quick-reference-card"><a class="header" href="#quick-reference-card">Quick Reference Card</a></h2>
<div class="table-wrapper"><table><thead><tr><th>Task</th><th>Say to Claude</th></tr></thead><tbody>
<tr><td>Search</td><td>"Find notes about X"</td></tr>
<tr><td>Add note</td><td>"Add a note about X with tags Y, Z"</td></tr>
<tr><td>Add decision</td><td>"Document decision to use X for Y"</td></tr>
<tr><td>Get guidelines</td><td>"What are our X guidelines?"</td></tr>
<tr><td>Link nodes</td><td>"Link A to B as implements"</td></tr>
<tr><td>Summarize</td><td>"Summarize project knowledge"</td></tr>
<tr><td>Export</td><td>"Export to Logseq format"</td></tr>
</tbody></table>
</div>
<hr />
<p><strong>Remember</strong>: Claude Code with MCP turns KOGRAL into an active participant in your development workflow. Ask questions, capture decisions, and let AI help you maintain your project's knowledge graph.</p>
</main>
<nav class="nav-wrapper" aria-label="Page navigation">
<!-- Mobile navigation buttons -->
<a rel="prev" href="../cli/nushell-scripts.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../apps/claude-code.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
<div style="clear: both"></div>
</nav>
</div>
</div>
<nav class="nav-wide-wrapper" aria-label="Page navigation">
<a rel="prev" href="../cli/nushell-scripts.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<i class="fa fa-angle-left"></i>
</a>
<a rel="next prefetch" href="../apps/claude-code.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<i class="fa fa-angle-right"></i>
</a>
</nav>
</div>
<script>
window.playground_copyable = true;
</script>
<script src="../elasticlunr.min.js"></script>
<script src="../mark.min.js"></script>
<script src="../searcher.js"></script>
<script src="../clipboard.min.js"></script>
<script src="../highlight.js"></script>
<script src="../book.js"></script>
<!-- Custom JS scripts -->
</div>
</body>
</html>