@shelv/mcp 0.2.0 → 0.2.1
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/CHANGELOG.md +15 -0
- package/LICENSE +173 -12
- package/README.md +6 -0
- package/dist/bin/shelv-mcp.js +26 -20
- package/dist/bin/shelv-mcp.js.map +1 -1
- package/dist/index.js +23 -19
- package/dist/index.js.map +1 -1
- package/package.json +18 -12
- package/server.json +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @shelv/mcp
|
|
2
|
+
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 47f4b58: Prepare `@shelv/adapters` and `@shelv/mcp` for public OSS repository sync and Apache-2.0 licensing.
|
|
8
|
+
- Updated dependencies [47f4b58]
|
|
9
|
+
- @shelv/adapters@0.1.1
|
|
10
|
+
|
|
11
|
+
## 0.2.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 6050828: Add the initial `@shelv/mcp` package with stdio and Streamable HTTP transports plus Shelv shelf tools.
|
package/LICENSE
CHANGED
|
@@ -1,15 +1,176 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
sublicense, or sell this software or any derivative works, in whole or in part,
|
|
6
|
-
except under a separate written agreement signed by Shelv.
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
10
|
-
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
11
|
-
SHELV BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN
|
|
12
|
-
ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
|
|
13
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
7
|
+
1. Definitions.
|
|
14
8
|
|
|
15
|
-
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
package/dist/bin/shelv-mcp.js
CHANGED
|
@@ -42,7 +42,11 @@ function loadConfig(env = process.env) {
|
|
|
42
42
|
apiKey: env.SHELV_API_KEY?.trim() || void 0,
|
|
43
43
|
transport: parseTransport(env.SHELV_MCP_TRANSPORT),
|
|
44
44
|
httpHost: env.SHELV_MCP_HTTP_HOST?.trim() || "127.0.0.1",
|
|
45
|
-
httpPort: parseInteger(
|
|
45
|
+
httpPort: parseInteger(
|
|
46
|
+
env.SHELV_MCP_HTTP_PORT,
|
|
47
|
+
3334,
|
|
48
|
+
"SHELV_MCP_HTTP_PORT"
|
|
49
|
+
),
|
|
46
50
|
enableWriteTools: parseBoolean(env.SHELV_MCP_ENABLE_WRITE_TOOLS, false),
|
|
47
51
|
searchMaxFiles: parseInteger(
|
|
48
52
|
env.SHELV_MCP_SEARCH_MAX_FILES,
|
|
@@ -232,13 +236,16 @@ var ShelvHttpClient = class {
|
|
|
232
236
|
});
|
|
233
237
|
}
|
|
234
238
|
async requestJson(method, path4, options) {
|
|
235
|
-
const response = await this.fetchImplementation(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
239
|
+
const response = await this.fetchImplementation(
|
|
240
|
+
`${this.apiBaseUrl}${path4}`,
|
|
241
|
+
{
|
|
242
|
+
method,
|
|
243
|
+
headers: {
|
|
244
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
245
|
+
},
|
|
246
|
+
body: options?.body
|
|
247
|
+
}
|
|
248
|
+
);
|
|
242
249
|
if (!response.ok) {
|
|
243
250
|
throw new ApiRequestError(
|
|
244
251
|
method,
|
|
@@ -564,17 +571,14 @@ function registerHydrateShelfTool(server, context) {
|
|
|
564
571
|
filesWritten += 1;
|
|
565
572
|
bytesWritten += Buffer.byteLength(content, "utf8");
|
|
566
573
|
}
|
|
567
|
-
return successResult(
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
archive_version: source.kind === "archive" ? source.archiveVersion : null
|
|
576
|
-
}
|
|
577
|
-
);
|
|
574
|
+
return successResult(`Hydrated ${filesWritten} files to ${targetDir}`, {
|
|
575
|
+
shelf_id: input.shelf_id,
|
|
576
|
+
source_kind: source.kind,
|
|
577
|
+
target_dir: targetDir,
|
|
578
|
+
files_written: filesWritten,
|
|
579
|
+
bytes_written: bytesWritten,
|
|
580
|
+
archive_version: source.kind === "archive" ? source.archiveVersion : null
|
|
581
|
+
});
|
|
578
582
|
} catch (error) {
|
|
579
583
|
return errorResult(error);
|
|
580
584
|
}
|
|
@@ -889,7 +893,9 @@ function createShelvMcpRuntime(env = process.env) {
|
|
|
889
893
|
}
|
|
890
894
|
|
|
891
895
|
// src/transports/http.ts
|
|
892
|
-
import {
|
|
896
|
+
import {
|
|
897
|
+
createServer
|
|
898
|
+
} from "http";
|
|
893
899
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
894
900
|
var MCP_PATH = "/mcp";
|
|
895
901
|
function stripPort(value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/server.ts","../../src/config.ts","../../src/errors.ts","../../src/http-client.ts","../../src/tools/create-shelf.ts","../../src/tools/common.ts","../../src/tools/get-shelf-tree.ts","../../src/tools/hydrate-shelf.ts","../../src/tools/list-shelves.ts","../../src/tools/read-shelf-file.ts","../../src/tools/search-shelf.ts","../../src/tools/index.ts","../../src/transports/http.ts","../../src/transports/stdio.ts","../../src/bin/shelv-mcp.ts"],"sourcesContent":["import { createShelvClient } from \"@shelv/adapters\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { loadConfig, type McpConfig } from \"./config\";\nimport { McpToolError } from \"./errors\";\nimport { ShelvHttpClient } from \"./http-client\";\nimport { registerShelvTools } from \"./tools\";\nimport type { ToolContext, ToolExtra } from \"./tools/context\";\n\nexport interface ShelvMcpRuntime {\n server: McpServer;\n config: McpConfig;\n}\n\nfunction validateApiKey(token: string): string {\n const trimmed = token.trim();\n if (!trimmed.startsWith(\"sk_\")) {\n throw new McpToolError({\n code: \"AUTH_ERROR\",\n message: \"Shelv API key must use sk_ prefix\",\n status: 401,\n retryable: false,\n });\n }\n\n return trimmed;\n}\n\nfunction createContext(config: McpConfig): ToolContext {\n return {\n config,\n getApiKey(extra?: ToolExtra) {\n const authToken = extra?.authInfo?.token;\n if (typeof authToken === \"string\" && authToken.trim().length > 0) {\n return validateApiKey(authToken);\n }\n\n if (config.apiKey) {\n return validateApiKey(config.apiKey);\n }\n\n throw new McpToolError({\n code: \"AUTH_ERROR\",\n message:\n \"Missing Shelv API key. Set SHELV_API_KEY or provide Authorization bearer token.\",\n status: 401,\n retryable: false,\n });\n },\n createShelvClient(apiKey: string) {\n return createShelvClient({\n apiKey,\n apiBaseUrl: config.apiBaseUrl,\n });\n },\n createHttpClient(apiKey: string) {\n return new ShelvHttpClient({\n apiKey,\n apiBaseUrl: config.apiBaseUrl,\n });\n },\n };\n}\n\nexport function createShelvMcpRuntime(env: NodeJS.ProcessEnv = process.env): ShelvMcpRuntime {\n const config = loadConfig(env);\n const context = createContext(config);\n\n const server = new McpServer(\n {\n name: \"shelv-mcp\",\n version: \"0.1.0\",\n },\n {\n instructions:\n \"Shelv MCP server for creating, listing, reading, searching, and hydrating document shelves.\",\n },\n );\n\n registerShelvTools(server, context);\n\n return { server, config };\n}\n","const API_BASE_URL = \"https://api.shelv.dev\";\n\nexport type TransportMode = \"stdio\" | \"http\";\n\nexport interface McpConfig {\n apiBaseUrl: string;\n apiKey?: string;\n transport: TransportMode;\n httpHost: string;\n httpPort: number;\n enableWriteTools: boolean;\n searchMaxFiles: number;\n searchMaxBytes: number;\n searchMaxMatches: number;\n readMaxBytes: number;\n}\n\nfunction parseBoolean(value: string | undefined, fallback: boolean): boolean {\n if (value === undefined) return fallback;\n const normalized = value.trim().toLowerCase();\n if (normalized === \"true\" || normalized === \"1\" || normalized === \"yes\") {\n return true;\n }\n if (normalized === \"false\" || normalized === \"0\" || normalized === \"no\") {\n return false;\n }\n throw new Error(`Invalid boolean value: ${value}`);\n}\n\nfunction parseInteger(\n value: string | undefined,\n fallback: number,\n label: string,\n): number {\n if (value === undefined || value.trim() === \"\") {\n return fallback;\n }\n\n const parsed = Number.parseInt(value, 10);\n if (!Number.isFinite(parsed) || parsed <= 0) {\n throw new Error(`${label} must be a positive integer`);\n }\n\n return parsed;\n}\n\nfunction parseTransport(value: string | undefined): TransportMode {\n if (!value || value.trim() === \"\") {\n return \"stdio\";\n }\n\n if (value === \"stdio\" || value === \"http\") {\n return value;\n }\n\n throw new Error(\"SHELV_MCP_TRANSPORT must be either 'stdio' or 'http'\");\n}\n\nexport function loadConfig(env: NodeJS.ProcessEnv = process.env): McpConfig {\n return {\n apiBaseUrl: API_BASE_URL,\n apiKey: env.SHELV_API_KEY?.trim() || undefined,\n transport: parseTransport(env.SHELV_MCP_TRANSPORT),\n httpHost: env.SHELV_MCP_HTTP_HOST?.trim() || \"127.0.0.1\",\n httpPort: parseInteger(env.SHELV_MCP_HTTP_PORT, 3334, \"SHELV_MCP_HTTP_PORT\"),\n enableWriteTools: parseBoolean(env.SHELV_MCP_ENABLE_WRITE_TOOLS, false),\n searchMaxFiles: parseInteger(\n env.SHELV_MCP_SEARCH_MAX_FILES,\n 500,\n \"SHELV_MCP_SEARCH_MAX_FILES\",\n ),\n searchMaxBytes: parseInteger(\n env.SHELV_MCP_SEARCH_MAX_BYTES,\n 5_000_000,\n \"SHELV_MCP_SEARCH_MAX_BYTES\",\n ),\n searchMaxMatches: parseInteger(\n env.SHELV_MCP_SEARCH_MAX_MATCHES,\n 200,\n \"SHELV_MCP_SEARCH_MAX_MATCHES\",\n ),\n readMaxBytes: parseInteger(\n env.SHELV_MCP_READ_MAX_BYTES,\n 250_000,\n \"SHELV_MCP_READ_MAX_BYTES\",\n ),\n };\n}\n","import { AdapterError } from \"@shelv/adapters\";\n\nexport type McpErrorCode =\n | \"INPUT_ERROR\"\n | \"AUTH_ERROR\"\n | \"BILLING_REQUIRED\"\n | \"NOT_FOUND\"\n | \"NOT_READY\"\n | \"RATE_LIMITED\"\n | \"UPSTREAM_ERROR\"\n | \"LOCAL_IO_ERROR\";\n\nexport interface McpToolErrorData {\n code: McpErrorCode;\n message: string;\n status?: number;\n details?: unknown;\n retryable?: boolean;\n}\n\nexport class McpToolError extends Error {\n readonly code: McpErrorCode;\n readonly status?: number;\n readonly details?: unknown;\n readonly retryable?: boolean;\n\n constructor(data: McpToolErrorData, options?: { cause?: unknown }) {\n super(data.message, options);\n this.name = \"McpToolError\";\n this.code = data.code;\n this.status = data.status;\n this.details = data.details;\n this.retryable = data.retryable;\n }\n}\n\nexport class ApiRequestError extends Error {\n readonly method: string;\n readonly path: string;\n readonly status: number;\n readonly body: unknown;\n\n constructor(\n method: string,\n path: string,\n status: number,\n body: unknown,\n options?: { cause?: unknown },\n ) {\n const message =\n typeof body === \"object\" &&\n body !== null &&\n \"message\" in body &&\n typeof (body as { message: unknown }).message === \"string\"\n ? (body as { message: string }).message\n : `Shelv API request failed (${status})`;\n\n super(message, options);\n this.name = \"ApiRequestError\";\n this.method = method;\n this.path = path;\n this.status = status;\n this.body = body;\n }\n}\n\nfunction statusToCode(status: number): McpErrorCode {\n if (status === 400) return \"INPUT_ERROR\";\n if (status === 401 || status === 403) return \"AUTH_ERROR\";\n if (status === 402) return \"BILLING_REQUIRED\";\n if (status === 404) return \"NOT_FOUND\";\n if (status === 409) return \"NOT_READY\";\n if (status === 429) return \"RATE_LIMITED\";\n return \"UPSTREAM_ERROR\";\n}\n\nfunction extractStatusFromMessage(message: string): number | undefined {\n const match = message.match(/\\((\\d{3})\\)/);\n if (!match) return undefined;\n const status = Number.parseInt(match[1] ?? \"\", 10);\n return Number.isFinite(status) ? status : undefined;\n}\n\nexport function toMcpToolError(\n error: unknown,\n fallbackMessage = \"Request failed\",\n): McpToolError {\n if (error instanceof McpToolError) {\n return error;\n }\n\n if (error instanceof ApiRequestError) {\n return new McpToolError(\n {\n code: statusToCode(error.status),\n status: error.status,\n message: error.message,\n details: error.body,\n retryable: error.status >= 500 || error.status === 429,\n },\n { cause: error },\n );\n }\n\n if (error instanceof AdapterError) {\n if (error.code === \"TREE_FETCH_FAILED\") {\n const status = extractStatusFromMessage(error.message);\n return new McpToolError(\n {\n code: status ? statusToCode(status) : \"UPSTREAM_ERROR\",\n status,\n message: error.message,\n retryable: status ? status >= 500 || status === 429 : false,\n },\n { cause: error },\n );\n }\n\n if (error.code === \"ARCHIVE_TIMEOUT\") {\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message,\n retryable: true,\n },\n { cause: error },\n );\n }\n\n if (error.code === \"ARCHIVE_PARSE_FAILED\") {\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message,\n retryable: false,\n },\n { cause: error },\n );\n }\n\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message,\n retryable: false,\n },\n { cause: error },\n );\n }\n\n if (error instanceof Error) {\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message || fallbackMessage,\n retryable: false,\n },\n { cause: error },\n );\n }\n\n return new McpToolError({\n code: \"UPSTREAM_ERROR\",\n message: fallbackMessage,\n details: error,\n retryable: false,\n });\n}\n\nexport function serializeToolError(error: McpToolError): {\n code: McpErrorCode;\n status?: number;\n details?: unknown;\n retryable?: boolean;\n message: string;\n} {\n return {\n code: error.code,\n status: error.status,\n details: error.details,\n retryable: error.retryable,\n message: error.message,\n };\n}\n","import { ApiRequestError } from \"./errors\";\n\nexport interface ShelfSummary {\n publicId: string;\n name: string;\n status: string;\n template: string | null;\n pageCount: number | null;\n reviewMode: boolean;\n createdAt: string;\n updatedAt: string;\n [key: string]: unknown;\n}\n\nexport interface ListShelvesResponse {\n data: ShelfSummary[];\n pagination: {\n page: number;\n limit: number;\n total: number;\n totalPages: number;\n };\n}\n\nexport interface CreateShelfInput {\n pdfBytes: Uint8Array;\n fileName: string;\n name?: string;\n template?: \"book\" | \"legal-contract\" | \"academic-paper\";\n review?: boolean;\n}\n\nexport interface ShelvHttpClientConfig {\n apiKey: string;\n apiBaseUrl: string;\n fetchImplementation?: typeof fetch;\n}\n\nexport class ShelvHttpClient {\n private readonly apiKey: string;\n private readonly apiBaseUrl: string;\n private readonly fetchImplementation: typeof fetch;\n\n constructor(config: ShelvHttpClientConfig) {\n this.apiKey = config.apiKey;\n this.apiBaseUrl = config.apiBaseUrl.replace(/\\/$/, \"\");\n this.fetchImplementation = config.fetchImplementation ?? fetch;\n }\n\n async listShelves(params?: {\n page?: number;\n limit?: number;\n }): Promise<ListShelvesResponse> {\n const search = new URLSearchParams();\n if (params?.page) search.set(\"page\", String(params.page));\n if (params?.limit) search.set(\"limit\", String(params.limit));\n\n const path =\n search.size > 0 ? `/v1/shelves?${search.toString()}` : \"/v1/shelves\";\n\n return this.requestJson<ListShelvesResponse>(\"GET\", path);\n }\n\n async createShelf(input: CreateShelfInput): Promise<ShelfSummary> {\n const formData = new FormData();\n formData.append(\n \"file\",\n new Blob([Buffer.from(input.pdfBytes)], { type: \"application/pdf\" }),\n input.fileName,\n );\n\n if (input.name) formData.append(\"name\", input.name);\n if (input.template) formData.append(\"template\", input.template);\n if (typeof input.review === \"boolean\") {\n formData.append(\"review\", input.review ? \"true\" : \"false\");\n }\n\n return this.requestJson<ShelfSummary>(\"POST\", \"/v1/shelves\", {\n body: formData,\n });\n }\n\n private async requestJson<T>(\n method: \"GET\" | \"POST\",\n path: string,\n options?: { body?: BodyInit },\n ): Promise<T> {\n const response = await this.fetchImplementation(`${this.apiBaseUrl}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: options?.body,\n });\n\n if (!response.ok) {\n throw new ApiRequestError(\n method,\n path,\n response.status,\n await this.parseErrorBody(response),\n );\n }\n\n return (await response.json()) as T;\n }\n\n private async parseErrorBody(response: Response): Promise<unknown> {\n const contentType = response.headers.get(\"content-type\") || \"\";\n if (contentType.includes(\"application/json\")) {\n try {\n return await response.json();\n } catch {\n return { message: \"Failed to parse API error body\" };\n }\n }\n\n try {\n return await response.text();\n } catch {\n return null;\n }\n }\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { McpToolError } from \"../errors\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst MAX_PDF_BYTES = 300 * 1024 * 1024;\n\nconst inputSchema = {\n pdf_path: z.string().min(1),\n name: z.string().min(1).max(100).optional(),\n template: z.enum([\"book\", \"legal-contract\", \"academic-paper\"]).optional(),\n review: z.boolean().optional(),\n};\n\nconst outputSchema = {\n shelf: z.object({\n publicId: z.string(),\n name: z.string(),\n status: z.string(),\n template: z.string().nullable(),\n pageCount: z.number().nullable(),\n reviewMode: z.boolean(),\n createdAt: z.string(),\n updatedAt: z.string(),\n }),\n};\n\nasync function assertPdfFile(filePath: string): Promise<void> {\n const stats = await fs.stat(filePath).catch(() => null);\n if (!stats || !stats.isFile()) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"pdf_path must point to an existing file\",\n status: 400,\n retryable: false,\n });\n }\n\n if (stats.size > MAX_PDF_BYTES) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"PDF exceeds 300 MB limit\",\n status: 400,\n retryable: false,\n });\n }\n\n if (path.extname(filePath).toLowerCase() !== \".pdf\") {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Only .pdf files are supported\",\n status: 400,\n retryable: false,\n });\n }\n\n const handle = await fs.open(filePath, \"r\");\n try {\n const header = Buffer.alloc(5);\n await handle.read(header, 0, 5, 0);\n if (header.toString(\"utf8\") !== \"%PDF-\") {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"File does not appear to be a valid PDF\",\n status: 400,\n retryable: false,\n });\n }\n } finally {\n await handle.close();\n }\n}\n\nexport function registerCreateShelfTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"create_shelf\",\n {\n title: \"Create Shelf\",\n description: \"Upload a local PDF and create a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: false },\n },\n async (input, extra) => {\n try {\n const absolutePath = path.resolve(input.pdf_path);\n await assertPdfFile(absolutePath);\n\n const fileBytes = new Uint8Array(await fs.readFile(absolutePath));\n const apiKey = context.getApiKey(extra);\n const client = context.createHttpClient(apiKey);\n const shelf = await client.createShelf({\n pdfBytes: fileBytes,\n fileName: path.basename(absolutePath),\n name: input.name,\n template: input.template,\n review: input.review,\n });\n\n return successResult(`Created shelf ${shelf.publicId}`, { shelf });\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import path from \"node:path\";\nimport type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport { McpToolError, serializeToolError, toMcpToolError } from \"../errors\";\n\nexport function successResult(\n text: string,\n structuredContent: Record<string, unknown>,\n): CallToolResult {\n return {\n content: [{ type: \"text\", text }],\n structuredContent,\n };\n}\n\nexport function errorResult(error: unknown): CallToolResult {\n const normalized = toMcpToolError(error, \"Tool execution failed\");\n\n return {\n isError: true,\n content: [{ type: \"text\", text: normalized.message }],\n structuredContent: {\n error: serializeToolError(normalized),\n },\n };\n}\n\nexport function ensureRelativePath(inputPath: string): string {\n const trimmed = inputPath.trim();\n\n if (!trimmed) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path is required\",\n status: 400,\n retryable: false,\n });\n }\n\n if (trimmed.includes(\"\\\\\") || trimmed.includes(\"\\0\")) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path contains unsupported characters\",\n status: 400,\n retryable: false,\n });\n }\n\n const normalized = path.posix.normalize(trimmed);\n if (normalized === \".\" || normalized === \"\") {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path must reference a file under the shelf root\",\n status: 400,\n retryable: false,\n });\n }\n\n if (\n normalized === \"..\" ||\n normalized.startsWith(\"../\") ||\n normalized.startsWith(\"/\")\n ) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path traversal is not allowed\",\n status: 400,\n retryable: false,\n });\n }\n\n return normalized;\n}\n\nexport function safeJoin(baseDir: string, relativePath: string): string {\n const resolvedBase = path.resolve(baseDir);\n const candidate = path.resolve(resolvedBase, relativePath);\n\n if (\n candidate !== resolvedBase &&\n !candidate.startsWith(`${resolvedBase}${path.sep}`)\n ) {\n throw new McpToolError({\n code: \"LOCAL_IO_ERROR\",\n message: `Unsafe output path: ${relativePath}`,\n retryable: false,\n });\n }\n\n return candidate;\n}\n\nexport function truncateUtf8(\n content: string,\n maxBytes: number,\n): { value: string; truncated: boolean; bytes: number } {\n const totalBytes = Buffer.byteLength(content, \"utf8\");\n if (totalBytes <= maxBytes) {\n return { value: content, truncated: false, bytes: totalBytes };\n }\n\n let low = 0;\n let high = content.length;\n while (low < high) {\n const mid = Math.ceil((low + high) / 2);\n const candidateBytes = Buffer.byteLength(content.slice(0, mid), \"utf8\");\n if (candidateBytes <= maxBytes) {\n low = mid;\n } else {\n high = mid - 1;\n }\n }\n\n const value = content.slice(0, low);\n return {\n value,\n truncated: true,\n bytes: Buffer.byteLength(value, \"utf8\"),\n };\n}\n\nexport function inferContentType(filePath: string): string {\n const ext = path.extname(filePath).toLowerCase();\n\n if (ext === \".md\") return \"text/markdown\";\n if (ext === \".json\") return \"application/json\";\n if (ext === \".txt\") return \"text/plain\";\n\n return \"text/plain\";\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n name: z.string(),\n file_count: z.number(),\n files: z.record(z.string()),\n};\n\nexport function registerGetShelfTreeTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"get_shelf_tree\",\n {\n title: \"Get Shelf Tree\",\n description: \"Get the full file tree and file contents for a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const apiKey = context.getApiKey(extra);\n const client = context.createShelvClient(apiKey);\n const tree = await client.getTree(input.shelf_id);\n\n return successResult(\n `Loaded ${tree.fileCount} files for shelf ${tree.shelfPublicId}`,\n {\n shelf_id: tree.shelfPublicId,\n name: tree.name,\n file_count: tree.fileCount,\n files: tree.files,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { resolveShelfSource } from \"@shelv/adapters\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { McpToolError } from \"../errors\";\nimport { ensureRelativePath, errorResult, safeJoin, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n target_dir: z.string().min(1),\n overwrite: z.boolean().optional(),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n source_kind: z.enum([\"archive\", \"tree\"]),\n target_dir: z.string(),\n files_written: z.number(),\n bytes_written: z.number(),\n archive_version: z.string().nullable(),\n};\n\nexport function registerHydrateShelfTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"hydrate_shelf\",\n {\n title: \"Hydrate Shelf\",\n description: \"Download and write shelf files into a local directory\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: false },\n },\n async (input, extra) => {\n try {\n const apiKey = context.getApiKey(extra);\n const source = await resolveShelfSource({\n client: context.createShelvClient(apiKey),\n shelfPublicId: input.shelf_id,\n mode: \"archive-first\",\n });\n\n const overwrite = input.overwrite ?? false;\n const targetDir = path.resolve(input.target_dir);\n\n await fs.mkdir(targetDir, { recursive: true });\n\n let filesWritten = 0;\n let bytesWritten = 0;\n\n for (const [relativePath, content] of Object.entries(source.files)) {\n const normalized = ensureRelativePath(relativePath);\n const fullPath = safeJoin(targetDir, normalized);\n\n if (!overwrite) {\n const exists = await fs\n .access(fullPath)\n .then(() => true)\n .catch(() => false);\n\n if (exists) {\n throw new McpToolError({\n code: \"LOCAL_IO_ERROR\",\n message: `Refusing to overwrite existing file: ${normalized}`,\n retryable: false,\n });\n }\n }\n\n await fs.mkdir(path.dirname(fullPath), { recursive: true });\n await fs.writeFile(fullPath, content, \"utf8\");\n\n filesWritten += 1;\n bytesWritten += Buffer.byteLength(content, \"utf8\");\n }\n\n return successResult(\n `Hydrated ${filesWritten} files to ${targetDir}`,\n {\n shelf_id: input.shelf_id,\n source_kind: source.kind,\n target_dir: targetDir,\n files_written: filesWritten,\n bytes_written: bytesWritten,\n archive_version: source.kind === \"archive\" ? source.archiveVersion : null,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n page: z.number().int().min(1).optional(),\n limit: z.number().int().min(1).max(100).optional(),\n};\n\nconst outputSchema = {\n shelves: z.array(\n z.object({\n publicId: z.string(),\n name: z.string(),\n status: z.string(),\n template: z.string().nullable(),\n pageCount: z.number().nullable(),\n reviewMode: z.boolean(),\n createdAt: z.string(),\n updatedAt: z.string(),\n }),\n ),\n pagination: z.object({\n page: z.number(),\n limit: z.number(),\n total: z.number(),\n totalPages: z.number(),\n }),\n};\n\nexport function registerListShelvesTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"list_shelves\",\n {\n title: \"List Shelves\",\n description: \"List shelves available to the authenticated user\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const apiKey = context.getApiKey(extra);\n const client = context.createHttpClient(apiKey);\n const result = await client.listShelves({\n page: input.page,\n limit: input.limit,\n });\n\n return successResult(\n `Loaded ${result.data.length} shelves (page ${result.pagination.page}/${result.pagination.totalPages})`,\n {\n shelves: result.data,\n pagination: result.pagination,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { ensureRelativePath, errorResult, inferContentType, successResult, truncateUtf8 } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n path: z.string().min(1),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n path: z.string(),\n content_type: z.string(),\n content: z.string(),\n bytes: z.number(),\n truncated: z.boolean(),\n};\n\nexport function registerReadShelfFileTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"read_shelf_file\",\n {\n title: \"Read Shelf File\",\n description: \"Read a single file from a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const normalizedPath = ensureRelativePath(input.path);\n const apiKey = context.getApiKey(extra);\n const client = context.createShelvClient(apiKey);\n const raw = await client.getFile(input.shelf_id, normalizedPath);\n\n const truncated = truncateUtf8(raw, context.config.readMaxBytes);\n\n return successResult(\n truncated.truncated\n ? `Read ${normalizedPath} (truncated to ${truncated.bytes} bytes)`\n : `Read ${normalizedPath}`,\n {\n shelf_id: input.shelf_id,\n path: normalizedPath,\n content_type: inferContentType(normalizedPath),\n content: truncated.value,\n bytes: truncated.bytes,\n truncated: truncated.truncated,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import { resolveShelfSource } from \"@shelv/adapters\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { McpToolError } from \"../errors\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n query: z.string().min(1),\n mode: z.enum([\"substring\", \"regex\"]).optional(),\n case_sensitive: z.boolean().optional(),\n max_matches: z.number().int().min(1).optional(),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n query: z.string(),\n mode: z.enum([\"substring\", \"regex\"]),\n case_sensitive: z.boolean(),\n matches: z.array(\n z.object({\n path: z.string(),\n line: z.string(),\n line_number: z.number(),\n snippet: z.string(),\n }),\n ),\n scanned_files: z.number(),\n scanned_bytes: z.number(),\n truncated: z.boolean(),\n};\n\nfunction buildMatcher(\n query: string,\n mode: \"substring\" | \"regex\",\n caseSensitive: boolean,\n): (line: string) => boolean {\n if (mode === \"regex\") {\n let regex: RegExp;\n try {\n regex = new RegExp(query, caseSensitive ? \"\" : \"i\");\n } catch {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Invalid regular expression\",\n status: 400,\n retryable: false,\n });\n }\n\n return (line: string) => regex.test(line);\n }\n\n const needle = caseSensitive ? query : query.toLowerCase();\n return (line: string) => {\n const haystack = caseSensitive ? line : line.toLowerCase();\n return haystack.includes(needle);\n };\n}\n\nexport function registerSearchShelfTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"search_shelf\",\n {\n title: \"Search Shelf\",\n description: \"Search for text across files in a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const mode = input.mode ?? \"substring\";\n const caseSensitive = input.case_sensitive ?? false;\n\n const apiKey = context.getApiKey(extra);\n const source = await resolveShelfSource({\n client: context.createShelvClient(apiKey),\n shelfPublicId: input.shelf_id,\n mode: \"archive-first\",\n });\n\n const matcher = buildMatcher(input.query, mode, caseSensitive);\n const maxMatches = Math.min(\n input.max_matches ?? context.config.searchMaxMatches,\n context.config.searchMaxMatches,\n );\n\n const matches: Array<{\n path: string;\n line: string;\n line_number: number;\n snippet: string;\n }> = [];\n\n let scannedFiles = 0;\n let scannedBytes = 0;\n let truncated = false;\n\n for (const [filePath, content] of Object.entries(source.files)) {\n if (scannedFiles >= context.config.searchMaxFiles) {\n truncated = true;\n break;\n }\n\n const bytes = Buffer.byteLength(content, \"utf8\");\n if (scannedBytes + bytes > context.config.searchMaxBytes) {\n truncated = true;\n break;\n }\n\n scannedFiles += 1;\n scannedBytes += bytes;\n\n const lines = content.split(/\\r?\\n/);\n for (let index = 0; index < lines.length; index += 1) {\n const line = lines[index] || \"\";\n if (!matcher(line)) continue;\n\n matches.push({\n path: filePath,\n line,\n line_number: index + 1,\n snippet: line.slice(0, 300),\n });\n\n if (matches.length >= maxMatches) {\n truncated = true;\n break;\n }\n }\n\n if (truncated) break;\n }\n\n return successResult(\n `Found ${matches.length} matches across ${scannedFiles} files`,\n {\n shelf_id: input.shelf_id,\n query: input.query,\n mode,\n case_sensitive: caseSensitive,\n matches,\n scanned_files: scannedFiles,\n scanned_bytes: scannedBytes,\n truncated,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { ToolContext } from \"./context\";\nimport { registerCreateShelfTool } from \"./create-shelf\";\nimport { registerGetShelfTreeTool } from \"./get-shelf-tree\";\nimport { registerHydrateShelfTool } from \"./hydrate-shelf\";\nimport { registerListShelvesTool } from \"./list-shelves\";\nimport { registerReadShelfFileTool } from \"./read-shelf-file\";\nimport { registerSearchShelfTool } from \"./search-shelf\";\n\nexport function registerShelvTools(server: McpServer, context: ToolContext): void {\n registerListShelvesTool(server, context);\n registerGetShelfTreeTool(server, context);\n registerReadShelfFileTool(server, context);\n registerSearchShelfTool(server, context);\n\n if (context.config.enableWriteTools) {\n registerCreateShelfTool(server, context);\n registerHydrateShelfTool(server, context);\n }\n}\n","import { createServer, type IncomingMessage, type Server as HttpServer, type ServerResponse } from \"node:http\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StreamableHTTPServerTransport } from \"@modelcontextprotocol/sdk/server/streamableHttp.js\";\nimport type { AuthInfo } from \"@modelcontextprotocol/sdk/server/auth/types.js\";\nimport type { McpConfig } from \"../config\";\n\nconst MCP_PATH = \"/mcp\";\ntype IncomingAuthenticatedRequest = IncomingMessage & { auth?: AuthInfo };\n\nfunction stripPort(value: string): string {\n const trimmed = value.trim();\n if (trimmed.startsWith(\"[\")) {\n const end = trimmed.indexOf(\"]\");\n if (end >= 0) return trimmed.slice(1, end).toLowerCase();\n }\n\n const [host] = trimmed.split(\":\");\n return (host || \"\").toLowerCase();\n}\n\nfunction getAllowedHosts(config: McpConfig): Set<string> {\n const configuredHost = stripPort(config.httpHost);\n const hosts = new Set([\"localhost\", \"127.0.0.1\", \"::1\", configuredHost]);\n return hosts;\n}\n\nfunction readJsonBody(req: IncomingMessage): Promise<unknown> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = [];\n\n req.on(\"data\", (chunk: Buffer) => {\n chunks.push(chunk);\n });\n\n req.on(\"error\", reject);\n\n req.on(\"end\", () => {\n if (chunks.length === 0) {\n resolve(undefined);\n return;\n }\n\n const raw = Buffer.concat(chunks).toString(\"utf8\");\n try {\n resolve(JSON.parse(raw));\n } catch {\n reject(new Error(\"Invalid JSON request body\"));\n }\n });\n });\n}\n\nfunction respondJson(\n res: ServerResponse,\n status: number,\n payload: Record<string, unknown>,\n): void {\n if (res.writableEnded) return;\n\n const body = JSON.stringify(payload);\n res.statusCode = status;\n res.setHeader(\"content-type\", \"application/json\");\n res.end(body);\n}\n\nfunction validateHostAndOrigin(\n req: IncomingMessage,\n config: McpConfig,\n): { ok: true } | { ok: false; reason: string } {\n const allowedHosts = getAllowedHosts(config);\n\n const hostHeader = req.headers.host;\n if (hostHeader) {\n const host = stripPort(hostHeader);\n if (!allowedHosts.has(host)) {\n return { ok: false, reason: \"Host header is not allowed\" };\n }\n }\n\n const origin = req.headers.origin;\n if (origin) {\n try {\n const originHost = stripPort(new URL(origin).host);\n if (!allowedHosts.has(originHost)) {\n return { ok: false, reason: \"Origin is not allowed\" };\n }\n } catch {\n return { ok: false, reason: \"Invalid Origin header\" };\n }\n }\n\n return { ok: true };\n}\n\nfunction parseAuth(\n req: IncomingMessage,\n config: McpConfig,\n): { ok: true; auth?: AuthInfo } | { ok: false; reason: string } {\n const header = req.headers.authorization;\n if (header === undefined || header.trim() === \"\") {\n if (config.apiKey) {\n return {\n ok: true,\n auth: {\n token: config.apiKey,\n clientId: \"env-fallback\",\n scopes: [],\n expiresAt: undefined,\n },\n };\n }\n\n return {\n ok: false,\n reason: \"Missing Authorization header\",\n };\n }\n\n if (!header.startsWith(\"Bearer \")) {\n return {\n ok: false,\n reason: \"Authorization must use Bearer token\",\n };\n }\n\n const token = header.slice(\"Bearer \".length).trim();\n if (!token.startsWith(\"sk_\")) {\n return {\n ok: false,\n reason: \"Shelv API key must use sk_ prefix\",\n };\n }\n\n return {\n ok: true,\n auth: {\n token,\n clientId: \"request-bearer\",\n scopes: [],\n expiresAt: undefined,\n },\n };\n}\n\nexport interface HttpTransportHandle {\n server: HttpServer;\n url: string;\n close(): Promise<void>;\n}\n\nexport async function runHttpTransport(\n server: McpServer,\n config: McpConfig,\n): Promise<HttpTransportHandle> {\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: undefined,\n });\n\n await server.connect(transport);\n\n const httpServer = createServer(async (req, res) => {\n try {\n const requestPath = req.url ? new URL(req.url, \"http://localhost\").pathname : \"/\";\n if (requestPath !== MCP_PATH) {\n respondJson(res, 404, { error: \"Not found\" });\n return;\n }\n\n const method = req.method || \"GET\";\n if (![\"GET\", \"POST\", \"DELETE\"].includes(method)) {\n respondJson(res, 405, { error: \"Method not allowed\" });\n return;\n }\n\n const security = validateHostAndOrigin(req, config);\n if (!security.ok) {\n respondJson(res, 403, { error: security.reason });\n return;\n }\n\n const auth = parseAuth(req, config);\n if (!auth.ok) {\n respondJson(res, 401, { error: auth.reason });\n return;\n }\n\n const authenticatedRequest = req as IncomingAuthenticatedRequest;\n authenticatedRequest.auth = auth.auth;\n\n const body = method === \"POST\" ? await readJsonBody(req) : undefined;\n await transport.handleRequest(authenticatedRequest, res, body);\n } catch (error) {\n respondJson(res, 500, {\n error: error instanceof Error ? error.message : \"Internal server error\",\n });\n }\n });\n\n await new Promise<void>((resolve, reject) => {\n httpServer.once(\"error\", reject);\n httpServer.listen(config.httpPort, config.httpHost, () => {\n httpServer.off(\"error\", reject);\n resolve();\n });\n });\n\n const host = config.httpHost.includes(\":\") ? `[${config.httpHost}]` : config.httpHost;\n const url = `http://${host}:${config.httpPort}${MCP_PATH}`;\n\n return {\n server: httpServer,\n url,\n close() {\n return new Promise((resolve, reject) => {\n httpServer.close((error) => {\n if (error) {\n reject(error);\n return;\n }\n resolve();\n });\n });\n },\n };\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\n\nexport async function runStdioTransport(server: McpServer): Promise<void> {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n}\n","#!/usr/bin/env node\nimport { createShelvMcpRuntime } from \"../server\";\nimport { runHttpTransport } from \"../transports/http\";\nimport { runStdioTransport } from \"../transports/stdio\";\n\nasync function main(): Promise<void> {\n const runtime = createShelvMcpRuntime();\n\n if (runtime.config.transport === \"stdio\") {\n if (!runtime.config.apiKey) {\n throw new Error(\"SHELV_API_KEY is required in stdio mode\");\n }\n\n await runStdioTransport(runtime.server);\n return;\n }\n\n const http = await runHttpTransport(runtime.server, runtime.config);\n console.error(`shelv-mcp listening at ${http.url}`);\n console.error(\n runtime.config.enableWriteTools\n ? \"write tools enabled\"\n : \"write tools disabled (set SHELV_MCP_ENABLE_WRITE_TOOLS=true to enable)\",\n );\n}\n\nmain().catch((error) => {\n console.error(\n error instanceof Error ? error.message : \"Failed to start shelv-mcp\",\n );\n process.exit(1);\n});\n"],"mappings":";;;AAAA,SAAS,yBAAyB;AAClC,SAAS,iBAAiB;;;ACD1B,IAAM,eAAe;AAiBrB,SAAS,aAAa,OAA2B,UAA4B;AAC3E,MAAI,UAAU,OAAW,QAAO;AAChC,QAAM,aAAa,MAAM,KAAK,EAAE,YAAY;AAC5C,MAAI,eAAe,UAAU,eAAe,OAAO,eAAe,OAAO;AACvE,WAAO;AAAA,EACT;AACA,MAAI,eAAe,WAAW,eAAe,OAAO,eAAe,MAAM;AACvE,WAAO;AAAA,EACT;AACA,QAAM,IAAI,MAAM,0BAA0B,KAAK,EAAE;AACnD;AAEA,SAAS,aACP,OACA,UACA,OACQ;AACR,MAAI,UAAU,UAAa,MAAM,KAAK,MAAM,IAAI;AAC9C,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,OAAO,SAAS,OAAO,EAAE;AACxC,MAAI,CA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ACxC,QAAI,CAAC,QAAQ,OAAO,QAAQ;AAC1B,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AAEA,UAAM,kBAAkB,QAAQ,MAAM;AACtC;AAAA,EACF;AAEA,QAAM,OAAO,MAAM,iBAAiB,QAAQ,QAAQ,QAAQ,MAAM;AAClE,UAAQ,MAAM,0BAA0B,KAAK,GAAG,EAAE;AAClD,UAAQ;AAAA,IACN,QAAQ,OAAO,mBACX,wBACA;AAAA,EACN;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,UAAU;AACtB,UAAQ;AAAA,IACN,iBAAiB,QAAQ,MAAM,UAAU;AAAA,EAC3C;AACA,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["path","path","path","path","z","inputSchema","z","outputSchema","fs","path","z","inputSchema","z","outputSchema","path","fs","z","inputSchema","z","outputSchema","z","inputSchema","z","outputSchema","resolveShelfSource","z","inputSchema","z","outputSchema","resolveShelfSource"]}
|
|
1
|
+
{"version":3,"sources":["../../src/server.ts","../../src/config.ts","../../src/errors.ts","../../src/http-client.ts","../../src/tools/create-shelf.ts","../../src/tools/common.ts","../../src/tools/get-shelf-tree.ts","../../src/tools/hydrate-shelf.ts","../../src/tools/list-shelves.ts","../../src/tools/read-shelf-file.ts","../../src/tools/search-shelf.ts","../../src/tools/index.ts","../../src/transports/http.ts","../../src/transports/stdio.ts","../../src/bin/shelv-mcp.ts"],"sourcesContent":["import { createShelvClient } from \"@shelv/adapters\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { loadConfig, type McpConfig } from \"./config\";\nimport { McpToolError } from \"./errors\";\nimport { ShelvHttpClient } from \"./http-client\";\nimport { registerShelvTools } from \"./tools\";\nimport type { ToolContext, ToolExtra } from \"./tools/context\";\n\nexport interface ShelvMcpRuntime {\n server: McpServer;\n config: McpConfig;\n}\n\nfunction validateApiKey(token: string): string {\n const trimmed = token.trim();\n if (!trimmed.startsWith(\"sk_\")) {\n throw new McpToolError({\n code: \"AUTH_ERROR\",\n message: \"Shelv API key must use sk_ prefix\",\n status: 401,\n retryable: false,\n });\n }\n\n return trimmed;\n}\n\nfunction createContext(config: McpConfig): ToolContext {\n return {\n config,\n getApiKey(extra?: ToolExtra) {\n const authToken = extra?.authInfo?.token;\n if (typeof authToken === \"string\" && authToken.trim().length > 0) {\n return validateApiKey(authToken);\n }\n\n if (config.apiKey) {\n return validateApiKey(config.apiKey);\n }\n\n throw new McpToolError({\n code: \"AUTH_ERROR\",\n message:\n \"Missing Shelv API key. Set SHELV_API_KEY or provide Authorization bearer token.\",\n status: 401,\n retryable: false,\n });\n },\n createShelvClient(apiKey: string) {\n return createShelvClient({\n apiKey,\n apiBaseUrl: config.apiBaseUrl,\n });\n },\n createHttpClient(apiKey: string) {\n return new ShelvHttpClient({\n apiKey,\n apiBaseUrl: config.apiBaseUrl,\n });\n },\n };\n}\n\nexport function createShelvMcpRuntime(\n env: NodeJS.ProcessEnv = process.env,\n): ShelvMcpRuntime {\n const config = loadConfig(env);\n const context = createContext(config);\n\n const server = new McpServer(\n {\n name: \"shelv-mcp\",\n version: \"0.1.0\",\n },\n {\n instructions:\n \"Shelv MCP server for creating, listing, reading, searching, and hydrating document shelves.\",\n },\n );\n\n registerShelvTools(server, context);\n\n return { server, config };\n}\n","const API_BASE_URL = \"https://api.shelv.dev\";\n\nexport type TransportMode = \"stdio\" | \"http\";\n\nexport interface McpConfig {\n apiBaseUrl: string;\n apiKey?: string;\n transport: TransportMode;\n httpHost: string;\n httpPort: number;\n enableWriteTools: boolean;\n searchMaxFiles: number;\n searchMaxBytes: number;\n searchMaxMatches: number;\n readMaxBytes: number;\n}\n\nfunction parseBoolean(value: string | undefined, fallback: boolean): boolean {\n if (value === undefined) return fallback;\n const normalized = value.trim().toLowerCase();\n if (normalized === \"true\" || normalized === \"1\" || normalized === \"yes\") {\n return true;\n }\n if (normalized === \"false\" || normalized === \"0\" || normalized === \"no\") {\n return false;\n }\n throw new Error(`Invalid boolean value: ${value}`);\n}\n\nfunction parseInteger(\n value: string | undefined,\n fallback: number,\n label: string,\n): number {\n if (value === undefined || value.trim() === \"\") {\n return fallback;\n }\n\n const parsed = Number.parseInt(value, 10);\n if (!Number.isFinite(parsed) || parsed <= 0) {\n throw new Error(`${label} must be a positive integer`);\n }\n\n return parsed;\n}\n\nfunction parseTransport(value: string | undefined): TransportMode {\n if (!value || value.trim() === \"\") {\n return \"stdio\";\n }\n\n if (value === \"stdio\" || value === \"http\") {\n return value;\n }\n\n throw new Error(\"SHELV_MCP_TRANSPORT must be either 'stdio' or 'http'\");\n}\n\nexport function loadConfig(env: NodeJS.ProcessEnv = process.env): McpConfig {\n return {\n apiBaseUrl: API_BASE_URL,\n apiKey: env.SHELV_API_KEY?.trim() || undefined,\n transport: parseTransport(env.SHELV_MCP_TRANSPORT),\n httpHost: env.SHELV_MCP_HTTP_HOST?.trim() || \"127.0.0.1\",\n httpPort: parseInteger(\n env.SHELV_MCP_HTTP_PORT,\n 3334,\n \"SHELV_MCP_HTTP_PORT\",\n ),\n enableWriteTools: parseBoolean(env.SHELV_MCP_ENABLE_WRITE_TOOLS, false),\n searchMaxFiles: parseInteger(\n env.SHELV_MCP_SEARCH_MAX_FILES,\n 500,\n \"SHELV_MCP_SEARCH_MAX_FILES\",\n ),\n searchMaxBytes: parseInteger(\n env.SHELV_MCP_SEARCH_MAX_BYTES,\n 5_000_000,\n \"SHELV_MCP_SEARCH_MAX_BYTES\",\n ),\n searchMaxMatches: parseInteger(\n env.SHELV_MCP_SEARCH_MAX_MATCHES,\n 200,\n \"SHELV_MCP_SEARCH_MAX_MATCHES\",\n ),\n readMaxBytes: parseInteger(\n env.SHELV_MCP_READ_MAX_BYTES,\n 250_000,\n \"SHELV_MCP_READ_MAX_BYTES\",\n ),\n };\n}\n","import { AdapterError } from \"@shelv/adapters\";\n\nexport type McpErrorCode =\n | \"INPUT_ERROR\"\n | \"AUTH_ERROR\"\n | \"BILLING_REQUIRED\"\n | \"NOT_FOUND\"\n | \"NOT_READY\"\n | \"RATE_LIMITED\"\n | \"UPSTREAM_ERROR\"\n | \"LOCAL_IO_ERROR\";\n\nexport interface McpToolErrorData {\n code: McpErrorCode;\n message: string;\n status?: number;\n details?: unknown;\n retryable?: boolean;\n}\n\nexport class McpToolError extends Error {\n readonly code: McpErrorCode;\n readonly status?: number;\n readonly details?: unknown;\n readonly retryable?: boolean;\n\n constructor(data: McpToolErrorData, options?: { cause?: unknown }) {\n super(data.message, options);\n this.name = \"McpToolError\";\n this.code = data.code;\n this.status = data.status;\n this.details = data.details;\n this.retryable = data.retryable;\n }\n}\n\nexport class ApiRequestError extends Error {\n readonly method: string;\n readonly path: string;\n readonly status: number;\n readonly body: unknown;\n\n constructor(\n method: string,\n path: string,\n status: number,\n body: unknown,\n options?: { cause?: unknown },\n ) {\n const message =\n typeof body === \"object\" &&\n body !== null &&\n \"message\" in body &&\n typeof (body as { message: unknown }).message === \"string\"\n ? (body as { message: string }).message\n : `Shelv API request failed (${status})`;\n\n super(message, options);\n this.name = \"ApiRequestError\";\n this.method = method;\n this.path = path;\n this.status = status;\n this.body = body;\n }\n}\n\nfunction statusToCode(status: number): McpErrorCode {\n if (status === 400) return \"INPUT_ERROR\";\n if (status === 401 || status === 403) return \"AUTH_ERROR\";\n if (status === 402) return \"BILLING_REQUIRED\";\n if (status === 404) return \"NOT_FOUND\";\n if (status === 409) return \"NOT_READY\";\n if (status === 429) return \"RATE_LIMITED\";\n return \"UPSTREAM_ERROR\";\n}\n\nfunction extractStatusFromMessage(message: string): number | undefined {\n const match = message.match(/\\((\\d{3})\\)/);\n if (!match) return undefined;\n const status = Number.parseInt(match[1] ?? \"\", 10);\n return Number.isFinite(status) ? status : undefined;\n}\n\nexport function toMcpToolError(\n error: unknown,\n fallbackMessage = \"Request failed\",\n): McpToolError {\n if (error instanceof McpToolError) {\n return error;\n }\n\n if (error instanceof ApiRequestError) {\n return new McpToolError(\n {\n code: statusToCode(error.status),\n status: error.status,\n message: error.message,\n details: error.body,\n retryable: error.status >= 500 || error.status === 429,\n },\n { cause: error },\n );\n }\n\n if (error instanceof AdapterError) {\n if (error.code === \"TREE_FETCH_FAILED\") {\n const status = extractStatusFromMessage(error.message);\n return new McpToolError(\n {\n code: status ? statusToCode(status) : \"UPSTREAM_ERROR\",\n status,\n message: error.message,\n retryable: status ? status >= 500 || status === 429 : false,\n },\n { cause: error },\n );\n }\n\n if (error.code === \"ARCHIVE_TIMEOUT\") {\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message,\n retryable: true,\n },\n { cause: error },\n );\n }\n\n if (error.code === \"ARCHIVE_PARSE_FAILED\") {\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message,\n retryable: false,\n },\n { cause: error },\n );\n }\n\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message,\n retryable: false,\n },\n { cause: error },\n );\n }\n\n if (error instanceof Error) {\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message || fallbackMessage,\n retryable: false,\n },\n { cause: error },\n );\n }\n\n return new McpToolError({\n code: \"UPSTREAM_ERROR\",\n message: fallbackMessage,\n details: error,\n retryable: false,\n });\n}\n\nexport function serializeToolError(error: McpToolError): {\n code: McpErrorCode;\n status?: number;\n details?: unknown;\n retryable?: boolean;\n message: string;\n} {\n return {\n code: error.code,\n status: error.status,\n details: error.details,\n retryable: error.retryable,\n message: error.message,\n };\n}\n","import { ApiRequestError } from \"./errors\";\n\nexport interface ShelfSummary {\n publicId: string;\n name: string;\n status: string;\n template: string | null;\n pageCount: number | null;\n reviewMode: boolean;\n createdAt: string;\n updatedAt: string;\n [key: string]: unknown;\n}\n\nexport interface ListShelvesResponse {\n data: ShelfSummary[];\n pagination: {\n page: number;\n limit: number;\n total: number;\n totalPages: number;\n };\n}\n\nexport interface CreateShelfInput {\n pdfBytes: Uint8Array;\n fileName: string;\n name?: string;\n template?: \"book\" | \"legal-contract\" | \"academic-paper\";\n review?: boolean;\n}\n\nexport interface ShelvHttpClientConfig {\n apiKey: string;\n apiBaseUrl: string;\n fetchImplementation?: typeof fetch;\n}\n\nexport class ShelvHttpClient {\n private readonly apiKey: string;\n private readonly apiBaseUrl: string;\n private readonly fetchImplementation: typeof fetch;\n\n constructor(config: ShelvHttpClientConfig) {\n this.apiKey = config.apiKey;\n this.apiBaseUrl = config.apiBaseUrl.replace(/\\/$/, \"\");\n this.fetchImplementation = config.fetchImplementation ?? fetch;\n }\n\n async listShelves(params?: {\n page?: number;\n limit?: number;\n }): Promise<ListShelvesResponse> {\n const search = new URLSearchParams();\n if (params?.page) search.set(\"page\", String(params.page));\n if (params?.limit) search.set(\"limit\", String(params.limit));\n\n const path =\n search.size > 0 ? `/v1/shelves?${search.toString()}` : \"/v1/shelves\";\n\n return this.requestJson<ListShelvesResponse>(\"GET\", path);\n }\n\n async createShelf(input: CreateShelfInput): Promise<ShelfSummary> {\n const formData = new FormData();\n formData.append(\n \"file\",\n new Blob([Buffer.from(input.pdfBytes)], { type: \"application/pdf\" }),\n input.fileName,\n );\n\n if (input.name) formData.append(\"name\", input.name);\n if (input.template) formData.append(\"template\", input.template);\n if (typeof input.review === \"boolean\") {\n formData.append(\"review\", input.review ? \"true\" : \"false\");\n }\n\n return this.requestJson<ShelfSummary>(\"POST\", \"/v1/shelves\", {\n body: formData,\n });\n }\n\n private async requestJson<T>(\n method: \"GET\" | \"POST\",\n path: string,\n options?: { body?: BodyInit },\n ): Promise<T> {\n const response = await this.fetchImplementation(\n `${this.apiBaseUrl}${path}`,\n {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: options?.body,\n },\n );\n\n if (!response.ok) {\n throw new ApiRequestError(\n method,\n path,\n response.status,\n await this.parseErrorBody(response),\n );\n }\n\n return (await response.json()) as T;\n }\n\n private async parseErrorBody(response: Response): Promise<unknown> {\n const contentType = response.headers.get(\"content-type\") || \"\";\n if (contentType.includes(\"application/json\")) {\n try {\n return await response.json();\n } catch {\n return { message: \"Failed to parse API error body\" };\n }\n }\n\n try {\n return await response.text();\n } catch {\n return null;\n }\n }\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { McpToolError } from \"../errors\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst MAX_PDF_BYTES = 300 * 1024 * 1024;\n\nconst inputSchema = {\n pdf_path: z.string().min(1),\n name: z.string().min(1).max(100).optional(),\n template: z.enum([\"book\", \"legal-contract\", \"academic-paper\"]).optional(),\n review: z.boolean().optional(),\n};\n\nconst outputSchema = {\n shelf: z.object({\n publicId: z.string(),\n name: z.string(),\n status: z.string(),\n template: z.string().nullable(),\n pageCount: z.number().nullable(),\n reviewMode: z.boolean(),\n createdAt: z.string(),\n updatedAt: z.string(),\n }),\n};\n\nasync function assertPdfFile(filePath: string): Promise<void> {\n const stats = await fs.stat(filePath).catch(() => null);\n if (!stats || !stats.isFile()) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"pdf_path must point to an existing file\",\n status: 400,\n retryable: false,\n });\n }\n\n if (stats.size > MAX_PDF_BYTES) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"PDF exceeds 300 MB limit\",\n status: 400,\n retryable: false,\n });\n }\n\n if (path.extname(filePath).toLowerCase() !== \".pdf\") {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Only .pdf files are supported\",\n status: 400,\n retryable: false,\n });\n }\n\n const handle = await fs.open(filePath, \"r\");\n try {\n const header = Buffer.alloc(5);\n await handle.read(header, 0, 5, 0);\n if (header.toString(\"utf8\") !== \"%PDF-\") {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"File does not appear to be a valid PDF\",\n status: 400,\n retryable: false,\n });\n }\n } finally {\n await handle.close();\n }\n}\n\nexport function registerCreateShelfTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"create_shelf\",\n {\n title: \"Create Shelf\",\n description: \"Upload a local PDF and create a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: false },\n },\n async (input, extra) => {\n try {\n const absolutePath = path.resolve(input.pdf_path);\n await assertPdfFile(absolutePath);\n\n const fileBytes = new Uint8Array(await fs.readFile(absolutePath));\n const apiKey = context.getApiKey(extra);\n const client = context.createHttpClient(apiKey);\n const shelf = await client.createShelf({\n pdfBytes: fileBytes,\n fileName: path.basename(absolutePath),\n name: input.name,\n template: input.template,\n review: input.review,\n });\n\n return successResult(`Created shelf ${shelf.publicId}`, { shelf });\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import path from \"node:path\";\nimport type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport { McpToolError, serializeToolError, toMcpToolError } from \"../errors\";\n\nexport function successResult(\n text: string,\n structuredContent: Record<string, unknown>,\n): CallToolResult {\n return {\n content: [{ type: \"text\", text }],\n structuredContent,\n };\n}\n\nexport function errorResult(error: unknown): CallToolResult {\n const normalized = toMcpToolError(error, \"Tool execution failed\");\n\n return {\n isError: true,\n content: [{ type: \"text\", text: normalized.message }],\n structuredContent: {\n error: serializeToolError(normalized),\n },\n };\n}\n\nexport function ensureRelativePath(inputPath: string): string {\n const trimmed = inputPath.trim();\n\n if (!trimmed) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path is required\",\n status: 400,\n retryable: false,\n });\n }\n\n if (trimmed.includes(\"\\\\\") || trimmed.includes(\"\\0\")) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path contains unsupported characters\",\n status: 400,\n retryable: false,\n });\n }\n\n const normalized = path.posix.normalize(trimmed);\n if (normalized === \".\" || normalized === \"\") {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path must reference a file under the shelf root\",\n status: 400,\n retryable: false,\n });\n }\n\n if (\n normalized === \"..\" ||\n normalized.startsWith(\"../\") ||\n normalized.startsWith(\"/\")\n ) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path traversal is not allowed\",\n status: 400,\n retryable: false,\n });\n }\n\n return normalized;\n}\n\nexport function safeJoin(baseDir: string, relativePath: string): string {\n const resolvedBase = path.resolve(baseDir);\n const candidate = path.resolve(resolvedBase, relativePath);\n\n if (\n candidate !== resolvedBase &&\n !candidate.startsWith(`${resolvedBase}${path.sep}`)\n ) {\n throw new McpToolError({\n code: \"LOCAL_IO_ERROR\",\n message: `Unsafe output path: ${relativePath}`,\n retryable: false,\n });\n }\n\n return candidate;\n}\n\nexport function truncateUtf8(\n content: string,\n maxBytes: number,\n): { value: string; truncated: boolean; bytes: number } {\n const totalBytes = Buffer.byteLength(content, \"utf8\");\n if (totalBytes <= maxBytes) {\n return { value: content, truncated: false, bytes: totalBytes };\n }\n\n let low = 0;\n let high = content.length;\n while (low < high) {\n const mid = Math.ceil((low + high) / 2);\n const candidateBytes = Buffer.byteLength(content.slice(0, mid), \"utf8\");\n if (candidateBytes <= maxBytes) {\n low = mid;\n } else {\n high = mid - 1;\n }\n }\n\n const value = content.slice(0, low);\n return {\n value,\n truncated: true,\n bytes: Buffer.byteLength(value, \"utf8\"),\n };\n}\n\nexport function inferContentType(filePath: string): string {\n const ext = path.extname(filePath).toLowerCase();\n\n if (ext === \".md\") return \"text/markdown\";\n if (ext === \".json\") return \"application/json\";\n if (ext === \".txt\") return \"text/plain\";\n\n return \"text/plain\";\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n name: z.string(),\n file_count: z.number(),\n files: z.record(z.string()),\n};\n\nexport function registerGetShelfTreeTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"get_shelf_tree\",\n {\n title: \"Get Shelf Tree\",\n description: \"Get the full file tree and file contents for a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const apiKey = context.getApiKey(extra);\n const client = context.createShelvClient(apiKey);\n const tree = await client.getTree(input.shelf_id);\n\n return successResult(\n `Loaded ${tree.fileCount} files for shelf ${tree.shelfPublicId}`,\n {\n shelf_id: tree.shelfPublicId,\n name: tree.name,\n file_count: tree.fileCount,\n files: tree.files,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { resolveShelfSource } from \"@shelv/adapters\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { McpToolError } from \"../errors\";\nimport {\n ensureRelativePath,\n errorResult,\n safeJoin,\n successResult,\n} from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n target_dir: z.string().min(1),\n overwrite: z.boolean().optional(),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n source_kind: z.enum([\"archive\", \"tree\"]),\n target_dir: z.string(),\n files_written: z.number(),\n bytes_written: z.number(),\n archive_version: z.string().nullable(),\n};\n\nexport function registerHydrateShelfTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"hydrate_shelf\",\n {\n title: \"Hydrate Shelf\",\n description: \"Download and write shelf files into a local directory\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: false },\n },\n async (input, extra) => {\n try {\n const apiKey = context.getApiKey(extra);\n const source = await resolveShelfSource({\n client: context.createShelvClient(apiKey),\n shelfPublicId: input.shelf_id,\n mode: \"archive-first\",\n });\n\n const overwrite = input.overwrite ?? false;\n const targetDir = path.resolve(input.target_dir);\n\n await fs.mkdir(targetDir, { recursive: true });\n\n let filesWritten = 0;\n let bytesWritten = 0;\n\n for (const [relativePath, content] of Object.entries(source.files)) {\n const normalized = ensureRelativePath(relativePath);\n const fullPath = safeJoin(targetDir, normalized);\n\n if (!overwrite) {\n const exists = await fs\n .access(fullPath)\n .then(() => true)\n .catch(() => false);\n\n if (exists) {\n throw new McpToolError({\n code: \"LOCAL_IO_ERROR\",\n message: `Refusing to overwrite existing file: ${normalized}`,\n retryable: false,\n });\n }\n }\n\n await fs.mkdir(path.dirname(fullPath), { recursive: true });\n await fs.writeFile(fullPath, content, \"utf8\");\n\n filesWritten += 1;\n bytesWritten += Buffer.byteLength(content, \"utf8\");\n }\n\n return successResult(`Hydrated ${filesWritten} files to ${targetDir}`, {\n shelf_id: input.shelf_id,\n source_kind: source.kind,\n target_dir: targetDir,\n files_written: filesWritten,\n bytes_written: bytesWritten,\n archive_version:\n source.kind === \"archive\" ? source.archiveVersion : null,\n });\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n page: z.number().int().min(1).optional(),\n limit: z.number().int().min(1).max(100).optional(),\n};\n\nconst outputSchema = {\n shelves: z.array(\n z.object({\n publicId: z.string(),\n name: z.string(),\n status: z.string(),\n template: z.string().nullable(),\n pageCount: z.number().nullable(),\n reviewMode: z.boolean(),\n createdAt: z.string(),\n updatedAt: z.string(),\n }),\n ),\n pagination: z.object({\n page: z.number(),\n limit: z.number(),\n total: z.number(),\n totalPages: z.number(),\n }),\n};\n\nexport function registerListShelvesTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"list_shelves\",\n {\n title: \"List Shelves\",\n description: \"List shelves available to the authenticated user\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const apiKey = context.getApiKey(extra);\n const client = context.createHttpClient(apiKey);\n const result = await client.listShelves({\n page: input.page,\n limit: input.limit,\n });\n\n return successResult(\n `Loaded ${result.data.length} shelves (page ${result.pagination.page}/${result.pagination.totalPages})`,\n {\n shelves: result.data,\n pagination: result.pagination,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport {\n ensureRelativePath,\n errorResult,\n inferContentType,\n successResult,\n truncateUtf8,\n} from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n path: z.string().min(1),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n path: z.string(),\n content_type: z.string(),\n content: z.string(),\n bytes: z.number(),\n truncated: z.boolean(),\n};\n\nexport function registerReadShelfFileTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"read_shelf_file\",\n {\n title: \"Read Shelf File\",\n description: \"Read a single file from a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const normalizedPath = ensureRelativePath(input.path);\n const apiKey = context.getApiKey(extra);\n const client = context.createShelvClient(apiKey);\n const raw = await client.getFile(input.shelf_id, normalizedPath);\n\n const truncated = truncateUtf8(raw, context.config.readMaxBytes);\n\n return successResult(\n truncated.truncated\n ? `Read ${normalizedPath} (truncated to ${truncated.bytes} bytes)`\n : `Read ${normalizedPath}`,\n {\n shelf_id: input.shelf_id,\n path: normalizedPath,\n content_type: inferContentType(normalizedPath),\n content: truncated.value,\n bytes: truncated.bytes,\n truncated: truncated.truncated,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import { resolveShelfSource } from \"@shelv/adapters\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { McpToolError } from \"../errors\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n query: z.string().min(1),\n mode: z.enum([\"substring\", \"regex\"]).optional(),\n case_sensitive: z.boolean().optional(),\n max_matches: z.number().int().min(1).optional(),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n query: z.string(),\n mode: z.enum([\"substring\", \"regex\"]),\n case_sensitive: z.boolean(),\n matches: z.array(\n z.object({\n path: z.string(),\n line: z.string(),\n line_number: z.number(),\n snippet: z.string(),\n }),\n ),\n scanned_files: z.number(),\n scanned_bytes: z.number(),\n truncated: z.boolean(),\n};\n\nfunction buildMatcher(\n query: string,\n mode: \"substring\" | \"regex\",\n caseSensitive: boolean,\n): (line: string) => boolean {\n if (mode === \"regex\") {\n let regex: RegExp;\n try {\n regex = new RegExp(query, caseSensitive ? \"\" : \"i\");\n } catch {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Invalid regular expression\",\n status: 400,\n retryable: false,\n });\n }\n\n return (line: string) => regex.test(line);\n }\n\n const needle = caseSensitive ? query : query.toLowerCase();\n return (line: string) => {\n const haystack = caseSensitive ? line : line.toLowerCase();\n return haystack.includes(needle);\n };\n}\n\nexport function registerSearchShelfTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"search_shelf\",\n {\n title: \"Search Shelf\",\n description: \"Search for text across files in a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const mode = input.mode ?? \"substring\";\n const caseSensitive = input.case_sensitive ?? false;\n\n const apiKey = context.getApiKey(extra);\n const source = await resolveShelfSource({\n client: context.createShelvClient(apiKey),\n shelfPublicId: input.shelf_id,\n mode: \"archive-first\",\n });\n\n const matcher = buildMatcher(input.query, mode, caseSensitive);\n const maxMatches = Math.min(\n input.max_matches ?? context.config.searchMaxMatches,\n context.config.searchMaxMatches,\n );\n\n const matches: Array<{\n path: string;\n line: string;\n line_number: number;\n snippet: string;\n }> = [];\n\n let scannedFiles = 0;\n let scannedBytes = 0;\n let truncated = false;\n\n for (const [filePath, content] of Object.entries(source.files)) {\n if (scannedFiles >= context.config.searchMaxFiles) {\n truncated = true;\n break;\n }\n\n const bytes = Buffer.byteLength(content, \"utf8\");\n if (scannedBytes + bytes > context.config.searchMaxBytes) {\n truncated = true;\n break;\n }\n\n scannedFiles += 1;\n scannedBytes += bytes;\n\n const lines = content.split(/\\r?\\n/);\n for (let index = 0; index < lines.length; index += 1) {\n const line = lines[index] || \"\";\n if (!matcher(line)) continue;\n\n matches.push({\n path: filePath,\n line,\n line_number: index + 1,\n snippet: line.slice(0, 300),\n });\n\n if (matches.length >= maxMatches) {\n truncated = true;\n break;\n }\n }\n\n if (truncated) break;\n }\n\n return successResult(\n `Found ${matches.length} matches across ${scannedFiles} files`,\n {\n shelf_id: input.shelf_id,\n query: input.query,\n mode,\n case_sensitive: caseSensitive,\n matches,\n scanned_files: scannedFiles,\n scanned_bytes: scannedBytes,\n truncated,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { ToolContext } from \"./context\";\nimport { registerCreateShelfTool } from \"./create-shelf\";\nimport { registerGetShelfTreeTool } from \"./get-shelf-tree\";\nimport { registerHydrateShelfTool } from \"./hydrate-shelf\";\nimport { registerListShelvesTool } from \"./list-shelves\";\nimport { registerReadShelfFileTool } from \"./read-shelf-file\";\nimport { registerSearchShelfTool } from \"./search-shelf\";\n\nexport function registerShelvTools(\n server: McpServer,\n context: ToolContext,\n): void {\n registerListShelvesTool(server, context);\n registerGetShelfTreeTool(server, context);\n registerReadShelfFileTool(server, context);\n registerSearchShelfTool(server, context);\n\n if (context.config.enableWriteTools) {\n registerCreateShelfTool(server, context);\n registerHydrateShelfTool(server, context);\n }\n}\n","import {\n createServer,\n type IncomingMessage,\n type Server as HttpServer,\n type ServerResponse,\n} from \"node:http\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StreamableHTTPServerTransport } from \"@modelcontextprotocol/sdk/server/streamableHttp.js\";\nimport type { AuthInfo } from \"@modelcontextprotocol/sdk/server/auth/types.js\";\nimport type { McpConfig } from \"../config\";\n\nconst MCP_PATH = \"/mcp\";\ntype IncomingAuthenticatedRequest = IncomingMessage & { auth?: AuthInfo };\n\nfunction stripPort(value: string): string {\n const trimmed = value.trim();\n if (trimmed.startsWith(\"[\")) {\n const end = trimmed.indexOf(\"]\");\n if (end >= 0) return trimmed.slice(1, end).toLowerCase();\n }\n\n const [host] = trimmed.split(\":\");\n return (host || \"\").toLowerCase();\n}\n\nfunction getAllowedHosts(config: McpConfig): Set<string> {\n const configuredHost = stripPort(config.httpHost);\n const hosts = new Set([\"localhost\", \"127.0.0.1\", \"::1\", configuredHost]);\n return hosts;\n}\n\nfunction readJsonBody(req: IncomingMessage): Promise<unknown> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = [];\n\n req.on(\"data\", (chunk: Buffer) => {\n chunks.push(chunk);\n });\n\n req.on(\"error\", reject);\n\n req.on(\"end\", () => {\n if (chunks.length === 0) {\n resolve(undefined);\n return;\n }\n\n const raw = Buffer.concat(chunks).toString(\"utf8\");\n try {\n resolve(JSON.parse(raw));\n } catch {\n reject(new Error(\"Invalid JSON request body\"));\n }\n });\n });\n}\n\nfunction respondJson(\n res: ServerResponse,\n status: number,\n payload: Record<string, unknown>,\n): void {\n if (res.writableEnded) return;\n\n const body = JSON.stringify(payload);\n res.statusCode = status;\n res.setHeader(\"content-type\", \"application/json\");\n res.end(body);\n}\n\nfunction validateHostAndOrigin(\n req: IncomingMessage,\n config: McpConfig,\n): { ok: true } | { ok: false; reason: string } {\n const allowedHosts = getAllowedHosts(config);\n\n const hostHeader = req.headers.host;\n if (hostHeader) {\n const host = stripPort(hostHeader);\n if (!allowedHosts.has(host)) {\n return { ok: false, reason: \"Host header is not allowed\" };\n }\n }\n\n const origin = req.headers.origin;\n if (origin) {\n try {\n const originHost = stripPort(new URL(origin).host);\n if (!allowedHosts.has(originHost)) {\n return { ok: false, reason: \"Origin is not allowed\" };\n }\n } catch {\n return { ok: false, reason: \"Invalid Origin header\" };\n }\n }\n\n return { ok: true };\n}\n\nfunction parseAuth(\n req: IncomingMessage,\n config: McpConfig,\n): { ok: true; auth?: AuthInfo } | { ok: false; reason: string } {\n const header = req.headers.authorization;\n if (header === undefined || header.trim() === \"\") {\n if (config.apiKey) {\n return {\n ok: true,\n auth: {\n token: config.apiKey,\n clientId: \"env-fallback\",\n scopes: [],\n expiresAt: undefined,\n },\n };\n }\n\n return {\n ok: false,\n reason: \"Missing Authorization header\",\n };\n }\n\n if (!header.startsWith(\"Bearer \")) {\n return {\n ok: false,\n reason: \"Authorization must use Bearer token\",\n };\n }\n\n const token = header.slice(\"Bearer \".length).trim();\n if (!token.startsWith(\"sk_\")) {\n return {\n ok: false,\n reason: \"Shelv API key must use sk_ prefix\",\n };\n }\n\n return {\n ok: true,\n auth: {\n token,\n clientId: \"request-bearer\",\n scopes: [],\n expiresAt: undefined,\n },\n };\n}\n\nexport interface HttpTransportHandle {\n server: HttpServer;\n url: string;\n close(): Promise<void>;\n}\n\nexport async function runHttpTransport(\n server: McpServer,\n config: McpConfig,\n): Promise<HttpTransportHandle> {\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: undefined,\n });\n\n await server.connect(transport);\n\n const httpServer = createServer(async (req, res) => {\n try {\n const requestPath = req.url\n ? new URL(req.url, \"http://localhost\").pathname\n : \"/\";\n if (requestPath !== MCP_PATH) {\n respondJson(res, 404, { error: \"Not found\" });\n return;\n }\n\n const method = req.method || \"GET\";\n if (![\"GET\", \"POST\", \"DELETE\"].includes(method)) {\n respondJson(res, 405, { error: \"Method not allowed\" });\n return;\n }\n\n const security = validateHostAndOrigin(req, config);\n if (!security.ok) {\n respondJson(res, 403, { error: security.reason });\n return;\n }\n\n const auth = parseAuth(req, config);\n if (!auth.ok) {\n respondJson(res, 401, { error: auth.reason });\n return;\n }\n\n const authenticatedRequest = req as IncomingAuthenticatedRequest;\n authenticatedRequest.auth = auth.auth;\n\n const body = method === \"POST\" ? await readJsonBody(req) : undefined;\n await transport.handleRequest(authenticatedRequest, res, body);\n } catch (error) {\n respondJson(res, 500, {\n error: error instanceof Error ? error.message : \"Internal server error\",\n });\n }\n });\n\n await new Promise<void>((resolve, reject) => {\n httpServer.once(\"error\", reject);\n httpServer.listen(config.httpPort, config.httpHost, () => {\n httpServer.off(\"error\", reject);\n resolve();\n });\n });\n\n const host = config.httpHost.includes(\":\")\n ? `[${config.httpHost}]`\n : config.httpHost;\n const url = `http://${host}:${config.httpPort}${MCP_PATH}`;\n\n return {\n server: httpServer,\n url,\n close() {\n return new Promise((resolve, reject) => {\n httpServer.close((error) => {\n if (error) {\n reject(error);\n return;\n }\n resolve();\n });\n });\n },\n };\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\n\nexport async function runStdioTransport(server: McpServer): Promise<void> {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n}\n","#!/usr/bin/env node\nimport { createShelvMcpRuntime } from \"../server\";\nimport { runHttpTransport } from \"../transports/http\";\nimport { runStdioTransport } from \"../transports/stdio\";\n\nasync function main(): Promise<void> {\n const runtime = createShelvMcpRuntime();\n\n if (runtime.config.transport === \"stdio\") {\n if (!runtime.config.apiKey) {\n throw new Error(\"SHELV_API_KEY is required in stdio mode\");\n }\n\n await runStdioTransport(runtime.server);\n return;\n }\n\n const http = await runHttpTransport(runtime.server, runtime.config);\n console.error(`shelv-mcp listening at ${http.url}`);\n console.error(\n runtime.config.enableWriteTools\n ? \"write tools enabled\"\n : \"write tools disabled (set SHELV_MCP_ENABLE_WRITE_TOOLS=true to enable)\",\n );\n}\n\nmain().catch((error) => {\n console.error(\n error instanceof Error ? error.message : \"Failed to start shelv-mcp\",\n );\n process.exit(1);\n});\n"],"mappings":";;;AAAA,SAAS,yBAAyB;AAClC,SAAS,iBAAiB;;;ACD1B,IAAM,eAAe;AAiBrB,SAAS,aAAa,OAA2B,UAA4B;AAC3E,MAAI,UAAU,OAAW,QAAO;AAChC,QAAM,aA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,WAAW;AACtC,mBAAW,MAAM,CAAC,UAAU;AAC1B,cAAI,OAAO;AACT,mBAAO,KAAK;AACZ;AAAA,UACF;AACA,kBAAQ;AAAA,QACV,CAAC;AAAA,MACH,CAAC;AAAA,IACH;AAAA,EACF;AACF;;;ACxOA,SAAS,4BAA4B;AAErC,eAAsB,kBAAkB,QAAkC;AACxE,QAAM,YAAY,IAAI,qBAAqB;AAC3C,QAAM,OAAO,QAAQ,SAAS;AAChC;;;ACDA,eAAe,OAAsB;AACnC,QAAM,UAAU,sBAAsB;AAEtC,MAAI,QAAQ,OAAO,cAAc,SAAS;AACxC,QAAI,CAAC,QAAQ,OAAO,QAAQ;AAC1B,YAAM,IAAI,MAAM,yCAAyC;AAAA,IAC3D;AAEA,UAAM,kBAAkB,QAAQ,MAAM;AACtC;AAAA,EACF;AAEA,QAAM,OAAO,MAAM,iBAAiB,QAAQ,QAAQ,QAAQ,MAAM;AAClE,UAAQ,MAAM,0BAA0B,KAAK,GAAG,EAAE;AAClD,UAAQ;AAAA,IACN,QAAQ,OAAO,mBACX,wBACA;AAAA,EACN;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,UAAU;AACtB,UAAQ;AAAA,IACN,iBAAiB,QAAQ,MAAM,UAAU;AAAA,EAC3C;AACA,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["path","path","path","path","z","inputSchema","z","outputSchema","fs","path","z","inputSchema","z","outputSchema","path","fs","z","inputSchema","z","outputSchema","z","inputSchema","z","outputSchema","resolveShelfSource","z","inputSchema","z","outputSchema","resolveShelfSource"]}
|
package/dist/index.js
CHANGED
|
@@ -40,7 +40,11 @@ function loadConfig(env = process.env) {
|
|
|
40
40
|
apiKey: env.SHELV_API_KEY?.trim() || void 0,
|
|
41
41
|
transport: parseTransport(env.SHELV_MCP_TRANSPORT),
|
|
42
42
|
httpHost: env.SHELV_MCP_HTTP_HOST?.trim() || "127.0.0.1",
|
|
43
|
-
httpPort: parseInteger(
|
|
43
|
+
httpPort: parseInteger(
|
|
44
|
+
env.SHELV_MCP_HTTP_PORT,
|
|
45
|
+
3334,
|
|
46
|
+
"SHELV_MCP_HTTP_PORT"
|
|
47
|
+
),
|
|
44
48
|
enableWriteTools: parseBoolean(env.SHELV_MCP_ENABLE_WRITE_TOOLS, false),
|
|
45
49
|
searchMaxFiles: parseInteger(
|
|
46
50
|
env.SHELV_MCP_SEARCH_MAX_FILES,
|
|
@@ -230,13 +234,16 @@ var ShelvHttpClient = class {
|
|
|
230
234
|
});
|
|
231
235
|
}
|
|
232
236
|
async requestJson(method, path4, options) {
|
|
233
|
-
const response = await this.fetchImplementation(
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
237
|
+
const response = await this.fetchImplementation(
|
|
238
|
+
`${this.apiBaseUrl}${path4}`,
|
|
239
|
+
{
|
|
240
|
+
method,
|
|
241
|
+
headers: {
|
|
242
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
243
|
+
},
|
|
244
|
+
body: options?.body
|
|
245
|
+
}
|
|
246
|
+
);
|
|
240
247
|
if (!response.ok) {
|
|
241
248
|
throw new ApiRequestError(
|
|
242
249
|
method,
|
|
@@ -562,17 +569,14 @@ function registerHydrateShelfTool(server, context) {
|
|
|
562
569
|
filesWritten += 1;
|
|
563
570
|
bytesWritten += Buffer.byteLength(content, "utf8");
|
|
564
571
|
}
|
|
565
|
-
return successResult(
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
archive_version: source.kind === "archive" ? source.archiveVersion : null
|
|
574
|
-
}
|
|
575
|
-
);
|
|
572
|
+
return successResult(`Hydrated ${filesWritten} files to ${targetDir}`, {
|
|
573
|
+
shelf_id: input.shelf_id,
|
|
574
|
+
source_kind: source.kind,
|
|
575
|
+
target_dir: targetDir,
|
|
576
|
+
files_written: filesWritten,
|
|
577
|
+
bytes_written: bytesWritten,
|
|
578
|
+
archive_version: source.kind === "archive" ? source.archiveVersion : null
|
|
579
|
+
});
|
|
576
580
|
} catch (error) {
|
|
577
581
|
return errorResult(error);
|
|
578
582
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts","../src/config.ts","../src/errors.ts","../src/http-client.ts","../src/tools/create-shelf.ts","../src/tools/common.ts","../src/tools/get-shelf-tree.ts","../src/tools/hydrate-shelf.ts","../src/tools/list-shelves.ts","../src/tools/read-shelf-file.ts","../src/tools/search-shelf.ts","../src/tools/index.ts"],"sourcesContent":["import { createShelvClient } from \"@shelv/adapters\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { loadConfig, type McpConfig } from \"./config\";\nimport { McpToolError } from \"./errors\";\nimport { ShelvHttpClient } from \"./http-client\";\nimport { registerShelvTools } from \"./tools\";\nimport type { ToolContext, ToolExtra } from \"./tools/context\";\n\nexport interface ShelvMcpRuntime {\n server: McpServer;\n config: McpConfig;\n}\n\nfunction validateApiKey(token: string): string {\n const trimmed = token.trim();\n if (!trimmed.startsWith(\"sk_\")) {\n throw new McpToolError({\n code: \"AUTH_ERROR\",\n message: \"Shelv API key must use sk_ prefix\",\n status: 401,\n retryable: false,\n });\n }\n\n return trimmed;\n}\n\nfunction createContext(config: McpConfig): ToolContext {\n return {\n config,\n getApiKey(extra?: ToolExtra) {\n const authToken = extra?.authInfo?.token;\n if (typeof authToken === \"string\" && authToken.trim().length > 0) {\n return validateApiKey(authToken);\n }\n\n if (config.apiKey) {\n return validateApiKey(config.apiKey);\n }\n\n throw new McpToolError({\n code: \"AUTH_ERROR\",\n message:\n \"Missing Shelv API key. Set SHELV_API_KEY or provide Authorization bearer token.\",\n status: 401,\n retryable: false,\n });\n },\n createShelvClient(apiKey: string) {\n return createShelvClient({\n apiKey,\n apiBaseUrl: config.apiBaseUrl,\n });\n },\n createHttpClient(apiKey: string) {\n return new ShelvHttpClient({\n apiKey,\n apiBaseUrl: config.apiBaseUrl,\n });\n },\n };\n}\n\nexport function createShelvMcpRuntime(env: NodeJS.ProcessEnv = process.env): ShelvMcpRuntime {\n const config = loadConfig(env);\n const context = createContext(config);\n\n const server = new McpServer(\n {\n name: \"shelv-mcp\",\n version: \"0.1.0\",\n },\n {\n instructions:\n \"Shelv MCP server for creating, listing, reading, searching, and hydrating document shelves.\",\n },\n );\n\n registerShelvTools(server, context);\n\n return { server, config };\n}\n","const API_BASE_URL = \"https://api.shelv.dev\";\n\nexport type TransportMode = \"stdio\" | \"http\";\n\nexport interface McpConfig {\n apiBaseUrl: string;\n apiKey?: string;\n transport: TransportMode;\n httpHost: string;\n httpPort: number;\n enableWriteTools: boolean;\n searchMaxFiles: number;\n searchMaxBytes: number;\n searchMaxMatches: number;\n readMaxBytes: number;\n}\n\nfunction parseBoolean(value: string | undefined, fallback: boolean): boolean {\n if (value === undefined) return fallback;\n const normalized = value.trim().toLowerCase();\n if (normalized === \"true\" || normalized === \"1\" || normalized === \"yes\") {\n return true;\n }\n if (normalized === \"false\" || normalized === \"0\" || normalized === \"no\") {\n return false;\n }\n throw new Error(`Invalid boolean value: ${value}`);\n}\n\nfunction parseInteger(\n value: string | undefined,\n fallback: number,\n label: string,\n): number {\n if (value === undefined || value.trim() === \"\") {\n return fallback;\n }\n\n const parsed = Number.parseInt(value, 10);\n if (!Number.isFinite(parsed) || parsed <= 0) {\n throw new Error(`${label} must be a positive integer`);\n }\n\n return parsed;\n}\n\nfunction parseTransport(value: string | undefined): TransportMode {\n if (!value || value.trim() === \"\") {\n return \"stdio\";\n }\n\n if (value === \"stdio\" || value === \"http\") {\n return value;\n }\n\n throw new Error(\"SHELV_MCP_TRANSPORT must be either 'stdio' or 'http'\");\n}\n\nexport function loadConfig(env: NodeJS.ProcessEnv = process.env): McpConfig {\n return {\n apiBaseUrl: API_BASE_URL,\n apiKey: env.SHELV_API_KEY?.trim() || undefined,\n transport: parseTransport(env.SHELV_MCP_TRANSPORT),\n httpHost: env.SHELV_MCP_HTTP_HOST?.trim() || \"127.0.0.1\",\n httpPort: parseInteger(env.SHELV_MCP_HTTP_PORT, 3334, \"SHELV_MCP_HTTP_PORT\"),\n enableWriteTools: parseBoolean(env.SHELV_MCP_ENABLE_WRITE_TOOLS, false),\n searchMaxFiles: parseInteger(\n env.SHELV_MCP_SEARCH_MAX_FILES,\n 500,\n \"SHELV_MCP_SEARCH_MAX_FILES\",\n ),\n searchMaxBytes: parseInteger(\n env.SHELV_MCP_SEARCH_MAX_BYTES,\n 5_000_000,\n \"SHELV_MCP_SEARCH_MAX_BYTES\",\n ),\n searchMaxMatches: parseInteger(\n env.SHELV_MCP_SEARCH_MAX_MATCHES,\n 200,\n \"SHELV_MCP_SEARCH_MAX_MATCHES\",\n ),\n readMaxBytes: parseInteger(\n env.SHELV_MCP_READ_MAX_BYTES,\n 250_000,\n \"SHELV_MCP_READ_MAX_BYTES\",\n ),\n };\n}\n","import { AdapterError } from \"@shelv/adapters\";\n\nexport type McpErrorCode =\n | \"INPUT_ERROR\"\n | \"AUTH_ERROR\"\n | \"BILLING_REQUIRED\"\n | \"NOT_FOUND\"\n | \"NOT_READY\"\n | \"RATE_LIMITED\"\n | \"UPSTREAM_ERROR\"\n | \"LOCAL_IO_ERROR\";\n\nexport interface McpToolErrorData {\n code: McpErrorCode;\n message: string;\n status?: number;\n details?: unknown;\n retryable?: boolean;\n}\n\nexport class McpToolError extends Error {\n readonly code: McpErrorCode;\n readonly status?: number;\n readonly details?: unknown;\n readonly retryable?: boolean;\n\n constructor(data: McpToolErrorData, options?: { cause?: unknown }) {\n super(data.message, options);\n this.name = \"McpToolError\";\n this.code = data.code;\n this.status = data.status;\n this.details = data.details;\n this.retryable = data.retryable;\n }\n}\n\nexport class ApiRequestError extends Error {\n readonly method: string;\n readonly path: string;\n readonly status: number;\n readonly body: unknown;\n\n constructor(\n method: string,\n path: string,\n status: number,\n body: unknown,\n options?: { cause?: unknown },\n ) {\n const message =\n typeof body === \"object\" &&\n body !== null &&\n \"message\" in body &&\n typeof (body as { message: unknown }).message === \"string\"\n ? (body as { message: string }).message\n : `Shelv API request failed (${status})`;\n\n super(message, options);\n this.name = \"ApiRequestError\";\n this.method = method;\n this.path = path;\n this.status = status;\n this.body = body;\n }\n}\n\nfunction statusToCode(status: number): McpErrorCode {\n if (status === 400) return \"INPUT_ERROR\";\n if (status === 401 || status === 403) return \"AUTH_ERROR\";\n if (status === 402) return \"BILLING_REQUIRED\";\n if (status === 404) return \"NOT_FOUND\";\n if (status === 409) return \"NOT_READY\";\n if (status === 429) return \"RATE_LIMITED\";\n return \"UPSTREAM_ERROR\";\n}\n\nfunction extractStatusFromMessage(message: string): number | undefined {\n const match = message.match(/\\((\\d{3})\\)/);\n if (!match) return undefined;\n const status = Number.parseInt(match[1] ?? \"\", 10);\n return Number.isFinite(status) ? status : undefined;\n}\n\nexport function toMcpToolError(\n error: unknown,\n fallbackMessage = \"Request failed\",\n): McpToolError {\n if (error instanceof McpToolError) {\n return error;\n }\n\n if (error instanceof ApiRequestError) {\n return new McpToolError(\n {\n code: statusToCode(error.status),\n status: error.status,\n message: error.message,\n details: error.body,\n retryable: error.status >= 500 || error.status === 429,\n },\n { cause: error },\n );\n }\n\n if (error instanceof AdapterError) {\n if (error.code === \"TREE_FETCH_FAILED\") {\n const status = extractStatusFromMessage(error.message);\n return new McpToolError(\n {\n code: status ? statusToCode(status) : \"UPSTREAM_ERROR\",\n status,\n message: error.message,\n retryable: status ? status >= 500 || status === 429 : false,\n },\n { cause: error },\n );\n }\n\n if (error.code === \"ARCHIVE_TIMEOUT\") {\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message,\n retryable: true,\n },\n { cause: error },\n );\n }\n\n if (error.code === \"ARCHIVE_PARSE_FAILED\") {\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message,\n retryable: false,\n },\n { cause: error },\n );\n }\n\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message,\n retryable: false,\n },\n { cause: error },\n );\n }\n\n if (error instanceof Error) {\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message || fallbackMessage,\n retryable: false,\n },\n { cause: error },\n );\n }\n\n return new McpToolError({\n code: \"UPSTREAM_ERROR\",\n message: fallbackMessage,\n details: error,\n retryable: false,\n });\n}\n\nexport function serializeToolError(error: McpToolError): {\n code: McpErrorCode;\n status?: number;\n details?: unknown;\n retryable?: boolean;\n message: string;\n} {\n return {\n code: error.code,\n status: error.status,\n details: error.details,\n retryable: error.retryable,\n message: error.message,\n };\n}\n","import { ApiRequestError } from \"./errors\";\n\nexport interface ShelfSummary {\n publicId: string;\n name: string;\n status: string;\n template: string | null;\n pageCount: number | null;\n reviewMode: boolean;\n createdAt: string;\n updatedAt: string;\n [key: string]: unknown;\n}\n\nexport interface ListShelvesResponse {\n data: ShelfSummary[];\n pagination: {\n page: number;\n limit: number;\n total: number;\n totalPages: number;\n };\n}\n\nexport interface CreateShelfInput {\n pdfBytes: Uint8Array;\n fileName: string;\n name?: string;\n template?: \"book\" | \"legal-contract\" | \"academic-paper\";\n review?: boolean;\n}\n\nexport interface ShelvHttpClientConfig {\n apiKey: string;\n apiBaseUrl: string;\n fetchImplementation?: typeof fetch;\n}\n\nexport class ShelvHttpClient {\n private readonly apiKey: string;\n private readonly apiBaseUrl: string;\n private readonly fetchImplementation: typeof fetch;\n\n constructor(config: ShelvHttpClientConfig) {\n this.apiKey = config.apiKey;\n this.apiBaseUrl = config.apiBaseUrl.replace(/\\/$/, \"\");\n this.fetchImplementation = config.fetchImplementation ?? fetch;\n }\n\n async listShelves(params?: {\n page?: number;\n limit?: number;\n }): Promise<ListShelvesResponse> {\n const search = new URLSearchParams();\n if (params?.page) search.set(\"page\", String(params.page));\n if (params?.limit) search.set(\"limit\", String(params.limit));\n\n const path =\n search.size > 0 ? `/v1/shelves?${search.toString()}` : \"/v1/shelves\";\n\n return this.requestJson<ListShelvesResponse>(\"GET\", path);\n }\n\n async createShelf(input: CreateShelfInput): Promise<ShelfSummary> {\n const formData = new FormData();\n formData.append(\n \"file\",\n new Blob([Buffer.from(input.pdfBytes)], { type: \"application/pdf\" }),\n input.fileName,\n );\n\n if (input.name) formData.append(\"name\", input.name);\n if (input.template) formData.append(\"template\", input.template);\n if (typeof input.review === \"boolean\") {\n formData.append(\"review\", input.review ? \"true\" : \"false\");\n }\n\n return this.requestJson<ShelfSummary>(\"POST\", \"/v1/shelves\", {\n body: formData,\n });\n }\n\n private async requestJson<T>(\n method: \"GET\" | \"POST\",\n path: string,\n options?: { body?: BodyInit },\n ): Promise<T> {\n const response = await this.fetchImplementation(`${this.apiBaseUrl}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: options?.body,\n });\n\n if (!response.ok) {\n throw new ApiRequestError(\n method,\n path,\n response.status,\n await this.parseErrorBody(response),\n );\n }\n\n return (await response.json()) as T;\n }\n\n private async parseErrorBody(response: Response): Promise<unknown> {\n const contentType = response.headers.get(\"content-type\") || \"\";\n if (contentType.includes(\"application/json\")) {\n try {\n return await response.json();\n } catch {\n return { message: \"Failed to parse API error body\" };\n }\n }\n\n try {\n return await response.text();\n } catch {\n return null;\n }\n }\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { McpToolError } from \"../errors\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst MAX_PDF_BYTES = 300 * 1024 * 1024;\n\nconst inputSchema = {\n pdf_path: z.string().min(1),\n name: z.string().min(1).max(100).optional(),\n template: z.enum([\"book\", \"legal-contract\", \"academic-paper\"]).optional(),\n review: z.boolean().optional(),\n};\n\nconst outputSchema = {\n shelf: z.object({\n publicId: z.string(),\n name: z.string(),\n status: z.string(),\n template: z.string().nullable(),\n pageCount: z.number().nullable(),\n reviewMode: z.boolean(),\n createdAt: z.string(),\n updatedAt: z.string(),\n }),\n};\n\nasync function assertPdfFile(filePath: string): Promise<void> {\n const stats = await fs.stat(filePath).catch(() => null);\n if (!stats || !stats.isFile()) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"pdf_path must point to an existing file\",\n status: 400,\n retryable: false,\n });\n }\n\n if (stats.size > MAX_PDF_BYTES) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"PDF exceeds 300 MB limit\",\n status: 400,\n retryable: false,\n });\n }\n\n if (path.extname(filePath).toLowerCase() !== \".pdf\") {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Only .pdf files are supported\",\n status: 400,\n retryable: false,\n });\n }\n\n const handle = await fs.open(filePath, \"r\");\n try {\n const header = Buffer.alloc(5);\n await handle.read(header, 0, 5, 0);\n if (header.toString(\"utf8\") !== \"%PDF-\") {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"File does not appear to be a valid PDF\",\n status: 400,\n retryable: false,\n });\n }\n } finally {\n await handle.close();\n }\n}\n\nexport function registerCreateShelfTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"create_shelf\",\n {\n title: \"Create Shelf\",\n description: \"Upload a local PDF and create a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: false },\n },\n async (input, extra) => {\n try {\n const absolutePath = path.resolve(input.pdf_path);\n await assertPdfFile(absolutePath);\n\n const fileBytes = new Uint8Array(await fs.readFile(absolutePath));\n const apiKey = context.getApiKey(extra);\n const client = context.createHttpClient(apiKey);\n const shelf = await client.createShelf({\n pdfBytes: fileBytes,\n fileName: path.basename(absolutePath),\n name: input.name,\n template: input.template,\n review: input.review,\n });\n\n return successResult(`Created shelf ${shelf.publicId}`, { shelf });\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import path from \"node:path\";\nimport type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport { McpToolError, serializeToolError, toMcpToolError } from \"../errors\";\n\nexport function successResult(\n text: string,\n structuredContent: Record<string, unknown>,\n): CallToolResult {\n return {\n content: [{ type: \"text\", text }],\n structuredContent,\n };\n}\n\nexport function errorResult(error: unknown): CallToolResult {\n const normalized = toMcpToolError(error, \"Tool execution failed\");\n\n return {\n isError: true,\n content: [{ type: \"text\", text: normalized.message }],\n structuredContent: {\n error: serializeToolError(normalized),\n },\n };\n}\n\nexport function ensureRelativePath(inputPath: string): string {\n const trimmed = inputPath.trim();\n\n if (!trimmed) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path is required\",\n status: 400,\n retryable: false,\n });\n }\n\n if (trimmed.includes(\"\\\\\") || trimmed.includes(\"\\0\")) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path contains unsupported characters\",\n status: 400,\n retryable: false,\n });\n }\n\n const normalized = path.posix.normalize(trimmed);\n if (normalized === \".\" || normalized === \"\") {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path must reference a file under the shelf root\",\n status: 400,\n retryable: false,\n });\n }\n\n if (\n normalized === \"..\" ||\n normalized.startsWith(\"../\") ||\n normalized.startsWith(\"/\")\n ) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path traversal is not allowed\",\n status: 400,\n retryable: false,\n });\n }\n\n return normalized;\n}\n\nexport function safeJoin(baseDir: string, relativePath: string): string {\n const resolvedBase = path.resolve(baseDir);\n const candidate = path.resolve(resolvedBase, relativePath);\n\n if (\n candidate !== resolvedBase &&\n !candidate.startsWith(`${resolvedBase}${path.sep}`)\n ) {\n throw new McpToolError({\n code: \"LOCAL_IO_ERROR\",\n message: `Unsafe output path: ${relativePath}`,\n retryable: false,\n });\n }\n\n return candidate;\n}\n\nexport function truncateUtf8(\n content: string,\n maxBytes: number,\n): { value: string; truncated: boolean; bytes: number } {\n const totalBytes = Buffer.byteLength(content, \"utf8\");\n if (totalBytes <= maxBytes) {\n return { value: content, truncated: false, bytes: totalBytes };\n }\n\n let low = 0;\n let high = content.length;\n while (low < high) {\n const mid = Math.ceil((low + high) / 2);\n const candidateBytes = Buffer.byteLength(content.slice(0, mid), \"utf8\");\n if (candidateBytes <= maxBytes) {\n low = mid;\n } else {\n high = mid - 1;\n }\n }\n\n const value = content.slice(0, low);\n return {\n value,\n truncated: true,\n bytes: Buffer.byteLength(value, \"utf8\"),\n };\n}\n\nexport function inferContentType(filePath: string): string {\n const ext = path.extname(filePath).toLowerCase();\n\n if (ext === \".md\") return \"text/markdown\";\n if (ext === \".json\") return \"application/json\";\n if (ext === \".txt\") return \"text/plain\";\n\n return \"text/plain\";\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n name: z.string(),\n file_count: z.number(),\n files: z.record(z.string()),\n};\n\nexport function registerGetShelfTreeTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"get_shelf_tree\",\n {\n title: \"Get Shelf Tree\",\n description: \"Get the full file tree and file contents for a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const apiKey = context.getApiKey(extra);\n const client = context.createShelvClient(apiKey);\n const tree = await client.getTree(input.shelf_id);\n\n return successResult(\n `Loaded ${tree.fileCount} files for shelf ${tree.shelfPublicId}`,\n {\n shelf_id: tree.shelfPublicId,\n name: tree.name,\n file_count: tree.fileCount,\n files: tree.files,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { resolveShelfSource } from \"@shelv/adapters\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { McpToolError } from \"../errors\";\nimport { ensureRelativePath, errorResult, safeJoin, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n target_dir: z.string().min(1),\n overwrite: z.boolean().optional(),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n source_kind: z.enum([\"archive\", \"tree\"]),\n target_dir: z.string(),\n files_written: z.number(),\n bytes_written: z.number(),\n archive_version: z.string().nullable(),\n};\n\nexport function registerHydrateShelfTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"hydrate_shelf\",\n {\n title: \"Hydrate Shelf\",\n description: \"Download and write shelf files into a local directory\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: false },\n },\n async (input, extra) => {\n try {\n const apiKey = context.getApiKey(extra);\n const source = await resolveShelfSource({\n client: context.createShelvClient(apiKey),\n shelfPublicId: input.shelf_id,\n mode: \"archive-first\",\n });\n\n const overwrite = input.overwrite ?? false;\n const targetDir = path.resolve(input.target_dir);\n\n await fs.mkdir(targetDir, { recursive: true });\n\n let filesWritten = 0;\n let bytesWritten = 0;\n\n for (const [relativePath, content] of Object.entries(source.files)) {\n const normalized = ensureRelativePath(relativePath);\n const fullPath = safeJoin(targetDir, normalized);\n\n if (!overwrite) {\n const exists = await fs\n .access(fullPath)\n .then(() => true)\n .catch(() => false);\n\n if (exists) {\n throw new McpToolError({\n code: \"LOCAL_IO_ERROR\",\n message: `Refusing to overwrite existing file: ${normalized}`,\n retryable: false,\n });\n }\n }\n\n await fs.mkdir(path.dirname(fullPath), { recursive: true });\n await fs.writeFile(fullPath, content, \"utf8\");\n\n filesWritten += 1;\n bytesWritten += Buffer.byteLength(content, \"utf8\");\n }\n\n return successResult(\n `Hydrated ${filesWritten} files to ${targetDir}`,\n {\n shelf_id: input.shelf_id,\n source_kind: source.kind,\n target_dir: targetDir,\n files_written: filesWritten,\n bytes_written: bytesWritten,\n archive_version: source.kind === \"archive\" ? source.archiveVersion : null,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n page: z.number().int().min(1).optional(),\n limit: z.number().int().min(1).max(100).optional(),\n};\n\nconst outputSchema = {\n shelves: z.array(\n z.object({\n publicId: z.string(),\n name: z.string(),\n status: z.string(),\n template: z.string().nullable(),\n pageCount: z.number().nullable(),\n reviewMode: z.boolean(),\n createdAt: z.string(),\n updatedAt: z.string(),\n }),\n ),\n pagination: z.object({\n page: z.number(),\n limit: z.number(),\n total: z.number(),\n totalPages: z.number(),\n }),\n};\n\nexport function registerListShelvesTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"list_shelves\",\n {\n title: \"List Shelves\",\n description: \"List shelves available to the authenticated user\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const apiKey = context.getApiKey(extra);\n const client = context.createHttpClient(apiKey);\n const result = await client.listShelves({\n page: input.page,\n limit: input.limit,\n });\n\n return successResult(\n `Loaded ${result.data.length} shelves (page ${result.pagination.page}/${result.pagination.totalPages})`,\n {\n shelves: result.data,\n pagination: result.pagination,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { ensureRelativePath, errorResult, inferContentType, successResult, truncateUtf8 } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n path: z.string().min(1),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n path: z.string(),\n content_type: z.string(),\n content: z.string(),\n bytes: z.number(),\n truncated: z.boolean(),\n};\n\nexport function registerReadShelfFileTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"read_shelf_file\",\n {\n title: \"Read Shelf File\",\n description: \"Read a single file from a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const normalizedPath = ensureRelativePath(input.path);\n const apiKey = context.getApiKey(extra);\n const client = context.createShelvClient(apiKey);\n const raw = await client.getFile(input.shelf_id, normalizedPath);\n\n const truncated = truncateUtf8(raw, context.config.readMaxBytes);\n\n return successResult(\n truncated.truncated\n ? `Read ${normalizedPath} (truncated to ${truncated.bytes} bytes)`\n : `Read ${normalizedPath}`,\n {\n shelf_id: input.shelf_id,\n path: normalizedPath,\n content_type: inferContentType(normalizedPath),\n content: truncated.value,\n bytes: truncated.bytes,\n truncated: truncated.truncated,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import { resolveShelfSource } from \"@shelv/adapters\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { McpToolError } from \"../errors\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n query: z.string().min(1),\n mode: z.enum([\"substring\", \"regex\"]).optional(),\n case_sensitive: z.boolean().optional(),\n max_matches: z.number().int().min(1).optional(),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n query: z.string(),\n mode: z.enum([\"substring\", \"regex\"]),\n case_sensitive: z.boolean(),\n matches: z.array(\n z.object({\n path: z.string(),\n line: z.string(),\n line_number: z.number(),\n snippet: z.string(),\n }),\n ),\n scanned_files: z.number(),\n scanned_bytes: z.number(),\n truncated: z.boolean(),\n};\n\nfunction buildMatcher(\n query: string,\n mode: \"substring\" | \"regex\",\n caseSensitive: boolean,\n): (line: string) => boolean {\n if (mode === \"regex\") {\n let regex: RegExp;\n try {\n regex = new RegExp(query, caseSensitive ? \"\" : \"i\");\n } catch {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Invalid regular expression\",\n status: 400,\n retryable: false,\n });\n }\n\n return (line: string) => regex.test(line);\n }\n\n const needle = caseSensitive ? query : query.toLowerCase();\n return (line: string) => {\n const haystack = caseSensitive ? line : line.toLowerCase();\n return haystack.includes(needle);\n };\n}\n\nexport function registerSearchShelfTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"search_shelf\",\n {\n title: \"Search Shelf\",\n description: \"Search for text across files in a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const mode = input.mode ?? \"substring\";\n const caseSensitive = input.case_sensitive ?? false;\n\n const apiKey = context.getApiKey(extra);\n const source = await resolveShelfSource({\n client: context.createShelvClient(apiKey),\n shelfPublicId: input.shelf_id,\n mode: \"archive-first\",\n });\n\n const matcher = buildMatcher(input.query, mode, caseSensitive);\n const maxMatches = Math.min(\n input.max_matches ?? context.config.searchMaxMatches,\n context.config.searchMaxMatches,\n );\n\n const matches: Array<{\n path: string;\n line: string;\n line_number: number;\n snippet: string;\n }> = [];\n\n let scannedFiles = 0;\n let scannedBytes = 0;\n let truncated = false;\n\n for (const [filePath, content] of Object.entries(source.files)) {\n if (scannedFiles >= context.config.searchMaxFiles) {\n truncated = true;\n break;\n }\n\n const bytes = Buffer.byteLength(content, \"utf8\");\n if (scannedBytes + bytes > context.config.searchMaxBytes) {\n truncated = true;\n break;\n }\n\n scannedFiles += 1;\n scannedBytes += bytes;\n\n const lines = content.split(/\\r?\\n/);\n for (let index = 0; index < lines.length; index += 1) {\n const line = lines[index] || \"\";\n if (!matcher(line)) continue;\n\n matches.push({\n path: filePath,\n line,\n line_number: index + 1,\n snippet: line.slice(0, 300),\n });\n\n if (matches.length >= maxMatches) {\n truncated = true;\n break;\n }\n }\n\n if (truncated) break;\n }\n\n return successResult(\n `Found ${matches.length} matches across ${scannedFiles} files`,\n {\n shelf_id: input.shelf_id,\n query: input.query,\n mode,\n case_sensitive: caseSensitive,\n matches,\n scanned_files: scannedFiles,\n scanned_bytes: scannedBytes,\n truncated,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { ToolContext } from \"./context\";\nimport { registerCreateShelfTool } from \"./create-shelf\";\nimport { registerGetShelfTreeTool } from \"./get-shelf-tree\";\nimport { registerHydrateShelfTool } from \"./hydrate-shelf\";\nimport { registerListShelvesTool } from \"./list-shelves\";\nimport { registerReadShelfFileTool } from \"./read-shelf-file\";\nimport { registerSearchShelfTool } from \"./search-shelf\";\n\nexport function registerShelvTools(server: McpServer, context: ToolContext): void {\n registerListShelvesTool(server, context);\n registerGetShelfTreeTool(server, context);\n registerReadShelfFileTool(server, context);\n registerSearchShelfTool(server, context);\n\n if (context.config.enableWriteTools) {\n registerCreateShelfTool(server, context);\n registerHydrateShelfTool(server, context);\n }\n}\n"],"mappings":";AAAA,SAAS,yBAAyB;AAClC,SAAS,iBAAiB;;;ACD1B,IAAM,eAAe;AAiBrB,SAAS,aAAa,OAA2B,UAA4B;AAC3E,MAAI,UAAU,OAAW,QAAO;AAChC,QAAM,aAAa,MAAM,KAAK,EAAE,YAAY;AAC5C,MAAI,eAAe,UAAU,eAAe,OAAO,eAAe,OAAO;AACvE,WAAO;AAAA,EACT;AACA,MAAI,eAAe,WAAW,eAAe,OAAO,eAAe,MAAM;AACvE,WAAO;AAAA,EACT;AACA,QAAM,IAAI,MAAM,0BAA0B,KAAK,EAAE;AACnD;AAEA,SAAS,aACP,OACA,UACA,OACQ;AACR,MAAI,UAAU,UAAa,MAAM,KAAK,MAAM,IAAI;AAC9C,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,OAAO,SAAS,OAAO,EAAE;AACxC,MAAI,CAAC,OAAO,SAAS,MAAM,KAAK,UAAU,GAAG;AAC3C,UAAM,IAAI,MAAM,GAAG,KAAK,6BAA6B;AAAA,EACvD;AAEA,SAAO;AACT;AAEA,SAAS,eAAe,OAA0C;AAChE,MAAI,CAAC,SAAS,MAAM,KAAK,MAAM,IAAI;AACjC,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,WAAW,UAAU,QAAQ;AACzC,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jB;AAAA,MACE,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,IACA;AAAA,MACE,cACE;AAAA,IACJ;AAAA,EACF;AAEA,qBAAmB,QAAQ,OAAO;AAElC,SAAO,EAAE,QAAQ,OAAO;AAC1B;","names":["path","path","path","path","z","inputSchema","z","outputSchema","fs","path","z","inputSchema","z","outputSchema","path","fs","z","inputSchema","z","outputSchema","z","inputSchema","z","outputSchema","resolveShelfSource","z","inputSchema","z","outputSchema","resolveShelfSource"]}
|
|
1
|
+
{"version":3,"sources":["../src/server.ts","../src/config.ts","../src/errors.ts","../src/http-client.ts","../src/tools/create-shelf.ts","../src/tools/common.ts","../src/tools/get-shelf-tree.ts","../src/tools/hydrate-shelf.ts","../src/tools/list-shelves.ts","../src/tools/read-shelf-file.ts","../src/tools/search-shelf.ts","../src/tools/index.ts"],"sourcesContent":["import { createShelvClient } from \"@shelv/adapters\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { loadConfig, type McpConfig } from \"./config\";\nimport { McpToolError } from \"./errors\";\nimport { ShelvHttpClient } from \"./http-client\";\nimport { registerShelvTools } from \"./tools\";\nimport type { ToolContext, ToolExtra } from \"./tools/context\";\n\nexport interface ShelvMcpRuntime {\n server: McpServer;\n config: McpConfig;\n}\n\nfunction validateApiKey(token: string): string {\n const trimmed = token.trim();\n if (!trimmed.startsWith(\"sk_\")) {\n throw new McpToolError({\n code: \"AUTH_ERROR\",\n message: \"Shelv API key must use sk_ prefix\",\n status: 401,\n retryable: false,\n });\n }\n\n return trimmed;\n}\n\nfunction createContext(config: McpConfig): ToolContext {\n return {\n config,\n getApiKey(extra?: ToolExtra) {\n const authToken = extra?.authInfo?.token;\n if (typeof authToken === \"string\" && authToken.trim().length > 0) {\n return validateApiKey(authToken);\n }\n\n if (config.apiKey) {\n return validateApiKey(config.apiKey);\n }\n\n throw new McpToolError({\n code: \"AUTH_ERROR\",\n message:\n \"Missing Shelv API key. Set SHELV_API_KEY or provide Authorization bearer token.\",\n status: 401,\n retryable: false,\n });\n },\n createShelvClient(apiKey: string) {\n return createShelvClient({\n apiKey,\n apiBaseUrl: config.apiBaseUrl,\n });\n },\n createHttpClient(apiKey: string) {\n return new ShelvHttpClient({\n apiKey,\n apiBaseUrl: config.apiBaseUrl,\n });\n },\n };\n}\n\nexport function createShelvMcpRuntime(\n env: NodeJS.ProcessEnv = process.env,\n): ShelvMcpRuntime {\n const config = loadConfig(env);\n const context = createContext(config);\n\n const server = new McpServer(\n {\n name: \"shelv-mcp\",\n version: \"0.1.0\",\n },\n {\n instructions:\n \"Shelv MCP server for creating, listing, reading, searching, and hydrating document shelves.\",\n },\n );\n\n registerShelvTools(server, context);\n\n return { server, config };\n}\n","const API_BASE_URL = \"https://api.shelv.dev\";\n\nexport type TransportMode = \"stdio\" | \"http\";\n\nexport interface McpConfig {\n apiBaseUrl: string;\n apiKey?: string;\n transport: TransportMode;\n httpHost: string;\n httpPort: number;\n enableWriteTools: boolean;\n searchMaxFiles: number;\n searchMaxBytes: number;\n searchMaxMatches: number;\n readMaxBytes: number;\n}\n\nfunction parseBoolean(value: string | undefined, fallback: boolean): boolean {\n if (value === undefined) return fallback;\n const normalized = value.trim().toLowerCase();\n if (normalized === \"true\" || normalized === \"1\" || normalized === \"yes\") {\n return true;\n }\n if (normalized === \"false\" || normalized === \"0\" || normalized === \"no\") {\n return false;\n }\n throw new Error(`Invalid boolean value: ${value}`);\n}\n\nfunction parseInteger(\n value: string | undefined,\n fallback: number,\n label: string,\n): number {\n if (value === undefined || value.trim() === \"\") {\n return fallback;\n }\n\n const parsed = Number.parseInt(value, 10);\n if (!Number.isFinite(parsed) || parsed <= 0) {\n throw new Error(`${label} must be a positive integer`);\n }\n\n return parsed;\n}\n\nfunction parseTransport(value: string | undefined): TransportMode {\n if (!value || value.trim() === \"\") {\n return \"stdio\";\n }\n\n if (value === \"stdio\" || value === \"http\") {\n return value;\n }\n\n throw new Error(\"SHELV_MCP_TRANSPORT must be either 'stdio' or 'http'\");\n}\n\nexport function loadConfig(env: NodeJS.ProcessEnv = process.env): McpConfig {\n return {\n apiBaseUrl: API_BASE_URL,\n apiKey: env.SHELV_API_KEY?.trim() || undefined,\n transport: parseTransport(env.SHELV_MCP_TRANSPORT),\n httpHost: env.SHELV_MCP_HTTP_HOST?.trim() || \"127.0.0.1\",\n httpPort: parseInteger(\n env.SHELV_MCP_HTTP_PORT,\n 3334,\n \"SHELV_MCP_HTTP_PORT\",\n ),\n enableWriteTools: parseBoolean(env.SHELV_MCP_ENABLE_WRITE_TOOLS, false),\n searchMaxFiles: parseInteger(\n env.SHELV_MCP_SEARCH_MAX_FILES,\n 500,\n \"SHELV_MCP_SEARCH_MAX_FILES\",\n ),\n searchMaxBytes: parseInteger(\n env.SHELV_MCP_SEARCH_MAX_BYTES,\n 5_000_000,\n \"SHELV_MCP_SEARCH_MAX_BYTES\",\n ),\n searchMaxMatches: parseInteger(\n env.SHELV_MCP_SEARCH_MAX_MATCHES,\n 200,\n \"SHELV_MCP_SEARCH_MAX_MATCHES\",\n ),\n readMaxBytes: parseInteger(\n env.SHELV_MCP_READ_MAX_BYTES,\n 250_000,\n \"SHELV_MCP_READ_MAX_BYTES\",\n ),\n };\n}\n","import { AdapterError } from \"@shelv/adapters\";\n\nexport type McpErrorCode =\n | \"INPUT_ERROR\"\n | \"AUTH_ERROR\"\n | \"BILLING_REQUIRED\"\n | \"NOT_FOUND\"\n | \"NOT_READY\"\n | \"RATE_LIMITED\"\n | \"UPSTREAM_ERROR\"\n | \"LOCAL_IO_ERROR\";\n\nexport interface McpToolErrorData {\n code: McpErrorCode;\n message: string;\n status?: number;\n details?: unknown;\n retryable?: boolean;\n}\n\nexport class McpToolError extends Error {\n readonly code: McpErrorCode;\n readonly status?: number;\n readonly details?: unknown;\n readonly retryable?: boolean;\n\n constructor(data: McpToolErrorData, options?: { cause?: unknown }) {\n super(data.message, options);\n this.name = \"McpToolError\";\n this.code = data.code;\n this.status = data.status;\n this.details = data.details;\n this.retryable = data.retryable;\n }\n}\n\nexport class ApiRequestError extends Error {\n readonly method: string;\n readonly path: string;\n readonly status: number;\n readonly body: unknown;\n\n constructor(\n method: string,\n path: string,\n status: number,\n body: unknown,\n options?: { cause?: unknown },\n ) {\n const message =\n typeof body === \"object\" &&\n body !== null &&\n \"message\" in body &&\n typeof (body as { message: unknown }).message === \"string\"\n ? (body as { message: string }).message\n : `Shelv API request failed (${status})`;\n\n super(message, options);\n this.name = \"ApiRequestError\";\n this.method = method;\n this.path = path;\n this.status = status;\n this.body = body;\n }\n}\n\nfunction statusToCode(status: number): McpErrorCode {\n if (status === 400) return \"INPUT_ERROR\";\n if (status === 401 || status === 403) return \"AUTH_ERROR\";\n if (status === 402) return \"BILLING_REQUIRED\";\n if (status === 404) return \"NOT_FOUND\";\n if (status === 409) return \"NOT_READY\";\n if (status === 429) return \"RATE_LIMITED\";\n return \"UPSTREAM_ERROR\";\n}\n\nfunction extractStatusFromMessage(message: string): number | undefined {\n const match = message.match(/\\((\\d{3})\\)/);\n if (!match) return undefined;\n const status = Number.parseInt(match[1] ?? \"\", 10);\n return Number.isFinite(status) ? status : undefined;\n}\n\nexport function toMcpToolError(\n error: unknown,\n fallbackMessage = \"Request failed\",\n): McpToolError {\n if (error instanceof McpToolError) {\n return error;\n }\n\n if (error instanceof ApiRequestError) {\n return new McpToolError(\n {\n code: statusToCode(error.status),\n status: error.status,\n message: error.message,\n details: error.body,\n retryable: error.status >= 500 || error.status === 429,\n },\n { cause: error },\n );\n }\n\n if (error instanceof AdapterError) {\n if (error.code === \"TREE_FETCH_FAILED\") {\n const status = extractStatusFromMessage(error.message);\n return new McpToolError(\n {\n code: status ? statusToCode(status) : \"UPSTREAM_ERROR\",\n status,\n message: error.message,\n retryable: status ? status >= 500 || status === 429 : false,\n },\n { cause: error },\n );\n }\n\n if (error.code === \"ARCHIVE_TIMEOUT\") {\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message,\n retryable: true,\n },\n { cause: error },\n );\n }\n\n if (error.code === \"ARCHIVE_PARSE_FAILED\") {\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message,\n retryable: false,\n },\n { cause: error },\n );\n }\n\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message,\n retryable: false,\n },\n { cause: error },\n );\n }\n\n if (error instanceof Error) {\n return new McpToolError(\n {\n code: \"UPSTREAM_ERROR\",\n message: error.message || fallbackMessage,\n retryable: false,\n },\n { cause: error },\n );\n }\n\n return new McpToolError({\n code: \"UPSTREAM_ERROR\",\n message: fallbackMessage,\n details: error,\n retryable: false,\n });\n}\n\nexport function serializeToolError(error: McpToolError): {\n code: McpErrorCode;\n status?: number;\n details?: unknown;\n retryable?: boolean;\n message: string;\n} {\n return {\n code: error.code,\n status: error.status,\n details: error.details,\n retryable: error.retryable,\n message: error.message,\n };\n}\n","import { ApiRequestError } from \"./errors\";\n\nexport interface ShelfSummary {\n publicId: string;\n name: string;\n status: string;\n template: string | null;\n pageCount: number | null;\n reviewMode: boolean;\n createdAt: string;\n updatedAt: string;\n [key: string]: unknown;\n}\n\nexport interface ListShelvesResponse {\n data: ShelfSummary[];\n pagination: {\n page: number;\n limit: number;\n total: number;\n totalPages: number;\n };\n}\n\nexport interface CreateShelfInput {\n pdfBytes: Uint8Array;\n fileName: string;\n name?: string;\n template?: \"book\" | \"legal-contract\" | \"academic-paper\";\n review?: boolean;\n}\n\nexport interface ShelvHttpClientConfig {\n apiKey: string;\n apiBaseUrl: string;\n fetchImplementation?: typeof fetch;\n}\n\nexport class ShelvHttpClient {\n private readonly apiKey: string;\n private readonly apiBaseUrl: string;\n private readonly fetchImplementation: typeof fetch;\n\n constructor(config: ShelvHttpClientConfig) {\n this.apiKey = config.apiKey;\n this.apiBaseUrl = config.apiBaseUrl.replace(/\\/$/, \"\");\n this.fetchImplementation = config.fetchImplementation ?? fetch;\n }\n\n async listShelves(params?: {\n page?: number;\n limit?: number;\n }): Promise<ListShelvesResponse> {\n const search = new URLSearchParams();\n if (params?.page) search.set(\"page\", String(params.page));\n if (params?.limit) search.set(\"limit\", String(params.limit));\n\n const path =\n search.size > 0 ? `/v1/shelves?${search.toString()}` : \"/v1/shelves\";\n\n return this.requestJson<ListShelvesResponse>(\"GET\", path);\n }\n\n async createShelf(input: CreateShelfInput): Promise<ShelfSummary> {\n const formData = new FormData();\n formData.append(\n \"file\",\n new Blob([Buffer.from(input.pdfBytes)], { type: \"application/pdf\" }),\n input.fileName,\n );\n\n if (input.name) formData.append(\"name\", input.name);\n if (input.template) formData.append(\"template\", input.template);\n if (typeof input.review === \"boolean\") {\n formData.append(\"review\", input.review ? \"true\" : \"false\");\n }\n\n return this.requestJson<ShelfSummary>(\"POST\", \"/v1/shelves\", {\n body: formData,\n });\n }\n\n private async requestJson<T>(\n method: \"GET\" | \"POST\",\n path: string,\n options?: { body?: BodyInit },\n ): Promise<T> {\n const response = await this.fetchImplementation(\n `${this.apiBaseUrl}${path}`,\n {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n },\n body: options?.body,\n },\n );\n\n if (!response.ok) {\n throw new ApiRequestError(\n method,\n path,\n response.status,\n await this.parseErrorBody(response),\n );\n }\n\n return (await response.json()) as T;\n }\n\n private async parseErrorBody(response: Response): Promise<unknown> {\n const contentType = response.headers.get(\"content-type\") || \"\";\n if (contentType.includes(\"application/json\")) {\n try {\n return await response.json();\n } catch {\n return { message: \"Failed to parse API error body\" };\n }\n }\n\n try {\n return await response.text();\n } catch {\n return null;\n }\n }\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { McpToolError } from \"../errors\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst MAX_PDF_BYTES = 300 * 1024 * 1024;\n\nconst inputSchema = {\n pdf_path: z.string().min(1),\n name: z.string().min(1).max(100).optional(),\n template: z.enum([\"book\", \"legal-contract\", \"academic-paper\"]).optional(),\n review: z.boolean().optional(),\n};\n\nconst outputSchema = {\n shelf: z.object({\n publicId: z.string(),\n name: z.string(),\n status: z.string(),\n template: z.string().nullable(),\n pageCount: z.number().nullable(),\n reviewMode: z.boolean(),\n createdAt: z.string(),\n updatedAt: z.string(),\n }),\n};\n\nasync function assertPdfFile(filePath: string): Promise<void> {\n const stats = await fs.stat(filePath).catch(() => null);\n if (!stats || !stats.isFile()) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"pdf_path must point to an existing file\",\n status: 400,\n retryable: false,\n });\n }\n\n if (stats.size > MAX_PDF_BYTES) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"PDF exceeds 300 MB limit\",\n status: 400,\n retryable: false,\n });\n }\n\n if (path.extname(filePath).toLowerCase() !== \".pdf\") {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Only .pdf files are supported\",\n status: 400,\n retryable: false,\n });\n }\n\n const handle = await fs.open(filePath, \"r\");\n try {\n const header = Buffer.alloc(5);\n await handle.read(header, 0, 5, 0);\n if (header.toString(\"utf8\") !== \"%PDF-\") {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"File does not appear to be a valid PDF\",\n status: 400,\n retryable: false,\n });\n }\n } finally {\n await handle.close();\n }\n}\n\nexport function registerCreateShelfTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"create_shelf\",\n {\n title: \"Create Shelf\",\n description: \"Upload a local PDF and create a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: false },\n },\n async (input, extra) => {\n try {\n const absolutePath = path.resolve(input.pdf_path);\n await assertPdfFile(absolutePath);\n\n const fileBytes = new Uint8Array(await fs.readFile(absolutePath));\n const apiKey = context.getApiKey(extra);\n const client = context.createHttpClient(apiKey);\n const shelf = await client.createShelf({\n pdfBytes: fileBytes,\n fileName: path.basename(absolutePath),\n name: input.name,\n template: input.template,\n review: input.review,\n });\n\n return successResult(`Created shelf ${shelf.publicId}`, { shelf });\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import path from \"node:path\";\nimport type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport { McpToolError, serializeToolError, toMcpToolError } from \"../errors\";\n\nexport function successResult(\n text: string,\n structuredContent: Record<string, unknown>,\n): CallToolResult {\n return {\n content: [{ type: \"text\", text }],\n structuredContent,\n };\n}\n\nexport function errorResult(error: unknown): CallToolResult {\n const normalized = toMcpToolError(error, \"Tool execution failed\");\n\n return {\n isError: true,\n content: [{ type: \"text\", text: normalized.message }],\n structuredContent: {\n error: serializeToolError(normalized),\n },\n };\n}\n\nexport function ensureRelativePath(inputPath: string): string {\n const trimmed = inputPath.trim();\n\n if (!trimmed) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path is required\",\n status: 400,\n retryable: false,\n });\n }\n\n if (trimmed.includes(\"\\\\\") || trimmed.includes(\"\\0\")) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path contains unsupported characters\",\n status: 400,\n retryable: false,\n });\n }\n\n const normalized = path.posix.normalize(trimmed);\n if (normalized === \".\" || normalized === \"\") {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path must reference a file under the shelf root\",\n status: 400,\n retryable: false,\n });\n }\n\n if (\n normalized === \"..\" ||\n normalized.startsWith(\"../\") ||\n normalized.startsWith(\"/\")\n ) {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Path traversal is not allowed\",\n status: 400,\n retryable: false,\n });\n }\n\n return normalized;\n}\n\nexport function safeJoin(baseDir: string, relativePath: string): string {\n const resolvedBase = path.resolve(baseDir);\n const candidate = path.resolve(resolvedBase, relativePath);\n\n if (\n candidate !== resolvedBase &&\n !candidate.startsWith(`${resolvedBase}${path.sep}`)\n ) {\n throw new McpToolError({\n code: \"LOCAL_IO_ERROR\",\n message: `Unsafe output path: ${relativePath}`,\n retryable: false,\n });\n }\n\n return candidate;\n}\n\nexport function truncateUtf8(\n content: string,\n maxBytes: number,\n): { value: string; truncated: boolean; bytes: number } {\n const totalBytes = Buffer.byteLength(content, \"utf8\");\n if (totalBytes <= maxBytes) {\n return { value: content, truncated: false, bytes: totalBytes };\n }\n\n let low = 0;\n let high = content.length;\n while (low < high) {\n const mid = Math.ceil((low + high) / 2);\n const candidateBytes = Buffer.byteLength(content.slice(0, mid), \"utf8\");\n if (candidateBytes <= maxBytes) {\n low = mid;\n } else {\n high = mid - 1;\n }\n }\n\n const value = content.slice(0, low);\n return {\n value,\n truncated: true,\n bytes: Buffer.byteLength(value, \"utf8\"),\n };\n}\n\nexport function inferContentType(filePath: string): string {\n const ext = path.extname(filePath).toLowerCase();\n\n if (ext === \".md\") return \"text/markdown\";\n if (ext === \".json\") return \"application/json\";\n if (ext === \".txt\") return \"text/plain\";\n\n return \"text/plain\";\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n name: z.string(),\n file_count: z.number(),\n files: z.record(z.string()),\n};\n\nexport function registerGetShelfTreeTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"get_shelf_tree\",\n {\n title: \"Get Shelf Tree\",\n description: \"Get the full file tree and file contents for a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const apiKey = context.getApiKey(extra);\n const client = context.createShelvClient(apiKey);\n const tree = await client.getTree(input.shelf_id);\n\n return successResult(\n `Loaded ${tree.fileCount} files for shelf ${tree.shelfPublicId}`,\n {\n shelf_id: tree.shelfPublicId,\n name: tree.name,\n file_count: tree.fileCount,\n files: tree.files,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { resolveShelfSource } from \"@shelv/adapters\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { McpToolError } from \"../errors\";\nimport {\n ensureRelativePath,\n errorResult,\n safeJoin,\n successResult,\n} from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n target_dir: z.string().min(1),\n overwrite: z.boolean().optional(),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n source_kind: z.enum([\"archive\", \"tree\"]),\n target_dir: z.string(),\n files_written: z.number(),\n bytes_written: z.number(),\n archive_version: z.string().nullable(),\n};\n\nexport function registerHydrateShelfTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"hydrate_shelf\",\n {\n title: \"Hydrate Shelf\",\n description: \"Download and write shelf files into a local directory\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: false },\n },\n async (input, extra) => {\n try {\n const apiKey = context.getApiKey(extra);\n const source = await resolveShelfSource({\n client: context.createShelvClient(apiKey),\n shelfPublicId: input.shelf_id,\n mode: \"archive-first\",\n });\n\n const overwrite = input.overwrite ?? false;\n const targetDir = path.resolve(input.target_dir);\n\n await fs.mkdir(targetDir, { recursive: true });\n\n let filesWritten = 0;\n let bytesWritten = 0;\n\n for (const [relativePath, content] of Object.entries(source.files)) {\n const normalized = ensureRelativePath(relativePath);\n const fullPath = safeJoin(targetDir, normalized);\n\n if (!overwrite) {\n const exists = await fs\n .access(fullPath)\n .then(() => true)\n .catch(() => false);\n\n if (exists) {\n throw new McpToolError({\n code: \"LOCAL_IO_ERROR\",\n message: `Refusing to overwrite existing file: ${normalized}`,\n retryable: false,\n });\n }\n }\n\n await fs.mkdir(path.dirname(fullPath), { recursive: true });\n await fs.writeFile(fullPath, content, \"utf8\");\n\n filesWritten += 1;\n bytesWritten += Buffer.byteLength(content, \"utf8\");\n }\n\n return successResult(`Hydrated ${filesWritten} files to ${targetDir}`, {\n shelf_id: input.shelf_id,\n source_kind: source.kind,\n target_dir: targetDir,\n files_written: filesWritten,\n bytes_written: bytesWritten,\n archive_version:\n source.kind === \"archive\" ? source.archiveVersion : null,\n });\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n page: z.number().int().min(1).optional(),\n limit: z.number().int().min(1).max(100).optional(),\n};\n\nconst outputSchema = {\n shelves: z.array(\n z.object({\n publicId: z.string(),\n name: z.string(),\n status: z.string(),\n template: z.string().nullable(),\n pageCount: z.number().nullable(),\n reviewMode: z.boolean(),\n createdAt: z.string(),\n updatedAt: z.string(),\n }),\n ),\n pagination: z.object({\n page: z.number(),\n limit: z.number(),\n total: z.number(),\n totalPages: z.number(),\n }),\n};\n\nexport function registerListShelvesTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"list_shelves\",\n {\n title: \"List Shelves\",\n description: \"List shelves available to the authenticated user\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const apiKey = context.getApiKey(extra);\n const client = context.createHttpClient(apiKey);\n const result = await client.listShelves({\n page: input.page,\n limit: input.limit,\n });\n\n return successResult(\n `Loaded ${result.data.length} shelves (page ${result.pagination.page}/${result.pagination.totalPages})`,\n {\n shelves: result.data,\n pagination: result.pagination,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport {\n ensureRelativePath,\n errorResult,\n inferContentType,\n successResult,\n truncateUtf8,\n} from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n path: z.string().min(1),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n path: z.string(),\n content_type: z.string(),\n content: z.string(),\n bytes: z.number(),\n truncated: z.boolean(),\n};\n\nexport function registerReadShelfFileTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"read_shelf_file\",\n {\n title: \"Read Shelf File\",\n description: \"Read a single file from a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const normalizedPath = ensureRelativePath(input.path);\n const apiKey = context.getApiKey(extra);\n const client = context.createShelvClient(apiKey);\n const raw = await client.getFile(input.shelf_id, normalizedPath);\n\n const truncated = truncateUtf8(raw, context.config.readMaxBytes);\n\n return successResult(\n truncated.truncated\n ? `Read ${normalizedPath} (truncated to ${truncated.bytes} bytes)`\n : `Read ${normalizedPath}`,\n {\n shelf_id: input.shelf_id,\n path: normalizedPath,\n content_type: inferContentType(normalizedPath),\n content: truncated.value,\n bytes: truncated.bytes,\n truncated: truncated.truncated,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import { resolveShelfSource } from \"@shelv/adapters\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { z } from \"zod\";\nimport { McpToolError } from \"../errors\";\nimport { errorResult, successResult } from \"./common\";\nimport type { ToolContext } from \"./context\";\n\nconst inputSchema = {\n shelf_id: z.string().min(1),\n query: z.string().min(1),\n mode: z.enum([\"substring\", \"regex\"]).optional(),\n case_sensitive: z.boolean().optional(),\n max_matches: z.number().int().min(1).optional(),\n};\n\nconst outputSchema = {\n shelf_id: z.string(),\n query: z.string(),\n mode: z.enum([\"substring\", \"regex\"]),\n case_sensitive: z.boolean(),\n matches: z.array(\n z.object({\n path: z.string(),\n line: z.string(),\n line_number: z.number(),\n snippet: z.string(),\n }),\n ),\n scanned_files: z.number(),\n scanned_bytes: z.number(),\n truncated: z.boolean(),\n};\n\nfunction buildMatcher(\n query: string,\n mode: \"substring\" | \"regex\",\n caseSensitive: boolean,\n): (line: string) => boolean {\n if (mode === \"regex\") {\n let regex: RegExp;\n try {\n regex = new RegExp(query, caseSensitive ? \"\" : \"i\");\n } catch {\n throw new McpToolError({\n code: \"INPUT_ERROR\",\n message: \"Invalid regular expression\",\n status: 400,\n retryable: false,\n });\n }\n\n return (line: string) => regex.test(line);\n }\n\n const needle = caseSensitive ? query : query.toLowerCase();\n return (line: string) => {\n const haystack = caseSensitive ? line : line.toLowerCase();\n return haystack.includes(needle);\n };\n}\n\nexport function registerSearchShelfTool(\n server: McpServer,\n context: ToolContext,\n): void {\n server.registerTool(\n \"search_shelf\",\n {\n title: \"Search Shelf\",\n description: \"Search for text across files in a shelf\",\n inputSchema,\n outputSchema,\n annotations: { readOnlyHint: true },\n },\n async (input, extra) => {\n try {\n const mode = input.mode ?? \"substring\";\n const caseSensitive = input.case_sensitive ?? false;\n\n const apiKey = context.getApiKey(extra);\n const source = await resolveShelfSource({\n client: context.createShelvClient(apiKey),\n shelfPublicId: input.shelf_id,\n mode: \"archive-first\",\n });\n\n const matcher = buildMatcher(input.query, mode, caseSensitive);\n const maxMatches = Math.min(\n input.max_matches ?? context.config.searchMaxMatches,\n context.config.searchMaxMatches,\n );\n\n const matches: Array<{\n path: string;\n line: string;\n line_number: number;\n snippet: string;\n }> = [];\n\n let scannedFiles = 0;\n let scannedBytes = 0;\n let truncated = false;\n\n for (const [filePath, content] of Object.entries(source.files)) {\n if (scannedFiles >= context.config.searchMaxFiles) {\n truncated = true;\n break;\n }\n\n const bytes = Buffer.byteLength(content, \"utf8\");\n if (scannedBytes + bytes > context.config.searchMaxBytes) {\n truncated = true;\n break;\n }\n\n scannedFiles += 1;\n scannedBytes += bytes;\n\n const lines = content.split(/\\r?\\n/);\n for (let index = 0; index < lines.length; index += 1) {\n const line = lines[index] || \"\";\n if (!matcher(line)) continue;\n\n matches.push({\n path: filePath,\n line,\n line_number: index + 1,\n snippet: line.slice(0, 300),\n });\n\n if (matches.length >= maxMatches) {\n truncated = true;\n break;\n }\n }\n\n if (truncated) break;\n }\n\n return successResult(\n `Found ${matches.length} matches across ${scannedFiles} files`,\n {\n shelf_id: input.shelf_id,\n query: input.query,\n mode,\n case_sensitive: caseSensitive,\n matches,\n scanned_files: scannedFiles,\n scanned_bytes: scannedBytes,\n truncated,\n },\n );\n } catch (error) {\n return errorResult(error);\n }\n },\n );\n}\n","import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { ToolContext } from \"./context\";\nimport { registerCreateShelfTool } from \"./create-shelf\";\nimport { registerGetShelfTreeTool } from \"./get-shelf-tree\";\nimport { registerHydrateShelfTool } from \"./hydrate-shelf\";\nimport { registerListShelvesTool } from \"./list-shelves\";\nimport { registerReadShelfFileTool } from \"./read-shelf-file\";\nimport { registerSearchShelfTool } from \"./search-shelf\";\n\nexport function registerShelvTools(\n server: McpServer,\n context: ToolContext,\n): void {\n registerListShelvesTool(server, context);\n registerGetShelfTreeTool(server, context);\n registerReadShelfFileTool(server, context);\n registerSearchShelfTool(server, context);\n\n if (context.config.enableWriteTools) {\n registerCreateShelfTool(server, context);\n registerHydrateShelfTool(server, context);\n }\n}\n"],"mappings":";AAAA,SAAS,yBAAyB;AAClC,SAAS,iBAAiB;;;ACD1B,IAAM,eAAe;AAiBrB,SAAS,aAAa,OAA2B,UAA4B;AAC3E,MAAI,UAAU,OAAW,QAAO;AAChC,QAAM,aAAa,MAAM,KAAK,EAAE,YAAY;AAC5C,MAAI,eAAe,UAAU,eAAe,OAAO,eAAe,OAAO;AACvE,WAAO;AAAA,EACT;AACA,MAAI,eAAe,WAAW,eAAe,OAAO,eAAe,MAAM;AACvE,WAAO;AAAA,EACT;AACA,QAAM,IAAI,MAAM,0BAA0B,KAAK,EAAE;AACnD;AAEA,SAAS,aACP,OACA,UACA,OACQ;AACR,MAAI,UAAU,UAAa,MAAM,KAAK,MAAM,IAAI;AAC9C,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,OAAO,SAAS,OAAO,EAAE;AACxC,MAAI,CAAC,OAAO,SAAS,MAAM,KAAK,UAAU,GAAG;AAC3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zB;AAAA,QACA,YAAY,OAAO;AAAA,MACrB,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,SAAS,sBACd,MAAyB,QAAQ,KAChB;AACjB,QAAM,SAAS,WAAW,GAAG;AAC7B,QAAM,UAAU,cAAc,MAAM;AAEpC,QAAM,SAAS,IAAI;AAAA,IACjB;AAAA,MACE,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,IACA;AAAA,MACE,cACE;AAAA,IACJ;AAAA,EACF;AAEA,qBAAmB,QAAQ,OAAO;AAElC,SAAO,EAAE,QAAQ,OAAO;AAC1B;","names":["path","path","path","path","z","inputSchema","z","outputSchema","fs","path","z","inputSchema","z","outputSchema","path","fs","z","inputSchema","z","outputSchema","z","inputSchema","z","outputSchema","resolveShelfSource","z","inputSchema","z","outputSchema","resolveShelfSource"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shelv/mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"private": false,
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"dist",
|
|
21
21
|
"README.md",
|
|
22
22
|
"LICENSE",
|
|
23
|
+
"CHANGELOG.md",
|
|
23
24
|
"server.json"
|
|
24
25
|
],
|
|
25
26
|
"sideEffects": false,
|
|
@@ -29,23 +30,28 @@
|
|
|
29
30
|
"publishConfig": {
|
|
30
31
|
"access": "public"
|
|
31
32
|
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/shelv-dev/shelv-mcp"
|
|
36
|
+
},
|
|
32
37
|
"homepage": "https://docs.shelv.dev",
|
|
38
|
+
"scripts": {
|
|
39
|
+
"clean": "rm -rf dist",
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"lint": "eslint .",
|
|
42
|
+
"type-check": "tsc --noEmit",
|
|
43
|
+
"test": "tsx --test src/*.test.ts src/**/*.test.ts",
|
|
44
|
+
"prepack": "pnpm run build"
|
|
45
|
+
},
|
|
33
46
|
"dependencies": {
|
|
34
47
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
48
|
+
"@shelv/adapters": "^0.1.1",
|
|
49
|
+
"zod": "^3.24.0"
|
|
37
50
|
},
|
|
38
51
|
"devDependencies": {
|
|
39
52
|
"@types/node": "^22.0.0",
|
|
40
53
|
"tsup": "^8.5.1",
|
|
41
54
|
"tsx": "^4.19.0",
|
|
42
55
|
"typescript": "^5.7.3"
|
|
43
|
-
},
|
|
44
|
-
"scripts": {
|
|
45
|
-
"clean": "rm -rf dist",
|
|
46
|
-
"build": "tsup",
|
|
47
|
-
"lint": "eslint .",
|
|
48
|
-
"type-check": "tsc --noEmit",
|
|
49
|
-
"test": "tsx --test src/*.test.ts src/**/*.test.ts"
|
|
50
56
|
}
|
|
51
|
-
}
|
|
57
|
+
}
|