@telvok/librarian-mcp 1.5.3 → 2.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.
Files changed (121) hide show
  1. package/dist/library/errors.d.ts +48 -0
  2. package/dist/library/errors.js +80 -0
  3. package/dist/library/parsers/jsonl.d.ts +9 -4
  4. package/dist/library/parsers/jsonl.js +52 -20
  5. package/dist/library/schemas.d.ts +6 -6
  6. package/dist/library/storage.d.ts +2 -2
  7. package/dist/library/storage.js +2 -2
  8. package/dist/library 2/embeddings.d.ts +21 -0
  9. package/dist/library 2/embeddings.js +86 -0
  10. package/dist/library 2/manager.d.ts +42 -0
  11. package/dist/library 2/manager.js +218 -0
  12. package/dist/library 2/parsers/cursor.d.ts +15 -0
  13. package/dist/library 2/parsers/cursor.js +168 -0
  14. package/dist/library 2/parsers/index.d.ts +6 -0
  15. package/dist/library 2/parsers/index.js +5 -0
  16. package/dist/library 2/parsers/json.d.ts +11 -0
  17. package/dist/library 2/parsers/json.js +95 -0
  18. package/dist/library 2/parsers/jsonl.d.ts +14 -0
  19. package/dist/library 2/parsers/jsonl.js +85 -0
  20. package/dist/library 2/parsers/markdown.d.ts +15 -0
  21. package/dist/library 2/parsers/markdown.js +77 -0
  22. package/dist/library 2/parsers/sqlite.d.ts +8 -0
  23. package/dist/library 2/parsers/sqlite.js +123 -0
  24. package/dist/library 2/parsers/types.d.ts +21 -0
  25. package/dist/library 2/parsers/types.js +4 -0
  26. package/dist/library 2/query.d.ts +26 -0
  27. package/dist/library 2/query.js +104 -0
  28. package/dist/library 2/schemas.d.ts +324 -0
  29. package/dist/library 2/schemas.js +79 -0
  30. package/dist/library 2/storage.d.ts +22 -0
  31. package/dist/library 2/storage.js +36 -0
  32. package/dist/library 2/vector-index.d.ts +55 -0
  33. package/dist/library 2/vector-index.js +160 -0
  34. package/dist/server 2.js +199 -0
  35. package/dist/server.d 2.ts +2 -0
  36. package/dist/server.js +102 -54
  37. package/dist/tools/adopt.d.ts +1 -0
  38. package/dist/tools/adopt.js +37 -10
  39. package/dist/tools/auth.d.ts +69 -0
  40. package/dist/tools/auth.js +379 -0
  41. package/dist/tools/bounty-claim.d.ts +28 -0
  42. package/dist/tools/bounty-claim.js +92 -0
  43. package/dist/tools/bounty-create.d.ts +47 -0
  44. package/dist/tools/bounty-create.js +118 -0
  45. package/dist/tools/bounty-list.d.ts +50 -0
  46. package/dist/tools/bounty-list.js +116 -0
  47. package/dist/tools/bounty-submit.d.ts +34 -0
  48. package/dist/tools/bounty-submit.js +94 -0
  49. package/dist/tools/brief.d.ts +94 -0
  50. package/dist/tools/brief.js +234 -15
  51. package/dist/tools/delete.d.ts +87 -0
  52. package/dist/tools/delete.js +266 -0
  53. package/dist/tools/feedback.d.ts +27 -0
  54. package/dist/tools/feedback.js +98 -0
  55. package/dist/tools/help.d.ts +22 -0
  56. package/dist/tools/help.js +482 -0
  57. package/dist/tools/import-memories.d.ts +1 -0
  58. package/dist/tools/import-memories.js +18 -13
  59. package/dist/tools/index.d.ts +11 -0
  60. package/dist/tools/index.js +12 -0
  61. package/dist/tools/library-buy.d.ts +31 -0
  62. package/dist/tools/library-buy.js +104 -0
  63. package/dist/tools/library-download.d.ts +27 -0
  64. package/dist/tools/library-download.js +177 -0
  65. package/dist/tools/library-publish.d.ts +112 -0
  66. package/dist/tools/library-publish.js +387 -0
  67. package/dist/tools/library-search.d.ts +110 -0
  68. package/dist/tools/library-search.js +132 -0
  69. package/dist/tools/mark-hit.d.ts +1 -0
  70. package/dist/tools/mark-hit.js +83 -5
  71. package/dist/tools/my-books.d.ts +51 -0
  72. package/dist/tools/my-books.js +115 -0
  73. package/dist/tools/my-bounties.d.ts +43 -0
  74. package/dist/tools/my-bounties.js +126 -0
  75. package/dist/tools/rate-book.d.ts +40 -0
  76. package/dist/tools/rate-book.js +147 -0
  77. package/dist/tools/rebuild-index.d.ts +1 -0
  78. package/dist/tools/rebuild-index.js +40 -8
  79. package/dist/tools/record.d.ts +18 -0
  80. package/dist/tools/record.js +30 -26
  81. package/dist/tools/seller-analytics.d.ts +53 -0
  82. package/dist/tools/seller-analytics.js +180 -0
  83. package/dist/tools/sync.d.ts +55 -0
  84. package/dist/tools/sync.js +304 -0
  85. package/dist/tools/unsubscribe.d.ts +48 -0
  86. package/dist/tools/unsubscribe.js +120 -0
  87. package/dist/tools 2/adopt.d.ts +24 -0
  88. package/dist/tools 2/adopt.js +154 -0
  89. package/dist/tools 2/auth.d.ts +35 -0
  90. package/dist/tools 2/auth.js +229 -0
  91. package/dist/tools 2/brief.d.ts +56 -0
  92. package/dist/tools 2/brief.js +414 -0
  93. package/dist/tools 2/help.d.ts +21 -0
  94. package/dist/tools 2/help.js +267 -0
  95. package/dist/tools 2/import-memories.d.ts +32 -0
  96. package/dist/tools 2/import-memories.js +231 -0
  97. package/dist/tools 2/index.d.ts +12 -0
  98. package/dist/tools 2/index.js +12 -0
  99. package/dist/tools 2/mark-hit.d.ts +20 -0
  100. package/dist/tools 2/mark-hit.js +71 -0
  101. package/dist/tools 2/marketplace-buy.d.ts +30 -0
  102. package/dist/tools 2/marketplace-buy.js +97 -0
  103. package/dist/tools 2/marketplace-download.d.ts +26 -0
  104. package/dist/tools 2/marketplace-download.js +160 -0
  105. package/dist/tools 2/marketplace-publish.d.ts +111 -0
  106. package/dist/tools 2/marketplace-publish.js +377 -0
  107. package/dist/tools 2/marketplace-search.d.ts +57 -0
  108. package/dist/tools 2/marketplace-search.js +96 -0
  109. package/dist/tools 2/my-books.d.ts +50 -0
  110. package/dist/tools 2/my-books.js +107 -0
  111. package/dist/tools 2/rate-book.d.ts +39 -0
  112. package/dist/tools 2/rate-book.js +139 -0
  113. package/dist/tools 2/rebuild-index.d.ts +23 -0
  114. package/dist/tools 2/rebuild-index.js +107 -0
  115. package/dist/tools 2/record.d.ts +40 -0
  116. package/dist/tools 2/record.js +205 -0
  117. package/dist/tools 2/seller-analytics.d.ts +35 -0
  118. package/dist/tools 2/seller-analytics.js +102 -0
  119. package/dist/tools 2/sync.d.ts +54 -0
  120. package/dist/tools 2/sync.js +298 -0
  121. package/package.json +1 -1
