-
Notifications
You must be signed in to change notification settings - Fork 21
Add store-db MCP server with lazy database connection management #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
skattoju
wants to merge
3
commits into
rh-ai-quickstart:main
Choose a base branch
from
skattoju:store_db
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Containerfile for MCP Store Server (Direct DB Access) | ||
|
|
||
| FROM registry.access.redhat.com/ubi9/python-311:latest | ||
|
|
||
| # Add metadata labels for better container management | ||
| LABEL org.opencontainers.image.title="MCP DBStore Server" | ||
| LABEL org.opencontainers.image.description="FastMCP server providing database-backed product inventory tools" | ||
| LABEL org.opencontainers.image.version="0.0.1" | ||
| LABEL org.opencontainers.image.source="https://github.com/yourusername/ai-virtual-assistant" | ||
| LABEL org.opencontainers.image.documentation="https://github.com/yourusername/ai-virtual-assistant/tree/main/mcpservers/mcp_dbstore" | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # UBI Python images already have curl-minimal which is sufficient for health checks | ||
| # No need to install additional packages | ||
|
|
||
| # Copy the source code from the src directory | ||
| # Build context is mcp-servers/store_db/ | ||
| COPY ./src /app/mcp_dbstore | ||
|
|
||
| # Install Python dependencies | ||
| RUN pip install --no-cache-dir -r /app/mcp_dbstore/requirements.txt | ||
|
|
||
| # Environment variables with defaults | ||
| # Main database connection URL - should be overridden at runtime | ||
| ENV DATABASE_URL="postgresql+asyncpg://mcpuser:mcppassword@postgres-service:5432/store_db" | ||
|
|
||
| # Ensures Python can find the mcp_dbstore package from the /app directory | ||
| ENV PYTHONPATH=/app | ||
|
|
||
| # Additional environment variables for configuration | ||
| ENV MCP_SERVER_PORT=8002 | ||
| ENV MCP_SERVER_HOST=0.0.0.0 | ||
| ENV MCP_SERVER_TRANSPORT=sse | ||
|
|
||
| # UBI Python images run as non-root by default | ||
|
|
||
| # Expose the correct port that matches store.py | ||
| EXPOSE 8002 | ||
|
|
||
| # Health check to ensure the server is running properly | ||
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | ||
| CMD curl -f http://localhost:8002/healthz || exit 1 | ||
|
|
||
| # Command to run the MCP server | ||
| CMD ["python", "-m", "mcp_dbstore.store"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| # MCP DBStore | ||
|
|
||
| [](https://opensource.org/licenses/MIT) | ||
| [](https://www.python.org/downloads/) | ||
| [](https://modelcontextprotocol.io/) | ||
|
|
||
| A **Model Context Protocol (MCP) server** that provides AI agents with intelligent access to inventory management systems. Built with FastMCP and PostgreSQL, MCP DBStore enables LLMs to answer questions about product availability, pricing, and inventory levels through natural language interactions. | ||
|
|
||
| ## 🎯 What is MCP DBStore? | ||
|
|
||
| MCP DBStore transforms your product inventory into an AI-accessible knowledge base. Instead of requiring users to learn complex database queries or inventory management systems, they can simply ask questions like: | ||
|
|
||
| - *"What products do we have in stock?"* | ||
| - *"How much does the Super Widget cost?"* | ||
| - *"Do we have any quantum related products available?"* | ||
| - *"Place an order for 5 Mega Gadgets for customer John Smith"* | ||
|
|
||
| The server provides 7 specialized tools that handle everything from browsing the product catalog to processing orders and updating inventory levels. | ||
|
|
||
| ## 🚀 Quick Start | ||
|
|
||
| ### Prerequisites | ||
| - Kubernetes cluster with Helm 3.2+ | ||
| - `kubectl` configured | ||
|
|
||
| ### Deploy in Minutes | ||
| ```bash | ||
| # Clone the repository | ||
| git clone https://github.com/rh-ai-kickstart/ai-architecture-charts.git | ||
| cd ai-architecture-charts/mcp-servers | ||
|
|
||
| # Deploy with Helm | ||
| helm install mcp-dbstore ./store_db/helm/mcp-dbstore | ||
|
|
||
| # Wait for deployment (2-3 minutes) | ||
| kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=mcp-dbstore --timeout=300s | ||
| ``` | ||
|
|
||
| ### Test Your Deployment | ||
| ```bash | ||
| # Port forward to access the server | ||
| kubectl port-forward svc/mcp-dbstore-mcp-server 8002:8002 & | ||
|
|
||
| # Install MCP inspector for testing | ||
| pip install mcp-inspector | ||
|
|
||
| # Test the server | ||
| mcp-inspector http://localhost:8002 | ||
| ``` | ||
|
|
||
| ## 🛠️ Available Tools | ||
|
|
||
| MCP DBStore provides 7 specialized tools for inventory management: | ||
|
|
||
| | Tool | Purpose | Example Use | | ||
| |------|---------|-------------| | ||
| | `get_products` | Browse entire product catalog | "Show me all available products" | | ||
| | `get_product_by_id` | Get specific product details | "What's the price of product ID 123?" | | ||
| | `search_products` | Find products by name/description | "Find all quantum-related products" | | ||
| | `add_product` | Create new inventory items | "Add a new product called 'Smart Speaker'" | | ||
| | `remove_product` | Delete products from catalog | "Remove the discontinued product" | | ||
| | `order_product` | Process orders & update inventory | "Order 5 widgets for customer Alice" | | ||
| | `get_product_by_name` | Exact product name lookup | "Get details for 'Super Widget'" | | ||
|
|
||
| ## 🔗 Integration Examples | ||
|
|
||
| ### With LlamaStack | ||
| ```bash | ||
| # Register the MCP server | ||
| curl -X POST localhost:8321/v1/toolgroups \ | ||
| -H "Content-Type: application/json" \ | ||
| --data '{ | ||
| "provider_id": "model-context-protocol", | ||
| "toolgroup_id": "mcp::dbstore", | ||
| "mcp_endpoint": { | ||
| "uri": "http://mcp-dbstore-mcp-server.default.svc.cluster.local:8002/sse" | ||
| } | ||
| }' | ||
| ``` | ||
|
|
||
| ### Direct API Usage | ||
| ```python | ||
| import aiohttp | ||
|
|
||
| async def get_product_info(): | ||
| async with aiohttp.ClientSession() as session: | ||
| # Get all products | ||
| async with session.post("http://localhost:8002/tools/get_products") as resp: | ||
| products = await resp.json() | ||
|
|
||
| # Search for specific products | ||
| async with session.post( | ||
| "http://localhost:8002/tools/search_products", | ||
| json={"query": "widget"} | ||
| ) as resp: | ||
| results = await resp.json() | ||
| ``` | ||
|
|
||
| ## 📊 Sample Data | ||
|
|
||
| The deployment includes 10 sample products to get you started: | ||
| - **Super Widget** - $29.99 (100 units) | ||
| - **Mega Gadget** - $79.50 (50 units) | ||
| - **Quantum Sprocket** - $199.00 (30 units) | ||
| - And 7 more products with varying prices and inventory levels | ||
|
|
||
| ## 🏗️ Architecture | ||
|
|
||
| ``` | ||
| ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐ | ||
| │ LLM Agent │ │ MCP DBStore │ │ PostgreSQL │ | ||
| │ │ │ Server │ │ Database │ | ||
| │ - Natural │◄──►│ - FastMCP │◄──►│ - Products │ | ||
| │ Language │ │ - SQLAlchemy │ │ - Orders │ | ||
| │ - Tool Calls │ │ - Async Tools │ │ - ACID │ | ||
| └─────────────────┘ └──────────────────┘ └─────────────────┘ | ||
| ``` | ||
|
|
||
| **Technology Stack:** | ||
| - **Protocol**: Model Context Protocol (MCP) | ||
| - **Framework**: FastMCP for high-performance async MCP servers | ||
| - **Database**: PostgreSQL 15 with SQLAlchemy async ORM | ||
| - **Container**: Docker with Kubernetes deployment | ||
| - **Package Manager**: Helm charts for easy deployment | ||
|
|
||
| ## 📚 Documentation | ||
|
|
||
| - **[Quick Start Guide](docs/mcp-dbstore-quickstart.md)** - Detailed deployment and testing instructions | ||
| - **[Developer Guide](docs/mcp-dbstore-developer-guide.md)** - Architecture, patterns, and best practices | ||
| - **[Developer Reference](docs/mcp-dbstore-developer-reference.md)** - Concise reference for extending the server | ||
| - **[Helm Chart README](../../deploy/helm/mcp-dbstore/README.md)** - Deployment configuration options | ||
|
|
||
| ## 🤝 Contributing | ||
|
|
||
| We welcome contributions! Here's how you can help: | ||
|
|
||
| ### Development Setup | ||
| ```bash | ||
| # Clone and setup development environment | ||
| git clone https://github.com/rh-ai-kickstart/ai-architecture-charts.git | ||
| cd ai-architecture-charts/mcp-servers/store_db/src | ||
|
|
||
| # Create virtual environment | ||
| python3.10 -m venv venv | ||
| source venv/bin/activate | ||
|
|
||
| # Install dependencies | ||
| pip install -r requirements.txt | ||
|
|
||
| # Set up local PostgreSQL | ||
| docker run --name dev-postgres \ | ||
| -e POSTGRES_USER=mcpuser \ | ||
| -e POSTGRES_PASSWORD=mcppassword \ | ||
| -e POSTGRES_DB=store_db \ | ||
| -p 5432:5432 \ | ||
| -d postgres:15-alpine | ||
|
|
||
| # Run the server | ||
| python -m mcpservers.mcp_dbstore.store | ||
| ``` | ||
|
|
||
| ### Areas for Contribution | ||
| - **New Tools**: Add domain-specific inventory management tools | ||
| - **Enhanced Analytics**: Create tools for inventory insights and reporting | ||
| - **Performance**: Optimize database queries and connection pooling | ||
| - **Security**: Implement authentication and authorization | ||
| - **Testing**: Add comprehensive test coverage | ||
| - **Documentation**: Improve guides and examples | ||
|
|
||
| ### Getting Started | ||
| 1. Fork the repository | ||
| 2. Create a feature branch (`git checkout -b feature/amazing-feature`) | ||
| 3. Make your changes | ||
| 4. Add tests for new functionality | ||
| 5. Commit your changes (`git commit -m 'Add amazing feature'`) | ||
| 6. Push to the branch (`git push origin feature/amazing-feature`) | ||
| 7. Open a Pull Request | ||
|
|
||
| ## 📄 License | ||
|
|
||
| This project is licensed under the MIT License - see the [LICENSE](../../LICENSE) file for details. | ||
|
|
||
| ## 🙏 Acknowledgments | ||
|
|
||
| - [Model Context Protocol](https://modelcontextprotocol.io/) for the standardized agent-tool communication | ||
| - [FastMCP](https://github.com/jlowin/fastmcp) for the high-performance MCP server framework | ||
| - [LlamaStack](https://github.com/meta-llama/llama-stack) for AI agent orchestration | ||
| - The open source community for inspiration and collaboration | ||
|
|
||
| ## 🔗 Related Projects | ||
|
|
||
| - [AI Virtual Assistant](https://github.com/yourusername/ai-virtual-assistant) - Main project repository | ||
| - [MCP Inspector](https://github.com/modelcontextprotocol/inspector) - Tool for testing MCP servers | ||
| - [LlamaStack](https://github.com/meta-llama/llama-stack) - AI agent framework | ||
|
|
||
| --- | ||
|
|
||
| **Made with ❤️ for the open source community** | ||
|
|
||
| Questions? Issues? Ideas? [Open an issue](https://github.com/rh-ai-kickstart/ai-architecture-charts/issues) or join our discussions! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| apiVersion: v2 | ||
| name: mcp-dbstore | ||
| description: A Helm chart for deploying MCP DBStore server with PostgreSQL database | ||
| type: application | ||
| version: 0.1.0 | ||
| appVersion: "0.0.1" | ||
| keywords: | ||
| - mcp | ||
| - model-context-protocol | ||
| - database | ||
| - fastmcp | ||
| - llama-stack | ||
| home: https://github.com/rh-ai-kickstart/ai-architecture-charts | ||
| sources: | ||
| - https://github.com/rh-ai-kickstart/ai-architecture-charts/tree/main/mcp-servers/store_db | ||
| maintainers: | ||
| - name: AI Architecture Team | ||
| email: team@ai-architecture | ||
| annotations: | ||
| category: AI/ML Tools | ||
| dependencies: [] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skattoju do we still need this? we don't have subcharts under mcp-servers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not exactly a sub chart but a chart by itself. This is to pick up mcp-servers that are not included in the mcp-servers helm chart. The reason for not including it was because it has additional components other than service and deployment like secrets, configmaps and pvcs etc.
I figured it would be simpler to add it as a standalone chart instead of adding templates to the mcp-server helm chart but it would mean that it would have to be manually installed or added as an additional dependency to a project that wants to include this "non standard" mcp server.
We could add some logic to handle additional templates as well but it would require some re-testing compared to just referring to the known working helm chart. I am curious to know the case against just adding new mcp-server charts as dependencies to the main mcp-server chart ? Wouldn't it effectively be the same where consumers can enable or disable charts they need in the values file ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you're saying - so you're not deploying an mcp server only, you're deploying a full blown app. It relates to my other question about deploying postgres by default.
The mcp-servers chart deploys mcp servers only, it should be simple like you said, an image with a service etc. I think we need to break this to 2 things - one is an mcp server that will be deployed through this chart and another is the app that the mcp server interacts with. If this is an AI building block, it can be in the toplevel directory of the project, and the mcp server can be under mcp-servers, something like that, wdyt? @skattoju @sauagarwa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the MCP server is kind of an app in its current state. The requirement was to have an example MCP server that interacts with a database. In its current state it will not run without postgres.
There is also an "API version" where the MCP server and the app are separate. I could repackage using that. However, it seems a bit awkward to include the app in the architecture charts repository since it's not exactly AI related.
May be we can include the app portion in AI virtual assistant ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuvalturg I have factored out the mcp part and left the rest to be in ai virtual assistant till we come up with a dedicated place for mcp server if that is something we want to do