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.
- 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.
- 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.
- Schema Retrieval: The service fetches the schema of the connected database.
- AI Query Generation: The query and schema are sent to an AI model, which generates the appropriate database query (SQL or MongoDB JSON).
- Database Execution: The generated query is executed against the configured database.
- AI Result Summarization: The raw results are summarized by the AI, focusing on the original query intent.
- Response: The MCP server returns both the raw data and the AI-generated summary.
- 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)
- Clone the repository:
git clone <repository-url> cd <project-directory>
- Install dependencies:
npm install
- 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.
- Set
- Start the MCP server:
The server runs via stdio for MCP agent integration.
npm run dev
Send a tools/list
request via stdio or an MCP client:
{
"jsonrpc": "2.0",
"id": "1",
"method": "tools/list",
"params": {}
}
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"
}
}
{
"result": {
"data": [ ... ],
"masked_summary": "...",
"ai_summary": "..."
}
}
- 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.
- 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!