Skip to content

Commit c3242cd

Browse files
authored
Merge pull request #25 from mkreyman/fix/issue-24-token-limit-with-metadata
Fix token limit overflow with includeMetadata (fixes #24)
2 parents 877da91 + 2e1f1ea commit c3242cd

File tree

11 files changed

+1684
-110
lines changed

11 files changed

+1684
-110
lines changed

CHANGELOG.md

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
## [0.10.1] - 2025-01-11
10+
## [0.10.2] - 2025-09-16
11+
12+
### Fixed
13+
14+
- **Critical Token Limit Issue (#24)** - Fixed token overflow with includeMetadata
15+
- Implemented dynamic token limit calculation based on actual content size
16+
- Automatically adjusts item limits based on average item size in session
17+
- More accurate token estimation (3.5 chars/token vs 4)
18+
- Configurable via environment variables (MCP_MAX_TOKENS, MCP_TOKEN_SAFETY_BUFFER)
19+
- Added tokenInfo to response metadata for transparency
20+
- Resolves "MCP tool context_get response exceeds maximum allowed tokens" errors
21+
22+
### Added
23+
24+
- **Token Limit Management Module** (`utils/token-limits.ts`)
25+
- Dynamic calculation of safe item limits
26+
- Response overhead estimation
27+
- Configurable token limits via environment
28+
- Better visibility into token usage
29+
- Proper TypeScript interfaces for context items
30+
- Environment variable validation with bounds checking
31+
- Safe JSON parsing with error handling
32+
- Well-documented constants replacing magic numbers
33+
34+
## [0.10.1] - 2025-07-11
1135

1236
### Fixed
1337

@@ -63,7 +87,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6387
- Added recipes for common patterns in RECIPES.md
6488
- Added troubleshooting tips for new features
6589

66-
## [0.10.0] - 2025-01-26
90+
## [0.10.0] - 2025-06-26
6791

6892
### Added
6993

@@ -102,7 +126,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
102126
- Enhanced validation for channel names
103127
- Backward compatible - existing items default to 'default' channel
104128

105-
## [0.9.0] - 2025-01-20
129+
## [0.9.0] - 2025-06-21
106130

107131
### Changed (BREAKING)
108132

@@ -125,7 +149,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
125149
- `context_get_shared` tool (use `context_get` instead)
126150
- Complex sharing mechanism that was causing inconsistencies
127151

128-
## [0.8.4] - 2025-01-19
152+
## [0.8.4] - 2025-06-19
129153

130154
### Fixed
131155

@@ -139,7 +163,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
139163
- Feature flags system (planned)
140164
- Database migration system (planned)
141165

142-
## [0.8.3] - 2025-01-19
166+
## [0.8.3] - 2025-06-19
143167

144168
### Added
145169

@@ -160,7 +184,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
160184

161185
- Automatic schema migration for existing databases to add the `working_directory` column
162186

163-
## [0.8.0] - 2024-01-18
187+
## [0.8.0] - 2025-06-18
164188

165189
### Added
166190

@@ -200,7 +224,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
200224
- New tables: `journal_entries`, `compressed_context`, `tool_events`
201225
- All 255 tests passing
202226

203-
## [0.7.0] - 2024-01-18
227+
## [0.7.0] - 2025-06-18
204228

205229
### Added
206230

@@ -224,7 +248,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
224248
- Added comprehensive test coverage (30 new tests)
225249
- All 236 tests passing
226250

227-
## [0.6.0] - 2024-01-17
251+
## [0.6.0] - 2025-06-17
228252

229253
### Added
230254

@@ -247,7 +271,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
247271
- Comprehensive test coverage for semantic search
248272
- All 206 tests passing
249273

250-
## [0.5.0] - 2024-01-17
274+
## [0.5.0] - 2025-06-17
251275

252276
### Added
253277

@@ -270,7 +294,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
270294
- Added `knowledge-graph.ts` utility module
271295
- Comprehensive test coverage for graph operations
272296

273-
## [0.4.2] - 2024-01-16
297+
## [0.4.2] - 2025-06-17
274298

275299
### Added
276300

@@ -284,7 +308,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
284308
- Git integration error handling
285309
- Session list date filtering
286310

287-
## [0.4.1] - 2024-01-16
311+
## [0.4.1] - 2025-06-17
288312

289313
### Fixed
290314

@@ -297,7 +321,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
297321
- Improved error messages for better debugging
298322
- Enhanced validation for file paths
299323

300-
## [0.4.0] - 2024-01-15
324+
## [0.4.0] - 2025-06-17
301325

302326
### Added
303327

@@ -318,7 +342,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
318342
- Created `git.ts` utility module
319343
- 97% test coverage maintained
320344

321-
## [0.3.0] - 2024-01-14
345+
## [0.3.0] - 2025-06-17
322346

323347
### Added
324348

@@ -347,7 +371,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
347371
- Implemented streaming for large exports
348372
- Transaction support for atomic operations
349373

350-
## [0.2.0] - 2024-01-13
374+
## [0.2.0] - 2025-06-17
351375

352376
### Added
353377

@@ -377,7 +401,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
377401
- Memory leak in file cache operations
378402
- Session switching race condition
379403

380-
## [0.1.0] - 2024-01-12
404+
## [0.1.0] - 2025-06-17
381405

382406
### Added
383407

@@ -405,12 +429,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
405429

406430
## Development Releases
407431

408-
### [0.1.0-beta.2] - 2024-01-11
432+
### [0.1.0-beta.2] - 2025-06-17
409433

410434
- Fixed Windows path handling
411435
- Added Node.js 18+ compatibility
412436

413-
### [0.1.0-beta.1] - 2024-01-10
437+
### [0.1.0-beta.1] - 2025-06-17
414438

415439
- Initial beta release
416440
- Basic functionality testing

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,36 @@ claude mcp add memory-keeper node /absolute/path/to/mcp-memory-keeper/dist/index
183183

184184
### Environment Variables
185185

186+
#### Storage and Installation
187+
186188
- `DATA_DIR` - Directory for database storage (default: `~/mcp-data/memory-keeper/`)
187189
- `MEMORY_KEEPER_INSTALL_DIR` - Installation directory (default: `~/.local/mcp-servers/memory-keeper/`)
188190
- `MEMORY_KEEPER_AUTO_UPDATE` - Set to `1` to enable auto-updates
189191

192+
#### Token Limit Configuration
193+
194+
- `MCP_MAX_TOKENS` - Maximum tokens allowed in responses (default: `25000`, range: `1000-100000`)
195+
- Adjust this if your MCP client has different limits
196+
- `MCP_TOKEN_SAFETY_BUFFER` - Safety buffer percentage (default: `0.8`, range: `0.1-1.0`)
197+
- Uses only this fraction of the max tokens to prevent overflows
198+
- `MCP_MIN_ITEMS` - Minimum items to return even if exceeding limits (default: `1`, range: `1-100`)
199+
- Ensures at least some results are returned
200+
- `MCP_MAX_ITEMS` - Maximum items allowed per response (default: `100`, range: `10-1000`)
201+
- Upper bound for result sets regardless of token limits
202+
- `MCP_CHARS_PER_TOKEN` - Characters per token ratio (default: `3.5`, range: `2.5-5.0`) **[Advanced]**
203+
- Adjusts token estimation accuracy for different content types
204+
- Lower values = more conservative (safer but returns fewer items)
205+
- Higher values = more aggressive (returns more items but risks overflow)
206+
207+
Example configuration for stricter token limits:
208+
209+
```bash
210+
export MCP_MAX_TOKENS=20000 # Lower max tokens
211+
export MCP_TOKEN_SAFETY_BUFFER=0.7 # More conservative buffer
212+
export MCP_MAX_ITEMS=50 # Fewer items per response
213+
export MCP_CHARS_PER_TOKEN=3.0 # More conservative estimation (optional)
214+
```
215+
190216
### Claude Code (CLI)
191217

192218
#### Configuration Scopes

package-lock.json

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mcp-memory-keeper",
3-
"version": "0.10.1",
3+
"version": "0.10.2",
44
"description": "MCP server for persistent context management in AI coding assistants",
55
"main": "dist/index.js",
66
"bin": {

0 commit comments

Comments
 (0)