midnight-mcp 0.1.41 → 0.2.2

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 (103) hide show
  1. package/README.md +32 -1
  2. package/dist/bin.d.ts +1 -0
  3. package/dist/bin.js +60 -0
  4. package/dist/chunk-HOWO4K5A.js +2197 -0
  5. package/dist/chunk-S7G4OHA4.js +8306 -0
  6. package/dist/db-YDGUWI5K.js +7 -0
  7. package/dist/index.d.ts +205 -3
  8. package/dist/index.js +28 -16
  9. package/package.json +16 -6
  10. package/dist/config/compact-version.d.ts +0 -183
  11. package/dist/config/compact-version.js +0 -423
  12. package/dist/db/index.d.ts +0 -3
  13. package/dist/db/index.js +0 -2
  14. package/dist/db/vectorStore.d.ts +0 -69
  15. package/dist/db/vectorStore.js +0 -196
  16. package/dist/pipeline/embeddings.d.ts +0 -25
  17. package/dist/pipeline/embeddings.js +0 -103
  18. package/dist/pipeline/github.d.ts +0 -84
  19. package/dist/pipeline/github.js +0 -399
  20. package/dist/pipeline/index.d.ts +0 -11
  21. package/dist/pipeline/index.js +0 -6
  22. package/dist/pipeline/indexer.d.ts +0 -41
  23. package/dist/pipeline/indexer.js +0 -254
  24. package/dist/pipeline/parser.d.ts +0 -46
  25. package/dist/pipeline/parser.js +0 -436
  26. package/dist/pipeline/releases.d.ts +0 -112
  27. package/dist/pipeline/releases.js +0 -298
  28. package/dist/pipeline/repository.d.ts +0 -372
  29. package/dist/pipeline/repository.js +0 -520
  30. package/dist/prompts/index.d.ts +0 -3
  31. package/dist/prompts/index.js +0 -2
  32. package/dist/prompts/templates.d.ts +0 -26
  33. package/dist/prompts/templates.js +0 -443
  34. package/dist/resources/code.d.ts +0 -15
  35. package/dist/resources/code.js +0 -122
  36. package/dist/resources/content/code-content.d.ts +0 -6
  37. package/dist/resources/content/code-content.js +0 -802
  38. package/dist/resources/content/docs-content.d.ts +0 -14
  39. package/dist/resources/content/docs-content.js +0 -1202
  40. package/dist/resources/content/index.d.ts +0 -6
  41. package/dist/resources/content/index.js +0 -6
  42. package/dist/resources/docs.d.ts +0 -15
  43. package/dist/resources/docs.js +0 -98
  44. package/dist/resources/index.d.ts +0 -6
  45. package/dist/resources/index.js +0 -13
  46. package/dist/resources/schemas.d.ts +0 -16
  47. package/dist/resources/schemas.js +0 -407
  48. package/dist/scripts/index-repos.d.ts +0 -12
  49. package/dist/scripts/index-repos.js +0 -53
  50. package/dist/server.d.ts +0 -43
  51. package/dist/server.js +0 -696
  52. package/dist/services/index.d.ts +0 -6
  53. package/dist/services/index.js +0 -6
  54. package/dist/services/sampling.d.ts +0 -62
  55. package/dist/services/sampling.js +0 -277
  56. package/dist/tools/analyze.d.ts +0 -106
  57. package/dist/tools/analyze.js +0 -431
  58. package/dist/tools/generation.d.ts +0 -9
  59. package/dist/tools/generation.js +0 -285
  60. package/dist/tools/health.d.ts +0 -120
  61. package/dist/tools/health.js +0 -365
  62. package/dist/tools/index.d.ts +0 -14
  63. package/dist/tools/index.js +0 -22
  64. package/dist/tools/meta.d.ts +0 -61
  65. package/dist/tools/meta.js +0 -282
  66. package/dist/tools/repository/constants.d.ts +0 -19
  67. package/dist/tools/repository/constants.js +0 -324
  68. package/dist/tools/repository/handlers.d.ts +0 -373
  69. package/dist/tools/repository/handlers.js +0 -724
  70. package/dist/tools/repository/index.d.ts +0 -9
  71. package/dist/tools/repository/index.js +0 -13
  72. package/dist/tools/repository/schemas.d.ts +0 -153
  73. package/dist/tools/repository/schemas.js +0 -106
  74. package/dist/tools/repository/tools.d.ts +0 -7
  75. package/dist/tools/repository/tools.js +0 -484
  76. package/dist/tools/repository/validation.d.ts +0 -106
  77. package/dist/tools/repository/validation.js +0 -820
  78. package/dist/tools/repository.d.ts +0 -6
  79. package/dist/tools/repository.js +0 -7
  80. package/dist/tools/search.d.ts +0 -76
  81. package/dist/tools/search.js +0 -423
  82. package/dist/types/index.d.ts +0 -2
  83. package/dist/types/index.js +0 -2
  84. package/dist/types/mcp.d.ts +0 -187
  85. package/dist/types/mcp.js +0 -6
  86. package/dist/utils/cache.d.ts +0 -77
  87. package/dist/utils/cache.js +0 -172
  88. package/dist/utils/config.d.ts +0 -70
  89. package/dist/utils/config.js +0 -294
  90. package/dist/utils/errors.d.ts +0 -111
  91. package/dist/utils/errors.js +0 -165
  92. package/dist/utils/health.d.ts +0 -29
  93. package/dist/utils/health.js +0 -132
  94. package/dist/utils/hosted-api.d.ts +0 -67
  95. package/dist/utils/hosted-api.js +0 -119
  96. package/dist/utils/index.d.ts +0 -16
  97. package/dist/utils/index.js +0 -15
  98. package/dist/utils/logger.d.ts +0 -48
  99. package/dist/utils/logger.js +0 -124
  100. package/dist/utils/rate-limit.d.ts +0 -61
  101. package/dist/utils/rate-limit.js +0 -148
  102. package/dist/utils/validation.d.ts +0 -52
  103. package/dist/utils/validation.js +0 -255
