n2-qln 3.1.0
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 +191 -0
- package/README.md +413 -0
- package/docs/README.md +2 -0
- package/docs/architecture.png +0 -0
- package/index.js +65 -0
- package/lib/config.js +65 -0
- package/lib/embedding.js +131 -0
- package/lib/executor.js +104 -0
- package/lib/registry.js +217 -0
- package/lib/router.js +160 -0
- package/lib/schema.js +95 -0
- package/lib/store.js +215 -0
- package/lib/validator.js +171 -0
- package/lib/vector-index.js +151 -0
- package/package.json +28 -0
- package/tools/qln-call.js +244 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2026 N2
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
# n2-qln
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/n2-qln) [](LICENSE) [](https://nodejs.org) [](https://www.npmjs.com/package/n2-qln)
|
|
4
|
+
|
|
5
|
+
**QLN** = **Q**uery **L**ayer **N**etwork — a semantic search layer that sits between the AI and your tools.
|
|
6
|
+
|
|
7
|
+
> **Route 1,000+ tools through 1 MCP tool.** The AI sees only the router — not all 1,000 tools.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
🔍 **One tool to rule them all** — Your AI sees `n2_qln_call` (~200 tokens), not 1,000 individual tools. 99.6% context reduction.
|
|
14
|
+
|
|
15
|
+
⚡ **Sub-5ms search** — 3-stage search engine (trigger + keyword + semantic) finds the right tool in under 5ms, even with 1,000+ tools indexed.
|
|
16
|
+
|
|
17
|
+
📈 **Self-learning ranking** — Tools that get used more and succeed more are automatically ranked higher over time. No manual tuning needed.
|
|
18
|
+
|
|
19
|
+
🔄 **Live tool management** — Add, update, or remove tools at runtime. No server restart required. Group tools by provider for bulk operations.
|
|
20
|
+
|
|
21
|
+
🛡️ **Enforced quality** — Strict validation on tool registration: `verb_target` naming, minimum description length, category constraints. Bad tools are rejected, not silently accepted.
|
|
22
|
+
|
|
23
|
+
🧠 **Semantic search (optional)** — Add [Ollama](https://ollama.ai) for vector similarity search. Without it, Stage 1 + 2 still deliver great results. Graceful degradation — if Ollama goes down, search keeps working.
|
|
24
|
+
|
|
25
|
+
📦 **Zero native dependencies** — Built on [sql.js](https://github.com/sql-js/sql.js) (WASM). No `node-gyp`, no build step, no platform-specific binaries. `npm install` and done.
|
|
26
|
+
|
|
27
|
+
🔌 **Dual execution** — Tools can run as local functions or HTTP endpoints. Register a handler directly, or point to a remote service. Mix and match.
|
|
28
|
+
|
|
29
|
+
🏗️ **Scales to 10,000+** — Centroid hierarchy partitions tools by category, then searches within partitions. 100 tools ~1ms, 1,000 ~3ms, 10,000 ~5ms.
|
|
30
|
+
|
|
31
|
+
🌍 **Universal MCP** — Works with Claude Desktop, Cursor, n2-soul, or any MCP-compatible client. Standard stdio transport.
|
|
32
|
+
|
|
33
|
+
## The Problem
|
|
34
|
+
|
|
35
|
+
Every MCP tool you register eats AI context tokens. With 10 tools that's manageable. With 100, the AI slows down. **With 1,000, it's impossible** — the context window is full before the conversation even starts.
|
|
36
|
+
|
|
37
|
+
QLN solves this by acting as a **semantic search router**:
|
|
38
|
+
|
|
39
|
+
1. Register all your tools in QLN's SQLite index
|
|
40
|
+
2. The AI sees only **one tool**: `n2_qln_call` (~200 tokens)
|
|
41
|
+
3. When the AI needs a tool, it **searches** → **finds the best match** → **executes**
|
|
42
|
+
|
|
43
|
+
**Result: ~200 tokens instead of ~50,000. 99.6% reduction.**
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install n2-qln
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Requirements:** Node.js ≥ 18
|
|
54
|
+
|
|
55
|
+
**Optional:** Install [Ollama](https://ollama.ai) for semantic vector search (Stage 3). See [Semantic Search Setup](#semantic-search-setup-optional).
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Setup
|
|
60
|
+
|
|
61
|
+
QLN is an MCP server. You connect it to any MCP-compatible AI client — Claude Desktop, Cursor, n2-soul, or any other host.
|
|
62
|
+
|
|
63
|
+
### Claude Desktop
|
|
64
|
+
|
|
65
|
+
Edit your Claude Desktop config file:
|
|
66
|
+
|
|
67
|
+
- **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
68
|
+
- **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"mcpServers": {
|
|
73
|
+
"n2-qln": {
|
|
74
|
+
"command": "npx",
|
|
75
|
+
"args": ["-y", "n2-qln"]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Restart Claude Desktop. The `n2_qln_call` tool will appear in your tool list.
|
|
82
|
+
|
|
83
|
+
### Cursor
|
|
84
|
+
|
|
85
|
+
Open **Settings → MCP Servers → Add Server** and configure:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"name": "n2-qln",
|
|
90
|
+
"command": "npx",
|
|
91
|
+
"args": ["-y", "n2-qln"]
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### n2-soul
|
|
96
|
+
|
|
97
|
+
Add to your Soul `config.local.js`:
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
module.exports = {
|
|
101
|
+
mcpServers: {
|
|
102
|
+
'n2-qln': {
|
|
103
|
+
command: 'node',
|
|
104
|
+
args: ['<path-to-qln>/index.js'],
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Or if published to npm:
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
module.exports = {
|
|
114
|
+
mcpServers: {
|
|
115
|
+
'n2-qln': {
|
|
116
|
+
command: 'npx',
|
|
117
|
+
args: ['-y', 'n2-qln'],
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Any MCP Client
|
|
124
|
+
|
|
125
|
+
QLN uses **stdio transport** — the standard MCP communication method. Any MCP-compatible client can connect using:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
command: npx
|
|
129
|
+
args: ["-y", "n2-qln"]
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Or if you cloned the repo:
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
command: node
|
|
136
|
+
args: ["/absolute/path/to/n2-qln/index.js"]
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
> **💡 Tip:** The easiest way to set this up? **Just ask your AI agent.** Tell it *"Add n2-qln to my MCP config"* — it already knows how to configure itself.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## How It Works
|
|
144
|
+
|
|
145
|
+
### Step-by-Step Example
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
User: "Take a screenshot of this page"
|
|
149
|
+
|
|
150
|
+
Step 1 → AI calls: n2_qln_call(action: "search", query: "screenshot page")
|
|
151
|
+
QLN searches 1,000+ tools in <5ms
|
|
152
|
+
Response: take_screenshot (score: 8.0)
|
|
153
|
+
|
|
154
|
+
Step 2 → AI calls: n2_qln_call(action: "exec", tool: "take_screenshot", args: {fullPage: true})
|
|
155
|
+
QLN routes to the actual tool and executes it
|
|
156
|
+
Response: ✅ screenshot saved
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
The AI only used `n2_qln_call`. It never saw the other 999 tools.
|
|
160
|
+
|
|
161
|
+
### 3-Stage Search Engine
|
|
162
|
+
|
|
163
|
+
QLN finds the right tool using three parallel search stages:
|
|
164
|
+
|
|
165
|
+
| Stage | Method | Speed | How it works |
|
|
166
|
+
|:---:|--------|:---:|------|
|
|
167
|
+
| **1** | Trigger Match | ⚡ <1ms | Matches exact words in tool names and trigger keywords |
|
|
168
|
+
| **2** | Keyword Search | ⚡ 1-3ms | Full-text search across descriptions, tags, and examples |
|
|
169
|
+
| **3** | Semantic Search | 🧠 5-15ms | Vector similarity using embeddings *(optional, requires Ollama)* |
|
|
170
|
+
|
|
171
|
+
Results from all stages are merged and ranked:
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
final_score = trigger_score × 3.0
|
|
175
|
+
+ keyword_score × 1.0
|
|
176
|
+
+ semantic_score × 2.0
|
|
177
|
+
+ log2(usage_count + 1) × 0.5
|
|
178
|
+
+ success_rate × 1.0
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Tools that are used more often and succeed more reliably are ranked higher over time.
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## API Reference
|
|
186
|
+
|
|
187
|
+
QLN exposes **one MCP tool** — `n2_qln_call` — with 5 actions.
|
|
188
|
+
|
|
189
|
+
### search — Find tools by natural language
|
|
190
|
+
|
|
191
|
+
```javascript
|
|
192
|
+
n2_qln_call({
|
|
193
|
+
action: "search",
|
|
194
|
+
query: "take a screenshot", // natural language query (required)
|
|
195
|
+
category: "capture", // filter by category (optional)
|
|
196
|
+
topK: 5 // max results, default: 5 (optional)
|
|
197
|
+
})
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**Response:**
|
|
201
|
+
```
|
|
202
|
+
🔍 Results for "take a screenshot" (3 found, 2ms):
|
|
203
|
+
|
|
204
|
+
1. take_screenshot [capture] (score: 8.0)
|
|
205
|
+
Take a full-page or viewport screenshot
|
|
206
|
+
Triggers: take_screenshot, screenshot, capture
|
|
207
|
+
|
|
208
|
+
2. record_video [capture] (score: 5.2)
|
|
209
|
+
Record browser video
|
|
210
|
+
Triggers: record_video, record, video
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### exec — Execute a tool by name
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
n2_qln_call({
|
|
217
|
+
action: "exec",
|
|
218
|
+
tool: "take_screenshot", // tool name (required)
|
|
219
|
+
args: { // tool arguments (optional)
|
|
220
|
+
fullPage: true,
|
|
221
|
+
format: "png"
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### create — Register a new tool
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
n2_qln_call({
|
|
230
|
+
action: "create",
|
|
231
|
+
name: "read_pdf", // required, verb_target format
|
|
232
|
+
description: "Read and extract text from PDF files", // required, min 10 chars
|
|
233
|
+
category: "data", // required, see categories below
|
|
234
|
+
provider: "pdf-tools", // optional, groups tools by source
|
|
235
|
+
tags: ["pdf", "read", "extract", "document"], // optional, improves search
|
|
236
|
+
examples: [ // optional, indexed for keyword search
|
|
237
|
+
"read this PDF file",
|
|
238
|
+
"extract text from PDF",
|
|
239
|
+
"open the PDF"
|
|
240
|
+
],
|
|
241
|
+
endpoint: "http://127.0.0.1:3100", // optional, for HTTP-based tools
|
|
242
|
+
toolSchema: { filePath: { type: "string" } } // optional, input schema
|
|
243
|
+
})
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**Validation rules (enforced — rejected if violated):**
|
|
247
|
+
|
|
248
|
+
| Rule | Requirement | Example |
|
|
249
|
+
|------|------------|---------|
|
|
250
|
+
| **Name** | `verb_target` format (lowercase + underscore) | `read_pdf`, `take_screenshot` |
|
|
251
|
+
| **Description** | Minimum 10 characters | `"Read and extract text from PDF files"` |
|
|
252
|
+
| **Category** | Must be one of the valid categories | `"data"` |
|
|
253
|
+
| **Unique** | No duplicate names allowed | — |
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
❌ pdfReader → Rejected: not verb_target format
|
|
257
|
+
❌ "PDF tool" → Rejected: description under 10 characters
|
|
258
|
+
❌ read_pdf (exists)→ Rejected: duplicate name, use action: "update"
|
|
259
|
+
✅ read_pdf → Accepted
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**Valid categories:** `web` · `data` · `file` · `dev` · `ai` · `capture` · `misc`
|
|
263
|
+
|
|
264
|
+
### update — Modify an existing tool
|
|
265
|
+
|
|
266
|
+
```javascript
|
|
267
|
+
n2_qln_call({
|
|
268
|
+
action: "update",
|
|
269
|
+
tool: "read_pdf", // tool to update (required)
|
|
270
|
+
description: "Enhanced PDF text extractor", // any field can be updated
|
|
271
|
+
examples: ["read this PDF", "parse PDF"],
|
|
272
|
+
tags: ["pdf", "read", "parse"]
|
|
273
|
+
})
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Only changed fields need to be provided. Unchanged fields keep their current values. The same validation rules apply — invalid updates are rejected.
|
|
277
|
+
|
|
278
|
+
### delete — Remove tools
|
|
279
|
+
|
|
280
|
+
```javascript
|
|
281
|
+
// Delete a single tool by name
|
|
282
|
+
n2_qln_call({
|
|
283
|
+
action: "delete",
|
|
284
|
+
tool: "read_pdf"
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
// Delete ALL tools from a provider
|
|
288
|
+
n2_qln_call({
|
|
289
|
+
action: "delete",
|
|
290
|
+
provider: "pdf-tools"
|
|
291
|
+
})
|
|
292
|
+
// → ✅ Deleted 3 tools from provider: pdf-tools
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## Configuration
|
|
298
|
+
|
|
299
|
+
QLN works out of the box with zero configuration. To customize, create `config.local.js` in the QLN directory:
|
|
300
|
+
|
|
301
|
+
```javascript
|
|
302
|
+
module.exports = {
|
|
303
|
+
dataDir: './data', // where SQLite DB is stored
|
|
304
|
+
embedding: {
|
|
305
|
+
enabled: true, // enable Stage 3 semantic search
|
|
306
|
+
provider: 'ollama',
|
|
307
|
+
model: 'nomic-embed-text',
|
|
308
|
+
baseUrl: 'http://127.0.0.1:11434',
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
> **Note:** `config.local.js` is gitignored. Your local settings won't be committed.
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Semantic Search Setup (Optional)
|
|
318
|
+
|
|
319
|
+
Without Ollama, QLN uses Stage 1 (trigger) + Stage 2 (keyword) matching, which already provides excellent results for most use cases.
|
|
320
|
+
|
|
321
|
+
For maximum accuracy, add semantic vector search (Stage 3):
|
|
322
|
+
|
|
323
|
+
### 1. Install Ollama
|
|
324
|
+
|
|
325
|
+
Download from [ollama.ai](https://ollama.ai) and install.
|
|
326
|
+
|
|
327
|
+
### 2. Pull the embedding model
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
ollama pull nomic-embed-text
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### 3. Enable in config
|
|
334
|
+
|
|
335
|
+
Create `config.local.js`:
|
|
336
|
+
|
|
337
|
+
```javascript
|
|
338
|
+
module.exports = {
|
|
339
|
+
embedding: {
|
|
340
|
+
enabled: true,
|
|
341
|
+
provider: 'ollama',
|
|
342
|
+
model: 'nomic-embed-text',
|
|
343
|
+
baseUrl: 'http://127.0.0.1:11434',
|
|
344
|
+
},
|
|
345
|
+
};
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Comparison
|
|
349
|
+
|
|
350
|
+
| Setup | Search Stages | Accuracy | Dependencies |
|
|
351
|
+
|:------|:---:|:---:|:---:|
|
|
352
|
+
| **Default** (no Ollama) | Stage 1 + 2 | ⭐⭐⭐⭐ Great | None |
|
|
353
|
+
| **With Ollama** | Stage 1 + 2 + 3 | ⭐⭐⭐⭐⭐ Perfect | Ollama running |
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## Project Structure
|
|
358
|
+
|
|
359
|
+
```
|
|
360
|
+
n2-qln/
|
|
361
|
+
├── index.js # MCP server entry point
|
|
362
|
+
├── lib/
|
|
363
|
+
│ ├── config.js # Config loader (merges default + local)
|
|
364
|
+
│ ├── store.js # SQLite storage engine (sql.js WASM)
|
|
365
|
+
│ ├── schema.js # Tool schema normalization + search text builder
|
|
366
|
+
│ ├── validator.js # Enforced validation (name, description, category)
|
|
367
|
+
│ ├── registry.js # Tool CRUD + usage tracking + embedding cache
|
|
368
|
+
│ ├── router.js # 3-stage parallel search engine
|
|
369
|
+
│ ├── vector-index.js # Float32 vector index with centroid hierarchy
|
|
370
|
+
│ ├── embedding.js # Ollama embedding client (nomic-embed-text)
|
|
371
|
+
│ └── executor.js # HTTP/function tool executor
|
|
372
|
+
├── tools/
|
|
373
|
+
│ └── qln-call.js # Unified MCP tool (search/exec/create/update/delete)
|
|
374
|
+
├── providers/ # Tool provider manifests (for bulk registration)
|
|
375
|
+
├── config.local.js # Local config overrides (gitignored)
|
|
376
|
+
└── data/ # SQLite database (gitignored, auto-created)
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## Tech Stack
|
|
380
|
+
|
|
381
|
+
| Component | Technology | Why |
|
|
382
|
+
|-----------|-----------|-----|
|
|
383
|
+
| Runtime | Node.js ≥ 18 | MCP SDK compatibility |
|
|
384
|
+
| Database | SQLite via [sql.js](https://github.com/sql-js/sql.js) (WASM) | Zero native deps, cross-platform, no build step |
|
|
385
|
+
| Embeddings | [Ollama](https://ollama.ai) + nomic-embed-text | Local, fast, free, optional |
|
|
386
|
+
| Protocol | [MCP](https://modelcontextprotocol.io) (Model Context Protocol) | Standard AI tool protocol |
|
|
387
|
+
| Validation | [Zod](https://zod.dev) | Runtime type-safe schema validation |
|
|
388
|
+
|
|
389
|
+
## Related Projects
|
|
390
|
+
|
|
391
|
+
| Project | Relationship |
|
|
392
|
+
|---------|-------------|
|
|
393
|
+
| [n2-soul](https://github.com/choihyunsus/n2-soul) | AI agent orchestrator — QLN serves as Soul's "tool brain" |
|
|
394
|
+
|
|
395
|
+
## Built & Battle-Tested
|
|
396
|
+
|
|
397
|
+
This isn't a weekend prototype. QLN has been **tested in production for 2+ months** and is actively used every day as the core tool router for [n2-soul](https://github.com/choihyunsus/n2-soul).
|
|
398
|
+
|
|
399
|
+
Written by **Rose** 🌹 — N2's first AI agent, and the one who routes through QLN hundreds of times a day.
|
|
400
|
+
|
|
401
|
+
If you run into issues or have ideas, feel free to open an issue. We'd love to hear how you use it.
|
|
402
|
+
|
|
403
|
+
## FAQ
|
|
404
|
+
|
|
405
|
+
**"Why do you publish so many projects?"**
|
|
406
|
+
|
|
407
|
+
The N2 ecosystem has been in active development for over 4 months. Every project you see — Soul, QLN, Ark — has been built, tested, and validated in real daily workflows before being published. There's still more to come, not because we're spamming, but because there's a lot that's already been built and proven in production.
|
|
408
|
+
|
|
409
|
+
This is a solo developer project. Building, testing, and documenting everything alone takes time. Thank you for your patience and interest 🙏
|
|
410
|
+
|
|
411
|
+
## License
|
|
412
|
+
|
|
413
|
+
Apache-2.0
|
package/docs/README.md
ADDED
|
Binary file
|
package/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// QLN — Quantum Layer Network MCP server entry point
|
|
3
|
+
// Semantic tool dispatcher: route 1000 tools through 1 router
|
|
4
|
+
const { McpServer } = require('@modelcontextprotocol/sdk/server/mcp.js');
|
|
5
|
+
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
|
|
6
|
+
const { z } = require('zod');
|
|
7
|
+
|
|
8
|
+
// Core
|
|
9
|
+
const { loadConfig } = require('./lib/config');
|
|
10
|
+
const { Store } = require('./lib/store');
|
|
11
|
+
const { Embedding } = require('./lib/embedding');
|
|
12
|
+
const { Registry } = require('./lib/registry');
|
|
13
|
+
const { VectorIndex } = require('./lib/vector-index');
|
|
14
|
+
const { Router } = require('./lib/router');
|
|
15
|
+
const { Executor } = require('./lib/executor');
|
|
16
|
+
|
|
17
|
+
// MCP Tool (unified)
|
|
18
|
+
const { registerQlnCall } = require('./tools/qln-call');
|
|
19
|
+
|
|
20
|
+
async function main() {
|
|
21
|
+
const config = loadConfig();
|
|
22
|
+
|
|
23
|
+
// 1. Core engine initialization
|
|
24
|
+
const store = new Store(config.dataDir);
|
|
25
|
+
await store.init();
|
|
26
|
+
|
|
27
|
+
const embedding = config.embedding?.enabled
|
|
28
|
+
? new Embedding(config.embedding)
|
|
29
|
+
: null;
|
|
30
|
+
|
|
31
|
+
const registry = new Registry(store, embedding);
|
|
32
|
+
registry.load();
|
|
33
|
+
|
|
34
|
+
const vectorIndex = new VectorIndex();
|
|
35
|
+
const router = new Router(registry, vectorIndex, embedding);
|
|
36
|
+
const executor = new Executor(config.executor || {});
|
|
37
|
+
|
|
38
|
+
// 2. Precompute embeddings + build vector index (async, non-blocking)
|
|
39
|
+
if (embedding) {
|
|
40
|
+
setImmediate(async () => {
|
|
41
|
+
try {
|
|
42
|
+
await registry.precomputeEmbeddings();
|
|
43
|
+
router.buildIndex();
|
|
44
|
+
} catch { /* Ollama not available — Stage 1+2 still work */ }
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 3. Create MCP server
|
|
49
|
+
const server = new McpServer({
|
|
50
|
+
name: 'n2-qln',
|
|
51
|
+
version: '3.1.0',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// 4. Register unified MCP tool (1 tool, 5 actions)
|
|
55
|
+
registerQlnCall(server, z, router, executor, registry);
|
|
56
|
+
|
|
57
|
+
// 5. Connect stdio transport
|
|
58
|
+
const transport = new StdioServerTransport();
|
|
59
|
+
await server.connect(transport);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
main().catch(err => {
|
|
63
|
+
console.error(`[QLN] Fatal: ${err.message}`);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
});
|