-
Notifications
You must be signed in to change notification settings - Fork 2
Code Mode
Value Proposition Empower autonomous agent capabilities by orchestrating complex, multi-step database operations within a unified, high-performance execution context. Significantly reduce network latency and maximize token efficiency. Read the full value proposition.
// Get all tables and their row counts in one call
const tables = await mysql.core.listTables();
const results = [];
for (const t of tables.tables) {
const count = await mysql.core.readQuery(
`SELECT COUNT(*) as n FROM \`${t.name}\``,
);
results.push({ table: t.name, rows: count.rows[0].n });
}
return results;The mysql object exposes all other tool groups via the API. Use mysql.help() in Code Mode. This lists all available tools and categories:
| Group | Methods | Example |
|---|---|---|
mysql.core |
includes methods like readQuery, writeQuery, listTables, etc. |
mysql.core.readQuery("SELECT 1") |
mysql.json |
includes JSON-specific methods | mysql.json.extract(...) |
Tool names strip prefixes and convert to camelCase. A key exception exists:
- Core tools map to
mysql.core - Non-core tool groups map to their respective namespace.
| Tool Name | API Call | Alias |
|---|---|---|
mysql_read_query |
mysql.core.readQuery(query) |
- |
mysql_check_version |
mysql.core.checkVersion() |
- |
mysql_json_extract |
mysql.json.extract(args) |
- |
Common tools accept positional arguments for convenience:
// These are equivalent:
await mysql.core.readQuery("SELECT * FROM users");
await mysql.core.readQuery({ query: "SELECT * FROM users" });// Full API overview
mysql.help();
// Group-specific help with examples
mysql.core.help();Note: The complete Code Mode API reference is available to agents dynamically. Gotchas and tool parameter aliases are also included. Access these via the
mysql://helpandmysql://help/[group]resources.
The server automatically injects TypeScript definitions. This enables rich IntelliSense and validation. You write type-safe code validated before execution. Dynamic types enforce tool filters.
Agents can dynamically introspect the database schema during Code Mode execution. Use this to discover tables, columns, and relationships. Do this before constructing complex queries:
// Discover schema dynamically
const schema = await mysql.core.listTables();
const tableDetails = await mysql.core.describeTable(schema.tables[0].name);
// Alternatively, query INFORMATION_SCHEMA directly
const keys = await mysql.core.readQuery(`
SELECT COLUMN_NAME, REFERENCED_TABLE_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE TABLE_NAME = '${schema.tables[0].name}'
`);Code Mode replaces multiple sequential tool calls with one execution:
| Approach | Tool Calls | Typical Tokens |
|---|---|---|
| Individual tools | Multiple sequential calls | Baseline usage |
| Code Mode | Unified execution | Substantial token savings |
Tip
Maximize Token Savings: Instruct your AI agent to prefer Code Mode over individual tool calls:
"When using mysql-mcp, prefer mysql_execute_code for multi-step database operations. This choice minimizes token usage."
For maximum savings, use --tool-filter codemode to run Code Mode exclusively. See configuration details below.
MCP clients automatically receive server instructions during initialization. Your client might lack native MCP instruction support. If so, point your agents to the Tools wiki page. This ensures optimal Code Mode usage.
Telemetry Note: When using HTTP transport and the
--metrics-exportflag, metrics are exported via the Prometheus/metricsendpoint. This includes token usage, execution times, and sandbox telemetry.
The system automatically includes Code Mode in curated presets. When filtering by individual tool groups, Code Mode must be added explicitly.
You can run with only Code Mode enabled. This single tool provides access to an extensive suite of capabilities. It uses the mysql.* API:
{
"mcpServers": {
"mysql-mcp": {
"command": "npx",
"args": [
"-y",
"@neverinfamous/mysql-mcp",
"--transport",
"stdio",
"--tool-filter",
"codemode"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_user",
"MYSQL_PASSWORD": "your_password",
"MYSQL_DATABASE": "your_database",
"CODEMODE_MAX_RESULT_SIZE": "102400"
}
}
}
}This streamlines the interface by exposing exclusively the mysql_execute_code capability. Agents seamlessly write JavaScript against our strictly typed mysql.* SDK, delivering exactly the required data in a single execution.
- Tool Filtering — Presets and custom tool filtering
- Tools — Complete tool list
- Configuration — MCP client configuration
Value Proposition Enforce strict execution boundaries and maximize LLM context efficiency for secure, autonomous database interactions. Read the full value proposition
- Installation
- Configuration
- Architecture
- HTTP Transport
- Tool Filtering
- Code Mode
- Tools
- Prompts
- Resources
- Observability & Telemetry