Skip to content

Commit 9972cf2

Browse files
John-Linclaude
andcommitted
Make MCP config optional with fallback default
Allow the bot to start without servers_config.json by returning a default empty config instead of raising FileNotFoundError. Remove dummy_servers_config.json and its COPY from Dockerfile. Add HTTP MCP example to README. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2e6e553 commit 9972cf2

5 files changed

Lines changed: 46 additions & 15 deletions

File tree

Dockerfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
88
COPY . /app
99
WORKDIR /app
1010

11-
# Provide empty MCP config as default; mount your own at runtime:
12-
# docker run -v /path/to/servers_config.json:/app/servers_config.json ...
13-
COPY dummy_servers_config.json /app/servers_config.json
14-
1511
# Sync the project into a new environment, asserting the lockfile is up to date
1612
RUN uv sync --locked
1713

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ Optional HTTP proxy for outbound requests:
6565
export HTTP_PROXY=""
6666
```
6767

68-
## MCP Server Configuration
68+
## MCP Server Configuration (Optional)
6969

70-
Edit `servers_config.json` to add your MCP servers:
70+
Create a `servers_config.json` file to add your MCP servers. If this file is not provided, the bot starts with no MCP servers configured.
7171

7272
```json
7373
{
@@ -81,6 +81,21 @@ Edit `servers_config.json` to add your MCP servers:
8181
}
8282
```
8383

84+
For HTTP-based MCP servers (Streamable HTTP), use `httpUrl`:
85+
86+
```json
87+
{
88+
"mcpServers": {
89+
"my-server": {
90+
"httpUrl": "https://mcp.example.com/mcp",
91+
"headers": {
92+
"Accept": "application/json, text/event-stream"
93+
}
94+
}
95+
}
96+
}
97+
```
98+
8499
For local MCP servers, use `uv --directory`:
85100

86101
```json
@@ -106,6 +121,18 @@ uv run bot
106121
```bash
107122
docker build -t agentic-slackbot .
108123

124+
docker run -d \
125+
--name slackbot \
126+
-e SLACK_BOT_TOKEN="" \
127+
-e SLACK_APP_TOKEN="" \
128+
-e OPENAI_API_KEY="" \
129+
-e OPENAI_MODEL="gpt-4.1" \
130+
agentic-slackbot
131+
```
132+
133+
To use MCP servers, mount your config file:
134+
135+
```bash
109136
docker run -d \
110137
--name slackbot \
111138
-e SLACK_BOT_TOKEN="" \

bot/config.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import json
2+
import logging
23
import os
34
from typing import Any
45

56
from dotenv import find_dotenv
67
from dotenv import load_dotenv
78

9+
logger = logging.getLogger(__name__)
10+
811

912
class Configuration:
1013
"""Manages configuration and environment variables for the MCP Slackbot."""
@@ -22,19 +25,27 @@ def load_env() -> None:
2225
"""Load environment variables from .env file."""
2326
load_dotenv(find_dotenv())
2427

28+
_DEFAULT_CONFIG: dict[str, Any] = {"mcpServers": {}}
29+
2530
@staticmethod
2631
def load_config(file_path: str) -> dict[str, Any]:
2732
"""Load server configuration from JSON file.
2833
34+
Returns a default empty config when the file does not exist,
35+
allowing the application to start without a config file.
36+
2937
Args:
3038
file_path: Path to the JSON configuration file.
3139
3240
Returns:
3341
Dict containing server configuration.
3442
3543
Raises:
36-
FileNotFoundError: If configuration file doesn't exist.
3744
JSONDecodeError: If configuration file is invalid JSON.
3845
"""
39-
with open(file_path) as f:
40-
return json.load(f)
46+
try:
47+
with open(file_path) as f:
48+
return json.load(f)
49+
except FileNotFoundError:
50+
logger.warning("Config file %s not found, using default empty config", file_path)
51+
return dict(Configuration._DEFAULT_CONFIG)

dummy_servers_config.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/test_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ def test_loads_valid_json(self, tmp_path):
5555
result = Configuration.load_config(str(config_file))
5656
assert result == config_data
5757

58-
def test_raises_on_missing_file(self):
59-
with pytest.raises(FileNotFoundError):
60-
Configuration.load_config("/nonexistent/config.json")
58+
def test_returns_default_on_missing_file(self):
59+
result = Configuration.load_config("/nonexistent/config.json")
60+
assert result == {"mcpServers": {}}
6161

6262
def test_raises_on_invalid_json(self, tmp_path):
6363
config_file = tmp_path / "bad.json"

0 commit comments

Comments
 (0)