Skip to content

Commit 6abf721

Browse files
feat: use dotenv to import environment variables in application
2 parents 5652a26 + 5dbc3d1 commit 6abf721

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ npm ci
4141
npm run build
4242
```
4343

44-
These commands will install all the dependencies and then transpile the typescript code in the `build` folder.
44+
These commands will install all the dependencies and then transpile the typescript code in the `build` folder.
45+
46+
> [!NOTE]
47+
> The server automatically loads environment variables from a `.env` file if present in the project root.
48+
> You can create one by copying `default.env` to `.env` and updating the values as needed.
49+
4550
Once these steps are completed you can setup the MCP server using the `node` command like the following:
4651

4752
```json
@@ -66,6 +71,9 @@ Once these steps are completed you can setup the MCP server using the `node` com
6671
}
6772
```
6873

74+
> [!TIP]
75+
> If you have a `.env` file configured with your credentials, you can omit the `env` section from the configuration above as the server will automatically load the environment variables.
76+
6977
## Local Development
7078

7179
To help with the development of the server you need Node.js installed on your machine.
@@ -78,7 +86,7 @@ following command:
7886
npm ci
7987
```
8088

81-
Once has finished you will have all the dependencies installed on the project, then you have to prepare an environent
89+
Once has finished you will have all the dependencies installed on the project, then you have to prepare an environment
8290
file by copying the default.env file and edit it accordingly.
8391

8492
```sh
@@ -88,7 +96,6 @@ cp default.env .env
8896
Finally to verify everything works, run:
8997

9098
```sh
91-
set -a && source .env
9299
npm run local:test
93100
```
94101

package-lock.json

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"commander": "^14.0.0",
3636
"fastify": "^5.5.0",
3737
"undici": "^7.15.0",
38+
"dotenv": "^17.2.2",
3839
"zod": "^3.25.76"
3940
},
4041
"devDependencies": {
@@ -48,4 +49,4 @@
4849
"typescript": "^5.9.2",
4950
"typescript-eslint": "^8.42.0"
5051
}
51-
}
52+
}

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { httpServer } from './server/httpserver'
2121
import { runStdioServer } from './server/stdio'
2222
import { description, version } from '../package.json'
2323

24+
import 'dotenv/config'
25+
2426
const program = new Command()
2527

2628
program.
@@ -33,7 +35,7 @@ program.
3335
description('start the Mia-Platform Console MCP Server').
3436
option('--stdio', 'run the server in stdio mode (default when using npx)', false).
3537
option('--server-host <serverHost>', 'host to expose the server on', '0.0.0.0').
36-
addOption(new Option('-p, --port <port>', 'port to run the server on').default('3000').env('HTTP_PORT')).
38+
addOption(new Option('-p, --port <port>', 'port to run the server on').env('HTTP_PORT').default('3000')).
3739
addOption(new Option('--host <host>', 'Mia-Platform Console host').env('CONSOLE_HOST')).
3840
action(({ host, stdio, port, serverHost }) => {
3941
const clientID = process.env.MIA_PLATFORM_CLIENT_ID || ''

0 commit comments

Comments
 (0)