feat: add configurable MCP timeout via environment variables#287
Open
PROJECT-OCULUS wants to merge 9 commits intocampfirein:mainfrom
Open
feat: add configurable MCP timeout via environment variables#287PROJECT-OCULUS wants to merge 9 commits intocampfirein:mainfrom
PROJECT-OCULUS wants to merge 9 commits intocampfirein:mainfrom
Conversation
…nager - Adds public getBackendType() method to properly expose backend type - Fixes Cypher query rejection despite successful Neo4j connection - Updates query-graph test mocks to include getBackendType() - Adds test coverage for backend type validation - Fixes pre-existing test missing mock method Problem: Neo4j connection succeeded but Cypher queries were rejected because the query-graph tool could not detect the backend type. The tool checked kgManager.getBackendType() which didn't exist, causing it to default to 'memory' and incorrectly reject Cypher queries. Solution: Added getBackendType() method to KnowledgeGraphManager that: - Delegates to backend instance when connected (source of truth) - Returns cached metadata when disconnected - Handles all lifecycle states (pre-connection, connected, disconnected) Changes: - manager.ts: Added getBackendType() method with comprehensive JSDoc - query-graph.test.ts: Updated mocks and added validation tests - All 16 tests passing Impact: - Cypher queries now work correctly with Neo4j - Backend type detection accurate in all scenarios - No breaking changes (purely additive) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Validates backend type before executing Cypher queries - Provides clear error messages for in-memory backend - Suggests alternative query types (node, edge, path) - Updated tool description to document backend requirements - Part of Neo4j backend detection fix (complements getBackendType() method) This ensures users get helpful feedback when attempting Cypher queries on backends that don't support them, improving the developer experience. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…attern matching - Enhanced JSON extraction with multiple fallback patterns - Added extractJSON() helper function for robust LLM response parsing - Improved fallback pattern matching with more comprehensive regex patterns - Better handling of LLM responses that use code blocks or varying formats - Enhanced error recovery when LLM returns malformed JSON These improvements make the relationship manager more resilient to variations in LLM output formatting, reducing parse failures and improving the overall reliability of relationship operations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…rror logging - Fixed filter constraint building to use actual property keys instead of counter - Previously used Object.keys(params).length as placeholder, causing incorrect queries - Now correctly references the key from the filter entry (e.g., 'age', 'name') - Applies to range filters (gte, gt, lte, lt) and array filters (any, all) - Improved error logging: changed console.error to this.logger.error for consistency This fix ensures that Neo4j queries with property filters work correctly, resolving issues where filter conditions weren't applied to the intended fields. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Added escapeRegex() helper function to properly escape special characters - Fixes "Invalid regular expression: /\bC++\b/: Nothing to repeat" error - Enables correct matching of technologies like C++, .NET, C#, etc. - Prevents regex quantifiers (+, *, ?, etc.) from breaking pattern matching - Applies to all technology/tool name extraction patterns Without this fix, entity extraction would crash when encountering technology names containing regex special characters, preventing proper knowledge graph population for many common programming languages and tools. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…l definition - Made metadata field optional in ReasoningTraceSchema (line 57) - Aligns Zod schema with tool parameter definition (which already marks it as optional) - Resolves validation failures when reasoning evaluation called without metadata - Allows reasoning evaluation to work with minimal trace information Previously, the schema required metadata even though the tool definition marked it as not required, causing validation errors. This fix ensures consistency between the schema validation and the tool's actual requirements. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Removed [DIAGNOSTIC-FACTORY] console logging statements - Removed verbose debug logging around manager creation - Cleaned up excessive debug statements for cleaner production code - Kept essential logging for actual errors and info messages This removes temporary debugging code that was added during development, keeping only the necessary logging for production operation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add CIPHER_MCP_TIMEOUT and MCP_TIMEOUT env var support - Replace hardcoded 30s timeout with DEFAULT_MCP_TIMEOUT - Add comprehensive Vitest test suite (10 tests, all passing) - Fixes timeout failures in intelligent_processor for complex operations - Maintains backward compatibility (30s default) Addresses issue where LLM-heavy operations (entity extraction, relationship identification, embeddings) regularly exceeded the hardcoded 30s limit, causing ~50% failure rate on complex inputs.
Import MIN_TIMEOUT_MS (5s) and MAX_TIMEOUT_MS (5min) from constants.js and use them to validate CIPHER_MCP_TIMEOUT and MCP_TIMEOUT env vars. - Values below 5s or above 5min are rejected with warning - Falls back to next env var or default (30s) when invalid - Prevents potential DoS from extremely high timeout values - Uses existing constants instead of duplicating magic numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds configurable MCP server timeout support via environment variables, extending Cipher's existing timeout configuration pattern to server connection timeouts.
Background: Existing Environment Variable Pattern
Cipher already uses MCP timeout environment variables (defined in
src/core/mcp/constants.ts):MCP_GLOBAL_TIMEOUT- Global timeout for all MCP operationsMCP_TOOL_TIMEOUT- Tool execution timeoutThis PR extends the existing pattern to server connection timeouts by:
MCP_TIMEOUTvariable (follows existing naming convention)CIPHER_MCP_TIMEOUTfor Cipher-specific granular controlProblem
The hardcoded 30-second server connection timeout in
config.tscauses failures in one scenario:1. Local Models (Ollama)
config.ts(hardcoded 30s limit)Solution
Configurable server connection timeout via environment variables, following Cipher's existing pattern:
Priority Order:
CIPHER_MCP_TIMEOUT(Cipher-specific, highest priority)MCP_TIMEOUT(generic MCP standard, aligns with existing env vars)30000ms(default, maintains backward compatibility)Implementation:
getDefaultMcpTimeout()helper function to read env varsStdioServerConfigSchemaSseServerConfigSchemaStreamableHttpServerConfigSchemaUsage Examples
For local Ollama models with slower performance:
For complex operations or slower networks:
In .env file:
Testing
Comprehensive Vitest test suite (10 tests, all passing):
Environment Variable Tests:
CIPHER_MCP_TIMEOUTenvironment variable respectedMCP_TIMEOUTfallback works correctlyTool Execution Tests:
Manual Testing:
Breaking Changes
None - Full backward compatibility maintained:
Files Changed
Modified (1 file):
src/core/mcp/config.ts- Timeout configuration implementation (~30 lines)Added (1 file):
src/core/brain/tools/__test__/timeout-behavior.test.ts- Comprehensive test suite (10 tests, ~335 lines)Total: 2 files changed, 362 insertions, 6 deletions
Alignment with Existing Codebase
This change:
MCP_*_TIMEOUTnaming conventionMCP_GLOBAL_TIMEOUTandMCP_TOOL_TIMEOUTconfig.ts