#!/usr/bin/env python3
"""
Example of connecting Stevia Store MCP Server to OpenAI Agents SDK
"""
import os
from openai_agents import Agent
from openai_agents.mcp import MCPServerStdio
async def main():
"""Main function to demonstrate OpenAI + MCP integration"""
# Set your OpenAI API key
os.environ["OPENAI_API_KEY"] = "your-openai-api-key-here"
# Create MCP server connection to our Stevia Store server
stevia_mcp_server = MCPServerStdio(
command="python",
args=["../src/stevia_store_server.py"],
env={
"DATABASE_PATH": "../stevia_store.db"
}
)
# Create OpenAI agent with MCP server
agent = Agent(
model="gpt-4", # or gpt-3.5-turbo
name="Stevia Store Assistant",
instructions="""
You are a helpful assistant for Organital's stevia store.
You can help customers with:
- Finding and recommending stevia products
- Managing inventory and stock levels
- Processing orders and customer information
- Providing health and usage information about stevia
Always be friendly, informative, and focus on natural health benefits.
When discussing prices, use ₪ (shekel) currency symbol.
Respond in Hebrew when appropriate for Israeli customers.
""",
mcp_servers=[stevia_mcp_server]
)
# Example interactions
print("🌿 Stevia Store Assistant with OpenAI + MCP")
print("=" * 50)
# Example 1: Get products
print("\n📦 Getting product catalog...")
response1 = await agent.run("Show me all available stevia products with their prices")
print(f"Assistant: {response1.content}")
# Example 2: Add a customer
print("\n👥 Adding a new customer...")
response2 = await agent.run(
"Add a new customer named 'Sarah Cohen' with email 'sarah@example.com' "
"and phone '050-1234567' from Tel Aviv"
)
print(f"Assistant: {response2.content}")
# Example 3: Check inventory
print("\n⚠️ Checking inventory alerts...")
response3 = await agent.run("Check if any products are running low on stock")
print(f"Assistant: {response3.content}")
# Example 4: Health consultation
print("\n💚 Health consultation...")
response4 = await agent.run(
"A customer asks: 'Is stevia safe for diabetics and how much should I use?'"
)
print(f"Assistant: {response4.content}")
if __name__ == "__main__":
import asyncio
asyncio.run(main())