midnight-mcp 0.1.40 → 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.
Files changed (100) hide show
  1. package/README.md +34 -0
  2. package/dist/bin.d.ts +1 -0
  3. package/dist/bin.js +10764 -0
  4. package/dist/index.d.ts +205 -3
  5. package/dist/index.js +10722 -15
  6. package/package.json +16 -6
  7. package/dist/config/compact-version.d.ts +0 -183
  8. package/dist/config/compact-version.js +0 -423
  9. package/dist/db/index.d.ts +0 -3
  10. package/dist/db/index.js +0 -2
  11. package/dist/db/vectorStore.d.ts +0 -69
  12. package/dist/db/vectorStore.js +0 -196
  13. package/dist/pipeline/embeddings.d.ts +0 -25
  14. package/dist/pipeline/embeddings.js +0 -103
  15. package/dist/pipeline/github.d.ts +0 -84
  16. package/dist/pipeline/github.js +0 -399
  17. package/dist/pipeline/index.d.ts +0 -11
  18. package/dist/pipeline/index.js +0 -6
  19. package/dist/pipeline/indexer.d.ts +0 -41
  20. package/dist/pipeline/indexer.js +0 -254
  21. package/dist/pipeline/parser.d.ts +0 -46
  22. package/dist/pipeline/parser.js +0 -436
  23. package/dist/pipeline/releases.d.ts +0 -112
  24. package/dist/pipeline/releases.js +0 -298
  25. package/dist/pipeline/repository.d.ts +0 -372
  26. package/dist/pipeline/repository.js +0 -520
  27. package/dist/prompts/index.d.ts +0 -3
  28. package/dist/prompts/index.js +0 -2
  29. package/dist/prompts/templates.d.ts +0 -26
  30. package/dist/prompts/templates.js +0 -443
  31. package/dist/resources/code.d.ts +0 -15
  32. package/dist/resources/code.js +0 -122
  33. package/dist/resources/content/code-content.d.ts +0 -6
  34. package/dist/resources/content/code-content.js +0 -802
  35. package/dist/resources/content/docs-content.d.ts +0 -14
  36. package/dist/resources/content/docs-content.js +0 -1202
  37. package/dist/resources/content/index.d.ts +0 -6
  38. package/dist/resources/content/index.js +0 -6
  39. package/dist/resources/docs.d.ts +0 -15
  40. package/dist/resources/docs.js +0 -98
  41. package/dist/resources/index.d.ts +0 -6
  42. package/dist/resources/index.js +0 -13
  43. package/dist/resources/schemas.d.ts +0 -16
  44. package/dist/resources/schemas.js +0 -407
  45. package/dist/scripts/index-repos.d.ts +0 -12
  46. package/dist/scripts/index-repos.js +0 -53
  47. package/dist/server.d.ts +0 -43
  48. package/dist/server.js +0 -693
  49. package/dist/services/index.d.ts +0 -6
  50. package/dist/services/index.js +0 -6
  51. package/dist/services/sampling.d.ts +0 -62
  52. package/dist/services/sampling.js +0 -277
  53. package/dist/tools/analyze.d.ts +0 -106
  54. package/dist/tools/analyze.js +0 -431
  55. package/dist/tools/generation.d.ts +0 -9
  56. package/dist/tools/generation.js +0 -285
  57. package/dist/tools/health.d.ts +0 -120
  58. package/dist/tools/health.js +0 -362
  59. package/dist/tools/index.d.ts +0 -14
  60. package/dist/tools/index.js +0 -22
  61. package/dist/tools/meta.d.ts +0 -61
  62. package/dist/tools/meta.js +0 -282
  63. package/dist/tools/repository/constants.d.ts +0 -19
  64. package/dist/tools/repository/constants.js +0 -324
  65. package/dist/tools/repository/handlers.d.ts +0 -373
  66. package/dist/tools/repository/handlers.js +0 -724
  67. package/dist/tools/repository/index.d.ts +0 -9
  68. package/dist/tools/repository/index.js +0 -13
  69. package/dist/tools/repository/schemas.d.ts +0 -153
  70. package/dist/tools/repository/schemas.js +0 -106
  71. package/dist/tools/repository/tools.d.ts +0 -7
  72. package/dist/tools/repository/tools.js +0 -484
  73. package/dist/tools/repository/validation.d.ts +0 -106
  74. package/dist/tools/repository/validation.js +0 -820
  75. package/dist/tools/repository.d.ts +0 -6
  76. package/dist/tools/repository.js +0 -7
  77. package/dist/tools/search.d.ts +0 -76
  78. package/dist/tools/search.js +0 -423
  79. package/dist/types/index.d.ts +0 -2
  80. package/dist/types/index.js +0 -2
  81. package/dist/types/mcp.d.ts +0 -187
  82. package/dist/types/mcp.js +0 -6
  83. package/dist/utils/cache.d.ts +0 -77
  84. package/dist/utils/cache.js +0 -172
  85. package/dist/utils/config.d.ts +0 -70
  86. package/dist/utils/config.js +0 -294
  87. package/dist/utils/errors.d.ts +0 -111
  88. package/dist/utils/errors.js +0 -165
  89. package/dist/utils/health.d.ts +0 -29
  90. package/dist/utils/health.js +0 -132
  91. package/dist/utils/hosted-api.d.ts +0 -67
  92. package/dist/utils/hosted-api.js +0 -119
  93. package/dist/utils/index.d.ts +0 -16
  94. package/dist/utils/index.js +0 -15
  95. package/dist/utils/logger.d.ts +0 -48
  96. package/dist/utils/logger.js +0 -124
  97. package/dist/utils/rate-limit.d.ts +0 -61
  98. package/dist/utils/rate-limit.js +0 -148
  99. package/dist/utils/validation.d.ts +0 -52
  100. package/dist/utils/validation.js +0 -255