@@ -1,431 +0,0 @@
1
- import { z } from "zod";
2
- import { parseCompactFile } from "../pipeline/index.js";
3
- import { logger } from "../utils/index.js";
4
- // Schema definitions
5
- export const AnalyzeContractInputSchema = z.object({
6
- code: z.string().describe("Compact contract source code"),
7
- checkSecurity: z
8
- .boolean()
9
- .optional()
10
- .default(true)
11
- .describe("Run security analysis"),
12
- });
13
- export const ExplainCircuitInputSchema = z.object({
14
- circuitCode: z.string().describe("Circuit definition from Compact"),
15
- });
16
- /**
17
- * Analyze a Compact smart contract for structure, patterns, and potential issues
18
- */
19
- export async function analyzeContract(input) {
20
- logger.debug("Analyzing Compact contract");
21
- const parsed = parseCompactFile("contract.compact", input.code);
22
- const findings = [];
23
- // Extract structured information
24
- const ledgerFields = parsed.codeUnits.filter((u) => u.type === "ledger");
25
- const circuits = parsed.codeUnits.filter((u) => u.type === "circuit");
26
- const witnesses = parsed.codeUnits.filter((u) => u.type === "witness");
27
- const types = parsed.codeUnits.filter((u) => u.type === "type");
28
- // Security analysis
29
- if (input.checkSecurity) {
30
- // Check for private state exposure
31
- const privateFields = ledgerFields.filter((f) => f.isPrivate);
32
- for (const field of privateFields) {
33
- // Check if private field is used in a public circuit without proper protection
34
- for (const circuit of circuits) {
35
- if (circuit.isPublic && circuit.code.includes(field.name)) {
36
- if (!circuit.code.includes("disclose") &&
37
- !circuit.code.includes("commit")) {
38
- findings.push({
39
- severity: "warning",
40
- message: `Private field '${field.name}' used in public circuit '${circuit.name}' without disclose/commit`,
41
- suggestion: "Consider using disclose() or commit() to properly handle private data",
42
- });
43
- }
44
- }
45
- }
46
- }
47
- // Check for missing access control on state-modifying circuits
48
- for (const circuit of circuits) {
49
- if (circuit.isPublic) {
50
- const modifiesState = circuit.code.includes(".insert") ||
51
- circuit.code.includes(".increment") ||
52
- circuit.code.includes(".decrement") ||
53
- circuit.code.includes("=");
54
- if (modifiesState && !circuit.code.includes("assert")) {
55
- findings.push({
56
- severity: "info",
57
- message: `Public circuit '${circuit.name}' modifies state without assertions`,
58
- suggestion: "Consider adding assertions to validate inputs and permissions",
59
- });
60
- }
61
- }
62
- }
63
- // Check for unused witnesses
64
- for (const witness of witnesses) {
65
- let isUsed = false;
66
- for (const circuit of circuits) {
67
- if (circuit.code.includes(witness.name)) {
68
- isUsed = true;
69
- break;
70
- }
71
- }
72
- if (!isUsed) {
73
- findings.push({
74
- severity: "info",
75
- message: `Witness '${witness.name}' is defined but not used in any circuit`,
76
- suggestion: "Remove unused witnesses or implement their usage",
77
- });
78
- }
79
- }
80
- // Check for common patterns
81
- if (!parsed.imports.includes("std")) {
82
- findings.push({
83
- severity: "info",
84
- message: "Standard library not imported",
85
- suggestion: "Consider adding 'include \"std\";' for common utilities",
86
- });
87
- }
88
- }
89
- // Generate summary
90
- const summary = {
91
- hasLedger: parsed.metadata.hasLedger,
92
- hasCircuits: parsed.metadata.hasCircuits,
93
- hasWitnesses: parsed.metadata.hasWitnesses,
94
- totalLines: parsed.metadata.lineCount,
95
- publicCircuits: circuits.filter((c) => c.isPublic).length,
96
- privateCircuits: circuits.filter((c) => !c.isPublic).length,
97
- publicState: ledgerFields.filter((f) => !f.isPrivate).length,
98
- privateState: ledgerFields.filter((f) => f.isPrivate).length,
99
- };
100
- return {
101
- summary,
102
- structure: {
103
- imports: parsed.imports,
104
- exports: parsed.exports,
105
- ledger: ledgerFields.map((f) => ({
106
- name: f.name,
107
- type: f.returnType,
108
- isPrivate: f.isPrivate,
109
- })),
110
- circuits: circuits.map((c) => ({
111
- name: c.name,
112
- isPublic: c.isPublic,
113
- parameters: c.parameters,
114
- returnType: c.returnType,
115
- })),
116
- witnesses: witnesses.map((w) => ({
117
- name: w.name,
118
- parameters: w.parameters,
119
- returnType: w.returnType,
120
- })),
121
- types: types.map((t) => ({
122
- name: t.name,
123
- definition: t.returnType,
124
- })),
125
- },
126
- securityFindings: findings,
127
- recommendations: findings.length === 0
128
- ? ["Contract structure looks good! No issues found."]
129
- : findings.map((f) => f.suggestion).filter(Boolean),
130
- };
131
- }
132
- /**
133
- * Explain what a specific circuit does in plain language
134
- */
135
- export async function explainCircuit(input) {
136
- logger.debug("Explaining circuit");
137
- const parsed = parseCompactFile("circuit.compact", input.circuitCode);
138
- const circuit = parsed.codeUnits.find((u) => u.type === "circuit");
139
- if (!circuit) {
140
- return {
141
- error: "No circuit definition found in the provided code",
142
- suggestion: "Make sure to provide a complete circuit definition including 'circuit' keyword",
143
- };
144
- }
145
- // Analyze the circuit
146
- const operations = [];
147
- const zkImplications = [];
148
- // Detect common operations
149
- if (circuit.code.includes("disclose")) {
150
- operations.push("Reveals private data selectively (disclose)");
151
- zkImplications.push("Data revealed via disclose() will be visible on-chain while proving possession of private data");
152
- }
153
- if (circuit.code.includes("commit")) {
154
- operations.push("Creates cryptographic commitments (commit)");
155
- zkImplications.push("Commitments allow hiding data while proving properties about it");
156
- }
157
- if (circuit.code.includes("hash")) {
158
- operations.push("Computes cryptographic hashes (hash)");
159
- zkImplications.push("Hashes are computed in-circuit and can be verified without revealing preimages");
160
- }
161
- if (circuit.code.includes("assert")) {
162
- operations.push("Validates constraints (assert)");
163
- zkImplications.push("Assertions create ZK constraints - the proof will fail if any assertion fails");
164
- }
165
- if (circuit.code.includes(".insert")) {
166
- operations.push("Inserts data into ledger storage");
167
- }
168
- if (circuit.code.includes(".increment")) {
169
- operations.push("Increments a counter value");
170
- }
171
- if (circuit.code.includes(".decrement")) {
172
- operations.push("Decrements a counter value");
173
- }
174
- // Build explanation
175
- const explanation = buildCircuitExplanation(circuit, operations);
176
- return {
177
- circuitName: circuit.name,
178
- isPublic: circuit.isPublic,
179
- parameters: circuit.parameters,
180
- returnType: circuit.returnType,
181
- explanation,
182
- operations,
183
- zkImplications: zkImplications.length > 0
184
- ? zkImplications
185
- : [
186
- "This circuit generates a zero-knowledge proof that the computation was performed correctly",
187
- ],
188
- privacyConsiderations: getPrivacyConsiderations(circuit),
189
- };
190
- }
191
- function buildCircuitExplanation(circuit, operations) {
192
- let explanation = `The circuit '${circuit.name}' is a `;
193
- if (circuit.isPublic) {
194
- explanation += "public (exported) function that can be called by anyone. ";
195
- }
196
- else {
197
- explanation += "private (internal) function used by other circuits. ";
198
- }
199
- if (circuit.parameters && circuit.parameters.length > 0) {
200
- explanation += `It takes ${circuit.parameters.length} parameter(s): `;
201
- explanation += circuit.parameters
202
- .map((p) => `${p.name} (${p.type})`)
203
- .join(", ");
204
- explanation += ". ";
205
- }
206
- if (circuit.returnType && circuit.returnType !== "Void") {
207
- explanation += `It returns a value of type ${circuit.returnType}. `;
208
- }
209
- if (operations.length > 0) {
210
- explanation += `\n\nKey operations performed:\n`;
211
- operations.forEach((op, i) => {
212
- explanation += `${i + 1}. ${op}\n`;
213
- });
214
- }
215
- return explanation;
216
- }
217
- function getPrivacyConsiderations(circuit) {
218
- const considerations = [];
219
- if (circuit.code.includes("disclose")) {
220
- considerations.push("Uses disclose() - some private data will be revealed on-chain");
221
- }
222
- if (circuit.isPublic) {
223
- considerations.push("Public circuit - anyone can call this and generate proofs");
224
- }
225
- if (circuit.code.includes("@private") || circuit.code.includes("witness")) {
226
- considerations.push("Accesses private state or witnesses - ensure sensitive data is handled correctly");
227
- }
228
- if (considerations.length === 0) {
229
- considerations.push("No specific privacy concerns identified in this circuit");
230
- }
231
- return considerations;
232
- }
233
- // Output schemas for analysis tools - aligned with actual function return types
234
- const analyzeContractOutputSchema = {
235
- type: "object",
236
- properties: {
237
- summary: {
238
- type: "object",
239
- description: "Summary statistics of the contract",
240
- properties: {
241
- hasLedger: { type: "boolean" },
242
- hasCircuits: { type: "boolean" },
243
- hasWitnesses: { type: "boolean" },
244
- totalLines: { type: "number" },
245
- publicCircuits: { type: "number" },
246
- privateCircuits: { type: "number" },
247
- publicState: { type: "number" },
248
- privateState: { type: "number" },
249
- },
250
- },
251
- structure: {
252
- type: "object",
253
- description: "Contract structure breakdown",
254
- properties: {
255
- imports: { type: "array", items: { type: "string" } },
256
- exports: { type: "array", items: { type: "string" } },
257
- ledger: {
258
- type: "array",
259
- description: "Ledger state fields",
260
- items: {
261
- type: "object",
262
- properties: {
263
- name: { type: "string" },
264
- type: { type: "string" },
265
- isPrivate: { type: "boolean" },
266
- },
267
- },
268
- },
269
- circuits: {
270
- type: "array",
271
- description: "Circuit definitions",
272
- items: {
273
- type: "object",
274
- properties: {
275
- name: { type: "string" },
276
- isPublic: { type: "boolean" },
277
- parameters: { type: "array", items: { type: "object" } },
278
- returnType: { type: "string" },
279
- },
280
- },
281
- },
282
- witnesses: {
283
- type: "array",
284
- description: "Witness functions",
285
- items: {
286
- type: "object",
287
- properties: {
288
- name: { type: "string" },
289
- parameters: { type: "array", items: { type: "object" } },
290
- returnType: { type: "string" },
291
- },
292
- },
293
- },
294
- types: {
295
- type: "array",
296
- description: "Type definitions",
297
- items: {
298
- type: "object",
299
- properties: {
300
- name: { type: "string" },
301
- definition: { type: "string" },
302
- },
303
- },
304
- },
305
- },
306
- },
307
- securityFindings: {
308
- type: "array",
309
- description: "Security analysis findings",
310
- items: {
311
- type: "object",
312
- properties: {
313
- severity: {
314
- type: "string",
315
- enum: ["info", "warning", "error"],
316
- },
317
- message: { type: "string" },
318
- suggestion: { type: "string" },
319
- },
320
- },
321
- },
322
- recommendations: {
323
- type: "array",
324
- items: { type: "string" },
325
- description: "Recommendations for improvement",
326
- },
327
- },
328
- required: ["summary", "structure", "securityFindings", "recommendations"],
329
- description: "Detailed contract analysis with security findings",
330
- };
331
- const explainCircuitOutputSchema = {
332
- type: "object",
333
- properties: {
334
- circuitName: { type: "string", description: "Circuit name" },
335
- isPublic: { type: "boolean", description: "Whether it's exported" },
336
- parameters: {
337
- type: "array",
338
- items: {
339
- type: "object",
340
- properties: {
341
- name: { type: "string" },
342
- type: { type: "string" },
343
- },
344
- },
345
- description: "Circuit parameters",
346
- },
347
- returnType: { type: "string", description: "Return type" },
348
- explanation: {
349
- type: "string",
350
- description: "Plain language explanation",
351
- },
352
- operations: {
353
- type: "array",
354
- items: { type: "string" },
355
- description: "Operations performed by the circuit",
356
- },
357
- zkImplications: {
358
- type: "array",
359
- items: { type: "string" },
360
- description: "Zero-knowledge proof implications",
361
- },
362
- privacyConsiderations: {
363
- type: "array",
364
- items: { type: "string" },
365
- description: "Privacy-related considerations",
366
- },
367
- },
368
- required: [
369
- "circuitName",
370
- "explanation",
371
- "zkImplications",
372
- "privacyConsiderations",
373
- ],
374
- description: "Detailed circuit explanation with privacy analysis",
375
- };
376
- // Tool definitions for MCP
377
- export const analyzeTools = [
378
- {
379
- name: "midnight-analyze-contract",
380
- description: "⚠️ STATIC ANALYSIS ONLY - Analyze contract structure and patterns. " +
381
- "🚫 THIS DOES NOT COMPILE THE CONTRACT. Cannot catch: sealed field rules, disclose() requirements, semantic errors. " +
382
- "👉 Use 'midnight-extract-contract-structure' for pre-compilation checks. " +
383
- "Use this for: understanding structure, security pattern analysis, recommendations. " +
384
- "NEVER claim a contract 'works' or 'compiles' based on this tool alone.",
385
- inputSchema: {
386
- type: "object",
387
- properties: {
388
- code: {
389
- type: "string",
390
- description: "Compact contract source code to analyze",
391
- },
392
- checkSecurity: {
393
- type: "boolean",
394
- description: "Run security analysis (default: true)",
395
- },
396
- },
397
- required: ["code"],
398
- },
399
- outputSchema: analyzeContractOutputSchema,
400
- annotations: {
401
- readOnlyHint: true,
402
- idempotentHint: true,
403
- title: "Analyze Compact Contract",
404
- category: "analyze",
405
- },
406
- handler: analyzeContract,
407
- },
408
- {
409
- name: "midnight-explain-circuit",
410
- description: "Explain what a specific Compact circuit does in plain language, including its zero-knowledge proof implications and privacy considerations.",
411
- inputSchema: {
412
- type: "object",
413
- properties: {
414
- circuitCode: {
415
- type: "string",
416
- description: "Circuit definition from Compact to explain",
417
- },
418
- },
419
- required: ["circuitCode"],
420
- },
421
- outputSchema: explainCircuitOutputSchema,
422
- annotations: {
423
- readOnlyHint: true,
424
- idempotentHint: true,
425
- title: "Explain Circuit",
426
- category: "analyze",
427
- },
428
- handler: explainCircuit,
429
- },
430
- ];
431
- //# sourceMappingURL=analyze.js.map
@@ -1,9 +0,0 @@
1
- /**
2
- * Contract generation tool using sampling capability
3
- *
4
- * Enables AI-assisted generation and review of Compact smart contracts
5
- */
6
- import type { ExtendedToolDefinition } from "../types/index.js";
7
- export declare const generationTools: ExtendedToolDefinition[];
8
- export declare const generationHandlers: Record<string, (args: any) => Promise<any>>;
9
- //# sourceMappingURL=generation.d.ts.map