-
Notifications
You must be signed in to change notification settings - Fork 171
Add MCP optimizer implementation for semantic tool discovery #3440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
fac6152 to
d809cfa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Large PR Detected
This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.
How to unblock this PR:
Add a section to your PR description with the following format:
## Large PR Justification
[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformationAlternative:
Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.
See our Contributing Guidelines for more details.
This review will be automatically dismissed once you add the justification section.
a5aa704 to
9e28406
Compare
8d707ff to
5c0713a
Compare
5c0713a to
16bbbfc
Compare
Large PR justification has been provided. Thank you!
|
✅ Large PR justification has been provided. The size review has been dismissed and this PR can now proceed with normal review. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3440 +/- ##
==========================================
- Coverage 65.15% 64.49% -0.67%
==========================================
Files 398 412 +14
Lines 38821 40301 +1480
==========================================
+ Hits 25295 25992 +697
- Misses 11564 12266 +702
- Partials 1962 2043 +81 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Eliminate the intermediate optimizer.Config type and ConfigFromVMCPConfig conversion function to use config.OptimizerConfig directly throughout the optimizer package. This addresses maintainability concerns by establishing a single source of truth for optimizer configuration. Changes: - Delete pkg/vmcp/optimizer/config.go containing the duplicate config type - Update optimizer.Factory and EmbeddingOptimizer to use *config.OptimizerConfig - Flatten embedding config in ingestion.Config (individual fields vs nested) - Add type aliases (Config, OptimizerIntegration) for test compatibility - Add test helper methods (OnRegisterSession, RegisterTools, IngestToolsForTesting) - Update all test files to use flattened config structure - Handle HybridSearchRatio as pointer with default value (70) Benefits: - Single source of truth (no config duplication) - No synchronization burden between config types - Eliminates risk of translation bugs - Clearer code flow without intermediate transformations Closes review comment in PR #3440 requesting removal of translation layers.
53b7e8d to
8d16359
Compare
Change optimizerIntegration field type from undefined OptimizerIntegration to optimizer.Optimizer to fix compilation errors. Fixes: - undefined: OptimizerIntegration (typecheck) - E2E test failures - Linting failures
Signed-off-by: nigel brown <nigel@stacklok.com>
Add nil receiver checks to IngestInitialBackends, OnRegisterSession, and Close methods to prevent panics when called on nil *EmbeddingOptimizer. The tests explicitly test nil integration handling, so these methods must safely handle nil receivers. Fixes: - TestClose_NilIntegration panic - TestIngestInitialBackends_NilIntegration panic - TestOnRegisterSession_NilIntegration panic - All related optimizer unit test failures
- Fix line length violations (lll) by wrapping long lines - Remove unused processedSessions field from EmbeddingOptimizer - Remove unused sync import - Change unused receivers to _ in convertSearchResults and resolveToolTarget - Rename unused ctx parameter to _ in NewEmbeddingOptimizer - Remove unused deserializeServerMetadata, update, and delete functions - Simplify createTestDatabase to return only Database (not unused embeddingFunc) - Add nolint directive for OptimizerIntegration type alias (kept for test compatibility) Fixes all golangci-lint errors: - lll: 2 line length violations - revive: 4 unused parameter/receiver issues - unparam: 1 unused return value - unused: 4 unused functions/fields
Add MCP Optimizer Implementation for Semantic Tool Discovery
This PR adds the complete MCP optimizer implementation to vMCP, enabling semantic tool discovery and reducing token usage for LLMs working with large toolsets.
Overview
The optimizer allows vMCP to expose
optim.find_toolandoptim.call_tooloperations instead of all backend tools directly. This reduces token usage by allowing LLMs to discover relevant tools on demand via semantic search rather than receiving all tool definitions upfront.Features
Core Optimizer Package
Semantic Tool Search (
pkg/optimizer/)Token Counting (
pkg/optimizer/tokens/)Database Layer (
pkg/optimizer/db/)Ingestion Service (
pkg/optimizer/ingestion/)vMCP Integration
Optimizer Endpoints (
pkg/vmcp/optimizer/)optim.find_tool: Semantic and string-based tool discoveryoptim.call_tool: Tool invocation with automatic routingServer Integration (
pkg/vmcp/server/)Router Updates (
pkg/vmcp/router/)optim_*prefixed toolsKubernetes Operator Support
Service Resolution (
cmd/thv-operator/pkg/vmcpconfig/converter.go)embeddingService→embeddingURLconversionCRD Schema (
deploy/charts/operator-crds/)Configuration
OptimizerConfig (
pkg/vmcp/config/config.go)enabled: Enable/disable optimizerembeddingBackend: Choose embedding providerembeddingURL: Embedding service URLembeddingModel: Model name for embeddingsembeddingDimension: Vector dimensionpersistPath: Optional persistence pathftsDBPath: FTS5 database pathhybridSearchRatio: Semantic vs BM25 mix (0-100%)embeddingService: Kubernetes service name (K8s only)CLI Integration (
cmd/vmcp/app/commands.go)Build System
Build Tags (
Taskfile.yml)-tags="fts5"build flag for SQLite FTS5 supportTest Task (
Taskfile.yml)test-optimizertask for optimizer integration testsExamples & Scripts
Example Configuration (
examples/vmcp-config-optimizer.yaml)Helper Scripts (
scripts/)test-optimizer-with-sqlite-vec.sh: Integration testinginspect-optimizer-db.sh: Database inspectionquery-optimizer-db.sh: Query testingDocumentation
pkg/optimizer/README.mdpkg/optimizer/INTEGRATION.mdTesting
Dependencies
chromem-go: Vector database for embeddingssqlite-vec: SQLite extension for vector similarity searchgo.uber.org/mock: Mock generation for testsBuild Requirements
-tags="fts5"build flag for FTS5 supportRelated
Large PR Justification