@telvok/librarian-mcp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,324 @@
1
+ import { z } from 'zod';
2
+ export declare const SourceTypeSchema: z.ZodEnum<["local", "imported", "archived"]>;
3
+ export type SourceType = z.infer<typeof SourceTypeSchema>;
4
+ export declare const EntrySourceSchema: z.ZodEnum<["manual", "precompact", "imported"]>;
5
+ export type EntrySource = z.infer<typeof EntrySourceSchema>;
6
+ export declare const LibraryEntrySchema: z.ZodObject<{
7
+ id: z.ZodString;
8
+ topics: z.ZodArray<z.ZodString, "many">;
9
+ content: z.ZodString;
10
+ created: z.ZodString;
11
+ source: z.ZodEnum<["local", "imported", "archived"]>;
12
+ origin: z.ZodOptional<z.ZodEnum<["manual", "precompact", "imported"]>>;
13
+ imported_from: z.ZodOptional<z.ZodString>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ content: string;
16
+ created: string;
17
+ source: "local" | "imported" | "archived";
18
+ id: string;
19
+ topics: string[];
20
+ origin?: "imported" | "manual" | "precompact" | undefined;
21
+ imported_from?: string | undefined;
22
+ }, {
23
+ content: string;
24
+ created: string;
25
+ source: "local" | "imported" | "archived";
26
+ id: string;
27
+ topics: string[];
28
+ origin?: "imported" | "manual" | "precompact" | undefined;
29
+ imported_from?: string | undefined;
30
+ }>;
31
+ export type LibraryEntry = z.infer<typeof LibraryEntrySchema>;
32
+ export declare const FrontmatterSchema: z.ZodObject<{
33
+ id: z.ZodString;
34
+ topics: z.ZodArray<z.ZodString, "many">;
35
+ created: z.ZodString;
36
+ source: z.ZodOptional<z.ZodEnum<["manual", "precompact", "imported"]>>;
37
+ imported_from: z.ZodOptional<z.ZodString>;
38
+ }, "strip", z.ZodTypeAny, {
39
+ created: string;
40
+ id: string;
41
+ topics: string[];
42
+ source?: "imported" | "manual" | "precompact" | undefined;
43
+ imported_from?: string | undefined;
44
+ }, {
45
+ created: string;
46
+ id: string;
47
+ topics: string[];
48
+ source?: "imported" | "manual" | "precompact" | undefined;
49
+ imported_from?: string | undefined;
50
+ }>;
51
+ export type Frontmatter = z.infer<typeof FrontmatterSchema>;
52
+ export declare const BriefParamsSchema: z.ZodObject<{
53
+ topic: z.ZodString;
54
+ context: z.ZodOptional<z.ZodString>;
55
+ }, "strip", z.ZodTypeAny, {
56
+ topic: string;
57
+ context?: string | undefined;
58
+ }, {
59
+ topic: string;
60
+ context?: string | undefined;
61
+ }>;
62
+ export type BriefParams = z.infer<typeof BriefParamsSchema>;
63
+ export declare const RecordParamsSchema: z.ZodObject<{
64
+ topics: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
65
+ content: z.ZodString;
66
+ }, "strip", z.ZodTypeAny, {
67
+ content: string;
68
+ topics: string | string[];
69
+ }, {
70
+ content: string;
71
+ topics: string | string[];
72
+ }>;
73
+ export type RecordParams = z.infer<typeof RecordParamsSchema>;
74
+ export declare const AdoptParamsSchema: z.ZodObject<{
75
+ entry_id: z.ZodString;
76
+ library_name: z.ZodOptional<z.ZodString>;
77
+ }, "strip", z.ZodTypeAny, {
78
+ entry_id: string;
79
+ library_name?: string | undefined;
80
+ }, {
81
+ entry_id: string;
82
+ library_name?: string | undefined;
83
+ }>;
84
+ export type AdoptParams = z.infer<typeof AdoptParamsSchema>;
85
+ export declare const BriefResultSchema: z.ZodObject<{
86
+ entries: z.ZodArray<z.ZodObject<{
87
+ id: z.ZodString;
88
+ topics: z.ZodArray<z.ZodString, "many">;
89
+ content: z.ZodString;
90
+ created: z.ZodString;
91
+ source: z.ZodEnum<["local", "imported", "archived"]>;
92
+ origin: z.ZodOptional<z.ZodEnum<["manual", "precompact", "imported"]>>;
93
+ imported_from: z.ZodOptional<z.ZodString>;
94
+ }, "strip", z.ZodTypeAny, {
95
+ content: string;
96
+ created: string;
97
+ source: "local" | "imported" | "archived";
98
+ id: string;
99
+ topics: string[];
100
+ origin?: "imported" | "manual" | "precompact" | undefined;
101
+ imported_from?: string | undefined;
102
+ }, {
103
+ content: string;
104
+ created: string;
105
+ source: "local" | "imported" | "archived";
106
+ id: string;
107
+ topics: string[];
108
+ origin?: "imported" | "manual" | "precompact" | undefined;
109
+ imported_from?: string | undefined;
110
+ }>, "many">;
111
+ conflict: z.ZodOptional<z.ZodBoolean>;
112
+ conflict_summary: z.ZodOptional<z.ZodString>;
113
+ }, "strip", z.ZodTypeAny, {
114
+ entries: {
115
+ content: string;
116
+ created: string;
117
+ source: "local" | "imported" | "archived";
118
+ id: string;
119
+ topics: string[];
120
+ origin?: "imported" | "manual" | "precompact" | undefined;
121
+ imported_from?: string | undefined;
122
+ }[];
123
+ conflict?: boolean | undefined;
124
+ conflict_summary?: string | undefined;
125
+ }, {
126
+ entries: {
127
+ content: string;
128
+ created: string;
129
+ source: "local" | "imported" | "archived";
130
+ id: string;
131
+ topics: string[];
132
+ origin?: "imported" | "manual" | "precompact" | undefined;
133
+ imported_from?: string | undefined;
134
+ }[];
135
+ conflict?: boolean | undefined;
136
+ conflict_summary?: string | undefined;
137
+ }>;
138
+ export type BriefResult = z.infer<typeof BriefResultSchema>;
139
+ export declare const ImportedLibrarySchema: z.ZodObject<{
140
+ name: z.ZodString;
141
+ entry_count: z.ZodNumber;
142
+ purchased_at: z.ZodString;
143
+ sync_preference: z.ZodOptional<z.ZodEnum<["auto", "manual", "pinned"]>>;
144
+ last_synced: z.ZodOptional<z.ZodString>;
145
+ }, "strip", z.ZodTypeAny, {
146
+ name: string;
147
+ entry_count: number;
148
+ purchased_at: string;
149
+ sync_preference?: "manual" | "auto" | "pinned" | undefined;
150
+ last_synced?: string | undefined;
151
+ }, {
152
+ name: string;
153
+ entry_count: number;
154
+ purchased_at: string;
155
+ sync_preference?: "manual" | "auto" | "pinned" | undefined;
156
+ last_synced?: string | undefined;
157
+ }>;
158
+ export type ImportedLibrary = z.infer<typeof ImportedLibrarySchema>;
159
+ export declare const StateResultSchema: z.ZodObject<{
160
+ entries: z.ZodArray<z.ZodObject<{
161
+ id: z.ZodString;
162
+ topics: z.ZodArray<z.ZodString, "many">;
163
+ content: z.ZodString;
164
+ created: z.ZodString;
165
+ source: z.ZodEnum<["local", "imported", "archived"]>;
166
+ origin: z.ZodOptional<z.ZodEnum<["manual", "precompact", "imported"]>>;
167
+ imported_from: z.ZodOptional<z.ZodString>;
168
+ }, "strip", z.ZodTypeAny, {
169
+ content: string;
170
+ created: string;
171
+ source: "local" | "imported" | "archived";
172
+ id: string;
173
+ topics: string[];
174
+ origin?: "imported" | "manual" | "precompact" | undefined;
175
+ imported_from?: string | undefined;
176
+ }, {
177
+ content: string;
178
+ created: string;
179
+ source: "local" | "imported" | "archived";
180
+ id: string;
181
+ topics: string[];
182
+ origin?: "imported" | "manual" | "precompact" | undefined;
183
+ imported_from?: string | undefined;
184
+ }>, "many">;
185
+ imported_libraries: z.ZodArray<z.ZodObject<{
186
+ name: z.ZodString;
187
+ entry_count: z.ZodNumber;
188
+ purchased_at: z.ZodString;
189
+ sync_preference: z.ZodOptional<z.ZodEnum<["auto", "manual", "pinned"]>>;
190
+ last_synced: z.ZodOptional<z.ZodString>;
191
+ }, "strip", z.ZodTypeAny, {
192
+ name: string;
193
+ entry_count: number;
194
+ purchased_at: string;
195
+ sync_preference?: "manual" | "auto" | "pinned" | undefined;
196
+ last_synced?: string | undefined;
197
+ }, {
198
+ name: string;
199
+ entry_count: number;
200
+ purchased_at: string;
201
+ sync_preference?: "manual" | "auto" | "pinned" | undefined;
202
+ last_synced?: string | undefined;
203
+ }>, "many">;
204
+ }, "strip", z.ZodTypeAny, {
205
+ entries: {
206
+ content: string;
207
+ created: string;
208
+ source: "local" | "imported" | "archived";
209
+ id: string;
210
+ topics: string[];
211
+ origin?: "imported" | "manual" | "precompact" | undefined;
212
+ imported_from?: string | undefined;
213
+ }[];
214
+ imported_libraries: {
215
+ name: string;
216
+ entry_count: number;
217
+ purchased_at: string;
218
+ sync_preference?: "manual" | "auto" | "pinned" | undefined;
219
+ last_synced?: string | undefined;
220
+ }[];
221
+ }, {
222
+ entries: {
223
+ content: string;
224
+ created: string;
225
+ source: "local" | "imported" | "archived";
226
+ id: string;
227
+ topics: string[];
228
+ origin?: "imported" | "manual" | "precompact" | undefined;
229
+ imported_from?: string | undefined;
230
+ }[];
231
+ imported_libraries: {
232
+ name: string;
233
+ entry_count: number;
234
+ purchased_at: string;
235
+ sync_preference?: "manual" | "auto" | "pinned" | undefined;
236
+ last_synced?: string | undefined;
237
+ }[];
238
+ }>;
239
+ export type StateResult = z.infer<typeof StateResultSchema>;
240
+ export declare const RecordResultSchema: z.ZodObject<{
241
+ entry: z.ZodObject<{
242
+ id: z.ZodString;
243
+ topics: z.ZodArray<z.ZodString, "many">;
244
+ content: z.ZodString;
245
+ created: z.ZodString;
246
+ source: z.ZodEnum<["local", "imported", "archived"]>;
247
+ origin: z.ZodOptional<z.ZodEnum<["manual", "precompact", "imported"]>>;
248
+ imported_from: z.ZodOptional<z.ZodString>;
249
+ }, "strip", z.ZodTypeAny, {
250
+ content: string;
251
+ created: string;
252
+ source: "local" | "imported" | "archived";
253
+ id: string;
254
+ topics: string[];
255
+ origin?: "imported" | "manual" | "precompact" | undefined;
256
+ imported_from?: string | undefined;
257
+ }, {
258
+ content: string;
259
+ created: string;
260
+ source: "local" | "imported" | "archived";
261
+ id: string;
262
+ topics: string[];
263
+ origin?: "imported" | "manual" | "precompact" | undefined;
264
+ imported_from?: string | undefined;
265
+ }>;
266
+ path: z.ZodString;
267
+ }, "strip", z.ZodTypeAny, {
268
+ path: string;
269
+ entry: {
270
+ content: string;
271
+ created: string;
272
+ source: "local" | "imported" | "archived";
273
+ id: string;
274
+ topics: string[];
275
+ origin?: "imported" | "manual" | "precompact" | undefined;
276
+ imported_from?: string | undefined;
277
+ };
278
+ }, {
279
+ path: string;
280
+ entry: {
281
+ content: string;
282
+ created: string;
283
+ source: "local" | "imported" | "archived";
284
+ id: string;
285
+ topics: string[];
286
+ origin?: "imported" | "manual" | "precompact" | undefined;
287
+ imported_from?: string | undefined;
288
+ };
289
+ }>;
290
+ export type RecordResult = z.infer<typeof RecordResultSchema>;
291
+ export declare const ExtractedEntrySchema: z.ZodObject<{
292
+ topics: z.ZodArray<z.ZodString, "many">;
293
+ content: z.ZodString;
294
+ }, "strip", z.ZodTypeAny, {
295
+ content: string;
296
+ topics: string[];
297
+ }, {
298
+ content: string;
299
+ topics: string[];
300
+ }>;
301
+ export type ExtractedEntry = z.infer<typeof ExtractedEntrySchema>;
302
+ export declare const ExtractionResultSchema: z.ZodObject<{
303
+ entries: z.ZodArray<z.ZodObject<{
304
+ topics: z.ZodArray<z.ZodString, "many">;
305
+ content: z.ZodString;
306
+ }, "strip", z.ZodTypeAny, {
307
+ content: string;
308
+ topics: string[];
309
+ }, {
310
+ content: string;
311
+ topics: string[];
312
+ }>, "many">;
313
+ }, "strip", z.ZodTypeAny, {
314
+ entries: {
315
+ content: string;
316
+ topics: string[];
317
+ }[];
318
+ }, {
319
+ entries: {
320
+ content: string;
321
+ topics: string[];
322
+ }[];
323
+ }>;
324
+ export type ExtractionResult = z.infer<typeof ExtractionResultSchema>;
@@ -0,0 +1,79 @@
1
+ import { z } from 'zod';
2
+ // ============================================================================
3
+ // Core Types
4
+ // ============================================================================
5
+ export const SourceTypeSchema = z.enum(['local', 'imported', 'archived']);
6
+ export const EntrySourceSchema = z.enum(['manual', 'precompact', 'imported']);
7
+ // ============================================================================
8
+ // Library Entry
9
+ // ============================================================================
10
+ export const LibraryEntrySchema = z.object({
11
+ id: z.string().uuid(),
12
+ topics: z.array(z.string().min(1)).min(1),
13
+ content: z.string().min(1),
14
+ created: z.string().datetime(),
15
+ source: SourceTypeSchema,
16
+ origin: EntrySourceSchema.optional(),
17
+ imported_from: z.string().optional(),
18
+ });
19
+ // ============================================================================
20
+ // File Frontmatter (YAML)
21
+ // ============================================================================
22
+ export const FrontmatterSchema = z.object({
23
+ id: z.string().uuid(),
24
+ topics: z.array(z.string().min(1)).min(1),
25
+ created: z.string().datetime(),
26
+ source: EntrySourceSchema.optional(),
27
+ imported_from: z.string().optional(),
28
+ });
29
+ // ============================================================================
30
+ // MCP Tool Parameters
31
+ // ============================================================================
32
+ export const BriefParamsSchema = z.object({
33
+ topic: z.string().min(1).describe('What to query (e.g., "deployment", "api-design")'),
34
+ context: z.string().optional().describe('Additional context to narrow results'),
35
+ });
36
+ export const RecordParamsSchema = z.object({
37
+ topics: z.union([
38
+ z.string().min(1),
39
+ z.array(z.string().min(1)).min(1),
40
+ ]).describe('Topic tags - string or array (e.g., "deployment" or ["stripe", "webhooks"])'),
41
+ content: z.string().min(1).describe('The reasoning to record'),
42
+ });
43
+ export const AdoptParamsSchema = z.object({
44
+ entry_id: z.string().uuid().describe('ID of the imported entry to adopt'),
45
+ library_name: z.string().optional().describe('Name of the imported library'),
46
+ });
47
+ // ============================================================================
48
+ // MCP Tool Results
49
+ // ============================================================================
50
+ export const BriefResultSchema = z.object({
51
+ entries: z.array(LibraryEntrySchema),
52
+ conflict: z.boolean().optional(),
53
+ conflict_summary: z.string().optional(),
54
+ });
55
+ export const ImportedLibrarySchema = z.object({
56
+ name: z.string(),
57
+ entry_count: z.number(),
58
+ purchased_at: z.string().datetime(),
59
+ sync_preference: z.enum(['auto', 'manual', 'pinned']).optional(),
60
+ last_synced: z.string().datetime().optional(),
61
+ });
62
+ export const StateResultSchema = z.object({
63
+ entries: z.array(LibraryEntrySchema),
64
+ imported_libraries: z.array(ImportedLibrarySchema),
65
+ });
66
+ export const RecordResultSchema = z.object({
67
+ entry: LibraryEntrySchema,
68
+ path: z.string(),
69
+ });
70
+ // ============================================================================
71
+ // Extraction Types
72
+ // ============================================================================
73
+ export const ExtractedEntrySchema = z.object({
74
+ topics: z.array(z.string().min(1)).min(1),
75
+ content: z.string().min(1),
76
+ });
77
+ export const ExtractionResultSchema = z.object({
78
+ entries: z.array(ExtractedEntrySchema),
79
+ });
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Get the library root path.
3
+ * Uses .librarian/ in the current working directory.
4
+ */
5
+ export declare function getLibraryPath(): string;
6
+ /**
7
+ * Get the local entries path.
8
+ */
9
+ export declare function getLocalPath(libraryPath: string): string;
10
+ /**
11
+ * Get the imported entries path.
12
+ */
13
+ export declare function getImportedPath(libraryPath: string): string;
14
+ /**
15
+ * Get the archived entries path.
16
+ */
17
+ export declare function getArchivedPath(libraryPath: string): string;
@@ -0,0 +1,29 @@
1
+ import * as path from 'path';
2
+ // ============================================================================
3
+ // Path Utilities
4
+ // ============================================================================
5
+ /**
6
+ * Get the library root path.
7
+ * Uses .librarian/ in the current working directory.
8
+ */
9
+ export function getLibraryPath() {
10
+ return path.join(process.cwd(), '.librarian');
11
+ }
12
+ /**
13
+ * Get the local entries path.
14
+ */
15
+ export function getLocalPath(libraryPath) {
16
+ return path.join(libraryPath, 'local');
17
+ }
18
+ /**
19
+ * Get the imported entries path.
20
+ */
21
+ export function getImportedPath(libraryPath) {
22
+ return path.join(libraryPath, 'imported');
23
+ }
24
+ /**
25
+ * Get the archived entries path.
26
+ */
27
+ export function getArchivedPath(libraryPath) {
28
+ return path.join(libraryPath, 'archived');
29
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/server.js ADDED
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
5
+ import { briefTool } from './tools/brief.js';
6
+ import { recordTool } from './tools/record.js';
7
+ import { adoptTool } from './tools/adopt.js';
8
+ const server = new Server({
9
+ name: 'librarian',
10
+ version: '1.0.0',
11
+ }, {
12
+ capabilities: {
13
+ tools: {},
14
+ },
15
+ });
16
+ // List available tools
17
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
18
+ return {
19
+ tools: [
20
+ {
21
+ name: briefTool.name,
22
+ description: briefTool.description,
23
+ inputSchema: briefTool.inputSchema,
24
+ },
25
+ {
26
+ name: recordTool.name,
27
+ description: recordTool.description,
28
+ inputSchema: recordTool.inputSchema,
29
+ },
30
+ {
31
+ name: adoptTool.name,
32
+ description: adoptTool.description,
33
+ inputSchema: adoptTool.inputSchema,
34
+ },
35
+ ],
36
+ };
37
+ });
38
+ // Handle tool calls
39
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
40
+ const { name, arguments: args } = request.params;
41
+ try {
42
+ let result;
43
+ switch (name) {
44
+ case 'brief':
45
+ result = await briefTool.handler(args);
46
+ break;
47
+ case 'record':
48
+ result = await recordTool.handler(args);
49
+ break;
50
+ case 'adopt':
51
+ result = await adoptTool.handler(args);
52
+ break;
53
+ default:
54
+ throw new Error(`Unknown tool: ${name}`);
55
+ }
56
+ return {
57
+ content: [
58
+ {
59
+ type: 'text',
60
+ text: JSON.stringify(result, null, 2),
61
+ },
62
+ ],
63
+ };
64
+ }
65
+ catch (error) {
66
+ const message = error instanceof Error ? error.message : String(error);
67
+ return {
68
+ content: [
69
+ {
70
+ type: 'text',
71
+ text: JSON.stringify({ error: message }),
72
+ },
73
+ ],
74
+ isError: true,
75
+ };
76
+ }
77
+ });
78
+ async function main() {
79
+ const transport = new StdioServerTransport();
80
+ await server.connect(transport);
81
+ }
82
+ main().catch(console.error);
@@ -0,0 +1,24 @@
1
+ export interface AdoptResult {
2
+ success: boolean;
3
+ from: string;
4
+ to: string;
5
+ }
6
+ export declare const adoptTool: {
7
+ name: string;
8
+ description: string;
9
+ inputSchema: {
10
+ type: "object";
11
+ properties: {
12
+ path: {
13
+ type: string;
14
+ description: string;
15
+ };
16
+ title: {
17
+ type: string;
18
+ description: string;
19
+ };
20
+ };
21
+ required: string[];
22
+ };
23
+ handler(args: unknown): Promise<AdoptResult>;
24
+ };