mirror of
https://github.com/hanzoai/mcp.git
synced 2026-10-15 12:30:12 +00:00
## Core Implementation - Unified search engine with strategy pattern for extensible search types - Full OpenAI MCP specification compliance for search and fetch tools - Multi-modal search strategies: Symbol, AST, Vector, Text, and File search - Automatic strategy selection based on query characteristics ## Security & Remote Access - Secure ngrok tunnel integration with automatic detection - Multi-method authentication (Bearer token, API keys, JWT) - Post-quantum TLS configuration support - Rate limiting and CORS protection - Access logging and monitoring - Only exposes files when ngrok credentials are present ## Testing & CI - 102 tests with 85% coverage on critical paths - GitHub Actions CI workflow for automated testing - Node.js 18.x and 20.x compatibility testing - Coverage reporting to Codecov - Security audit checks ## Documentation - Comprehensive documentation in LLM.md - Security guide in docs/SECURITY.md - .npmrc excluded from repository for security This implementation provides a production-ready search system for AI tools like ChatGPT and Claude Desktop.
4.5 KiB
4.5 KiB
MCP Search Configuration Examples
URL Configuration for Different Scenarios
1. Local Development (Default)
When running locally, files are referenced with file:// URLs:
// No configuration needed - this is the default
// Results will have URLs like:
// file:///Users/z/work/project/src/index.ts
// vscode://file//Users/z/work/project/src/index.ts:42:1 (with line numbers)
2. Remote Access via Ngrok
When exposing your MCP server via ngrok:
import { configureUrlHelper, startFileServer } from '@hanzo/mcp/search';
// Configure URL helper for ngrok
configureUrlHelper({
baseUrl: 'https://abc123.ngrok.io', // Your ngrok URL
servePath: '/files',
enableFileServing: true,
workspaceRoot: process.cwd()
});
// Start the file server on port 8080
await startFileServer({
port: 8080,
host: '0.0.0.0', // Listen on all interfaces
enableCors: true // Enable CORS for remote access
});
// Now search results will have URLs like:
// https://abc123.ngrok.io/files/src/index.ts#L42
3. Environment Variable Configuration
Set these environment variables to automatically configure URLs:
# Configure for remote access
export MCP_BASE_URL="https://your-domain.com"
export MCP_SERVE_PATH="/files"
export MCP_ENABLE_FILE_SERVING="true"
export MCP_WORKSPACE_ROOT="/path/to/workspace"
# Start your MCP server
hanzo-mcp serve
File Server Features
HTML Preview with Line Highlighting
Access files with syntax highlighting and line numbers:
https://your-domain.com/files/src/index.ts#L42?preview=true
Direct File Access
Get raw file content:
https://your-domain.com/files/src/index.ts
Security Features
- Only serves allowed file extensions (configurable)
- Prevents directory traversal attacks
- File size limits (default 10MB)
- CORS support for cross-origin access
Custom Search Strategies
Adding a Custom Search Strategy
import { SearchStrategy, SearchType } from '@hanzo/mcp/search';
class CustomSearchStrategy implements SearchStrategy {
readonly name = 'custom' as SearchType;
shouldApply(query: string): boolean {
// Your logic to determine when to use this strategy
return query.startsWith('custom:');
}
getPriority(): number {
return 25; // Priority for ranking results
}
async search(query: string, options?: SearchOptions): Promise<InternalSearchResult[]> {
// Your search implementation
return [];
}
}
// Add to search engine
import { SearchEngine } from '@hanzo/mcp/search';
const searchEngine = new SearchEngine({
strategies: [
new CustomSearchStrategy(),
// ... other strategies
]
});
Integration with ChatGPT
When using with ChatGPT or other AI services that need to access files:
- Start MCP server with file serving:
import { startFileServer } from '@hanzo/mcp/search';
// Start file server before MCP server
await startFileServer({
port: 8080,
enableCors: true
});
- Expose via ngrok:
# Expose file server
ngrok http 8080
# Configure MCP with ngrok URL
export MCP_BASE_URL="https://your-ngrok-url.ngrok.io"
- Search results will include accessible URLs:
{
"results": [
{
"id": "src/utils/helper.ts:42:function",
"title": "helper.ts:42",
"url": "https://your-ngrok-url.ngrok.io/files/src/utils/helper.ts#L42"
}
]
}
- Fetch will return full content with metadata:
{
"id": "src/utils/helper.ts:42",
"title": "helper.ts",
"text": "// File content here...",
"url": "https://your-ngrok-url.ngrok.io/files/src/utils/helper.ts#L42",
"metadata": {
"type": "file",
"language": "typescript",
"lines": 150,
"excerpt": true,
"startLine": 1,
"endLine": 100
}
}
VSCode Integration
For local development with VSCode:
// URLs will automatically use vscode:// protocol
// vscode://file//path/to/file.ts:line:column
// This allows clicking to open directly in VSCode
Security Considerations
-
File Access Control:
- Configure
allowedExtensionsto limit file types - Set
maxFileSizeto prevent large file transfers - Use
basePathto restrict access to specific directories
- Configure
-
Remote Access:
- Enable CORS only when needed
- Consider authentication middleware for production
- Use HTTPS (ngrok provides this automatically)
-
Environment Variables:
- Never commit
MCP_BASE_URLwith production URLs - Use
.envfiles for local configuration - Rotate ngrok URLs regularly
- Never commit