Social Benefits Assistant with FastMCP
FastMCP is a higher-level, decorator-based Python framework that simplifies building Model Context Protocol (MCP) servers by providing an interface for registering tools, resources, and prompts.
Introduction
The Social Benefits Assistant is a sophisticated system designed to help users navigate social benefit programs and handle grievances. Built using the Model Context Protocol (MCP) framework with FastMCP implementation, it provides a modern, scalable architecture for AI-powered assistance.
Key Features
Program Eligibility Assessment: Helps users find relevant social programs and assess their eligibility
Grievance Management: Handles user complaints, creates tickets, and tracks status
Natural Language Interface: Powered by Ollama LLMs for conversational interactions
Modular Architecture: Separate MCP servers for different subsystems
Standardized Communication: Uses MCP protocol for all inter-component communication
Why FastMCP?
FastMCP provides a cleaner, more ergonomic interface for building MCP servers. Key advantages include:
Decorator-based tool registration
Built-in support for resources and prompts
Standard transport mechanisms (stdio, SSE, WebSocket)
Proper context management
Type-safe implementations
Architecture Overview
The Social Benefits Assistant uses a distributed architecture based on the Model Context Protocol (MCP). The system consists of three main components:
System Architecture:
Key Architectural Decisions
Separation of Concerns: Each subsystem (eligibility, grievance) has its own MCP server
Standard Protocol: All communication uses the MCP protocol
LLM Integration: Ollama serves as the intelligent routing layer
Tool-Based Interface: Each server exposes functionality through MCP tools
Resource Management: Static data is exposed through MCP resources
Prompt Templates: Response formatting is handled through MCP prompts
Communication Flow
User sends query to the MCP client
Client uses Ollama to analyze intent
Based on intent, client calls appropriate MCP server(s)
Server processes request using tools
Server returns results via MCP protocol
Client formats response using prompts and Ollama
Final response is presented to user
FastMCP Integration
What is FastMCP?
FastMCP is a higher-level interface for the Model Context Protocol that simplifies the creation of MCP servers. It provides a more ergonomic API compared to the low-level MCP implementation.
Integration Approach
Our integration of FastMCP involved:
1. Server Creation
Instead of using the low-level Server
class, we use FastMCP
:
2. Tool Registration
Tools are registered using decorators instead of manual registration:
3. Resource Definition
Resources are defined with decorators for dynamic content:
4. Prompt Templates
Prompts are registered for response formatting:
5. Context Management
FastMCP provides a Context
object for accessing MCP features:
Benefits of FastMCP Integration
Cleaner Code: Decorator-based registration is more intuitive
Type Safety: Better type hints and validation
Built-in Features: Automatic parameter validation, error handling
Standard Patterns: Follows Python conventions
Easier Testing: Better separation of concerns
System Components
Overview
The Social Benefits Assistant consists of three main components:
Eligibility Server: Handles program search and eligibility assessment
Grievance Server: Manages user complaints and ticket tracking
MCP Client: Orchestrates communication and provides user interface
Each component is built using FastMCP and follows standard MCP patterns.
Component Interaction
Database Architecture
The system uses two databases:
Program Database (
program_db
):Stores program information
Used by Eligibility Server
Includes FAISS index for semantic search
Grievance Database (
grievance_db.sqlite
):Stores user memberships
Tracks complaints and tickets
Used by Grievance Server
Eligibility Server
The Eligibility Server is responsible for helping users find relevant social benefit programs and assess their eligibility.
Architecture
Key Components
1. Database Connection
Uses aiosqlite
for async database operations:
2. FAISS Integration
Semantic search using FAISS and HuggingFace embeddings:
3. Tools
extract_user_details
Extracts user profile information from queries:
search_programs
Finds relevant programs using semantic search:
analyze_eligibility
Assesses eligibility for specific programs:
4. Prompts
eligibility_response
Formats eligibility results for user presentation:
5. Resources
program_eligibility_resource
Provides eligibility information for specific programs:
Data Models
UserProfile
ProgramInfo
EligibilityAnalysis
Grievance Server
The Grievance Server handles user complaints, ticket creation, and status tracking.
Architecture
Key Components
1. Tools
identify_user_id
Checks if query contains a valid USER ID:
verify_user
Verifies user credentials and retrieves information:
process_complaint
Analyzes complaints for completeness:
create_ticket
Creates support tickets for complaints:
check_status
Checks program enrollment or ticket status:
2. Prompts
user_verification_response: Formats successful verification
verification_failed_response: Handles failed verification
ticket_creation_response: Confirms ticket creation
status_check_response: Presents status information
3. Resources
user_status_resource: Provides user status information
ticket_details_resource: Returns ticket details
Data Models
UserDetails
ComplaintAnalysis
MCP Client
The MCP Client serves as the central orchestrator, connecting to Ollama LLM and routing queries to appropriate MCP servers.
Architecture
The client implements the MCP protocol to communicate with FastMCP servers:
Key Features
1. Ollama Integration
Direct integration with Ollama for LLM capabilities:
2. Intent Analysis
Determines which subsystem to use:
3. Server Connection
Establishes SSE connections to MCP servers:
4. Query Processing
Routes queries based on intent:
5. Tool Calling
Uses MCP protocol to call server tools:
Conversation Management
The client maintains conversation history with Ollama:
Last updated
Was this helpful?