Skip to content

Commit 09b3efb

Browse files
committed
refactor: reduce llm api calls and expose semantic docs to mcp
1 parent 1359aee commit 09b3efb

File tree

7 files changed

+171
-258
lines changed

7 files changed

+171
-258
lines changed

README.md

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ The core RAG server that handles documentation ingestion and querying.
1313
**Features:**
1414
- Ingests documentation from GitHub repositories into Supabase vector store
1515
- Supports multiple LLM providers (OpenAI, Anthropic, Google, Mistral)
16-
- REST API with multiple endpoints (`/ask`, `/ingest`, `/mcp/ask`, `/webhook/github`)
16+
- OpenAI-compatible chat completions endpoint (`/v1/chat/completions`)
17+
- MCP endpoint for semantic document search (`/mcp/ask`)
1718
- GitHub webhook integration for automatic re-ingestion
18-
- Streaming responses support
19+
- Streaming responses support (OpenAI-compatible and custom SSE)
1920
- Configurable chunking and embedding strategies
2021

2122
**Quick Start:**
@@ -36,22 +37,31 @@ MCP server that connects AI assistants (Claude Code, Cline, Claude Desktop) to t
3637

3738
**Features:**
3839
- Exposes `askDocs` tool for AI assistants via MCP protocol
39-
- No server API key required (bypasses mimir-rag authentication)
40-
- Dynamic LLM configuration per client
40+
- No configuration required - just install and use
41+
- Fast semantic search without additional LLM calls
4142
- Easy integration with VS Code and Claude Desktop
4243

4344
**Quick Start:**
45+
46+
For production (via npm):
47+
```json
48+
{
49+
"mcpServers": {
50+
"mimir": {
51+
"command": "npx",
52+
"args": ["-y", "@your-org/mimir-mcp"]
53+
}
54+
}
55+
}
56+
```
57+
58+
For local development:
4459
```bash
4560
cd mimir-mcp
4661
npm install
4762
npm run build
4863
```
4964

50-
Then configure in VS Code:
51-
1. Open Command Palette (`Cmd+Shift+P` / `Ctrl+Shift+P`)
52-
2. Search for **"MCP: Open User Configuration"**
53-
3. Add the mimir MCP server configuration
54-
5565
See the [mimir-mcp README](./mimir-mcp/README.md) for detailed setup instructions.
5666

5767
## Architecture
@@ -95,13 +105,14 @@ See the [mimir-mcp README](./mimir-mcp/README.md) for detailed setup instruction
95105
- AI assistant invokes the `askDocs` tool from mimir-mcp
96106
- mimir-mcp sends request to mimir-rag's `/mcp/ask` endpoint
97107
- mimir-rag retrieves relevant document chunks using vector similarity
98-
- mimir-rag generates answer using the provided LLM
99-
- Answer is returned to the AI assistant
108+
- Document chunks with content and metadata are returned to the AI assistant
109+
- AI assistant synthesizes an answer from the retrieved content
100110

101111
3. **Query Phase (via REST API):**
102-
- Direct HTTP POST to `/ask` endpoint with API key authentication
103-
- Same retrieval and generation process as MCP
104-
- Returns JSON response with answer and sources
112+
- Direct HTTP POST to `/v1/chat/completions` endpoint (OpenAI-compatible)
113+
- Supports streaming and non-streaming responses
114+
- Works with Vercel AI SDK and other OpenAI-compatible clients
115+
- Returns OpenAI-formatted responses with answers and sources
105116

106117
## Use Cases
107118

@@ -162,17 +173,22 @@ Both projects are configured via environment variables. See individual README fi
162173

163174
### mimir-rag Endpoints
164175

165-
- **POST /ask** - Query documentation (requires API key)
166-
- **POST /mcp/ask** - Query documentation via MCP (no API key required)
167-
- **POST /ingest** - Trigger manual ingestion (requires API key)
168-
- **POST /webhook/github** - GitHub webhook for auto-ingestion
176+
**Public Endpoints (require API key):**
177+
- **POST /v1/chat/completions** - OpenAI-compatible chat completions (streaming & non-streaming)
178+
- **POST /ingest** - Trigger manual ingestion
169179
- **GET /health** - Health check
170180

