fantsec-docmost-cli 2.2.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
2
+ import { resolveToolAuthContext } from "../mcp.js";
3
+ const ORIGINAL_ENV = { ...process.env };
4
+ beforeEach(() => {
5
+ process.env = {
6
+ ...ORIGINAL_ENV,
7
+ DOCMOST_API_URL: "https://docs.example.com/api",
8
+ };
9
+ });
10
+ afterEach(() => {
11
+ process.env = { ...ORIGINAL_ENV };
12
+ });
13
+ describe("docmost MCP auth resolution", () => {
14
+ it("falls back to env auth for local stdio calls without request headers", () => {
15
+ expect(resolveToolAuthContext(undefined)).toBeUndefined();
16
+ });
17
+ it("parses bearer token headers for remote calls", () => {
18
+ expect(resolveToolAuthContext({
19
+ authorization: "Bearer token-123",
20
+ })).toEqual({
21
+ apiUrl: process.env.DOCMOST_API_URL,
22
+ token: "token-123",
23
+ });
24
+ });
25
+ it("rejects remote calls that omit authorization headers", () => {
26
+ expect(() => resolveToolAuthContext({})).toThrow("Authorization header is required for remote Docmost tool calls.");
27
+ });
28
+ });
package/build/mcp.js CHANGED
@@ -3,6 +3,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
3
  import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
4
4
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
5
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
6
+ import { realpathSync } from "fs";
6
7
  import { pathToFileURL } from "url";
7
8
  import { getVersion } from "./program.js";
8
9
  import { executeTool, listMcpTools, parseDocmostBearer, } from "./lib/mcp-tooling.js";
@@ -73,11 +74,7 @@ export function createMcpServer() {
73
74
  inputSchema: tool.inputSchema,
74
75
  annotations: tool.annotations,
75
76
  }, async (args, extra) => {
76
- const authHeader = getAuthorizationHeader(extra?.requestInfo?.headers);
77
- if (!authHeader) {
78
- throw new Error("Authorization header is required for Docmost tool calls.");
79
- }
80
- const auth = parseDocmostBearer(extractBearerToken(authHeader));
77
+ const auth = resolveToolAuthContext(extra?.requestInfo?.headers);
81
78
  const result = await executeTool(tool, args, auth);
82
79
  return {
83
80
  content: [
@@ -92,6 +89,18 @@ export function createMcpServer() {
92
89
  }
93
90
  return server;
94
91
  }
92
+ export function resolveToolAuthContext(headers) {
93
+ const authHeader = getAuthorizationHeader(headers);
94
+ if (authHeader) {
95
+ return parseDocmostBearer(extractBearerToken(authHeader));
96
+ }
97
+ // Local stdio MCP calls do not provide request headers. In that case we
98
+ // intentionally fall back to DOCMOST_* env vars so local client configs work.
99
+ if (!headers) {
100
+ return undefined;
101
+ }
102
+ throw new Error("Authorization header is required for remote Docmost tool calls.");
103
+ }
95
104
  function getAuthorizationHeader(headers) {
96
105
  if (!headers) {
97
106
  return undefined;
@@ -177,7 +186,19 @@ async function main() {
177
186
  const transport = new StdioServerTransport();
178
187
  await server.connect(transport);
179
188
  }
180
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
189
+ function isDirectExecution() {
190
+ const entrypoint = process.argv[1];
191
+ if (!entrypoint) {
192
+ return false;
193
+ }
194
+ try {
195
+ return import.meta.url === pathToFileURL(realpathSync(entrypoint)).href;
196
+ }
197
+ catch {
198
+ return import.meta.url === pathToFileURL(entrypoint).href;
199
+ }
200
+ }
201
+ if (isDirectExecution()) {
181
202
  main().catch((error) => {
182
203
  const message = error instanceof Error ? error.message : String(error);
183
204
  console.error(`Docmost MCP server error: ${message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fantsec-docmost-cli",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "A Docmost CLI and standard MCP server for documentation automation.",
5
5
  "main": "build/index.js",
6
6
  "bin": {