A Model Context Protocol (MCP) server that provides access to the FatSecret nutrition database API with full 3-Legged OAuth authentication support.
- Complete OAuth 1.0a Implementation: Full 3-legged OAuth flow for user authentication
- Food Database Access: Search and retrieve detailed nutrition information
- Recipe Database: Search for recipes and get detailed cooking instructions
- User Data Management: Access user food diaries, weight tracking, and add entries
- Secure Credential Storage: Encrypted storage of API credentials and tokens
The following features require OAuth 2.0 authentication which is not yet supported:
foods.autocompleteβ Food name autocomplete suggestionsfood.find_id_for_barcodeβ Barcode scanning lookup
- Node.js (v14 or higher)
- npm or yarn
- A FatSecret developer account
# Clone the repository
git clone https://github.com/astartsky/fatsecret-mcp.git
cd fatsecret-mcp
# Install dependencies
npm install
# Build the TypeScript
npm run build- Visit the FatSecret Platform
- Create a developer account and register your application
- Note down your Client ID and Client Secret
The server needs to be configured in your MCP client (like Claude Desktop). Add this to your MCP configuration:
{
"mcpServers": {
"fatsecret": {
"command": "node",
"args": ["path/to/fatsecret-mcp-server/dist/index.js"]
}
}
}The easiest way to authenticate is using the included OAuth console utility:
# Make sure you've built the project first
npm run build
# Run the OAuth console utility
node dist/cli.jsThis interactive utility will:
- Ask for your Client ID and Client Secret
- Save them securely in
~/.fatsecret-mcp-config.json - Guide you through the OAuth flow:
- Opens your browser to the FatSecret authorization page
- Prompts you to paste the verifier code after authorization
- Saves the access tokens for future use
If you prefer to authenticate through the MCP interface (e.g., in Claude):
-
Set your API credentials:
Use tool: set_credentials Parameters: - clientId: "your_client_id_here" - clientSecret: "your_client_secret_here" -
Start the OAuth flow:
Use tool: start_oauth_flow Parameters: - callbackUrl: "oob" (for out-of-band authentication) -
Visit the authorization URL provided in the response:
- Log in to your FatSecret account (or create one)
- Click "Allow" to authorize the application
- Copy the verifier code shown on the page
-
Complete the OAuth flow:
Use tool: complete_oauth_flow Parameters: - requestToken: [from step 2 response] - requestTokenSecret: [from step 2 response] - verifier: [the code you copied from the authorization page]
You can also provide credentials via environment variables:
# Create a .env file in the project root
CLIENT_ID=your_client_id_here
CLIENT_SECRET=your_client_secret_here
# The server will automatically load these on startupNote: You'll still need to complete the OAuth flow for user-specific operations.
First, set your FatSecret API credentials:
Use the set_credentials tool with your Client ID and Client Secret
For user-specific operations, you need to complete the OAuth flow:
1. Use start_oauth_flow tool (with callback URL or "oob" for out-of-band)
2. Visit the provided authorization URL
3. Authorize the application and get the verifier code
4. Use complete_oauth_flow tool with the request token, secret, and verifier
Once authenticated, you can use all available tools:
search_foods: Search for foods in the databaseget_food: Get detailed nutrition information for a specific food
search_recipes: Search for recipesget_recipe: Get detailed recipe information including ingredients and instructions
get_user_profile: Get the authenticated user's profileget_user_food_entries: Get food diary entries for a specific dateadd_food_entry: Add a food entry to the user's diary
check_auth_status: Check current authentication status
Set your FatSecret API credentials.
Parameters:
clientId(string, required): Your FatSecret Client IDclientSecret(string, required): Your FatSecret Client Secret
Start the 3-legged OAuth flow.
Parameters:
callbackUrl(string, optional): OAuth callback URL (default: "oob")
Complete the OAuth flow with authorization.
Parameters:
requestToken(string, required): Request token from start_oauth_flowrequestTokenSecret(string, required): Request token secret from start_oauth_flowverifier(string, required): OAuth verifier from authorization
Check current authentication status.
Search for foods in the FatSecret database.
Parameters:
searchExpression(string, required): Search termpageNumber(number, optional): Page number (default: 0)maxResults(number, optional): Max results per page (default: 20)
Get detailed information about a specific food.
Parameters:
foodId(string, required): FatSecret food ID
Search for recipes in the FatSecret database.
Parameters:
searchExpression(string, required): Search termpageNumber(number, optional): Page number (default: 0)maxResults(number, optional): Max results per page (default: 20)
Get detailed information about a specific recipe.
Parameters:
recipeId(string, required): FatSecret recipe ID
Get the authenticated user's profile information.
Get user's food diary entries for a specific date.
Parameters:
date(string, optional): Date in YYYY-MM-DD format (default: today)
Add a food entry to the user's diary.
Parameters:
foodId(string, required): FatSecret food IDfoodName(string, required): Name/description of the food itemservingId(string, required): Serving ID for the foodquantity(number, required): Quantity of the servingmealType(string, required): Meal type (breakfast, lunch, dinner, other)date(string, optional): Date in YYYY-MM-DD format (default: today)
Edit an existing food diary entry.
Parameters:
foodEntryId(string, required): The food entry ID to editfoodName(string, optional): New name/descriptionservingId(string, optional): New serving IDquantity(number, optional): New quantitymealType(string, optional): New meal type (breakfast, lunch, dinner, other)
Delete a food diary entry.
Parameters:
foodEntryId(string, required): The food entry ID to delete
Get summary of user's food diary entries for a month.
Parameters:
date(string, optional): Date in YYYY-MM-DD format to specify the month (default: current month)
Get user's weight entries for a specific month.
Parameters:
date(string, optional): Date in YYYY-MM-DD format to specify the month (default: current month)
Add or update a weight entry.
Parameters:
currentWeightKg(number, required): Current weight in kilogramsdate(string, optional): Date in YYYY-MM-DD format (default: today)goalWeightKg(number, optional): Goal weight in kilogramscomment(string, optional): Optional comment for the weight entry
-
Setup Credentials:
Tool: set_credentials - clientId: "your_client_id" - clientSecret: "your_client_secret" -
Search for Foods:
Tool: search_foods - searchExpression: "chicken breast" -
Get Food Details:
Tool: get_food - foodId: "12345" -
Authenticate User (if needed):
Tool: start_oauth_flow - callbackUrl: "oob" # Follow the authorization URL, then: Tool: complete_oauth_flow - requestToken: "from_start_oauth_flow" - requestTokenSecret: "from_start_oauth_flow" - verifier: "from_authorization_page" -
Add Food to Diary:
Tool: add_food_entry - foodId: "12345" - servingId: "67890" - quantity: 1 - mealType: "lunch"
The server stores configuration (credentials and tokens) in ~/.fatsecret-mcp-config.json. This file contains:
- API credentials (Client ID and Secret)
- OAuth access tokens (when authenticated)
- User ID (when authenticated)
- Credentials are stored locally in your home directory
- OAuth tokens are securely managed using proper HMAC-SHA1 signing
- All API communications use HTTPS
- The server implements proper OAuth 1.0a security measures
This server implements the FatSecret Platform API. For detailed API documentation, visit:
The server provides detailed error messages for common issues:
- Missing or invalid credentials
- OAuth flow errors
- API rate limiting
- Network connectivity issues
- Invalid parameters
Unit tests use mocked HTTP requests and don't require API credentials.
npm test # Watch mode
npm run test:run # Single run
npm run test:coverage # With coverage reportTest structure:
src/__tests__/
βββ oauth/ # OAuth signature and request tests
βββ utils/ # Utility functions (encoding, date)
βββ methods/ # API method tests
βββ schemas/ # Zod validation schema tests
βββ integration/ # Integration tests (real API)
βββ client.test.ts # FatSecret client tests
Integration tests call the real FatSecret API and verify actual responses.
Setup credentials:
Create a .env file in the project root:
# Required for public API methods (foods, recipes)
FATSECRET_CLIENT_ID=your_client_id
FATSECRET_CLIENT_SECRET=your_client_secret
# Required for authenticated methods (profile, diary, weight)
FATSECRET_ACCESS_TOKEN=user_access_token
FATSECRET_ACCESS_TOKEN_SECRET=user_access_token_secretRun integration tests:
npm run test:integrationTest coverage:
| Module | Methods | Tests |
|---|---|---|
| Foods | searchFoods, getFood |
9 |
| Recipes | searchRecipes, getRecipe |
11 |
| Profile | getProfile |
5 |
| Diary | getFoodEntries, createFoodEntry, editFoodEntry, deleteFoodEntry, getFoodEntriesMonth |
16 |
| Weight | getWeightMonth, updateWeight |
12 |
Notes:
- Tests are automatically skipped when credentials are not available
createFoodEntrytests create real entries in your FatSecret diary- Integration tests have a 30-second timeout for API calls
- Restart Claude Desktop after configuring the MCP server
- Look for "fatsecret" in the available tools
- Start by using
check_auth_statusto verify the connection
- The FatSecret API expects dates as days since epoch (1970-01-01)
- The server automatically converts YYYY-MM-DD format dates
- If you get this error, ensure you're using the latest version
- Verify your Client ID and Client Secret are correct
- Ensure you're using the correct URLs (authentication.fatsecret.com for OAuth)
- Check that you're copying the entire verifier code from the authorization page
- Ensure the path in your MCP configuration is absolute, not relative
- Verify the server was built successfully (
npm run build) - Check Claude's logs for any error messages
- Complete the OAuth flow using either the CLI utility or MCP tools
- Check authentication status with
check_auth_statustool - Tokens are saved in
~/.fatsecret-mcp-config.json
To modify or extend the server:
# Install dependencies
npm install
# Build and run
npm run build
npm start
# Development mode with auto-rebuild
npm run devfatsecret-mcp/
βββ src/
β βββ index.ts # Main MCP server implementation
β βββ cli.ts # OAuth console utility
β βββ client.ts # FatSecret API client
β βββ methods/ # API method implementations
β βββ oauth/ # OAuth 1.0a implementation
β βββ schemas/ # Zod validation schemas
β βββ utils/ # Utility functions
β βββ __tests__/ # Unit and integration tests
βββ dist/ # Compiled JavaScript files
βββ package.json
βββ tsconfig.json
βββ README.md
Originally created by Felipe Coury. Now maintained by Dmitry Sinev.
MIT License - see LICENSE file for details.