A high-performance MCP (Message Control Protocol) server for evaluating financial formulas and indicators.
- Extensible Architecture: Easily add new financial indicators by implementing the
Formula
interface. - High Performance: Built with Go for optimal performance and concurrency.
- RESTful API: Simple HTTP/JSON interface for easy integration.
- Modular Design: Clear separation of concerns with well-defined components.
- Go 1.16 or higher
- Git
-
Clone the repository:
git clone https://github.com/yourusername/quantmcp-server.git cd quantmcp-server
-
Build the server:
go build -o quantmcp ./cmd/server.go
-
Run the server:
./quantmcp
The server will start on http://localhost:8080
.
The server includes several performance optimizations:
- L1 Cache: Fast in-memory cache for hot items with lock-free reads
- L2 Cache: Sharded cache for larger storage to reduce contention
- Automatic cleanup of expired entries
- Metrics collection for cache performance monitoring
- Efficient reuse of database connections
- Configurable pool size based on workload
- Batch processing of multiple formula evaluations
- Reduced overhead for high-throughput scenarios
- Object pooling for formula instances
- Efficient memory allocation patterns
- Automatic garbage collection tuning
The server exposes Prometheus metrics at /metrics
endpoint:
- Cache Metrics: Hits, misses, size, and entry count
- HTTP Metrics: Request counts, latencies, and response sizes
- System Metrics: Memory usage, goroutines, and GC stats
Example metrics:
# HELP http_requests_total Total number of HTTP requests
# TYPE http_requests_total counter
http_requests_total{method="POST",path="/evaluate",status="200"} 42
# HELP cache_hits_total Total number of cache hits
# TYPE cache_hits_total counter
cache_hits_total 1234
# HELP cache_misses_total Total number of cache misses
# TYPE cache_misses_total counter
cache_misses_total 56
POST /evaluate
- Evaluate a single formula (legacy)POST /v2/evaluate
- Optimized formula evaluation with cachingPOST /v2/evaluate/batch
- Batch process multiple formulasGET /metrics
- Prometheus metrics endpointGET /health
- Health check endpointGET /formulas
- List available formulasGET /version
- Server version information
POST /evaluate
Content-Type: application/json
{
"command": "compute",
"instrument": "MACD",
"params": {
"fast": 12,
"slow": 26,
"signal": 9
},
"inputs": {
"close": [1.23, 1.25, 1.28, 1.30, ...]
}
}
{
"status": "success",
"instrument": "MACD",
"result": {
"macd": [0.0023, 0.0031, 0.0027, ...],
"signal": [0.0025, 0.0029, 0.0028, ...],
"histogram": [-0.0002, 0.0002, -0.0001, ...]
}
}
- Create a new file in the
internal/formulas
directory. - Implement the
Formula
interface. - Register the formula in an
init()
function.
Example:
package formulas
import "github.com/quantmcp/server/internal/formulas"
func init() {
formulas.RegisterFormula(NewYourFormula())
}
Run the test suite:
go test ./...
Benchmark tests are available to measure performance characteristics:
# Run all benchmarks
go test -bench=. -benchmem ./...
# Run benchmarks with memory profiling
go test -bench=. -benchmem -memprofile=mem.out ./...
Example using wrk
:
wrk -t4 -c100 -d30s -s scripts/loadtest.lua http://localhost:8080/evaluate
When running the server in test mode, metrics are available at http://localhost:8080/metrics
for monitoring performance during testing.
This project is licensed under the MIT License - see the LICENSE file for details.