Skip to content

Commit 10f489a

Browse files
Phil Whittakerclaude
andcommitted
Add .env file support for MCP server configuration
- Centralize configuration management in new config.ts module - Load environment variables from .env file (default) or custom path via --env flag - Support CLI argument overrides for all configuration options (--umbraco-*) - Track configuration sources (CLI vs ENV) for transparency - Add comprehensive validation and error reporting for missing credentials - Update documentation with .env usage examples and .mcp.json configuration - Refactor tests to use centralized config system - Remove deprecated env.ts helper - Improve multi-culture document test with proper setup and cleanup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent febda2b commit 10f489a

File tree

20 files changed

+886
-152
lines changed

20 files changed

+886
-152
lines changed

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,34 @@ claude mcp list
8080

8181
This will add umbraco-mcp to the existing project in the claude.json config file.
8282

83+
#### Configuration via .mcp.json (Project-specific)
84+
85+
For project-specific Claude Code configuration, create a `.mcp.json` file in your project root that references environment variables for sensitive data:
86+
87+
```json
88+
{
89+
"mcpServers": {
90+
"umbraco-mcp": {
91+
"command": "npx",
92+
"args": ["@umbraco-cms/mcp-dev@beta"],
93+
"env": {
94+
"NODE_TLS_REJECT_UNAUTHORIZED": "0",
95+
"UMBRACO_CLIENT_ID": "umbraco-back-office-mcp",
96+
"UMBRACO_CLIENT_SECRET": "your-client-secret-here",
97+
"UMBRACO_BASE_URL": "https://localhost:44391",
98+
"UMBRACO_INCLUDE_TOOL_COLLECTIONS": "culture,document,media",
99+
"UMBRACO_EXCLUDE_TOOLS": "delete-document,empty-recycle-bin"
100+
}
101+
}
102+
}
103+
}
104+
```
105+
106+
Using the `.mcp.json` file allows you to:
107+
- Configure MCP servers per project
108+
- Share configuration with team members (commit to version control)
109+
- Override global Claude Code MCP settings for specific projects
110+
- Move the environment varaibles to a .env file to prevent leaking of secrets to your code repo
83111

84112
</details>
85113

@@ -142,6 +170,7 @@ Add the following to the config file and update the env variables.
142170
```
143171
</details>
144172

173+
145174
#### Authentication Configuration Keys
146175

147176
- `UMBRACO_CLIENT_ID`
@@ -156,6 +185,40 @@ Umbraco API User client secert
156185

157186
Url of the Umbraco site, it only needs to be the scheme and domain e.g https://<nolink/>example.com
158187

188+
### Environment Configuration Options
189+
190+
The Umbraco MCP server supports environment configuration via:
191+
1. **Environment variables in MCP client config as above** (Claude Desktop, VS Code, etc.)
192+
2. **Local `.env` file** for development (see `.env.example`)
193+
3. **CLI arguments** when running directly
194+
195+
**Configuration precedence:** CLI arguments > Environment variables > `.env` file
196+
197+
#### Using a `.env` file (Development)
198+
199+
For local development, you can create a `.env` file in the project root:
200+
201+
```bash
202+
# Edit with your values
203+
UMBRACO_CLIENT_ID=your-api-user-id
204+
UMBRACO_CLIENT_SECRET=your-api-secret
205+
UMBRACO_BASE_URL=http://localhost:56472
206+
```
207+
208+
The `.env` file is gitignored to keep your secrets secure.
209+
210+
#### CLI Arguments
211+
212+
You can also pass configuration via CLI arguments:
213+
214+
```bash
215+
npx @umbraco-cms/mcp-dev@beta \
216+
--umbraco-client-id="your-id" \
217+
--umbraco-client-secret="your-secret" \
218+
--umbraco-base-url="http://localhost:56472" \
219+
--env="/path/to/custom/.env"
220+
```
221+
159222
## API Coverage
160223

161224
This MCP server provides **comprehensive coverage** of the Umbraco Management API. We have achieved **full parity** with all applicable endpoints, implementing tools for every operational endpoint suitable for AI-assisted content management.

docs/tool-collection-filtering.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ Some collections have dependencies that are automatically resolved:
8989

9090
### Configuration Loading
9191

92-
Configuration is loaded from environment variables with automatic parsing:
92+
Configuration is loaded from the server config object:
9393

9494
```typescript
9595
export class CollectionConfigLoader {
96-
static loadFromEnv(): CollectionConfiguration {
96+
static loadFromConfig(config: UmbracoServerConfig): CollectionConfiguration {
9797
return {
98-
enabledCollections: env.UMBRACO_INCLUDE_TOOL_COLLECTIONS ?? DEFAULT_COLLECTION_CONFIG.enabledCollections,
99-
disabledCollections: env.UMBRACO_EXCLUDE_TOOL_COLLECTIONS ?? DEFAULT_COLLECTION_CONFIG.disabledCollections,
100-
enabledTools: env.UMBRACO_INCLUDE_TOOLS ?? DEFAULT_COLLECTION_CONFIG.enabledTools,
101-
disabledTools: env.UMBRACO_EXCLUDE_TOOLS ?? DEFAULT_COLLECTION_CONFIG.disabledTools,
98+
enabledCollections: config.includeToolCollections ?? DEFAULT_COLLECTION_CONFIG.enabledCollections,
99+
disabledCollections: config.excludeToolCollections ?? DEFAULT_COLLECTION_CONFIG.disabledCollections,
100+
enabledTools: config.includeTools ?? DEFAULT_COLLECTION_CONFIG.enabledTools,
101+
disabledTools: config.excludeTools ?? DEFAULT_COLLECTION_CONFIG.disabledTools,
102102
};
103103
}
104104
}
@@ -108,7 +108,7 @@ export class CollectionConfigLoader {
108108

109109
The `UmbracoToolFactory` processes configuration and loads tools:
110110

111-
1. Load configuration from environment variables
111+
1. Load configuration from server config
112112
2. Validate collection names and dependencies
113113
3. Resolve collection dependencies automatically
114114
4. Filter collections based on configuration

jest.setup.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
import dotenv from 'dotenv';
2+
import { initializeUmbracoAxios } from './src/orval/client/umbraco-axios.js';
23

3-
// Load environment variables from .env.test
4-
dotenv.config({ path: '.env' });
4+
// Load environment variables from .env
5+
dotenv.config({ path: '.env' });
6+
7+
// Initialize Umbraco Axios client with environment variables
8+
initializeUmbracoAxios({
9+
clientId: process.env.UMBRACO_CLIENT_ID || '',
10+
clientSecret: process.env.UMBRACO_CLIENT_SECRET || '',
11+
baseUrl: process.env.UMBRACO_BASE_URL || ''
12+
});

0 commit comments

Comments
 (0)