Skip to content

A tool that provides an AI-powered setup for communicating with various databases through natural language queries

Notifications You must be signed in to change notification settings

manicdon7/NL-Bank-Database-MCP-Tool

Repository files navigation

AI-Powered Banking MCP Server

This project is an intelligent backend service that allows users and AI agents to interact with banking data using natural language queries. It leverages AI to translate human language into database queries, execute them, and summarize the results in a human-readable format. The server exposes its capabilities via the Model Context Protocol (MCP) for seamless integration with AI agents and tools.

✨ Key Features

  • Natural Language to Database Query: Convert plain English questions into executable database queries (SQL for relational databases, JSON objects for MongoDB).
  • AI-Powered Summarization: Get concise, human-readable summaries of complex database results, focusing on answering the original user's intent.
  • Multi-Database Support: Configurable to connect to MySQL, PostgreSQL, SQLite3, or MongoDB.
  • MCP Integration: Exposes tools via MCP for agent/AI integration (stdio-based communication).
  • Robust Prompt Handling: Automatically truncates large schemas and data to avoid API errors.
  • Modular and Extensible: Easily add new tools/endpoints for custom queries or actions.

πŸš€ How it Works

  1. User/Agent Input: A natural language query (e.g., "List all customers over age 30") is sent to the MCP server via stdio or an MCP-compatible client.
  2. Schema Retrieval: The service fetches the schema of the connected database.
  3. AI Query Generation: The query and schema are sent to an AI model, which generates the appropriate database query (SQL or MongoDB JSON).
  4. Database Execution: The generated query is executed against the configured database.
  5. AI Result Summarization: The raw results are summarized by the AI, focusing on the original query intent.
  6. Response: The MCP server returns both the raw data and the AI-generated summary.

πŸ› οΈ Technologies Used

  • Node.js (ES modules)
  • @modelcontextprotocol/sdk (MCP server)
  • Knex.js (SQL DBs)
  • Mongoose (MongoDB)
  • Zod (schema validation)
  • Axios (HTTP client for AI APIs)
  • OpenAI, xAI, Anthropic, Pollinations (AI providers)

βš™οΈ Setup and Installation

  1. Clone the repository:
    git clone <repository-url>
    cd <project-directory>
  2. Install dependencies:
    npm install
  3. Configure your database and AI API keys: Edit config.json in the root directory with your DB connection details and AI API keys. Example:
    {
      "activeDataSource": "mongodb",
      "dataSources": {
        "mysql": { ... },
        "postgresql": { ... },
        "sqlite3": { ... },
        "mongodb": { "uri": "mongodb://127.0.0.1:27017/bank_db_mongo" }
      },
      "openaiApiKey": "YOUR_OPENAI_API_KEY",
      "xaiApiKey": "YOUR_XAI_KEY",
      "anthropicApiKey": "YOUR_ANTHROPIC_API_KEY"
    }
    • Set activeDataSource to your DB type.
    • Fill in your API keys.
  4. Start the MCP server:
    npm run dev
    The server runs via stdio for MCP agent integration.

πŸ€– Usage: MCP Tools

List Available Tools

Send a tools/list request via stdio or an MCP client:

{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "tools/list",
  "params": {}
}

Dynamic Natural Language Query

Send a tools/dynamicQuery request:

{
  "jsonrpc": "2.0",
  "id": "2",
  "method": "tools/dynamicQuery",
  "params": {
    "nl_query": "Find customers who have both a housing loan and a personal loan.",
    "language": "English",
    "tone": "formal"
  }
}

Example Response

{
  "result": {
    "data": [ ... ],
    "masked_summary": "...",
    "ai_summary": "..."
  }
}

🧩 Adding New Tools

  • Define your tool in the tool registry/controller (see controllers/mcpToolController.js).
  • Implement the handler logic (query DB, format result).
  • Register the tool so it appears in tools/list and can be called via MCP.

πŸ“ Notes

  • The server is designed for stdio/MCP agent integration, not as a REST API.
  • Prompts are automatically truncated for large schemas/data to avoid AI API errors.
  • You can extend the system with new tools, endpoints, or summarization logic as needed.

For more details, see the code and comments in the main files:

  • index.js (MCP server entry)
  • controllers/ (tool handlers)
  • utils/aiPrompts.js (prompt generation)
  • utils/dbHelpers.js (DB connection)

Enjoy your AI-powered banking MCP server!

About

A tool that provides an AI-powered setup for communicating with various databases through natural language queries

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published