nocturnusai-mcp 0.3.11

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.
package/LICENSE ADDED
@@ -0,0 +1,103 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: Auctalis LLC.
6
+ Licensed Work: Nocturnus.AI
7
+ The Licensed Work is (c) 2026 Auctalis LLC.
8
+ Additional Use Grant: You may make non-production use of the Licensed Work,
9
+ and you may make internal production use of the Licensed
10
+ Work within your own organization.
11
+ "Non-production use" means use for development, testing,
12
+ evaluation, demonstration, and educational purposes.
13
+ "Internal production use" means use of the Licensed Work
14
+ in a production environment solely for your organization's
15
+ own internal operations, where the Licensed Work is not
16
+ offered, sold, or made available to third parties.
17
+ The following uses require a separate commercial license
18
+ from the Licensor: any use that directly or indirectly
19
+ offers the Licensed Work or any substantial portion of
20
+ its functionality to third parties as a commercial
21
+ product, hosted service, managed service, embedded
22
+ component, or value-added offering.
23
+ Change Date: Four years from the date of each version release, or
24
+ 2030-02-19 for the initial release, whichever comes first.
25
+ Change License: Apache License, Version 2.0
26
+
27
+ For information about alternative licensing arrangements for the Licensed Work,
28
+ please contact: licensing@nocturnus.ai
29
+
30
+ Terms
31
+
32
+ The Licensor hereby grants you the right to copy, modify, create derivative
33
+ works, redistribute, and make non-production use of the Licensed Work. The
34
+ Licensor may make an Additional Use Grant, above, permitting limited production
35
+ use.
36
+
37
+ Effective on the Change Date, or the fourth anniversary of the first publicly
38
+ available distribution of a specific version of the Licensed Work under this
39
+ License, whichever comes first, the Licensor hereby grants you rights under
40
+ the terms of the Change License, and the rights granted in the paragraph
41
+ above terminate.
42
+
43
+ If your use of the Licensed Work does not comply with the requirements
44
+ currently in effect as described in this License, you must purchase a
45
+ commercial license from the Licensor, its affiliated entities, or authorized
46
+ resellers, or you must refrain from using the Licensed Work.
47
+
48
+ All copies of the original and modified Licensed Work, and derivative works
49
+ of the Licensed Work, are subject to this License. This License applies
50
+ separately for each version of the Licensed Work and the Change Date may vary
51
+ for each version of the Licensed Work released by Licensor.
52
+
53
+ You must conspicuously display this License on each original or modified copy
54
+ of the Licensed Work. If you receive the Licensed Work in original or
55
+ modified form from a third party, the terms and conditions set forth in this
56
+ License apply to your use of that work.
57
+
58
+ Any use of the Licensed Work in violation of this License will automatically
59
+ terminate your rights under this License for the current and all other
60
+ versions of the Licensed Work.
61
+
62
+ This License does not grant you any right in any trademark or logo of
63
+ Licensor or its affiliates (provided that you may use a trademark or logo of
64
+ Licensor as expressly required by this License).
65
+
66
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
67
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
68
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
69
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
70
+ TITLE.
71
+
72
+ MariaDB hereby grants you permission to use this License's text to license
73
+ your works, and to refer to it using the trademark "Business Source License",
74
+ as long as you comply with the Covenants of Licensor below.
75
+
76
+ Covenants of Licensor
77
+
78
+ In consideration of the right to use this License's text and the "Business
79
+ Source License" name and trademark, Licensor covenants to MariaDB, and to all
80
+ other recipients of the licensed work to be provided by Licensor:
81
+
82
+ To specify as the Change License the GPL Version 2.0 or any later version,
83
+ or a license that is compatible with GPL Version 2.0 or a later version,
84
+ where "compatible" means that software provided under the Change License can
85
+ be included in a program with software provided under GPL Version 2.0 or a
86
+ later version. Licensor may specify additional Change Licenses without
87
+ limitation.
88
+
89
+ To either: (a) specify an additional grant of rights to use that does not
90
+ impose any additional restriction on the right granted in this License, as
91
+ the Additional Use Grant; or (b) insert the text "None" to specify a Change
92
+ Date.
93
+
94
+ Not to modify this License in any other way.
95
+
96
+ Notice
97
+
98
+ The Business Source License (this document, or the "License") is not an Open
99
+ Source license. However, the Licensed Work will eventually be made available
100
+ under an Open Source License, as stated in this License.
101
+
102
+ License text copyright (c) 2024 MariaDB plc, All Rights Reserved.
103
+ "Business Source License" is a trademark of MariaDB plc.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # nocturnusai-mcp
2
+
3
+ MCP stdio server for [NocturnusAI](https://nocturnus.ai/) — agent reasoning, memory, and token-optimized context for AI applications. Point any MCP-compatible client (Claude Desktop, Cursor, Windsurf, etc.) at a running NocturnusAI instance and get:
4
+
5
+ - **Deterministic reasoning** — multi-step inference with proof chains, not LLM guessing
6
+ - **Token-optimized context** — salience-ranked retrieval puts only the most relevant facts in your context window, cutting token waste
7
+ - **Agent memory lifecycle** — temporal facts, auto-expiration, consolidation, and decay so long-running agents stay focused
8
+ - **Truth maintenance** — automatic retraction of derived knowledge when premises change
9
+
10
+ This package is a thin stdio shim. It forwards MCP requests to a NocturnusAI server's `/mcp` JSON-RPC endpoint. It does not include the server itself.
11
+
12
+ ## Quick start — run a NocturnusAI server
13
+
14
+ The fastest way to get a server running locally:
15
+
16
+ ```bash
17
+ docker run -d --name nocturnusai -p 9300:9300 ghcr.io/auctalis/nocturnusai:latest
18
+ ```
19
+
20
+ Data persists to a named Docker volume. Point your MCP client at this instance via the config below.
21
+
22
+ Alternatives: build from source (`./gradlew :nocturnusai-server:run` from [the repo](https://github.com/Auctalis/nocturnusai)) or deploy to your own infra.
23
+
24
+ ## Client configuration
25
+
26
+ ### Claude Desktop (`claude_desktop_config.json`)
27
+
28
+ ```json
29
+ {
30
+ "mcpServers": {
31
+ "nocturnusai": {
32
+ "command": "npx",
33
+ "args": ["-y", "nocturnusai-mcp"],
34
+ "env": {
35
+ "NOCTURNUSAI_URL": "http://localhost:9300"
36
+ }
37
+ }
38
+ }
39
+ }
40
+ ```
41
+
42
+ ### Cursor / Windsurf
43
+
44
+ Same structure — most clients accept a `command` + `args` + `env` block.
45
+
46
+ ## Environment variables
47
+
48
+ | Variable | Default | Purpose |
49
+ | --------------------- | ------------------------ | ------------------------------------------------- |
50
+ | `NOCTURNUSAI_URL` | `http://localhost:9300` | Base URL of the NocturnusAI server |
51
+ | `NOCTURNUSAI_API_KEY` | _(none)_ | Sent as `X-API-Key` when set |
52
+ | `NOCTURNUSAI_DATABASE`| `default` | Sent as `X-Database` header |
53
+ | `NOCTURNUSAI_TENANT` | `default` | Sent as `X-Tenant-ID` header |
54
+
55
+ ## What tools are available
56
+
57
+ Whatever tools the upstream NocturnusAI server exposes. As of 0.3.x this includes `tell`, `ask`, `teach`, `forget`, `predicates`, `context`, `aggregate`, `bulk_assert`, `retract_pattern`, `fork_scope`, `merge_scope`, `list_scopes`, `delete_scope`. The shim is transparent — new tools added to the server appear automatically without a package update.
58
+
59
+ ## Design
60
+
61
+ - `tools/list` and `tools/call` requests are forwarded via HTTP JSON-RPC 2.0 to `${NOCTURNUSAI_URL}/mcp`.
62
+ - Tool schemas come from the upstream server. This package doesn't duplicate them.
63
+ - Startup prints a warning to stderr if `/health` is unreachable so misconfig fails loudly.
64
+
65
+ ## License
66
+
67
+ BUSL-1.1
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * NocturnusAI MCP stdio shim.
4
+ *
5
+ * Speaks MCP over stdio to an LLM client (Claude, Cursor, etc.) and forwards
6
+ * every tools/list and tools/call request to a NocturnusAI server's JSON-RPC
7
+ * /mcp endpoint over HTTP.
8
+ *
9
+ * Configuration via environment variables:
10
+ * NOCTURNUSAI_URL Base URL of NocturnusAI server (default: http://localhost:9300)
11
+ * NOCTURNUSAI_API_KEY Optional API key sent as X-API-Key
12
+ * NOCTURNUSAI_DATABASE Database name, sent as X-Database (default: default)
13
+ * NOCTURNUSAI_TENANT Tenant id, sent as X-Tenant-ID (default: default)
14
+ */
15
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
16
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
17
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
18
+ const URL_BASE = (process.env.NOCTURNUSAI_URL ?? "http://localhost:9300").replace(/\/$/, "");
19
+ const API_KEY = process.env.NOCTURNUSAI_API_KEY;
20
+ const DATABASE = process.env.NOCTURNUSAI_DATABASE ?? "default";
21
+ const TENANT = process.env.NOCTURNUSAI_TENANT ?? "default";
22
+ let rpcId = 0;
23
+ function headers() {
24
+ const h = {
25
+ "Content-Type": "application/json",
26
+ "X-Database": DATABASE,
27
+ "X-Tenant-ID": TENANT,
28
+ };
29
+ if (API_KEY)
30
+ h["X-API-Key"] = API_KEY;
31
+ return h;
32
+ }
33
+ async function rpc(method, params) {
34
+ const body = {
35
+ jsonrpc: "2.0",
36
+ id: ++rpcId,
37
+ method,
38
+ params: params ?? {},
39
+ };
40
+ const res = await fetch(`${URL_BASE}/mcp`, {
41
+ method: "POST",
42
+ headers: headers(),
43
+ body: JSON.stringify(body),
44
+ });
45
+ if (!res.ok) {
46
+ const text = await res.text().catch(() => "");
47
+ throw new Error(`NocturnusAI /mcp ${res.status} ${res.statusText}: ${text}`);
48
+ }
49
+ const json = (await res.json());
50
+ if (json.error) {
51
+ const msg = json.error.message || "upstream error";
52
+ throw new Error(`NocturnusAI RPC error ${json.error.code}: ${msg}`);
53
+ }
54
+ return json.result;
55
+ }
56
+ const server = new Server({
57
+ name: "nocturnusai-mcp",
58
+ version: "0.3.0",
59
+ }, {
60
+ capabilities: {
61
+ tools: {},
62
+ },
63
+ });
64
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
65
+ const result = (await rpc("tools/list"));
66
+ return { tools: result.tools ?? [] };
67
+ });
68
+ server.setRequestHandler(CallToolRequestSchema, async (req) => {
69
+ const result = (await rpc("tools/call", {
70
+ name: req.params.name,
71
+ arguments: req.params.arguments ?? {},
72
+ }));
73
+ return {
74
+ content: result.content ?? [],
75
+ isError: result.isError,
76
+ };
77
+ });
78
+ async function main() {
79
+ // Quick connectivity check. Not fatal — a startup failure would hide behind
80
+ // the first tool call otherwise, which is confusing to debug.
81
+ try {
82
+ const res = await fetch(`${URL_BASE}/health`, { headers: headers() });
83
+ if (!res.ok) {
84
+ process.stderr.write(`[nocturnusai-mcp] warning: ${URL_BASE}/health returned ${res.status}\n`);
85
+ }
86
+ }
87
+ catch (err) {
88
+ process.stderr.write(`[nocturnusai-mcp] warning: cannot reach ${URL_BASE}: ${err.message}\n` +
89
+ `[nocturnusai-mcp] start the server or set NOCTURNUSAI_URL\n`);
90
+ }
91
+ const transport = new StdioServerTransport();
92
+ await server.connect(transport);
93
+ }
94
+ main().catch((err) => {
95
+ process.stderr.write(`[nocturnusai-mcp] fatal: ${err.stack ?? err}\n`);
96
+ process.exit(1);
97
+ });
98
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAE5C,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,uBAAuB,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAC7F,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;AAChD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,SAAS,CAAC;AAC/D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,SAAS,CAAC;AAE3D,IAAI,KAAK,GAAG,CAAC,CAAC;AAEd,SAAS,OAAO;IACd,MAAM,CAAC,GAA2B;QAChC,cAAc,EAAE,kBAAkB;QAClC,YAAY,EAAE,QAAQ;Q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AAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA6B,GAAa,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC;IAClF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "nocturnusai-mcp",
3
+ "version": "0.3.11",
4
+ "description": "MCP stdio server for NocturnusAI — agent reasoning, memory lifecycle, and token-optimized context windows for AI applications.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "nocturnusai-mcp": "dist/index.js"
9
+ },
10
+ "mcpName": "ai.nocturnus/logic-server",
11
+ "files": [
12
+ "dist",
13
+ "src",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "prepublishOnly": "tsc",
20
+ "start": "node dist/index.js",
21
+ "dev": "tsc --watch"
22
+ },
23
+ "keywords": [
24
+ "nocturnusai",
25
+ "mcp",
26
+ "model-context-protocol",
27
+ "logic",
28
+ "inference",
29
+ "memory",
30
+ "reasoning",
31
+ "agent"
32
+ ],
33
+ "license": "BUSL-1.1",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/Auctalis/nocturnusai.git",
37
+ "directory": "sdks/mcp-server"
38
+ },
39
+ "homepage": "https://nocturnus.ai/",
40
+ "bugs": {
41
+ "url": "https://github.com/Auctalis/nocturnusai/issues"
42
+ },
43
+ "dependencies": {
44
+ "@modelcontextprotocol/sdk": "^1.0.4"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^22.0.0",
48
+ "typescript": "^5.3.0"
49
+ },
50
+ "engines": {
51
+ "node": ">=18.0.0"
52
+ }
53
+ }
package/src/index.ts ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * NocturnusAI MCP stdio shim.
4
+ *
5
+ * Speaks MCP over stdio to an LLM client (Claude, Cursor, etc.) and forwards
6
+ * every tools/list and tools/call request to a NocturnusAI server's JSON-RPC
7
+ * /mcp endpoint over HTTP.
8
+ *
9
+ * Configuration via environment variables:
10
+ * NOCTURNUSAI_URL Base URL of NocturnusAI server (default: http://localhost:9300)
11
+ * NOCTURNUSAI_API_KEY Optional API key sent as X-API-Key
12
+ * NOCTURNUSAI_DATABASE Database name, sent as X-Database (default: default)
13
+ * NOCTURNUSAI_TENANT Tenant id, sent as X-Tenant-ID (default: default)
14
+ */
15
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
16
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
17
+ import {
18
+ CallToolRequestSchema,
19
+ ListToolsRequestSchema,
20
+ } from "@modelcontextprotocol/sdk/types.js";
21
+
22
+ const URL_BASE = (process.env.NOCTURNUSAI_URL ?? "http://localhost:9300").replace(/\/$/, "");
23
+ const API_KEY = process.env.NOCTURNUSAI_API_KEY;
24
+ const DATABASE = process.env.NOCTURNUSAI_DATABASE ?? "default";
25
+ const TENANT = process.env.NOCTURNUSAI_TENANT ?? "default";
26
+
27
+ let rpcId = 0;
28
+
29
+ function headers(): Record<string, string> {
30
+ const h: Record<string, string> = {
31
+ "Content-Type": "application/json",
32
+ "X-Database": DATABASE,
33
+ "X-Tenant-ID": TENANT,
34
+ };
35
+ if (API_KEY) h["X-API-Key"] = API_KEY;
36
+ return h;
37
+ }
38
+
39
+ async function rpc(method: string, params?: unknown): Promise<unknown> {
40
+ const body = {
41
+ jsonrpc: "2.0",
42
+ id: ++rpcId,
43
+ method,
44
+ params: params ?? {},
45
+ };
46
+ const res = await fetch(`${URL_BASE}/mcp`, {
47
+ method: "POST",
48
+ headers: headers(),
49
+ body: JSON.stringify(body),
50
+ });
51
+ if (!res.ok) {
52
+ const text = await res.text().catch(() => "");
53
+ throw new Error(`NocturnusAI /mcp ${res.status} ${res.statusText}: ${text}`);
54
+ }
55
+ const json = (await res.json()) as {
56
+ result?: unknown;
57
+ error?: { code: number; message: string; data?: unknown };
58
+ };
59
+ if (json.error) {
60
+ const msg = json.error.message || "upstream error";
61
+ throw new Error(`NocturnusAI RPC error ${json.error.code}: ${msg}`);
62
+ }
63
+ return json.result;
64
+ }
65
+
66
+ const server = new Server(
67
+ {
68
+ name: "nocturnusai-mcp",
69
+ version: "0.3.0",
70
+ },
71
+ {
72
+ capabilities: {
73
+ tools: {},
74
+ },
75
+ }
76
+ );
77
+
78
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
79
+ const result = (await rpc("tools/list")) as { tools: unknown[] };
80
+ return { tools: result.tools ?? [] };
81
+ });
82
+
83
+ server.setRequestHandler(CallToolRequestSchema, async (req) => {
84
+ const result = (await rpc("tools/call", {
85
+ name: req.params.name,
86
+ arguments: req.params.arguments ?? {},
87
+ })) as { content: unknown[]; isError?: boolean };
88
+ return {
89
+ content: result.content ?? [],
90
+ isError: result.isError,
91
+ };
92
+ });
93
+
94
+ async function main(): Promise<void> {
95
+ // Quick connectivity check. Not fatal — a startup failure would hide behind
96
+ // the first tool call otherwise, which is confusing to debug.
97
+ try {
98
+ const res = await fetch(`${URL_BASE}/health`, { headers: headers() });
99
+ if (!res.ok) {
100
+ process.stderr.write(
101
+ `[nocturnusai-mcp] warning: ${URL_BASE}/health returned ${res.status}\n`
102
+ );
103
+ }
104
+ } catch (err) {
105
+ process.stderr.write(
106
+ `[nocturnusai-mcp] warning: cannot reach ${URL_BASE}: ${(err as Error).message}\n` +
107
+ `[nocturnusai-mcp] start the server or set NOCTURNUSAI_URL\n`
108
+ );
109
+ }
110
+
111
+ const transport = new StdioServerTransport();
112
+ await server.connect(transport);
113
+ }
114
+
115
+ main().catch((err) => {
116
+ process.stderr.write(`[nocturnusai-mcp] fatal: ${(err as Error).stack ?? err}\n`);
117
+ process.exit(1);
118
+ });