MCP_USDA_Server_Quantized
If you are the rightful owner of MCP_USDA_Server_Quantized and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A modular MCP server template for fetching and formatting agricultural data from the USDA Foreign Agricultural Service (FAS) Production, Supply and Distribution (PSD) database.
MCP USDA Server
A modular MCP (Model Control Protocol) server template for fetching and formatting agricultural data from the USDA Foreign Agricultural Service (FAS) Production, Supply and Distribution (PSD) database.
๐พ Overview
This project serves as a template for creating Model Control Protocol (MCP) servers that expose agricultural data tools to Large Language Models (LLMs). It demonstrates how to fetch data from the USDA FAS API, process it, and present it in a format that's optimized for LLM consumption.
The server implements a modular architecture that makes it easy to:
- Add new data sources and tools
- Format complex data for LLM consumption
- Create anti-hallucination guardrails
- Connect to an MCP client that aggregates tools from multiple servers
๐ Architecture
This project implements a client-server architecture using the MCP (Model Control Protocol) approach:
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ โ โ โ โ โ
โ LLM โโโโโโบโ MCP Client โโโโโโบโ MCP Servers โ
โ โ โ โ โ โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
Core Components:
-
MCP Client:
- Aggregates tools from multiple MCP servers
- Provides a unified interface for the LLM to access all tools
- Routes tool calls to the appropriate server based on the tool name
-
MCP USDA Server:
- Implements specialized tools for USDA agricultural data
- Handles the API calls, data processing, and formatting
- Returns data in a format optimized for LLM consumption
-
Communication Protocol:
- Uses JSON-RPC 2.0 for standardized client-server communication
- Supports tool listing, tool metadata, and tool execution requests
๐งฐ Available Tools
This server implements five USDA data tools:
- usda-psd-regions: Get region data from the USDA FAS PSD database
- usda-psd-countries: Get country data with region associations
- usda-psd-commodities: Get agricultural commodity definitions
- usda-psd-units-of-measure: Get units of measure for agricultural quantities
- usda-psd-commodity-attributes: Get commodity attributes (production, supply, distribution)
Each tool is designed to fetch data from the USDA API, filter it based on user queries, and format it into markdown that's optimized for LLM consumption.
๐ Project Structure
The project follows a modular architecture:
MCP_USDA_Server/
โโโ src/
โ โโโ tools/ # Core implementation of each tool
โ โโโ handlers/ # Request handlers for each tool
โ โโโ formatters/ # Format tool results for LLM consumption
โ โโโ routers/ # Route requests to the appropriate handler
โ โโโ utils/ # Utility functions
โ โโโ server.js # Main server entry point
โโโ Architecture.md # Detailed architecture documentation
โโโ package.json # Dependencies and scripts
Key Files:
- src/server.js: Main entry point that starts the HTTP server and initializes the request processor
- src/tools/registry.js: Central registry of all available tools with metadata
- src/routers/toolRouter.js: Routes tool-related requests to the appropriate handler
- src/tools/psd.js*: Implementation of USDA PSD data fetching for different endpoints
- src/formatters/psd*Formatter.js: Formats API results into markdown for LLM consumption
- src/handlers/psd*Handler.js: Handles incoming requests for each tool
๐ JSON-RPC Communication
The server communicates with the MCP client using JSON-RPC 2.0:
Examples:
1. Tool Listing Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}
2. Tool Execution Request:
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/execute",
"params": {
"name": "usda-psd-regions",
"args": {
"query": "asia"
}
}
}
โ๏ธ LLM Integration
This server is designed to be LLM-agnostic, meaning it can work with any LLM that supports either:
- Function/Tool Calling: For LLMs that have native function calling capabilities (e.g., OpenAI's GPT-4, Anthropic's Claude 3, Google's Gemini)
- Instruction Following: For LLMs that can follow structured instructions about available tools
The system works best with LLMs that have:
- Function/tool calling capabilities
- Ability to parse and generate structured data
- Contextual understanding of agricultural data
๐ Getting Started
Prerequisites:
- Node.js (v14+)
- npm or yarn
Installation:
- Clone this repository:
git clone https://github.com/yourusername/MCP_USDA_Server.git
cd MCP_USDA_Server
- Install dependencies:
npm install
- Start the server:
npm start
The server will start on port 3100 by default (configurable in .env).
Connecting with MCP Client:
The server is designed to work with an MCP client that aggregates tools from multiple servers. See the companion MCP_WebAgent_Client repository for implementation details.
๐ง Extending the Server
Adding a New Tool:
- Create a new tool implementation in
src/tools/
- Create a formatter in
src/formatters/
- Create a handler in
src/handlers/
- Register the tool in
src/tools/registry.js
- Update the router in
src/routers/toolRouter.js
See the existing tools for implementation examples.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgements
- USDA Foreign Agricultural Service for providing the PSD API
- The open-source community for inspiration and examples of modular architecture
Created as a template for building MCP servers that expose domain-specific data to LLMs.