feat: Implement MCP Server Components - Phases 1-3.3 (CFOS-27)#41
Merged
jayscambler merged 3 commits intomainfrom Jun 19, 2025
Merged
feat: Implement MCP Server Components - Phases 1-3.3 (CFOS-27)#41jayscambler merged 3 commits intomainfrom
jayscambler merged 3 commits intomainfrom
Conversation
…n (CFOS-27) ## Phase 2: Basic MCP Server Implementation ✅ Implemented a fully functional MCP server with stdio transport: ### Core Infrastructure - JSON-RPC 2.0 message handling with proper error codes - Async architecture for concurrent operations - Pydantic schemas for request/response validation - Protocol-compliant initialization handshake ### 13 Tools Implemented **Core Document Tools (6):** - search_documents: Vector/text/hybrid search with SQL filtering - add_document: Document creation with chunking support - get_document: Retrieve by UUID with field selection - list_documents: Paginated listing with filters - update_document: Update content/metadata with re-embedding - delete_document: Safe deletion by UUID **Enhancement Tools (5):** - enhance_context: Add purpose-specific context - extract_metadata: Extract custom metadata using LLM - generate_tags: Auto-generate relevant tags - improve_title: Generate or improve titles - enhance_for_purpose: Multi-field enhancement **Extraction Tools (2):** - extract_from_file: Extract from MD, JSON, YAML, CSV, TXT - batch_extract: Process entire directories ### Resource System - Dataset info, schema, and statistics - Collection and relationship exploration - JSON-formatted read-only access ### Key Fixes - Updated field names: content → text_content, embeddings → vector - Fixed dataset.add() to use single record (not list) - Implemented text search with filter using scanner API - Enhanced error handling for ValidationErrors → InvalidParams - Fixed resource handlers to use _dataset attributes ## Phase 3.1: Transport Abstraction Layer ✅ Created transport-agnostic architecture for Phase 3: ### Core Abstractions contextframe/mcp/core/ ├── transport.py # TransportAdapter base class └── streaming.py # StreamingAdapter for unified streaming ### Transport Features - **Progress Handling**: Collected for stdio, streamed for HTTP - **Subscriptions**: Polling for stdio, SSE for HTTP - **Batch Operations**: Buffered for stdio, streamed for HTTP - **Zero Breaking Changes**: Existing implementation wrapped cleanly ### StdioAdapter Implementation contextframe/mcp/transports/ └── stdio.py # Wraps existing StdioTransport This ensures all 26 new tools in Phase 3 will work with both transports!
…-27) Implemented all 8 batch operation tools for the MCP server: Core Infrastructure: - BatchOperationHandler with transport-agnostic progress tracking - Parallel execution support with semaphore-based concurrency control - Transaction support with full rollback capability for atomic operations - Unified error handling with max_errors support Batch Tools Implemented: 1. batch_search - Execute multiple searches in parallel 2. batch_add - Bulk document insertion with atomic transactions 3. batch_update - Update documents by filter or IDs 4. batch_delete - Safe bulk deletion with dry-run and confirm count 5. batch_enhance - LLM enhancement for multiple documents 6. batch_extract - Extract content from multiple file sources 7. batch_export - Export documents to JSON/JSONL/CSV/Parquet 8. batch_import - Import documents from various formats Key Features: - Progress tracking works differently per transport (buffered for stdio, streaming for future HTTP) - All tools support both filter-based and ID-based operations - Atomic operations with full rollback on any failure - Comprehensive error handling with continue-on-error support - Batch processing with configurable sizes for efficiency Tests: - 6 comprehensive unit tests for BatchOperationHandler - Mock transport adapter for testing without stdio conflicts - All handler tests passing with 87% coverage This completes Phase 3.2 of the MCP implementation, providing powerful batch capabilities that work seamlessly with both current stdio and future HTTP transports. Next: Phase 3.3 - Collection Management Tools
Adds comprehensive collection management capabilities to the MCP server: - Implemented 6 collection management tools: * create_collection: Create collections with metadata and templates * update_collection: Update collection properties and membership * delete_collection: Delete collections with recursive options * list_collections: List collections with filtering and sorting * move_documents: Move documents between collections * get_collection_stats: Get detailed collection statistics - Collection features: * Hierarchical collections with parent-child relationships * Collection templates (project, research, knowledge_base, dataset, legal_case) * Shared metadata inheritance * Member tracking and statistics * Lance-native filtering for performance - Technical implementation: * Uses custom_metadata field for proper Lance persistence * Leverages existing schema fields for filtering * Excludes raw_data from scans to avoid serialization issues * Full test coverage with 18 passing tests
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
This PR implements the Model Context Protocol (MCP) server components for ContextFrame, covering Phases 1 through 3.3 of the enhancement plan.
Implementation Progress
✅ Phase 1: MCP Bash Script Wrappers
✅ Phase 2: Core MCP Server
✅ Phase 3.1: Transport Abstraction
✅ Phase 3.2: Batch Operations
✅ Phase 3.3: Collection Management
Key Features
Testing
All components have full test coverage:
Next Steps
Future phases will add:
Related Issues
Closes CFOS-27