
mcp
一个基于 TypeScript 的服务器,用于通过 MCP 协议与 MySQL 数据库交互。
Repository Info
About This Server
一个基于 TypeScript 的服务器,用于通过 MCP 协议与 MySQL 数据库交互。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
MCP Server
A TypeScript-based server for interacting with MySQL databases using the Model Context Protocol (MCP). Provides tools to list tables, retrieve table schemas, and execute queries.
Tools
mysql-list-tables:- Description: Retrieves a list of all tables in the database.
- Input:
{}(optional) or no arguments.
mysql-get-table-info:- Description: Returns the schema (via
SHOW CREATE TABLE) and up to 3 sample rows for a specified table. - Input:
{ "table": "string" }- The table name.
- Description: Returns the schema (via
mysql-execute-query:- Description: Executes a
SELECTquery to retrieve data, anINSERTquery to add data, anUPDATEquery to modify data, or aDELETEquery to remove data, returning the results or affected rows. - Input:
{ "query": "string" }- TheSELECT,INSERT,UPDATE, orDELETEquery. - Note: Only
SELECT,INSERT,UPDATE, andDELETEqueries are permitted for safety;DROPqueries are blocked.
- Description: Executes a
Integration
Node.js
To integrate with a Node.js-based MCP client: cursor, windsurf, claud
{
"mcpServers": {
"mcp": {
"command": "npx",
"args": ["-y", "@syntaxtrash/mcp"],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "<your-username>",
"MYSQL_PASSWORD": "<your-password>",
"MYSQL_DATABASE": "<your-database>"
}
}
}
}
- Update
<your-username>,<your-password>, and<your-database>with your MySQL credentials.
Docker
-
Build the Image:
docker build -t mcp-server:latest . -
Configure in
mcp_config.json:{ "mcpServers": { "mcp": { "command": "docker", "args": [ "run", "--rm", "-i", "-e", "MYSQL_HOST", "-e", "MYSQL_USER", "-e", "MYSQL_PASSWORD", "-e", "MYSQL_DATABASE", "mcp-server:latest" ], "env": { "MYSQL_HOST": "host.docker.internal", "MYSQL_PORT": "3306", "MYSQL_USER": "<your-username>", "MYSQL_PASSWORD": "<your-password>", "MYSQL_DATABASE": "<your-database>" } } } }- Use
host.docker.internalfor MySQL on the host machine (Docker Desktop). - Substitute
<your-username>,<your-password>, and<your-database>with your MySQL credentials.
- Use
Development
Prerequisites
- Node.js 20+
- MySQL 8.0+
- npm 10+
- Docker 27+ (optional, for containerized deployment)
Setup
-
Clone and Install:
git clone <repository-url> cd mcp-main npm install -
Configure Environment: Create a
.envfile in the project root:MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USER=root MYSQL_PASSWORD=<your-password> MYSQL_DATABASE=<your-database> -
Build:
npm run build -
Test Locally:
npm run dev # Watch mode for development
Project Structure
mcp-main/
├── dist/ # Compiled JavaScript output
│ ├── common/ # Shared utilities and types
│ ├── operations/ # MySQL operations
│ └── index.js # Server entry point
├── src/ # TypeScript source files
├── .eslintrc.json # ESLint configuration
├── .gitignore # Git ignore settings
├── Dockerfile # Docker configuration
├── package.json # Dependencies and scripts
└── tsconfig.json # TypeScript configuration
Security Configuration
MySQL
Create a MySQL user with appropriate privileges instead of using the root account:
-
Log in to MySQL as Root:
mysql -u root -p -
Create the User:
CREATE USER 'mcp_user'@'localhost' IDENTIFIED BY 'secure_password'; -
Grant Privileges:
GRANT SELECT, INSERT, UPDATE, DELETE ON your_database.* TO 'mcp_user'@'localhost'; FLUSH PRIVILEGES; -
Verify Permissions:
SHOW GRANTS FOR 'mcp_user'@'localhost'; -
Update Configuration: Use these credentials in your
.envor MCP client config:MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USER=mcp_user MYSQL_PASSWORD=secure_password # Optional; omit if no password is set MYSQL_DATABASE=your_database
- Replace
your_databasewith your target database name. - For Docker, use
host.docker.internalinstead oflocalhostif MySQL runs on the host.
Quick Start
Clone the repository
git clone https://github.com/syntaxtrash/mcpInstall dependencies
cd mcp
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.