finance-mcp-server-java

yogesh-ch-ss/finance-mcp-server-java

3.2

If you are the rightful owner of finance-mcp-server-java and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The Finance MCP Server is a Model Context Protocol server designed for financial analysis, offering stock technical analysis and sentiment analysis based on recent news.

Tools
2
Resources
0
Prompts
0

Finance MCP Server

MCP server providing stock technical analysis and news sentiment analysis using Alpha Vantage API.

Features

  • Stock Analysis: MA20/MA50, RSI, volatility, BUY/SELL/HOLD recommendations
  • News Sentiment: Aggregates sentiment from recent articles with market impact assessment
  • AI-Powered Q&A (RAG): Ask questions about the project using Claude AI with retrieval augmented generation

Prerequisites

  • Java 21+
  • Maven 3.6+
  • Alpha Vantage API key (free tier: 5 calls/min, 100/day)
  • Ollama installed (optional, for RAG features - 100% FREE)

Setup

Set Alpha Vantage API key via environment variable or src/main/resources/application.properties:

export ALPHA_VANTAGE_API_KEY=your_alpha_vantage_key_here

For RAG features, install and run Ollama (100% FREE):

# Install Ollama
brew install ollama

# Pull the model (Phi-4 Mini - lightweight and fast)
ollama pull phi4-mini

# Start Ollama (runs in background)
ollama serve

Build and run:

mvn clean package
java -jar target/mcp.finance-0.0.1-SNAPSHOT.jar
# Or: mvn spring-boot:run

Server runs on http://localhost:8080

API Endpoints

MCP Tools

GET /mcp/tools/list - List available tools POST /mcp/tools/call - Execute a tool

Example call:

curl -X POST http://localhost:8080/mcp/tools/call \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": "1",
    "method": "tools/call",
    "params": {
      "name": "analyze_stock",
      "arguments": {"symbol": "AAPL"}
    }
  }'

RAG (AI Assistant)

POST /rag/ask - Ask questions about the Finance MCP Server GET /rag/ask?q=your_question - Simple query endpoint POST /rag/reindex - Re-index documentation (after code changes) GET /rag/health - Check RAG service status

Example RAG query:

curl -X POST http://localhost:8080/rag/ask \
  -H "Content-Type: application/json" \
  -d '{
    "question": "How do I analyze a stock?",
    "includeSources": true
  }'

Or use the simple GET endpoint:

curl "http://localhost:8080/rag/ask?q=How%20do%20I%20get%20started?"

Available Tools

  • analyze_stock - Technical analysis with MA, RSI, volatility
  • analyze_stock_sentiment - News sentiment analysis

Test symbols: AAPL, GOOGL, MSFT, TSLA, JPM

Project Structure

src/main/java/com/yogeshchsamant/mcp/finance/
├── FinanceMcpServerApplication.java          # Main application entry point
├── config/
│   ├── AlphaVantageConfig.java               # Alpha Vantage client configuration
│   └── RagConfig.java                        # RAG (Claude AI) configuration
├── controller/
│   ├── McpController.java                    # MCP protocol endpoints
│   └── RagController.java                    # RAG Q&A endpoints
├── dto/
│   ├── StockAnalysisDto.java                 # Stock analysis data transfer object
│   ├── NewsAnalysisDto.java                  # News analysis data transfer object
│   ├── RagQueryDto.java                      # RAG query request DTO
│   └── RagResponseDto.java                   # RAG query response DTO
├── model/
│   ├── McpRequest.java                       # MCP request model
│   ├── McpResponse.java                      # MCP response model
│   ├── StockData.java                        # Stock data model
│   ├── NewsData.java                         # News data model
│   └── SentimentResult.java                  # Sentiment analysis result
└── service/
    ├── AlphaVantageService.java              # Alpha Vantage API integration
    ├── StockAnalysisService.java             # Stock technical analysis logic
    ├── SentimentAnalysisService.java         # News sentiment analysis logic
    ├── DocumentIndexerService.java           # Indexes docs/code for RAG
    └── RagService.java                       # RAG retrieval & generation logic

Tech Stack

Java 21, Spring Boot 3.5.6, Spring WebFlux, Maven, Lombok, LangChain4j, Ollama (Phi-4 Mini), all-MiniLM-L6-v2 embeddings

RAG Implementation Details

The RAG (Retrieval Augmented Generation) system uses:

  • Embedding Model: all-MiniLM-L6-v2 (local, no API calls needed)
  • Vector Store: In-memory (for production, consider Pinecone, Weaviate, or pgvector)
  • LLM: Phi-4 Mini via Ollama (100% FREE, runs locally, no API key needed)
  • Document Sources: README.md + all Java source files (controllers, services, models, DTOs)

The system automatically indexes your documentation on startup. Ask questions like:

  • "How do I analyze a stock?"
  • "What endpoints are available?"
  • "How does sentiment analysis work?"
  • "What's the structure of the MCP request?"