Skip to content

feat: support OBSIDIAN_REST_API_PORT environment variable#64

Open
dominikblei wants to merge 1 commit intojacksteamdev:mainfrom
dominikblei:feat/port-env-var
Open

feat: support OBSIDIAN_REST_API_PORT environment variable#64
dominikblei wants to merge 1 commit intojacksteamdev:mainfrom
dominikblei:feat/port-env-var

Conversation

@dominikblei
Copy link
Copy Markdown

Adds support for configuring the REST API port via the OBSIDIAN_REST_API_PORT environment variable.

This enables running multiple Obsidian vaults simultaneously, each with their own MCP server instance on different ports.

Usage:

{
  "mcpServers": {
    "vault-a": {
      "command": ".../mcp-server",
      "env": {
        "OBSIDIAN_API_KEY": "...",
        "OBSIDIAN_REST_API_PORT": "27124"
      }
    },
    "vault-b": {
      "command": ".../mcp-server",
      "env": {
        "OBSIDIAN_API_KEY": "...",
        "OBSIDIAN_REST_API_PORT": "27125"
      }
    }
  }
}

Closes #40

@netlify
Copy link
Copy Markdown

netlify bot commented Jan 15, 2026

Deploy Preview for superb-starlight-b5acb5 canceled.

Name Link
🔨 Latest commit 049f5dc
🔍 Latest deploy log https://app.netlify.com/projects/superb-starlight-b5acb5/deploys/69694dcc5b79f400083b9c0d

istefox added a commit to istefox/obsidian-mcp-connector that referenced this pull request Apr 11, 2026
Resolve the long-standing port hardcoding: users running Obsidian with
Local REST API on a non-default port (multiple vaults, WSL cross-machine,
security hardening, custom plugin configurations) could not connect the
MCP server at all.

Unix-style precedence for port resolution, highest priority first:
1. `--port <value>` or `--port=<value>` CLI argument
2. `OBSIDIAN_PORT` environment variable
3. Protocol default (27124 for HTTPS, 27123 for HTTP)

Both parsePort() and resolvePortFromArgs() are exported for unit
testing; all non-numeric, out-of-range, and malformed inputs fall
through cleanly to the next source in the chain. OBSIDIAN_HOST is
unchanged — it controls host separately, so users can still mix
OBSIDIAN_HOST=localhost with OBSIDIAN_PORT=9000 via Claude Desktop's
env block.

Adopted PR jacksteamdev#74 (vinhltt) as the base, because CLI args > env var is
the standard Unix precedence and is the most ergonomic override for
cross-machine setups (WSL/remote). Rejected PR jacksteamdev#64 (env var only,
incomplete) and PR jacksteamdev#56 (two separate HTTP/HTTPS env vars, less
elegant and divergent from how OBSIDIAN_HOST already works).

Adds makeRequest.test.ts with 20 unit tests:
- parsePort: low/mid/high valid values, zero rejection, out-of-range
  rejection, non-numeric rejection, negative rejection, empty string,
  undefined, whitespace-only
- resolvePortFromArgs: empty argv, unrelated flags, --port space form,
  --port= equals form, missing value, invalid value both forms, equals
  form precedence, prefix-only ("--port-info") non-match

Also adds OBSIDIAN_PORT and OBSIDIAN_HOST to the ProcessEnv type
declaration in global.d.ts.

Refs: jacksteamdev#40, jacksteamdev#66, jacksteamdev#67
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add support for custom HTTP and HTTPS ports via environment variables

1 participant