Skip to content

Commit 1a73a1f

Browse files
authored
Update environment variable for HOST & PORT, Add version cli command (#40)
* Update environment variable names for HOST & PORT - Changed environment variable from FASTMCP_PORT to MCP_PORT in server, Dockerfile and README.md. * Add version information to the MCP server - Implemented version option in mcp_server.py for the couchbase-mcp-server package. - Added a command to check the server version in README.md. * Refactor transport handling in MCP server - Updated environment variable names for transport and query mode to include new prefixes while marking old ones as deprecated. - Introduced a mapping from user-friendly transport names to SDK transport names for improved compatibility. - Adjusted the server configuration to utilize the new transport mapping when running the server. * Update README.md to reflect new environment variable naming conventions - Changed `READ_ONLY_QUERY_MODE` to `CB_MCP_READ_ONLY_QUERY_MODE` for consistency. - Updated `MCP_TRANSPORT`, `MCP_HOST`, and `MCP_PORT` to `CB_MCP_TRANSPORT`, `CB_MCP_HOST`, and `CB_MCP_PORT` respectively. * Update environment variable names in Dockerfile for consistency with recent changes - Changed `READ_ONLY_QUERY_MODE`, `MCP_TRANSPORT`, and `MCP_PORT` to `CB_MCP_READ_ONLY_QUERY_MODE`, `CB_MCP_TRANSPORT`, and `CB_MCP_PORT` respectively to align with updated naming conventions. * Update README.md to reflect new environment variable naming conventions and fix typos - Changed `READ_ONLY_QUERY_MODE` to `CB_MCP_READ_ONLY_QUERY_MODE` for consistency with recent updates. - Corrected the description of `CB_MCP_PORT` to specify its applicability in HTTP transport modes as `http` and `sse`.
1 parent 2130846 commit 1a73a1f

File tree

5 files changed

+64
-33
lines changed

5 files changed

+64
-33
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ RUN chown -R mcpuser:mcpuser /app /opt/venv
3939
USER mcpuser
4040

4141
# Environment variables with defaults
42-
ENV READ_ONLY_QUERY_MODE="true" \
43-
MCP_TRANSPORT="stdio" \
44-
FASTMCP_PORT="8000"
42+
ENV CB_MCP_READ_ONLY_QUERY_MODE="true" \
43+
CB_MCP_TRANSPORT="stdio" \
44+
CB_MCP_PORT="8000"
4545

4646
# Expose default port for SSE mode
4747
EXPOSE 8000

README.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
An [MCP](https://modelcontextprotocol.io/) server implementation of Couchbase that allows LLMs to directly interact with Couchbase clusters.
44

5-
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/) [![PyPI version](https://badge.fury.io/py/couchbase-mcp-server.svg)](https://pypi.org/project/couchbase-mcp-server/) [![Verified on MseeP](https://mseep.ai/badge.svg)](https://mseep.ai/app/13fce476-0e74-4b1e-ab82-1df2a3204809) [![smithery badge](https://smithery.ai/badge/@Couchbase-Ecosystem/mcp-server-couchbase)](https://smithery.ai/server/@Couchbase-Ecosystem/mcp-server-couchbase)
5+
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/) [![PyPI version](https://badge.fury.io/py/couchbase-mcp-server.svg)](https://pypi.org/project/couchbase-mcp-server/) [![Verified on MseeP](https://mseep.ai/badge.svg)](https://mseep.ai/app/13fce476-0e74-4b1e-ab82-1df2a3204809)
66

77
<a href="https://glama.ai/mcp/servers/@Couchbase-Ecosystem/mcp-server-couchbase">
88
<img width="380" height="200" src="https://glama.ai/mcp/servers/@Couchbase-Ecosystem/mcp-server-couchbase/badge" alt="Couchbase Server MCP server" />
@@ -16,7 +16,7 @@ An [MCP](https://modelcontextprotocol.io/) server implementation of Couchbase th
1616
- Upsert a document by ID to a specified scope and collection
1717
- Delete a document by ID from a specified scope and collection
1818
- Run a [SQL++ query](https://www.couchbase.com/sqlplusplus/) on a specified scope
19-
- There is an option in the MCP server, `READ_ONLY_QUERY_MODE` that is set to true by default to disable running SQL++ queries that change the data or the underlying collection structure. Note that the documents can still be updated by ID.
19+
- There is an option in the MCP server, `CB_MCP_READ_ONLY_QUERY_MODE` that is set to true by default to disable running SQL++ queries that change the data or the underlying collection structure. Note that the documents can still be updated by ID.
2020
- Get the status of the MCP server
2121
- Check the cluster credentials by connecting to the cluster
2222

@@ -100,16 +100,22 @@ This is the common configuration for the MCP clients such as Claude Desktop, Cur
100100

101101
The server can be configured using environment variables or command line arguments:
102102

103-
| Environment Variable | CLI Argument | Description | Default |
104-
| ---------------------- | ------------------------ | ------------------------------------------------- | ------------ |
105-
| `CB_CONNECTION_STRING` | `--connection-string` | Connection string to the Couchbase cluster | **Required** |
106-
| `CB_USERNAME` | `--username` | Username with bucket access | **Required** |
107-
| `CB_PASSWORD` | `--password` | Password for authentication | **Required** |
108-
| `CB_BUCKET_NAME` | `--bucket-name` | Name of the bucket to access | **Required** |
109-
| `READ_ONLY_QUERY_MODE` | `--read-only-query-mode` | Prevent data modification queries | `true` |
110-
| `MCP_TRANSPORT` | `--transport` | Transport mode: `stdio`, `streamable-http`, `sse` | `stdio` |
111-
| `FASTMCP_HOST` | `--host` | Host for HTTP/SSE transport modes | `127.0.0.1` |
112-
| `FASTMCP_PORT` | `--port` | Port for HTTP/SSE transport modes | `8000` |
103+
| Environment Variable | CLI Argument | Description | Default |
104+
| ----------------------------- | ------------------------ | ------------------------------------------ | ------------ |
105+
| `CB_CONNECTION_STRING` | `--connection-string` | Connection string to the Couchbase cluster | **Required** |
106+
| `CB_USERNAME` | `--username` | Username with bucket access | **Required** |
107+
| `CB_PASSWORD` | `--password` | Password for authentication | **Required** |
108+
| `CB_BUCKET_NAME` | `--bucket-name` | Name of the bucket to access | **Required** |
109+
| `CB_MCP_READ_ONLY_QUERY_MODE` | `--read-only-query-mode` | Prevent data modification queries | `true` |
110+
| `CB_MCP_TRANSPORT` | `--transport` | Transport mode: `stdio`, `http`, `sse` | `stdio` |
111+
| `CB_MCP_HOST` | `--host` | Host for HTTP/SSE transport modes | `127.0.0.1` |
112+
| `CB_MCP_PORT` | `--port` | Port for HTTP/SSE transport modes | `8000` |
113+
114+
You can also check the version of the server using:
115+
116+
```bash
117+
uvx couchbase-mcp-server --version
118+
```
113119

114120
#### Client Specific Configuration
115121

@@ -189,13 +195,13 @@ For more details about MCP integration with Windsurf Editor, refer to the offici
189195
## Streamable HTTP Transport Mode
190196

191197
The MCP Server can be run in [Streamable HTTP](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#streamable-http) transport mode which allows multiple clients to connect to the same server instance via HTTP.
192-
Check if your [MCP client](https://modelcontextprotocol.io/clients) supports streamable-http transport before attempting to connect to MCP server in this mode.
198+
Check if your [MCP client](https://modelcontextprotocol.io/clients) supports streamable http transport before attempting to connect to MCP server in this mode.
193199

194200
> Note: This mode does not include authorization support.
195201
196202
### Usage
197203

198-
By default, the MCP server will run on port 8000 but this can be configured using the `--port` or `FASTMCP_PORT` environment variable.
204+
By default, the MCP server will run on port 8000 but this can be configured using the `--port` or `CB_MCP_PORT` environment variable.
199205

200206
```bash
201207
uvx couchbase-mcp-server --connection-string='<couchbase_connection_string>' --username='<database_username>' --password='<database_password>' --bucket-name='<couchbase_bucket_to_use>' --read-only-query-mode=true --transport=streamable-http
@@ -208,22 +214,22 @@ The server will be available on http://localhost:8000/mcp. This can be used in M
208214
```json
209215
{
210216
"mcpServers": {
211-
"couchbase-streamable-http": {
217+
"couchbase-http": {
212218
"url": "http://localhost:8000/mcp"
213219
}
214220
}
215221
}
216222
```
217223

218-
## SSE Transport Mode (Deprecated)
224+
## SSE Transport Mode
219225

220226
There is an option to run the MCP server in [Server-Sent Events (SSE)](https://modelcontextprotocol.io/specification/2024-11-05/basic/transports#http-with-sse) transport mode.
221227

222228
> Note: SSE mode has been [deprecated](https://modelcontextprotocol.io/docs/concepts/transports#server-sent-events-sse-deprecated) by MCP. We have support for [Streamable HTTP](#streamable-http-transport-mode).
223229
224230
### Usage
225231

226-
By default, the MCP server will run on port 8000 but this can be configured using the `--port` or `FASTMCP_PORT` environment variable.
232+
By default, the MCP server will run on port 8000 but this can be configured using the `--port` or `CB_MCP_PORT` environment variable.
227233

228234
```bash
229235
uvx couchbase-mcp-server --connection-string='<couchbase_connection_string>' --username='<database_username>' --password='<database_password>' --bucket-name='<couchbase_bucket_to_use>' --read-only-query-mode=true --transport=sse
@@ -267,14 +273,14 @@ docker run --rm -i \
267273
-e CB_USERNAME='<database_user>' \
268274
-e CB_PASSWORD='<database_password>' \
269275
-e CB_BUCKET_NAME='<bucket_name>' \
270-
-e MCP_TRANSPORT='<streamable-http|sse|stdio>' \
271-
-e READ_ONLY_QUERY_MODE='<true|false>' \
272-
-e FASTMCP_PORT=9001 \
276+
-e CB_MCP_TRANSPORT='<http|sse|stdio>' \
277+
-e CB_MCP_READ_ONLY_QUERY_MODE='<true|false>' \
278+
-e CB_MCP_PORT=9001 \
273279
-p 9001:9001 \
274280
mcp/couchbase
275281
```
276282

277-
The `FASTMCP_PORT` environment variable is only applicable in the case of HTTP transport modes like streamable-http and sse.
283+
The `CB_MCP_PORT` environment variable is only applicable in the case of HTTP transport modes like http and sse.
278284

279285
#### MCP Client Configuration
280286

src/mcp_server.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
DEFAULT_TRANSPORT,
2323
MCP_SERVER_NAME,
2424
NETWORK_TRANSPORTS,
25+
NETWORK_TRANSPORTS_SDK_MAPPING,
2526
AppContext,
2627
get_settings,
2728
)
@@ -83,30 +84,37 @@ async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]:
8384
)
8485
@click.option(
8586
"--read-only-query-mode",
86-
envvar="READ_ONLY_QUERY_MODE",
87+
envvar=[
88+
"CB_MCP_READ_ONLY_QUERY_MODE",
89+
"READ_ONLY_QUERY_MODE", # Deprecated
90+
],
8791
type=bool,
8892
default=DEFAULT_READ_ONLY_MODE,
8993
help="Enable read-only query mode. Set to True (default) to allow only read-only queries. Can be set to False to allow data modification queries.",
9094
)
9195
@click.option(
9296
"--transport",
93-
envvar="MCP_TRANSPORT",
97+
envvar=[
98+
"CB_MCP_TRANSPORT",
99+
"MCP_TRANSPORT", # Deprecated
100+
],
94101
type=click.Choice(ALLOWED_TRANSPORTS),
95102
default=DEFAULT_TRANSPORT,
96-
help="Transport mode for the server (stdio, streamable-http or sse)",
103+
help="Transport mode for the server (stdio, http or sse). Default is stdio",
97104
)
98105
@click.option(
99106
"--host",
100-
envvar="FASTMCP_HOST",
107+
envvar="CB_MCP_HOST",
101108
default=DEFAULT_HOST,
102109
help="Host to run the server on (default: 127.0.0.1)",
103110
)
104111
@click.option(
105112
"--port",
106-
envvar="FASTMCP_PORT",
113+
envvar="CB_MCP_PORT",
107114
default=DEFAULT_PORT,
108115
help="Port to run the server on (default: 8000)",
109116
)
117+
@click.version_option(package_name="couchbase-mcp-server")
110118
@click.pass_context
111119
def main(
112120
ctx,
@@ -132,8 +140,19 @@ def main(
132140
"port": port,
133141
}
134142

143+
# Map user-friendly transport names to SDK transport names
144+
sdk_transport = NETWORK_TRANSPORTS_SDK_MAPPING.get(transport, transport)
145+
135146
# If the transport is network based, we need to pass the host and port to the MCP server
136-
config = {"host": host, "port": port} if transport in NETWORK_TRANSPORTS else {}
147+
config = (
148+
{
149+
"host": host,
150+
"port": port,
151+
"transport": sdk_transport,
152+
}
153+
if transport in NETWORK_TRANSPORTS
154+
else {}
155+
)
137156

138157
mcp = FastMCP(MCP_SERVER_NAME, lifespan=app_lifespan, **config)
139158

@@ -142,7 +161,7 @@ def main(
142161
mcp.add_tool(tool)
143162

144163
# Run the server
145-
mcp.run(transport=transport)
164+
mcp.run(transport=sdk_transport) # type: ignore
146165

147166

148167
if __name__ == "__main__":

src/utils/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
DEFAULT_TRANSPORT,
2828
MCP_SERVER_NAME,
2929
NETWORK_TRANSPORTS,
30+
NETWORK_TRANSPORTS_SDK_MAPPING,
3031
)
3132

3233
# Context utilities
@@ -58,4 +59,5 @@
5859
"DEFAULT_PORT",
5960
"ALLOWED_TRANSPORTS",
6061
"NETWORK_TRANSPORTS",
62+
"NETWORK_TRANSPORTS_SDK_MAPPING",
6163
]

src/utils/constants.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
DEFAULT_PORT = 8000
99

1010
# Allowed Transport Types
11-
ALLOWED_TRANSPORTS = ["stdio", "streamable-http", "sse"]
12-
NETWORK_TRANSPORTS = ["streamable-http", "sse"]
11+
ALLOWED_TRANSPORTS = ["stdio", "http", "sse"]
12+
NETWORK_TRANSPORTS = ["http", "sse"]
13+
NETWORK_TRANSPORTS_SDK_MAPPING = {
14+
"http": "streamable-http",
15+
"sse": "sse",
16+
}
1317

1418
# Logging Configuration
1519
# Change this to DEBUG, WARNING, ERROR as needed

0 commit comments

Comments
 (0)