181+
**MCP Endpoints (no API key required):**
182+
- **POST /mcp/ask** - Semantic search returning document chunks with content and metadata
183+
184+
**Webhook Endpoints:**
185+
- **POST /webhook/github** - GitHub webhook for auto-ingestion
186+
171187
See [mimir-rag API documentation](./mimir-rag/README.md#api-endpoints) for detailed endpoint specifications.
172188

173189
### mimir-mcp Tools
174190

175-
- **askDocs** - Query documentation from AI assistants
191+
- **askDocs** - Semantic search for documentation from AI assistants
176192

177193
See [mimir-mcp usage](./mimir-mcp/README.md#using-the-askdocs-tool) for details.
178194

mimir-mcp/README.md

Lines changed: 87 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
11
# mimir-mcp
22

3-
MCP (Model Context Protocol) server that connects your AI coding assistant to the Mimir documentation RAG system. This allows AI assistants like Claude Code, VS Code extensions, or other MCP clients to query your ingested documentation directly.
3+
MCP (Model Context Protocol) server that connects your AI coding assistant to the Mimir documentation RAG system. This allows AI assistants like Claude Code, VS Code extensions, or other MCP clients to semantically search your ingested documentation.
44

55
## What is MCP?
66

7-
[Model Context Protocol](https://modelcontextprotocol.io/) is an open protocol that enables AI assistants to securely access external data sources and tools. This MCP server exposes your Mimir documentation as a tool that AI assistants can use to answer questions based on your ingested docs.
7+
[Model Context Protocol](https://modelcontextprotocol.io/) is an open protocol that enables AI assistants to securely access external data sources and tools. This MCP server exposes your Mimir documentation as a semantic search tool that AI assistants can use to find relevant documentation chunks.
88

99
## Features
1010

11-
- **Documentation Query Tool**: Provides an `askDocs` tool that AI assistants can invoke
12-
- **Dynamic LLM Configuration**: Each MCP client can use its own LLM provider and API key
13-
- **No Server API Key Required**: Bypasses mimir-rag's `MIMIR_SERVER_API_KEY` authentication
14-
- **Configurable Parameters**: Supports custom match count, similarity threshold, and system prompts
11+
- **Documentation Search Tool**: Provides an `askDocs` tool that AI assistants can invoke
12+
- **Zero Configuration**: No API keys or environment variables needed - just install via npm
13+
- **No Authentication Required**: Bypasses mimir-rag's `MIMIR_SERVER_API_KEY` authentication
14+
- **Fast and Cost-Effective**: Skips additional LLM calls - returns document chunks directly
15+
- **Configurable Parameters**: Supports custom match count and similarity threshold
1516

1617
## Installation
1718

18-
1. Navigate to the `mimir-mcp` directory:
19+
### Option 1: Install from npm (Recommended)
20+
21+
Once published to npm, users can install and use the MCP server without any local setup:
22+
23+
1. Open VS Code Command Palette (`Cmd+Shift+P` on macOS or `Ctrl+Shift+P` on Windows/Linux)
24+
2. Search for and select **"MCP: Open User Configuration"**
25+
3. Add the following configuration:
26+
27+
```json
28+
{
29+
"mcpServers": {
30+
"mimir": {
31+
"command": "npx",
32+
"args": ["-y", "@your-org/mimir-mcp"]
33+
}
34+
}
35+
}
36+
```
37+
38+
**Note**: Replace `@your-org/mimir-mcp` with the actual npm package name once published.
39+
40+
4. Restart VS Code or reload the MCP extension
41+
42+
The MCP server is pre-configured to use the production backend URL - no additional configuration needed!
43+
44+
### Option 2: Local Development
45+
46+
For local development and testing:
47+
48+
1. Clone the repository and navigate to the `mimir-mcp` directory:
1949
```bash
2050
cd mimir-mcp
2151
```
@@ -25,123 +55,106 @@ MCP (Model Context Protocol) server that connects your AI coding assistant to th
2555
npm install
2656
```
2757

28-
3. Build the project:
58+
3. Modify `MIMIR_API_URL` in `src/index.ts` to point to your local backend:
59+
```typescript
60+
const MIMIR_API_URL = "http://localhost:3000";
61+
```
62+
63+
4. Build the project:
2964
```bash
3065
npm run build
3166
```
3267

33-
## Configuration for VS Code (Claude Code, Cline, etc.)
68+
5. Configure in VS Code:
69+
```json
70+
{
71+
"mcpServers": {
72+
"mimir": {
73+
"command": "node",
74+
"args": ["/absolute/path/to/mimir/mimir-mcp/dist/index.js"]
75+
}
76+
}
77+
}
78+
```
3479

35-
### Step 1: Build the MCP Server
80+
6. Restart VS Code or reload the MCP extension
3681

37-
Make sure you've built the project:
82+
## Configuration for Claude Desktop
3883

39-
```bash
40-
npm run build
41-
```
84+
**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
4285

43-
### Step 2: Configure MCP in VS Code
86+
**Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
4487

45-
1. Open VS Code Command Palette (`Cmd+Shift+P` on macOS or `Ctrl+Shift+P` on Windows/Linux)
46-
2. Search for and select **"MCP: Open User Configuration"**
47-
3. Add the following configuration to the JSON file that opens:
88+
### Option 1: Using npm package (Recommended)
4889

4990
```json
5091
{
5192
"mcpServers": {
5293
"mimir": {
53-
"command": "node",
54-
"args": ["/absolute/path/to/mimir/mimir-mcp/dist/index.js"],
55-
"env": {
56-
"MIMIR_API_URL": "http://localhost:3000",
57-
"MIMIR_PROVIDER": "anthropic",
58-
"MIMIR_MODEL": "claude-3-5-sonnet-20241022",
59-
"MIMIR_API_KEY": "your-api-key-here"
60-
}
94+
"command": "npx",
95+
"args": ["-y", "@your-org/mimir-mcp"]
6196
}
6297
}
6398
}
6499
```
65100

66-
**Important**: Replace `/absolute/path/to/mimir` with the actual absolute path to your mimir project directory.
67-
68-
### Step 3: Restart VS Code or Reload the MCP Extension
69-
70-
After saving the configuration, restart VS Code or reload the MCP extension to apply the changes.
71-
72-
### Configuration Parameters
101+
**Note**: Replace `@your-org/mimir-mcp` with the actual npm package name once published.
73102

74-
The `env` object accepts the following parameters:
75-
76-
- **MIMIR_API_URL** (optional): URL of your mimir-rag server. Default: `http://localhost:3000`
77-
- **MIMIR_PROVIDER** (required): LLM provider name (`openai`, `anthropic`, `google`, `mistral`)
78-
- **MIMIR_MODEL** (required): Model identifier (e.g., `claude-3-5-sonnet-20241022`, `gpt-4`, etc.)
79-
- **MIMIR_API_KEY** (required): API key for your chosen LLM provider
80-
81-
## Configuration for Claude Desktop
82-
83-
To use this MCP server with Claude Desktop, add it to your Claude Desktop configuration file:
84-
85-
**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
86-
87-
**Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
103+
### Option 2: Local development
88104

89105
```json
90106
{
91107
"mcpServers": {
92108
"mimir": {
93109
"command": "node",
94-
"args": ["/absolute/path/to/mimir/mimir-mcp/dist/index.js"],
95-
"env": {
96-
"MIMIR_API_URL": "http://localhost:3000",
97-
"MIMIR_PROVIDER": "anthropic",
98-
"MIMIR_MODEL": "claude-3-5-sonnet-20241022",
99-
"MIMIR_API_KEY": "your-api-key-here"
100-
}
110+
"args": ["/absolute/path/to/mimir/mimir-mcp/dist/index.js"]
101111
}
102112
}
103113
}
104114
```
105115

116+
**Note**: For local development, remember to modify `MIMIR_API_URL` in `src/index.ts` to `http://localhost:3000`.
117+
106118
## Using the askDocs Tool
107119

108120
Once configured, the AI assistant will have access to an `askDocs` tool. You can ask questions like:
109121

110-
- "Use askDocs to find out how to implement authentication"
111-
- "Check the docs for API endpoint examples"
122+
- "Find documentation about authentication implementation"
123+
- "Search the docs for API endpoint examples"
112124
- "What does the documentation say about error handling?"
113125

126+
The AI assistant will automatically invoke `askDocs`, retrieve relevant documentation chunks, and synthesize an answer for you.
127+
114128
The tool accepts these parameters:
115129

116-
- **question** (required): Your documentation question
130+
- **question** (required): Your documentation search query
117131
- **matchCount** (optional): Number of document chunks to retrieve (default: 10)
118132
- **similarityThreshold** (optional): Minimum similarity score (default: 0.2)
119-
- **systemPrompt** (optional): Custom system prompt to guide the AI's response
120133

121134
## How It Works
122135

123136
1. The MCP server registers an `askDocs` tool with the AI assistant
124-
2. When invoked, it sends a request to the mimir-rag server's `/mcp/ask` endpoint
125-
3. The request includes the question and your configured LLM credentials
126-
4. mimir-rag retrieves relevant documentation chunks and generates an answer using your LLM
127-
5. The answer is returned to the AI assistant, which can use it to help you
137+
2. When invoked, it sends a request to the mimir-rag backend's `/mcp/ask` endpoint
138+
3. mimir-rag performs semantic search using OpenAI embeddings
139+
4. Relevant documentation chunks with content and metadata are returned
140+
5. The AI assistant synthesizes an answer based on the retrieved content
128141

129142
## Prerequisites
130143

131-
- A running [mimir-rag](../mimir-rag) server with ingested documentation
144+
- A hosted [mimir-rag](../mimir-rag) backend with ingested documentation (or running locally for testing)
132145
- Node.js 20 or later
133146
- An AI assistant that supports MCP (Claude Code, Cline, Claude Desktop, etc.)
134-
- API key for your chosen LLM provider
135147

136148
## Troubleshooting
137149

138150
### Connection Issues
139151

140152
If the MCP server can't connect to mimir-rag:
141153

142-
1. Verify your mimir-rag server is running: `curl http://localhost:3000/health`
143-
2. Check the `MIMIR_API_URL` in your MCP configuration
154+
1. Verify the mimir-rag backend is accessible: `curl https://your-backend.com/health`
155+
2. For local development, ensure you've modified `MIMIR_API_URL` in `src/index.ts` to `http://localhost:3000`
144156
3. Ensure there are no firewall or network issues
157+
4. For local testing, verify the backend is running on the correct port
145158

146159
### AI Assistant Not Seeing the Tool
147160

@@ -151,11 +164,11 @@ If the MCP server can't connect to mimir-rag:
151164
4. Open Command Palette and verify MCP configuration was saved correctly
152165
5. Check the AI assistant's MCP logs for errors
153166

154-
### API Key Issues
167+
### Empty Results
155168

156-
1. Verify your `MIMIR_API_KEY` is valid for the specified provider
157-
2. Check you have sufficient quota/credits with your LLM provider
158-
3. Ensure the `MIMIR_PROVIDER` and `MIMIR_MODEL` match your API key
169+
1. Verify your mimir-rag server has ingested documentation
170+
2. Check the embeddings were created successfully during ingestion
171+
3. Try lowering the `similarityThreshold` parameter for broader matches
159172

160173
## Development
161174

@@ -172,13 +185,11 @@ The build process uses `tsup` to compile TypeScript to ESM format.
172185
While this is primarily designed as an MCP server, you can also run it standalone for testing:
173186

174187
```bash
175-
# Set environment variables
176-
export MIMIR_API_URL=http://localhost:3000
177-
export MIMIR_PROVIDER=anthropic
178-
export MIMIR_MODEL=claude-3-5-sonnet-20241022
179-
export MIMIR_API_KEY=your-api-key-here
188+
# For local testing, first modify MIMIR_API_URL in src/index.ts to:
189+
# const MIMIR_API_URL = "http://localhost:3000";
180190

181-
# Run the server
191+
# Then rebuild and run
192+
npm run build
182193
node dist/index.js
183194
```
184195

0 commit comments

Comments
 (0)