← cd ~/projects

MF Investor Conversational Agent

AI-powered conversational agent for mutual fund investors — natural language portfolio queries, compliance guardrails, and multi-MCP server orchestration built with NestJS and Vercel AI SDK.

TypeScriptNestJSMCPVercel AI SDKBun

Overview

A production-grade multi-agent system that lets mutual fund investors query portfolios, access financial reports, and execute transactions through natural language — with compliance guardrails baked in at every layer.

Architecture

Two-tier Nx monorepo with clear separation of concerns:

  • Gateway — REST API handling auth, session management, request validation, and output sanitization (PAN masking)
  • Orchestrator — Intent classification, agent routing, MCP server coordination, and agentic loop execution

Agent System

BaseAgentService (abstract)
  ├── ReadAgent     → Portfolio queries, NAV, XIRR, reports
  └── TransactAgent → Buy/sell orders

Each agent runs a Vercel AI SDK agent loop with MCP tools, validated through compliance rules at input, output, and tool-call boundaries.

MCP Integration

Three external MCP servers connected via SSE:

  • mcp-portfolio — Holdings, NAV, XIRR, transaction history
  • mcp-reports — Statement generation, report catalog
  • mcp-actions — Transaction preview, intent capture, and execution

Tool calls auto-route to the correct server. Agents get a unified tool interface via getAllTools() and createExecutor().

Compliance & Guardrails

  • Input validation with injection detection and banned phrase filtering
  • Output sanitization — PAN masking, risk disclaimer injection
  • Tool call consent tracking for transactional operations
  • Per-agent system prompts with compliance rules and AMC branding

Tech Stack

  • NestJS with dependency injection and dynamic modules
  • Vercel AI SDK for unified LLM provider abstraction (Anthropic, OpenAI, xAI)
  • MCP SDK for Model Context Protocol client integration
  • Zod for schema validation
  • Bun runtime + Nx monorepo orchestration
  • Redis for production session storage (memory store for dev)

Monorepo Structure

7 shared libraries: common, compliance, observability, mcp-core, llm, session, execution-gate — each with colocated tests and barrel exports.