@@ -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,22 @@
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
+ * @deprecated Use getPackagesPath for marketplace content
13
+ */
14
+ export declare function getImportedPath(libraryPath: string): string;
15
+ /**
16
+ * Get the packages path (marketplace content from others).
17
+ */
18
+ export declare function getPackagesPath(libraryPath: string): string;
19
+ /**
20
+ * Get the archived entries path.
21
+ */
22
+ export declare function getArchivedPath(libraryPath: string): string;
@@ -0,0 +1,36 @@
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
+ * @deprecated Use getPackagesPath for marketplace content
21
+ */
22
+ export function getImportedPath(libraryPath) {
23
+ return path.join(libraryPath, 'imported');
24
+ }
25
+ /**
26
+ * Get the packages path (marketplace content from others).
27
+ */
28
+ export function getPackagesPath(libraryPath) {
29
+ return path.join(libraryPath, 'packages');
30
+ }
31
+ /**
32
+ * Get the archived entries path.
33
+ */
34
+ export function getArchivedPath(libraryPath) {
35
+ return path.join(libraryPath, 'archived');
36
+ }
@@ -0,0 +1,55 @@
1
+ export interface IndexEntry {
2
+ path: string;
3
+ title: string;
4
+ embedding: number[];
5
+ chunk: number;
6
+ preview: string;
7
+ }
8
+ export interface VectorIndex {
9
+ version: number;
10
+ rebuilt: string;
11
+ modelId: string;
12
+ entries: IndexEntry[];
13
+ }
14
+ export interface SemanticMatch {
15
+ path: string;
16
+ title: string;
17
+ similarity: number;
18
+ preview: string;
19
+ }
20
+ /**
21
+ * Load the vector index from disk.
22
+ * Returns empty index if file doesn't exist or is invalid.
23
+ */
24
+ export declare function loadIndex(): Promise<VectorIndex>;
25
+ /**
26
+ * Save the vector index to disk.
27
+ */
28
+ export declare function saveIndex(index: VectorIndex): Promise<void>;
29
+ /**
30
+ * Add or update an entry in the index.
31
+ * Chunks the content and generates embeddings for each chunk.
32
+ */
33
+ export declare function addToIndex(index: VectorIndex, entryPath: string, title: string, content: string): Promise<void>;
34
+ /**
35
+ * Remove an entry from the index.
36
+ */
37
+ export declare function removeFromIndex(index: VectorIndex, entryPath: string): void;
38
+ /**
39
+ * Search the index for entries semantically similar to the query.
40
+ * Returns paths ranked by similarity, deduped to best chunk per entry.
41
+ */
42
+ export declare function semanticSearch(index: VectorIndex, query: string, limit?: number): Promise<SemanticMatch[]>;
43
+ /**
44
+ * Check if the index might be stale (model changed).
45
+ */
46
+ export declare function isIndexStale(index: VectorIndex): boolean;
47
+ /**
48
+ * Get index statistics.
49
+ */
50
+ export declare function getIndexStats(index: VectorIndex): {
51
+ entryCount: number;
52
+ chunkCount: number;
53
+ modelId: string;
54
+ rebuilt: string;
55
+ };
@@ -0,0 +1,160 @@
1
+ import * as fs from 'fs/promises';
2
+ import * as path from 'path';
3
+ import { getLibraryPath } from './storage.js';
4
+ import { getEmbedding, chunkText, cosineSimilarity, EMBEDDING_MODEL_ID } from './embeddings.js';
5
+ // ============================================================================
6
+ // Constants
7
+ // ============================================================================
8
+ const INDEX_FILENAME = 'index.json';
9
+ const CURRENT_VERSION = 1;
10
+ // ============================================================================
11
+ // Index File Operations
12
+ // ============================================================================
13
+ /**
14
+ * Get path to the index file.
15
+ */
16
+ function getIndexPath() {
17
+ return path.join(getLibraryPath(), INDEX_FILENAME);
18
+ }
19
+ /**
20
+ * Load the vector index from disk.
21
+ * Returns empty index if file doesn't exist or is invalid.
22
+ */
23
+ export async function loadIndex() {
24
+ const indexPath = getIndexPath();
25
+ try {
26
+ const data = await fs.readFile(indexPath, 'utf-8');
27
+ const index = JSON.parse(data);
28
+ // Validate structure
29
+ if (!index.version || !Array.isArray(index.entries)) {
30
+ return createEmptyIndex();
31
+ }
32
+ return index;
33
+ }
34
+ catch {
35
+ // File doesn't exist or is invalid
36
+ return createEmptyIndex();
37
+ }
38
+ }
39
+ /**
40
+ * Save the vector index to disk.
41
+ */
42
+ export async function saveIndex(index) {
43
+ const indexPath = getIndexPath();
44
+ // Update metadata
45
+ index.rebuilt = new Date().toISOString();
46
+ index.modelId = EMBEDDING_MODEL_ID;
47
+ // Ensure directory exists
48
+ await fs.mkdir(path.dirname(indexPath), { recursive: true });
49
+ // Write atomically by writing to temp file first
50
+ const tempPath = indexPath + '.tmp';
51
+ await fs.writeFile(tempPath, JSON.stringify(index, null, 2), 'utf-8');
52
+ await fs.rename(tempPath, indexPath);
53
+ }
54
+ /**
55
+ * Create an empty index.
56
+ */
57
+ function createEmptyIndex() {
58
+ return {
59
+ version: CURRENT_VERSION,
60
+ rebuilt: '',
61
+ modelId: EMBEDDING_MODEL_ID,
62
+ entries: [],
63
+ };
64
+ }
65
+ // ============================================================================
66
+ // Index Operations
67
+ // ============================================================================
68
+ /**
69
+ * Add or update an entry in the index.
70
+ * Chunks the content and generates embeddings for each chunk.
71
+ */
72
+ export async function addToIndex(index, entryPath, title, content) {
73
+ // Remove any existing entries for this path
74
+ index.entries = index.entries.filter(e => e.path !== entryPath);
75
+ // Chunk the content
76
+ const chunks = chunkText(content);
77
+ // Generate embeddings for each chunk
78
+ for (let i = 0; i < chunks.length; i++) {
79
+ const chunk = chunks[i];
80
+ try {
81
+ const embedding = await getEmbedding(chunk);
82
+ index.entries.push({
83
+ path: entryPath,
84
+ title,
85
+ embedding,
86
+ chunk: i,
87
+ preview: chunk.slice(0, 100) + (chunk.length > 100 ? '...' : ''),
88
+ });
89
+ }
90
+ catch (error) {
91
+ // Log but don't fail - entry will still be searchable via keywords
92
+ console.error(`Failed to embed chunk ${i} for ${entryPath}:`, error);
93
+ }
94
+ }
95
+ }
96
+ /**
97
+ * Remove an entry from the index.
98
+ */
99
+ export function removeFromIndex(index, entryPath) {
100
+ index.entries = index.entries.filter(e => e.path !== entryPath);
101
+ }
102
+ // ============================================================================
103
+ // Semantic Search
104
+ // ============================================================================
105
+ /**
106
+ * Search the index for entries semantically similar to the query.
107
+ * Returns paths ranked by similarity, deduped to best chunk per entry.
108
+ */
109
+ export async function semanticSearch(index, query, limit = 5) {
110
+ if (index.entries.length === 0) {
111
+ return [];
112
+ }
113
+ // Get query embedding
114
+ const queryEmbedding = await getEmbedding(query);
115
+ // Score all entries
116
+ const scored = index.entries.map(entry => ({
117
+ ...entry,
118
+ similarity: cosineSimilarity(queryEmbedding, entry.embedding),
119
+ }));
120
+ // Dedupe by path - keep the chunk with highest similarity
121
+ const byPath = new Map();
122
+ for (const entry of scored) {
123
+ const existing = byPath.get(entry.path);
124
+ if (!existing || entry.similarity > existing.similarity) {
125
+ byPath.set(entry.path, entry);
126
+ }
127
+ }
128
+ // Sort by similarity descending and apply limit
129
+ const results = [...byPath.values()]
130
+ .sort((a, b) => b.similarity - a.similarity)
131
+ .slice(0, limit)
132
+ .map(entry => ({
133
+ path: entry.path,
134
+ title: entry.title,
135
+ similarity: entry.similarity,
136
+ preview: entry.preview,
137
+ }));
138
+ return results;
139
+ }
140
+ // ============================================================================
141
+ // Index Health
142
+ // ============================================================================
143
+ /**
144
+ * Check if the index might be stale (model changed).
145
+ */
146
+ export function isIndexStale(index) {
147
+ return index.modelId !== EMBEDDING_MODEL_ID;
148
+ }
149
+ /**
150
+ * Get index statistics.
151
+ */
152
+ export function getIndexStats(index) {
153
+ const uniquePaths = new Set(index.entries.map(e => e.path));
154
+ return {
155
+ entryCount: uniquePaths.size,
156
+ chunkCount: index.entries.length,
157
+ modelId: index.modelId,
158
+ rebuilt: index.rebuilt,
159
+ };
160
+ }
@@ -0,0 +1,199 @@
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
+ import { markHitTool } from './tools/mark-hit.js';
9
+ import { importMemoriesTool } from './tools/import-memories.js';
10
+ import { rebuildIndexTool } from './tools/rebuild-index.js';
11
+ import { authTool } from './tools/auth.js';
12
+ import { marketplaceSearchTool } from './tools/marketplace-search.js';
13
+ import { marketplaceBuyTool } from './tools/marketplace-buy.js';
14
+ import { marketplaceDownloadTool } from './tools/marketplace-download.js';
15
+ import { marketplacePublishTool } from './tools/marketplace-publish.js';
16
+ import { myBooksTool } from './tools/my-books.js';
17
+ import { syncTool } from './tools/sync.js';
18
+ import { sellerAnalyticsTool } from './tools/seller-analytics.js';
19
+ import { rateBookTool } from './tools/rate-book.js';
20
+ import { helpTool } from './tools/help.js';
21
+ const server = new Server({
22
+ name: 'librarian',
23
+ version: '1.0.0',
24
+ }, {
25
+ capabilities: {
26
+ tools: {},
27
+ },
28
+ });
29
+ // List available tools
30
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
31
+ return {
32
+ tools: [
33
+ {
34
+ name: briefTool.name,
35
+ description: briefTool.description,
36
+ inputSchema: briefTool.inputSchema,
37
+ },
38
+ {
39
+ name: recordTool.name,
40
+ description: recordTool.description,
41
+ inputSchema: recordTool.inputSchema,
42
+ },
43
+ {
44
+ name: adoptTool.name,
45
+ description: adoptTool.description,
46
+ inputSchema: adoptTool.inputSchema,
47
+ },
48
+ {
49
+ name: markHitTool.name,
50
+ description: markHitTool.description,
51
+ inputSchema: markHitTool.inputSchema,
52
+ },
53
+ {
54
+ name: importMemoriesTool.name,
55
+ description: importMemoriesTool.description,
56
+ inputSchema: importMemoriesTool.inputSchema,
57
+ },
58
+ {
59
+ name: rebuildIndexTool.name,
60
+ description: rebuildIndexTool.description,
61
+ inputSchema: rebuildIndexTool.inputSchema,
62
+ },
63
+ {
64
+ name: authTool.name,
65
+ description: authTool.description,
66
+ inputSchema: authTool.inputSchema,
67
+ },
68
+ {
69
+ name: marketplaceSearchTool.name,
70
+ description: marketplaceSearchTool.description,
71
+ inputSchema: marketplaceSearchTool.inputSchema,
72
+ },
73
+ {
74
+ name: marketplaceBuyTool.name,
75
+ description: marketplaceBuyTool.description,
76
+ inputSchema: marketplaceBuyTool.inputSchema,
77
+ },
78
+ {
79
+ name: marketplaceDownloadTool.name,
80
+ description: marketplaceDownloadTool.description,
81
+ inputSchema: marketplaceDownloadTool.inputSchema,
82
+ },
83
+ {
84
+ name: marketplacePublishTool.name,
85
+ description: marketplacePublishTool.description,
86
+ inputSchema: marketplacePublishTool.inputSchema,
87
+ },
88
+ {
89
+ name: myBooksTool.name,
90
+ description: myBooksTool.description,
91
+ inputSchema: myBooksTool.inputSchema,
92
+ },
93
+ {
94
+ name: syncTool.name,
95
+ description: syncTool.description,
96
+ inputSchema: syncTool.inputSchema,
97
+ },
98
+ {
99
+ name: sellerAnalyticsTool.name,
100
+ description: sellerAnalyticsTool.description,
101
+ inputSchema: sellerAnalyticsTool.inputSchema,
102
+ },
103
+ {
104
+ name: rateBookTool.name,
105
+ description: rateBookTool.description,
106
+ inputSchema: rateBookTool.inputSchema,
107
+ },
108
+ {
109
+ name: helpTool.name,
110
+ description: helpTool.description,
111
+ inputSchema: helpTool.inputSchema,
112
+ },
113
+ ],
114
+ };
115
+ });
116
+ // Handle tool calls
117
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
118
+ const { name, arguments: args } = request.params;
119
+ try {
120
+ let result;
121
+ switch (name) {
122
+ case 'brief':
123
+ result = await briefTool.handler(args);
124
+ break;
125
+ case 'record':
126
+ result = await recordTool.handler(args);
127
+ break;
128
+ case 'adopt':
129
+ result = await adoptTool.handler(args);
130
+ break;
131
+ case 'mark_hit':
132
+ result = await markHitTool.handler(args);
133
+ break;
134
+ case 'import_memories':
135
+ result = await importMemoriesTool.handler(args);
136
+ break;
137
+ case 'rebuild_index':
138
+ result = await rebuildIndexTool.handler(args);
139
+ break;
140
+ case 'auth':
141
+ result = await authTool.handler(args);
142
+ break;
143
+ case 'marketplace_search':
144
+ result = await marketplaceSearchTool.handler(args);
145
+ break;
146
+ case 'marketplace_buy':
147
+ result = await marketplaceBuyTool.handler(args);
148
+ break;
149
+ case 'marketplace_download':
150
+ result = await marketplaceDownloadTool.handler(args);
151
+ break;
152
+ case 'marketplace_publish':
153
+ result = await marketplacePublishTool.handler(args);
154
+ break;
155
+ case 'my_books':
156
+ result = await myBooksTool.handler(args);
157
+ break;
158
+ case 'sync':
159
+ result = await syncTool.handler(args);
160
+ break;
161
+ case 'seller_analytics':
162
+ result = await sellerAnalyticsTool.handler();
163
+ break;
164
+ case 'rate_book':
165
+ result = await rateBookTool.handler(args);
166
+ break;
167
+ case 'help':
168
+ result = await helpTool.handler(args);
169
+ break;
170
+ default:
171
+ throw new Error(`Unknown tool: ${name}`);
172
+ }
173
+ return {
174
+ content: [
175
+ {
176
+ type: 'text',
177
+ text: JSON.stringify(result, null, 2),
178
+ },
179
+ ],
180
+ };
181
+ }
182
+ catch (error) {
183
+ const message = error instanceof Error ? error.message : String(error);
184
+ return {
185
+ content: [
186
+ {
187
+ type: 'text',
188
+ text: JSON.stringify({ error: message }),
189
+ },
190
+ ],
191
+ isError: true,
192
+ };
193
+ }
194
+ });
195
+ async function main() {
196
+ const transport = new StdioServerTransport();
197
+ await server.connect(transport);
198
+ }
199
+ main().catch(console.error);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};