@@ -1,6 +0,0 @@
1
- /**
2
- * Repository tools
3
- * Re-exports from modular structure for backward compatibility
4
- */
5
- export * from "./repository/index.js";
6
- //# sourceMappingURL=repository.d.ts.map
@@ -1,7 +0,0 @@
1
- /**
2
- * Repository tools
3
- * Re-exports from modular structure for backward compatibility
4
- */
5
- // Re-export everything from the repository module
6
- export * from "./repository/index.js";
7
- //# sourceMappingURL=repository.js.map
@@ -1,76 +0,0 @@
1
- import { z } from "zod";
2
- import type { ExtendedToolDefinition } from "../types/index.js";
3
- export declare const SearchCompactInputSchema: z.ZodObject<{
4
- query: z.ZodString;
5
- limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
6
- filter: z.ZodOptional<z.ZodObject<{
7
- repository: z.ZodOptional<z.ZodString>;
8
- isPublic: z.ZodOptional<z.ZodBoolean>;
9
- }, "strip", z.ZodTypeAny, {
10
- repository?: string | undefined;
11
- isPublic?: boolean | undefined;
12
- }, {
13
- repository?: string | undefined;
14
- isPublic?: boolean | undefined;
15
- }>>;
16
- }, "strip", z.ZodTypeAny, {
17
- query: string;
18
- limit: number;
19
- filter?: {
20
- repository?: string | undefined;
21
- isPublic?: boolean | undefined;
22
- } | undefined;
23
- }, {
24
- query: string;
25
- filter?: {
26
- repository?: string | undefined;
27
- isPublic?: boolean | undefined;
28
- } | undefined;
29
- limit?: number | undefined;
30
- }>;
31
- export declare const SearchTypeScriptInputSchema: z.ZodObject<{
32
- query: z.ZodString;
33
- includeTypes: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
34
- includeExamples: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
35
- limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
36
- }, "strip", z.ZodTypeAny, {
37
- query: string;
38
- limit: number;
39
- includeTypes: boolean;
40
- includeExamples: boolean;
41
- }, {
42
- query: string;
43
- limit?: number | undefined;
44
- includeTypes?: boolean | undefined;
45
- includeExamples?: boolean | undefined;
46
- }>;
47
- export declare const SearchDocsInputSchema: z.ZodObject<{
48
- query: z.ZodString;
49
- category: z.ZodDefault<z.ZodOptional<z.ZodEnum<["guides", "api", "concepts", "all"]>>>;
50
- limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
51
- }, "strip", z.ZodTypeAny, {
52
- query: string;
53
- limit: number;
54
- category: "all" | "guides" | "api" | "concepts";
55
- }, {
56
- query: string;
57
- limit?: number | undefined;
58
- category?: "all" | "guides" | "api" | "concepts" | undefined;
59
- }>;
60
- export type SearchCompactInput = z.infer<typeof SearchCompactInputSchema>;
61
- export type SearchTypeScriptInput = z.infer<typeof SearchTypeScriptInputSchema>;
62
- export type SearchDocsInput = z.infer<typeof SearchDocsInputSchema>;
63
- /**
64
- * Search Compact smart contract code and patterns
65
- */
66
- export declare function searchCompact(input: SearchCompactInput): Promise<{}>;
67
- /**
68
- * Search TypeScript SDK code, types, and API implementations
69
- */
70
- export declare function searchTypeScript(input: SearchTypeScriptInput): Promise<{}>;
71
- /**
72
- * Full-text search across official Midnight documentation
73
- */
74
- export declare function searchDocs(input: SearchDocsInput): Promise<{}>;
75
- export declare const searchTools: ExtendedToolDefinition[];
76
- //# sourceMappingURL=search.d.ts.map
@@ -1,423 +0,0 @@
1
- import { z } from "zod";
2
- import { vectorStore } from "../db/index.js";
3
- import { logger, validateQuery, validateNumber, searchCache, createCacheKey, isHostedMode, searchCompactHosted, searchTypeScriptHosted, searchDocsHosted, } from "../utils/index.js";
4
- // ============================================================================
5
- // Common Output Schema for Search Results
6
- // ============================================================================
7
- const searchResultSchema = {
8
- type: "object",
9
- properties: {
10
- results: {
11
- type: "array",
12
- description: "Array of search results",
13
- items: {
14
- type: "object",
15
- properties: {
16
- code: { type: "string", description: "The matched code content" },
17
- relevanceScore: {
18
- type: "number",
19
- description: "Relevance score from 0 to 1",
20
- },
21
- source: {
22
- type: "object",
23
- description: "Source location information",
24
- properties: {
25
- repository: { type: "string", description: "Repository name" },
26
- filePath: { type: "string", description: "File path" },
27
- lines: {
28
- type: "string",
29
- description: "Line range (e.g., 10-50)",
30
- },
31
- },
32
- },
33
- codeType: {
34
- type: "string",
35
- description: "Type of code (compact, typescript, markdown)",
36
- },
37
- name: { type: "string", description: "Name of the code element" },
38
- },
39
- },
40
- },
41
- totalResults: {
42
- type: "number",
43
- description: "Total number of results returned",
44
- },
45
- query: { type: "string", description: "The search query used" },
46
- warnings: {
47
- type: "array",
48
- description: "Any warnings about the search",
49
- items: { type: "string" },
50
- },
51
- },
52
- required: ["results", "totalResults", "query"],
53
- description: "Search results with relevance scores and source information",
54
- };
55
- // Common annotations for search tools
56
- const searchToolAnnotations = {
57
- readOnlyHint: true,
58
- idempotentHint: true,
59
- openWorldHint: true,
60
- category: "search",
61
- };
62
- /**
63
- * Validate and prepare common search parameters
64
- * Extracts common validation logic used by all search functions
65
- */
66
- function validateSearchInput(query, limit) {
67
- const queryValidation = validateQuery(query);
68
- if (!queryValidation.isValid) {
69
- return {
70
- success: false,
71
- error: {
72
- error: "Invalid query",
73
- details: queryValidation.errors,
74
- suggestion: "Provide a valid search query with at least 2 characters",
75
- },
76
- };
77
- }
78
- const limitValidation = validateNumber(limit, {
79
- min: 1,
80
- max: 50,
81
- defaultValue: 10,
82
- });
83
- return {
84
- success: true,
85
- context: {
86
- sanitizedQuery: queryValidation.sanitized,
87
- limit: limitValidation.value,
88
- warnings: queryValidation.warnings,
89
- },
90
- };
91
- }
92
- /**
93
- * Check cache for existing search results
94
- */
95
- function checkSearchCache(cacheKey) {
96
- const cached = searchCache.get(cacheKey);
97
- if (cached) {
98
- logger.debug("Search cache hit", { cacheKey });
99
- return cached;
100
- }
101
- return null;
102
- }
103
- /**
104
- * Execute hosted search with fallback handling
105
- */
106
- async function tryHostedSearch(searchType, hostedSearchFn, cacheKey, warnings) {
107
- if (!isHostedMode()) {
108
- return null;
109
- }
110
- try {
111
- const response = await hostedSearchFn();
112
- searchCache.set(cacheKey, response);
113
- return {
114
- result: {
115
- ...response,
116
- ...(warnings.length > 0 && { warnings }),
117
- },
118
- cached: true,
119
- };
120
- }
121
- catch (error) {
122
- logger.warn(`Hosted API ${searchType} search failed, falling back to local`, {
123
- error: String(error),
124
- });
125
- return null;
126
- }
127
- }
128
- /**
129
- * Add warnings to response and cache it
130
- */
131
- function finalizeResponse(response, cacheKey, warnings) {
132
- const finalResponse = {
133
- ...response,
134
- ...(warnings.length > 0 && { warnings }),
135
- };
136
- searchCache.set(cacheKey, finalResponse);
137
- return finalResponse;
138
- }
139
- // ============================================================================
140
- // Schema Definitions
141
- // ============================================================================
142
- // Schema definitions for tool inputs
143
- export const SearchCompactInputSchema = z.object({
144
- query: z.string().describe("Natural language search query for Compact code"),
145
- limit: z
146
- .number()
147
- .optional()
148
- .default(10)
149
- .describe("Maximum results to return"),
150
- filter: z
151
- .object({
152
- repository: z.string().optional(),
153
- isPublic: z.boolean().optional(),
154
- })
155
- .optional()
156
- .describe("Optional filters"),
157
- });
158
- export const SearchTypeScriptInputSchema = z.object({
159
- query: z.string().describe("Search query for TypeScript SDK code"),
160
- includeTypes: z
161
- .boolean()
162
- .optional()
163
- .default(true)
164
- .describe("Include type definitions"),
165
- includeExamples: z
166
- .boolean()
167
- .optional()
168
- .default(true)
169
- .describe("Include usage examples"),
170
- limit: z.number().optional().default(10),
171
- });
172
- export const SearchDocsInputSchema = z.object({
173
- query: z.string().describe("Documentation search query"),
174
- category: z
175
- .enum(["guides", "api", "concepts", "all"])
176
- .optional()
177
- .default("all")
178
- .describe("Filter by documentation category"),
179
- limit: z.number().optional().default(10),
180
- });
181
- /**
182
- * Search Compact smart contract code and patterns
183
- */
184
- export async function searchCompact(input) {
185
- // Validate input using common helper
186
- const validation = validateSearchInput(input.query, input.limit);
187
- if (!validation.success) {
188
- return validation.error;
189
- }
190
- const { sanitizedQuery, limit, warnings } = validation.context;
191
- logger.debug("Searching Compact code", {
192
- query: sanitizedQuery,
193
- mode: isHostedMode() ? "hosted" : "local",
194
- });
195
- // Check cache first
196
- const cacheKey = createCacheKey("compact", sanitizedQuery, limit, input.filter?.repository);
197
- const cached = checkSearchCache(cacheKey);
198
- if (cached)
199
- return cached;
200
- // Try hosted API first
201
- const hostedResult = await tryHostedSearch("compact", () => searchCompactHosted(sanitizedQuery, limit), cacheKey, warnings);
202
- if (hostedResult)
203
- return hostedResult.result;
204
- // Local search (fallback or when in local mode)
205
- const filter = {
206
- language: "compact",
207
- ...input.filter,
208
- };
209
- const results = await vectorStore.search(sanitizedQuery, limit, filter);
210
- const response = {
211
- results: results.map((r) => ({
212
- code: r.content,
213
- relevanceScore: r.score,
214
- source: {
215
- repository: r.metadata.repository,
216
- filePath: r.metadata.filePath,
217
- lines: `${r.metadata.startLine}-${r.metadata.endLine}`,
218
- },
219
- codeType: r.metadata.codeType,
220
- name: r.metadata.codeName,
221
- })),
222
- totalResults: results.length,
223
- query: sanitizedQuery,
224
- };
225
- return finalizeResponse(response, cacheKey, warnings);
226
- }
227
- /**
228
- * Search TypeScript SDK code, types, and API implementations
229
- */
230
- export async function searchTypeScript(input) {
231
- // Validate input using common helper
232
- const validation = validateSearchInput(input.query, input.limit);
233
- if (!validation.success) {
234
- return validation.error;
235
- }
236
- const { sanitizedQuery, limit, warnings } = validation.context;
237
- logger.debug("Searching TypeScript code", {
238
- query: sanitizedQuery,
239
- mode: isHostedMode() ? "hosted" : "local",
240
- });
241
- // Check cache
242
- const cacheKey = createCacheKey("typescript", sanitizedQuery, limit, input.includeTypes, input.includeExamples);
243
- const cached = checkSearchCache(cacheKey);
244
- if (cached)
245
- return cached;
246
- // Try hosted API first
247
- const hostedResult = await tryHostedSearch("typescript", () => searchTypeScriptHosted(sanitizedQuery, limit, input.includeTypes), cacheKey, warnings);
248
- if (hostedResult)
249
- return hostedResult.result;
250
- // Local search (fallback or when in local mode)
251
- const filter = {
252
- language: "typescript",
253
- };
254
- const results = await vectorStore.search(sanitizedQuery, limit, filter);
255
- // Filter based on type preferences
256
- let filteredResults = results;
257
- if (!input.includeTypes) {
258
- filteredResults = results.filter((r) => r.metadata.codeType !== "type" && r.metadata.codeType !== "interface");
259
- }
260
- const response = {
261
- results: filteredResults.map((r) => ({
262
- code: r.content,
263
- relevanceScore: r.score,
264
- source: {
265
- repository: r.metadata.repository,
266
- filePath: r.metadata.filePath,
267
- lines: `${r.metadata.startLine}-${r.metadata.endLine}`,
268
- },
269
- codeType: r.metadata.codeType,
270
- name: r.metadata.codeName,
271
- isExported: r.metadata.isPublic,
272
- })),
273
- totalResults: filteredResults.length,
274
- query: sanitizedQuery,
275
- };
276
- return finalizeResponse(response, cacheKey, warnings);
277
- }
278
- /**
279
- * Full-text search across official Midnight documentation
280
- */
281
- export async function searchDocs(input) {
282
- // Validate input using common helper
283
- const validation = validateSearchInput(input.query, input.limit);
284
- if (!validation.success) {
285
- return validation.error;
286
- }
287
- const { sanitizedQuery, limit, warnings } = validation.context;
288
- logger.debug("Searching documentation", {
289
- query: sanitizedQuery,
290
- mode: isHostedMode() ? "hosted" : "local",
291
- });
292
- // Check cache
293
- const cacheKey = createCacheKey("docs", sanitizedQuery, limit, input.category);
294
- const cached = checkSearchCache(cacheKey);
295
- if (cached)
296
- return cached;
297
- // Try hosted API first
298
- const hostedResult = await tryHostedSearch("docs", () => searchDocsHosted(sanitizedQuery, limit, input.category), cacheKey, warnings);
299
- if (hostedResult)
300
- return hostedResult.result;
301
- // Local search (fallback or when in local mode)
302
- const filter = {
303
- language: "markdown",
304
- };
305
- // If category is specified, add repository filter
306
- if (input.category !== "all") {
307
- // Docs are typically in the midnight-docs repo
308
- filter.repository = "midnightntwrk/midnight-docs";
309
- }
310
- const results = await vectorStore.search(sanitizedQuery, limit, filter);
311
- const response = {
312
- results: results.map((r) => ({
313
- content: r.content,
314
- relevanceScore: r.score,
315
- source: {
316
- repository: r.metadata.repository,
317
- filePath: r.metadata.filePath,
318
- section: r.metadata.codeName,
319
- },
320
- })),
321
- totalResults: results.length,
322
- query: sanitizedQuery,
323
- category: input.category,
324
- };
325
- return finalizeResponse(response, cacheKey, warnings);
326
- }
327
- // Tool definitions for MCP
328
- export const searchTools = [
329
- {
330
- name: "midnight-search-compact",
331
- description: "Semantic search across Compact smart contract code and patterns. Use this to find circuit definitions, witness functions, ledger declarations, and best practices for Midnight smart contracts.",
332
- inputSchema: {
333
- type: "object",
334
- properties: {
335
- query: {
336
- type: "string",
337
- description: "Natural language search query for Compact code",
338
- },
339
- limit: {
340
- type: "number",
341
- description: "Maximum results to return (default: 10)",
342
- },
343
- filter: {
344
- type: "object",
345
- properties: {
346
- repository: { type: "string" },
347
- isPublic: { type: "boolean" },
348
- },
349
- description: "Optional filters",
350
- },
351
- },
352
- required: ["query"],
353
- },
354
- outputSchema: searchResultSchema,
355
- annotations: {
356
- ...searchToolAnnotations,
357
- title: "Search Compact Contracts",
358
- },
359
- handler: searchCompact,
360
- },
361
- {
362
- name: "midnight-search-typescript",
363
- description: "Search TypeScript SDK code, types, and API implementations. Use this to find how to use the Midnight JavaScript SDK, type definitions, and integration patterns.",
364
- inputSchema: {
365
- type: "object",
366
- properties: {
367
- query: {
368
- type: "string",
369
- description: "Search query for TypeScript SDK code",
370
- },
371
- includeTypes: {
372
- type: "boolean",
373
- description: "Include type definitions (default: true)",
374
- },
375
- includeExamples: {
376
- type: "boolean",
377
- description: "Include usage examples (default: true)",
378
- },
379
- limit: {
380
- type: "number",
381
- description: "Maximum results to return (default: 10)",
382
- },
383
- },
384
- required: ["query"],
385
- },
386
- outputSchema: searchResultSchema,
387
- annotations: {
388
- ...searchToolAnnotations,
389
- title: "Search TypeScript SDK",
390
- },
391
- handler: searchTypeScript,
392
- },
393
- {
394
- name: "midnight-search-docs",
395
- description: "Full-text search across official Midnight documentation. Use this to find guides, API documentation, and conceptual explanations about Midnight blockchain and the Compact language.",
396
- inputSchema: {
397
- type: "object",
398
- properties: {
399
- query: {
400
- type: "string",
401
- description: "Documentation search query",
402
- },
403
- category: {
404
- type: "string",
405
- enum: ["guides", "api", "concepts", "all"],
406
- description: "Filter by documentation category (default: all)",
407
- },
408
- limit: {
409
- type: "number",
410
- description: "Maximum results to return (default: 10)",
411
- },
412
- },
413
- required: ["query"],
414
- },
415
- outputSchema: searchResultSchema,
416
- annotations: {
417
- ...searchToolAnnotations,
418
- title: "Search Documentation",
419
- },
420
- handler: searchDocs,
421
- },
422
- ];
423
- //# sourceMappingURL=search.js.map
@@ -1,2 +0,0 @@
1
- export * from "./mcp.js";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,2 +0,0 @@
1
- export * from "./mcp.js";
2
- //# sourceMappingURL=index.js.map