diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..bfeb18e --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +# Appwrite Configuration +# Copy this file to .env in your current working directory and fill in your values + +# Your Appwrite Project ID +APPWRITE_PROJECT_ID=your-project-id-here + +# Your Appwrite API Endpoint (e.g., https://cloud.appwrite.io/v1 or your self-hosted URL) +APPWRITE_API_ENDPOINT=https://cloud.appwrite.io/v1 + +# Your Appwrite API Key (Server API Key with required permissions) +APPWRITE_API_KEY=your-api-key-here \ No newline at end of file diff --git a/.gitignore b/.gitignore index 56d9c34..ca780fa 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,7 @@ yarn-error.log* dist/ build/ -# Environment and config files -appwrite-config.json +# Environment and config files .env .env.local .env.development.local diff --git a/README.md b/README.md index e2d56ca..e309906 100644 --- a/README.md +++ b/README.md @@ -37,23 +37,21 @@ npm install npm run build ``` -4. Configure your Appwrite credentials by creating `appwrite-config.json` in your **current working directory** (where you run Claude Code from), not in the cloned repository: +4. Configure your Appwrite credentials by creating a `.env` file in your **current working directory** (where you run Claude Code from): ```bash -# Copy the template to your current working directory -cp /path/to/app-write-mcp/appwrite-config.json.template ./appwrite-config.json +# Copy the example file to your current working directory +cp /path/to/app-write-mcp/.env.example ./.env ``` -5. Edit the `appwrite-config.json` file in your current directory with your Appwrite project details: -```json -{ - "projectId": "your-project-id", - "apiEndpoint": "https://cloud.appwrite.io/v1", - "apiKey": "your-api-key" -} +5. Edit the `.env` file in your current directory with your Appwrite project details: +```bash +APPWRITE_PROJECT_ID=your-project-id +APPWRITE_API_ENDPOINT=https://cloud.appwrite.io/v1 +APPWRITE_API_KEY=your-api-key ``` -**Important:** The MCP server looks for `appwrite-config.json` in the directory where Claude Code is currently running, not in the repository directory. This allows you to use different configurations for different projects without modifying the repository. +**Important:** The MCP server looks for `.env` in the directory where Claude Code is currently running, not in the repository directory. This allows you to use different configurations for different projects without modifying the repository. ## Adding to Claude Code diff --git a/appwrite-config.json.template b/appwrite-config.json.template deleted file mode 100644 index 5607edf..0000000 --- a/appwrite-config.json.template +++ /dev/null @@ -1,5 +0,0 @@ -{ - "projectId": "YOUR_PROJECT_ID_HERE", - "apiEndpoint": "YOUR_API_ENDPOINT_HERE", - "apiKey": "YOUR_API_KEY_HERE" -} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 61dfb79..7ea4307 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "@modelcontextprotocol/sdk": "^1.0.0", + "dotenv": "^17.2.1", "node-appwrite": "^14.0.0" }, "devDependencies": { @@ -229,6 +230,18 @@ "node": ">= 0.8" } }, + "node_modules/dotenv": { + "version": "17.2.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.1.tgz", + "integrity": "sha512-kQhDYKZecqnM0fCnzI5eIv5L4cAe/iRI+HqMbO/hbRdTAeXDG+M9FjipUxNfbARuEg4iHIbhnhs78BCHNbSxEQ==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", diff --git a/package.json b/package.json index bc6ffe7..916539c 100644 --- a/package.json +++ b/package.json @@ -9,15 +9,21 @@ "start": "node dist/index.js", "dev": "tsc --watch" }, - "keywords": ["mcp", "appwrite", "claude", "model-context-protocol"], + "keywords": [ + "mcp", + "appwrite", + "claude", + "model-context-protocol" + ], "author": "", "license": "MIT", "dependencies": { "@modelcontextprotocol/sdk": "^1.0.0", + "dotenv": "^17.2.1", "node-appwrite": "^14.0.0" }, "devDependencies": { "@types/node": "^22.0.0", "typescript": "^5.6.0" } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 1c42b53..ec115e3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,6 +23,7 @@ import { } from "node-appwrite"; import { readFileSync, existsSync } from "fs"; import { join } from "path"; +import * as dotenv from "dotenv"; interface AppwriteConfig { projectId: string; @@ -58,25 +59,25 @@ class AppwriteMCPServer { } private loadConfig(): void { - const configPath = join(process.cwd(), "appwrite-config.json"); + // Load environment variables from .env file in current working directory + dotenv.config({ path: join(process.cwd(), '.env') }); - if (!existsSync(configPath)) { - console.error("Appwrite configuration file not found. Please create appwrite-config.json"); + const projectId = process.env.APPWRITE_PROJECT_ID; + const apiEndpoint = process.env.APPWRITE_API_ENDPOINT; + const apiKey = process.env.APPWRITE_API_KEY; + + if (!projectId || !apiEndpoint || !apiKey) { + console.error("Appwrite configuration missing. Please create a .env file with APPWRITE_PROJECT_ID, APPWRITE_API_ENDPOINT, and APPWRITE_API_KEY"); return; } - try { - const configData = readFileSync(configPath, "utf-8"); - this.config = JSON.parse(configData); - - if (!this.config?.projectId || !this.config?.apiEndpoint || !this.config?.apiKey) { - throw new Error("Missing required configuration fields"); - } + this.config = { + projectId, + apiEndpoint, + apiKey + }; - this.initializeAppwrite(); - } catch (error) { - console.error("Error loading Appwrite configuration:", error); - } + this.initializeAppwrite(); } private initializeAppwrite(): void {