Skip to content

Commit 4e70ab9

Browse files
committed
docs(mcp): describe the credential lookup without the rationale
- replace the env-file prose with a CLI/server table - state the credential-file order as steps, drop the reasons - merge the duplicated credential setup into one section - fix quick install: osw-mcp is the console script, not the server name - correct the default `claude mcp add` scope to local
1 parent 38a49ea commit 4e70ab9

1 file changed

Lines changed: 59 additions & 103 deletions

File tree

‎docs/cli-and-mcp.md‎

Lines changed: 59 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ OSW_USERNAME=your-user
4141
OSW_PASSWORD=your-password
4242
```
4343

44-
The CLI finds that file by searching upward from the working directory, so
45-
`osw status` now reports the instance and connection state. The MCP server does
46-
not search: its settings come from the `env` block of its registration, see
47-
[Registering a server](#registering-a-server). Everything that can be set is
48-
listed under [Configuration](#configuration).
44+
The CLI searches upward from the working directory for it, so `osw status` now
45+
reports the instance and connection state. The MCP server takes its settings
46+
from the `env` block of its registration instead, see
47+
[Registering a server](#registering-a-server). Every variable is listed under
48+
[Configuration](#configuration).
4949

5050
## Command line
5151

@@ -111,27 +111,22 @@ For Claude Code, one command registers the server. Replace the domain and the
111111
credential file path with your own:
112112

113113
```bash
114-
claude mcp add osw \
114+
claude mcp add osw-dev \
115115
-e OSW_DOMAIN=wiki-dev.open-semantic-lab.org \
116116
-e OSW_CRED_FILEPATH=/abs/path/to/accounts.pwd.yaml \
117117
-- uvx --from "osw[mcp]" osw-mcp
118118
```
119119

120-
Quote `osw[mcp]`, otherwise the shell tries to expand the square brackets. On
121-
Windows, write the path with forward slashes.
120+
Notes:
122121

123-
Everything after `--` is the command Claude Code runs. `uvx` downloads and
124-
starts the server without installing it first. If osw is already installed in
125-
an environment, use that environment's `osw-mcp` instead of the `uvx` line.
126-
127-
The entry is written for the current project only. Pass `-s user` to make it
128-
available in every project, or `-s project` to write it to a `.mcp.json` that
129-
is committed with the repository. With `-s project`, keep to `OSW_CRED_FILEPATH`
130-
and never put `OSW_PASSWORD` in the `env` block.
131-
132-
Check the result with `claude mcp list` or `claude mcp get osw`, and remove the
133-
entry again with `claude mcp remove osw`. The next section explains what the
134-
entry contains, and how to point it at a `.env` file instead.
122+
- `osw-dev` is the server name and becomes the tool prefix, so every call site
123+
reads `mcp__osw-dev__get_entity`. Pick one name per instance, e.g. `osw-prod`.
124+
- `osw-mcp` is the program `uvx` runs. It is the console script this package
125+
installs, so it does not change.
126+
- On Windows, write the path with forward slashes.
127+
- The default scope is `local`: this project, your machine only. Use `-s user`
128+
for every project, or `-s project` to write a shared `.mcp.json`.
129+
- List what is registered with `claude mcp list`.
135130

136131
### Registering a server
137132

@@ -144,12 +139,9 @@ A server entry can carry its settings in two ways:
144139
several tools share one settings file, or when the client config is committed
145140
and the settings file is not.
146141

147-
Prefer the `env` block naming `OSW_CRED_FILEPATH` and `OSW_DOMAIN`: the
148-
destination instance is spelled out in the entry itself, so it is visible at a
149-
glance and in a diff rather than one indirection away. The secret stays out of
150-
the client config either way, since a credential file contributes a path and an
151-
instance name and nothing else. Never put `OSW_PASSWORD` inline in a committed
152-
`.mcp.json`.
142+
Prefer the `env` block naming `OSW_CRED_FILEPATH` and `OSW_DOMAIN`, so the
143+
destination instance is visible in the entry itself. Never put `OSW_PASSWORD`
144+
in a committed `.mcp.json`.
153145

154146
```json
155147
{
@@ -168,8 +160,8 @@ instance name and nothing else. Never put `OSW_PASSWORD` inline in a committed
168160
```
169161

170162
At startup the server checks that the credential file has an entry matching
171-
`OSW_DOMAIN` and, if not, names the iris the file does contain (never their
172-
secrets), so a typo surfaces immediately rather than on the first tool call.
163+
`OSW_DOMAIN`. If it does not, the server stops and names the iris the file does
164+
contain, never their secrets.
173165

174166
Registering the same entry from a shell is easiest with `add-json`, which takes
175167
it verbatim. Note that a Windows path needs forward slashes or doubled
@@ -244,93 +236,58 @@ Both adapters share the settings below.
244236

245237
### Where settings come from
246238

247-
Settings are read from the process environment. A `.env` file is one optional
248-
way to fill it, and a real environment variable always wins over the same name
249-
in a file.
250-
251-
- `OSW_ENV_FILE` set: exactly that file is loaded, and nothing is searched for.
252-
- Unset, **CLI**: searches upward from the working directory, so a `.env` in a
253-
project root applies to every `osw` command run anywhere inside it.
254-
- Unset, **MCP server**: searches nowhere. Its working directory is picked by
255-
the MCP client, so an implicit search would tie the credentials it loads to
256-
how the client happened to be launched.
257-
258-
The credential file is looked up separately, in this order:
259-
260-
1. An explicit `OSW_CRED_FILEPATH` (or its aliases), whether it came from the
261-
real environment or from a `.env` file, always wins. If this file has no
262-
entry for the configured domain, that is an error. This check does not
263-
apply when `OSW_USERNAME` and `OSW_PASSWORD` are both set, because osw
264-
then builds credentials for any instance from those two variables.
265-
2. Otherwise, an `accounts.pwd.yaml` file in the working directory, if one
266-
exists there. This lookup does not walk up to parent directories, and it
267-
runs for the CLI only, never for the MCP server, for the same reason the
268-
`.env` search does not: the server's working directory belongs to the
269-
client, not to the operator. If this file has no entry for the configured
270-
domain, it is ignored rather than treated as an error, since it was only
271-
discovered, not configured.
272-
3. Otherwise, no credential file is used.
273-
274-
The working-directory lookup is skipped entirely when either `OSW_USERNAME`
275-
or `OSW_PASSWORD` is already set, including their `OSL_USERNAME` /
276-
`OSL_PASSWORD` aliases, so it never displaces credentials configured
277-
explicitly.
278-
279-
Both print the source they resolved to stderr before connecting, in one of
280-
these forms:
281-
282-
- `(from the OSW_CRED_FILEPATH environment variable)`
283-
- `(from OSW_CRED_FILEPATH in the env file)`
284-
- `(accounts.pwd.yaml found in the working directory)`
285-
- `(accounts.pwd.yaml found in the working directory, ignored: no entry for domain '<domain>')`, when the discovered file is rejected for the reason given in step 2 above.
286-
287-
Those four forms all belong to a line labelled `credential file`. When no
288-
credential file is used at all, the line is labelled `credentials` instead and
289-
takes one of these forms:
239+
Settings are read from the process environment. A `.env` file fills that
240+
environment; a real environment variable wins over the same name in a file.
241+
242+
**Env file**
243+
244+
| `OSW_ENV_FILE` | CLI | MCP server |
245+
| --- | --- | --- |
246+
| set | loads that file, searches nowhere | loads that file, searches nowhere |
247+
| unset | searches upward from the working directory | searches nowhere |
248+
249+
**Credential file.** The first step that produces a file wins:
250+
251+
1. `OSW_CRED_FILEPATH` or an alias, set in the environment or the env file.
252+
The run fails if this file has no entry for `OSW_DOMAIN`. That check is
253+
skipped when `OSW_USERNAME` and `OSW_PASSWORD` are both set.
254+
2. CLI only: `accounts.pwd.yaml` in the working directory. Parent directories
255+
are not searched. This step is skipped when `OSW_USERNAME` or
256+
`OSW_PASSWORD` is set. If the file has no entry for `OSW_DOMAIN` it is
257+
ignored and the run continues.
258+
3. No credential file.
259+
260+
**Source report.** Both adapters write to stderr before connecting. The first
261+
line is labelled `credential file` when a file was found:
262+
263+
- `<path> (from the OSW_CRED_FILEPATH environment variable)`
264+
- `<path> (from OSW_CRED_FILEPATH in the env file)`
265+
- `<path> (accounts.pwd.yaml found in the working directory)`
266+
- `<path> (accounts.pwd.yaml found in the working directory, ignored: no entry for domain '<domain>')`
267+
268+
and `credentials` when none was:
290269

291270
- `OSW_USERNAME/OSW_PASSWORD (from the environment)`
292271
- `OSW_USERNAME/OSW_PASSWORD (from the env file)`
293272
- `not configured (set OSW_CRED_FILEPATH, or OSW_USERNAME/OSW_PASSWORD)`
294273

295-
The MCP server always prints both lines, the credential one first, then the
296-
env-file one. The CLI prints one line by default, naming where the
297-
credential came from. Pass `--verbose` to also print the env-file line. A
298-
failing command prints both lines regardless of `--verbose`, so a report
299-
still names every source that was checked.
300-
301-
For example, a verbose CLI run or the MCP server prints:
274+
The second line is labelled `env file`. The MCP server prints both lines. The
275+
CLI prints the first only, adding the second with `--verbose` or when the
276+
command fails:
302277

303278
```text
304279
[osw] credential file: /home/me/project/accounts.pwd.yaml (accounts.pwd.yaml found in the working directory)
305280
[osw] env file : /home/me/project/.env (found from the working directory upward)
306281
```
307282

308-
A non-verbose, successful CLI run prints only the first of those two lines.
309-
310283
### Credentials
311284

312285
Keep credentials in a gitignored file. They are read once per process, into that
313-
process only, and never written back to disk.
314-
315-
```dotenv
316-
OSW_DOMAIN=wiki-dev.open-semantic-lab.org
317-
OSW_USERNAME=your-user
318-
OSW_PASSWORD=your-password
319-
# optional
320-
OSW_SPARQL_ENDPOINT=https://.../sparql
321-
OSW_READ_ONLY=false # true hides all mutating tools
322-
```
323-
324-
Alternatively, authenticate from an osw credential file, so the password is not
325-
duplicated into a second plaintext file:
326-
327-
```dotenv
328-
OSW_DOMAIN=wiki-dev.open-semantic-lab.org
329-
OSW_CRED_FILEPATH=/abs/path/to/accounts.pwd.yaml
330-
```
286+
process only, and never written back to disk. Set either `OSW_USERNAME` and
287+
`OSW_PASSWORD`, or `OSW_CRED_FILEPATH`.
331288

332-
The file is the YAML format osw's `CredentialManager` already reads, keyed by
333-
iri, so deployments that configure it need no extra setup:
289+
A credential file uses the YAML format osw's `CredentialManager` reads, keyed
290+
by iri:
334291

335292
```yaml
336293
wiki-dev.open-semantic-lab.org:
@@ -339,9 +296,8 @@ wiki-dev.open-semantic-lab.org:
339296
```
340297
341298
A credential file may hold several iris. The CLI selects one automatically if it
342-
is the only one, and otherwise wants `osw --instance <iri>`. The MCP server
343-
never selects one, see
344-
[One server per instance](#mcp-server).
299+
is the only one, and otherwise requires `osw --instance <iri>`. The MCP server
300+
never selects one, see [One server per instance](#mcp-server).
345301

346302
### Variable reference
347303

0 commit comments

Comments
 (0)