Create custom MCP server to Query MySQL - without code
Hoshang Mehta
Create custom MCP server to Query MySQL - without code
MySQL powers a huge portion of the web, from legacy enterprise applications to modern microservices and e-commerce platforms like Magento or WooCommerce. But giving AI agents access to this operational data is risky. You can't just hand over a database password to an LLM.
Traditionally, building a secure API layer for your MySQL database would require spinning up a new backend service, managing connection pools, and writing boilerplate code for every new query you want to expose.
Pylar changes this.
This guide shows you how to use Pylar to build a secure, custom MCP (Model Context Protocol) server for MySQL in under 2 minutes—without writing a single line of code.
Why Pylar for MySQL?
Pylar acts as a secure gateway between your MySQL database and your AI agents.
- No Backend Code: Stop writing Node.js or Python wrappers just to run a
SELECTquery. - Sandboxed Views: Expose only specific tables or columns (e.g.,
inventory_count) while hiding sensitive data (e.g.,cost_price). - Connection Management: Pylar handles the connection pooling and keep-alives for you.
Step-by-Step Walkthrough
Step 1: Connect MySQL to Pylar
- Prepare your User: Create a dedicated MySQL user for Pylar with
SELECTpermissions only.CREATE USER 'pylar_reader'@'%' IDENTIFIED BY 'secure_password'; GRANT SELECT ON my_database.* TO 'pylar_reader'@'%'; - In Pylar, go to Connections -> MySQL.
- Enter your Host, Port (default 3306), Database Name, Username, and Password.
- Naming Rule: Use lowercase letters and underscores (e.g.,
ecommerce_prod).
- Naming Rule: Use lowercase letters and underscores (e.g.,

- Whitelist IP: You MUST whitelist Pylar's IP (
34.122.205.142) in your server's firewall (iptables, AWS Security Group, etc.). Pylar will test the connection and index your schema metadata.
Step 2: Create a Sandboxed View
Let's say you want an agent to check product inventory, but you don't want it to see supplier pricing.
In Pylar's SQL IDE, create a view:
-- view: check_inventory
SELECT
sku,
product_name,
stock_quantity,
category,
is_active
FROM products
WHERE is_active = 1

This view is a secure window. The agent can only see these columns.
Step 3: Auto-Build the MCP Tool
- Select your view (
check_inventory) in the right sidebar. - Click "Create MCP Tool" and choose "Create with AI".
- Type a prompt: "Create a tool that checks stock levels by SKU or product name."
- Pylar generates the tool configuration:
- Name:
check_product_stock - Description: "Retrieves current stock quantity for a product given its SKU or name."
- Parameters:
sku(string),product_name(string)
- Name:

Step 4: Publish & Connect
- Click "Publish" in the right sidebar.
- Click "Generate Token".
- Copy your MCP HTTP Stream URL (
https://mcp.publish.pylar.ai/mcp) and Authorization Bearer Token.

Connect to n8n: You can now use this tool in an n8n workflow to automate inventory checks.
- Use the HTTP Request node.
- Method: POST.
- URL:
https://api.pylar.ai/mcp/v1/server/YOUR_SERVER_ID/tools/call. - Header:
Authorization: Bearer YOUR_TOKEN. - Body:
{"name": "check_product_stock", "arguments": {"sku": "WIDGET-123"}}.
Advanced Use Cases for MySQL Agents
1. E-commerce Customer Support
Goal: Allow a support bot to check order status without accessing the full order history or payment details.
- View: Join
orderswithorder_itemsandshipping_status. - Tool Prompt: "Create a tool that gets the shipping status and tracking number for an order ID."
- User Query: "Where is my order #998877?"
2. Legacy App Modernization
Goal: Build a modern chat interface on top of a 10-year-old legacy MySQL database without rewriting the backend.
- View: Expose key business entities like
clientsorprojects. - Tool Prompt: "Create a tool that searches for clients by name."
- User Query: "Show me the contact details for Client X."
Conclusion
MySQL powers millions of applications worldwide, from legacy enterprise systems to modern web applications. But as you add AI features, you need a way to give agents secure access to your MySQL data without compromising security or spending weeks building custom APIs.
With Pylar, you can transform your MySQL database into an AI-ready data source in under 2 minutes—no coding required. By connecting Pylar to your MySQL instance (or a read replica for production safety), creating sandboxed views that protect sensitive data, and auto-generating MCP tools with natural language, you bridge the gap between traditional relational databases and modern AI agents.
Whether you're building a modern chat interface on top of legacy data, creating an internal operations assistant, or enabling AI-powered customer support, Pylar gives you the governance layer you need. Your views act as security boundaries, and with support for AWS RDS, Google Cloud SQL, and other managed MySQL services, you can securely connect any MySQL database.
Stop building custom gatekeepers. Start unlocking your MySQL data for AI today.
