Skip to content

Add .env file support for local development #69

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database
```

## Local Development with .env Files
For local development, you can use a .env file instead of setting environment variables manually:

Copy .env.example to .env:
``` bash
cp .env.example .env

# Edit .env with your database credentials:
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database
```
The server will automatically load these variables when starting


Note: The .env file is for local development convenience. In production or when using Smithery, continue to use environment variables as documented above.

## Usage
### With Claude Desktop
Add this to your `claude_desktop_config.json`:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mcp>=1.0.0
mysql-connector-python>=9.1.0
python-dotenv>=1.0.0
8 changes: 8 additions & 0 deletions src/mysql_mcp_server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database
MYSQL_CHARSET=utf8mb4
MYSQL_COLLATION=utf8mb4_unicode_ci
MYSQL_SQL_MODE=TRADITIONAL
3 changes: 3 additions & 0 deletions src/mysql_mcp_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from mcp.server import Server
from mcp.types import Resource, Tool, TextContent
from pydantic import AnyUrl
from dotenv import load_dotenv

load_dotenv()

# Configure logging
logging.basicConfig(
Expand Down