Skip to content

copyleftdev/quantmcp-server

Repository files navigation

QuantMCP Server

A high-performance MCP (Message Control Protocol) server for evaluating financial formulas and indicators.

Features

  • 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.

Getting Started

Prerequisites

  • Go 1.16 or higher
  • Git

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/quantmcp-server.git
    cd quantmcp-server
  2. Build the server:

    go build -o quantmcp ./cmd/server.go
  3. Run the server:

    ./quantmcp

The server will start on http://localhost:8080.

Performance Optimizations

The server includes several performance optimizations:

Two-Level Caching

  • 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

Connection Pooling

  • Efficient reuse of database connections
  • Configurable pool size based on workload

Request Batching

  • Batch processing of multiple formula evaluations
  • Reduced overhead for high-throughput scenarios

Memory Management

  • Object pooling for formula instances
  • Efficient memory allocation patterns
  • Automatic garbage collection tuning

Monitoring

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

API Usage

Endpoints

  • POST /evaluate - Evaluate a single formula (legacy)
  • POST /v2/evaluate - Optimized formula evaluation with caching
  • POST /v2/evaluate/batch - Batch process multiple formulas
  • GET /metrics - Prometheus metrics endpoint
  • GET /health - Health check endpoint
  • GET /formulas - List available formulas
  • GET /version - Server version information

Evaluate a Formula

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, ...]
  }
}

Response

{
  "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, ...]
  }
}

Adding New Formulas

  1. Create a new file in the internal/formulas directory.
  2. Implement the Formula interface.
  3. Register the formula in an init() function.

Example:

package formulas

import "github.com/quantmcp/server/internal/formulas"

func init() {
    formulas.RegisterFormula(NewYourFormula())
}

Testing

Unit Tests

Run the test suite:

go test ./...

Performance Testing

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 ./...

Load Testing

Example using wrk:

wrk -t4 -c100 -d30s -s scripts/loadtest.lua http://localhost:8080/evaluate

Monitoring During Tests

When running the server in test mode, metrics are available at http://localhost:8080/metrics for monitoring performance during testing.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published