Skip to content

MCP Integration Guide

Model Context Protocol (MCP) enables the agent to execute external tools. This is optional - the agent works without it.

MCP provides tool execution via JSON-RPC 2.0:

  • External tools: Search products, get purchase history, fetch web pages
  • Server-side execution: Tools run on MCP server, not locally
  • Authentication: Requires auth token from AWS Secrets Manager

When enabled, the agent can call 6 tools for shopping assistance.

  • AWS CLI configured with SSO access
  • Access to rover-mcp/auth-tokens in AWS Secrets Manager
  • MCP server URL (stage or prod)
  1. Get auth token from AWS:
Terminal window
# Login to AWS SSO
aws sso login --profile stage-services-admin
# Retrieve token
aws secretsmanager get-secret-value \
--secret-id rover-mcp/auth-tokens \
--profile stage-services-admin \
--query SecretString \
--output text
  1. Add token to .env:
Terminal window
# Copy example file if needed
cp .env.example .env
# Edit .env and add:
ROVER_MCP_AUTHORIZATION=your-token-from-aws
  1. Verify MCP config in settings.yaml:
rover_mcp:
server_url: https://stage-partners-gateway.fetchrewards.com/rover-mcp
timeout: 90.0
  1. Test connection:
Terminal window
# Direct server test
curl -H "Authorization: Bearer $ROVER_MCP_AUTHORIZATION" \
https://stage-partners-gateway.fetchrewards.com/rover-mcp/health

Expected response: {"status": "ok"}

The agent has access to 6 MCP tools:

Search for products by description.

Input:

{
"descriptions": ["Mountain Dew", "eggs", "organic milk"]
}

Use case: Find specific products or categories.

Search for available offers.

Input:

{
"query": "summer treats",
"user_id": "user123",
"limit": 200
}

Use case: Find relevant offers for a user.

Search for offers near a location.

Input:

{
"user_id": "user123",
"latitude": 37.7749,
"longitude": -122.4194,
"query": "coffee drinks"
}

Use case: Find offers at nearby stores.

Get user’s past purchases with optional filtering.

Input:

{
"user_id": "user123",
"start_time": "2024-01-01T00:00:00Z", # optional, RFC3339, defaults to 90 days ago
"end_time": "2024-12-31T23:59:59Z", # optional, RFC3339, defaults to now
"category": "snacks", # optional, natural language filter
"brand": "coca cola" # optional, natural language filter
}

Use case: Understand user preferences and shopping patterns. Supports semantic search for category/brand filtering.

Fetch and parse a webpage.

Input:

{
"url": "https://example.com",
"depth": 0 # 0-2, prevents crawling
}

Use case: Extract content from web pages.

Submit feedback about tools.

Input:

{
"message": "User wanted to search by brand"
}

Use case: Report feature requests or missing capabilities.

Pass MCP config when creating the agent:

from consumer_agent.agent import Agent
from consumer_agent.factory import create_chat_model
from consumer_agent.utils.tools import build_mcp_tools
from consumer_agent.config import settings
# Build tools if MCP is configured
tools = []
if settings.rover_mcp.server_url and settings.rover_mcp.authorization:
tools = build_mcp_tools(
server_url=settings.rover_mcp.server_url,
auth_token=settings.rover_mcp.authorization,
timeout=settings.rover_mcp.timeout
)
# Create agent with tools
model = create_chat_model()
agent = Agent(model, tools=tools)

MCP is automatically enabled if ROVER_MCP_AUTHORIZATION is set:

# From src/consumer_agent/api/main.py
# Tools are created via factory.create_agent_from_config()
# which checks settings.rover_mcp configuration
agent = create_agent_from_config(agent_id="conversational")

Each tool is a LangChain BaseTool wrapper (src/consumer_agent/utils/tools.py) that provides:

  • Provider-agnostic: Works with any LLM, not just OpenAI
  • Type safety: Pydantic schemas validate inputs
  • Error handling: Catches and logs errors gracefully
  • Async: Non-blocking tool execution

JSON-RPC 2.0 client for server communication (src/consumer_agent/utils/mcp_client.py). Handles tool calls and tool listing.

Features:

  • Auto-formats auth header (adds “Bearer” prefix)
  • Constructs MCP endpoint URL (adds “/mcp” suffix)
  • Handles JSON-RPC errors
  • Logs all requests/responses
from consumer_agent.agent import Agent
from consumer_agent.factory import create_chat_model
from consumer_agent.utils.tools import build_mcp_tools
from consumer_agent.config import settings
# Setup
tools = build_mcp_tools(
settings.rover_mcp.server_url,
settings.rover_mcp.authorization,
settings.rover_mcp.timeout
)
model = create_chat_model()
agent = Agent(model, tools=tools)
# Use agent
messages = [{"role": "user", "content": "Find offers for coffee"}]
system_prompt = "You are a shopping assistant."
async for event in agent.stream(messages, system_prompt):
if isinstance(event, ToolCallStartEvent):
print(f"Calling: {event.tool_name}")
elif isinstance(event, TextEvent):
print(event.content)
from consumer_agent.utils.mcp_client import MCPClient
from consumer_agent.config import settings
client = MCPClient(
settings.rover_mcp.server_url,
settings.rover_mcp.authorization,
settings.rover_mcp.timeout
)
# List tools from server
tools = await client.list_tools()
for tool in tools:
print(f"- {tool['name']}: {tool['description']}")
from consumer_agent.utils.mcp_client import MCPClient
client = MCPClient(server_url, auth_token, timeout=90.0)
# Search for products
result = await client.call_tool(
"search_products",
{"descriptions": ["coffee", "milk"]}
)
print(result)

Error: ROVER_MCP_AUTHORIZATION environment variable not found

Section titled “Error: ROVER_MCP_AUTHORIZATION environment variable not found”

MCP is optional. This is not an error if you don’t need tools.

To enable MCP:

  1. Get auth token from AWS Secrets Manager (see setup checklist)
  2. Add to .env: ROVER_MCP_AUTHORIZATION=your-token

Auth token is invalid or expired.

Fix:

  1. Retrieve fresh token from AWS Secrets Manager
  2. Update .env with new token
  3. Restart application

MCP server did not respond within timeout.

Fix:

# Increase timeout in settings.yaml
rover_mcp:
timeout: 120.0 # Increase from 90

Check MCP server status:

Terminal window
curl -H "Authorization: Bearer $ROVER_MCP_AUTHORIZATION" \
https://stage-partners-gateway.fetchrewards.com/rover-mcp/health

If server is down, contact infrastructure team.

Possible causes:

  1. Tools not bound: Verify tools passed to agent constructor
  2. System prompt: Prompt may discourage tool use
  3. Model limitations: Some models prefer not to use tools

Debug:

# Check if tools are loaded
print(f"Agent has {len(agent._tools)} tools")
for tool in agent._tools:
print(f" - {tool.name}")

ImportError: No module named 'consumer_agent.utils.tools'

Section titled “ImportError: No module named 'consumer_agent.utils.tools'”

Dependencies not installed or virtual environment not activated.

Fix:

Terminal window
uv sync
source .venv/bin/activate

To run without MCP:

  1. Remove from .env:
Terminal window
# Delete or comment out:
# ROVER_MCP_AUTHORIZATION=...
  1. Agent still works:
# Without ROVER_MCP_AUTHORIZATION, no tools are loaded
agent = create_agent_from_config(agent_id="conversational")
# Agent has no tools but operates normally using LLM knowledge

The agent operates normally without tools, using only its knowledge.