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
- * Services index
3
- * Export all service modules
4
- */
5
- export { isSamplingAvailable, registerSamplingCallback, requestCompletion, generateContract, reviewContract, generateDocumentation, } from "./sampling.js";
6
- //# sourceMappingURL=index.js.map
@@ -1,62 +0,0 @@
1
- /**
2
- * Sampling service for agentic workflows
3
- *
4
- * Enables the MCP server to request LLM completions from the client,
5
- * allowing for sophisticated multi-step workflows like:
6
- * - Auto-generating contracts from examples
7
- * - Code review with suggested fixes
8
- * - Documentation generation
9
- */
10
- import type { SamplingRequest, SamplingResponse, ModelPreferences } from "../types/index.js";
11
- type SamplingCallback = (request: SamplingRequest) => Promise<SamplingResponse>;
12
- /**
13
- * Check if sampling is available
14
- */
15
- export declare function isSamplingAvailable(): boolean;
16
- /**
17
- * Register the sampling callback from the client
18
- * This is called during server initialization when client supports sampling
19
- */
20
- export declare function registerSamplingCallback(callback: SamplingCallback): void;
21
- /**
22
- * Request a completion from the LLM via the client
23
- */
24
- export declare function requestCompletion(messages: {
25
- role: "user" | "assistant";
26
- content: string;
27
- }[], options?: {
28
- systemPrompt?: string;
29
- maxTokens?: number;
30
- temperature?: number;
31
- modelPreferences?: ModelPreferences;
32
- }): Promise<string>;
33
- /**
34
- * Generate a Compact contract based on requirements
35
- */
36
- export declare function generateContract(requirements: string, options?: {
37
- baseExample?: string;
38
- contractType?: "counter" | "token" | "voting" | "custom";
39
- }): Promise<{
40
- code: string;
41
- explanation: string;
42
- warnings: string[];
43
- }>;
44
- /**
45
- * Review contract code and suggest improvements
46
- */
47
- export declare function reviewContract(code: string): Promise<{
48
- summary: string;
49
- issues: Array<{
50
- severity: "error" | "warning" | "info";
51
- line?: number;
52
- message: string;
53
- suggestion?: string;
54
- }>;
55
- improvedCode?: string;
56
- }>;
57
- /**
58
- * Generate documentation for a contract
59
- */
60
- export declare function generateDocumentation(code: string, format?: "markdown" | "jsdoc"): Promise<string>;
61
- export {};
62
- //# sourceMappingURL=sampling.d.ts.map
@@ -1,277 +0,0 @@
1
- /**
2
- * Sampling service for agentic workflows
3
- *
4
- * Enables the MCP server to request LLM completions from the client,
5
- * allowing for sophisticated multi-step workflows like:
6
- * - Auto-generating contracts from examples
7
- * - Code review with suggested fixes
8
- * - Documentation generation
9
- */
10
- import { logger } from "../utils/index.js";
11
- // Store for the sampling callback
12
- let samplingCallback = null;
13
- /**
14
- * Check if sampling is available
15
- */
16
- export function isSamplingAvailable() {
17
- return samplingCallback !== null;
18
- }
19
- /**
20
- * Register the sampling callback from the client
21
- * This is called during server initialization when client supports sampling
22
- */
23
- export function registerSamplingCallback(callback) {
24
- samplingCallback = callback;
25
- logger.info("Sampling capability registered");
26
- }
27
- /**
28
- * Request a completion from the LLM via the client
29
- */
30
- export async function requestCompletion(messages, options = {}) {
31
- if (!samplingCallback) {
32
- throw new Error("Sampling not available - client does not support this capability");
33
- }
34
- const request = {
35
- messages: messages.map((m) => ({
36
- role: m.role,
37
- content: { type: "text", text: m.content },
38
- })),
39
- systemPrompt: options.systemPrompt,
40
- maxTokens: options.maxTokens ?? 2048,
41
- temperature: options.temperature ?? 0.7,
42
- modelPreferences: options.modelPreferences ?? {
43
- hints: [{ name: "claude-3-sonnet" }, { name: "gpt-4" }],
44
- intelligencePriority: 0.8,
45
- speedPriority: 0.5,
46
- },
47
- };
48
- logger.debug("Requesting LLM completion", {
49
- messageCount: messages.length,
50
- maxTokens: request.maxTokens,
51
- });
52
- const response = await samplingCallback(request);
53
- if (response.content.type !== "text") {
54
- throw new Error("Unexpected response content type");
55
- }
56
- return response.content.text;
57
- }
58
- /**
59
- * Generate a Compact contract based on requirements
60
- */
61
- export async function generateContract(requirements, options = {}) {
62
- if (!isSamplingAvailable()) {
63
- return {
64
- code: "",
65
- explanation: "Sampling not available - this feature requires a client that supports the sampling capability (like Claude Desktop)",
66
- warnings: ["Feature unavailable without sampling support"],
67
- };
68
- }
69
- const systemPrompt = `You are an expert Compact smart contract developer for the Midnight blockchain.
70
- Your task is to generate secure, well-documented Compact contracts based on user requirements.
71
-
72
- Key Compact concepts:
73
- - \`ledger { }\` - Defines on-chain state (public and private)
74
- - \`@private\` - Marks state as private/shielded
75
- - \`export circuit\` - Public functions that generate ZK proofs
76
- - \`witness\` - Off-chain computation functions
77
- - \`assert()\` - Creates ZK constraints
78
- - \`Counter\`, \`Map<K,V>\`, \`Set<T>\` - Built-in collection types
79
- - \`Field\`, \`Boolean\`, \`Uint<N>\`, \`Bytes<N>\` - Primitive types
80
-
81
- Always include:
82
- 1. Proper imports (include "std")
83
- 2. Clear ledger state definitions
84
- 3. Access control where appropriate
85
- 4. Comprehensive inline comments
86
-
87
- Return ONLY the Compact code, no explanations.`;
88
- const userPrompt = options.baseExample
89
- ? `Based on this example contract:
90
- \`\`\`compact
91
- ${options.baseExample}
92
- \`\`\`
93
-
94
- Generate a new contract with these requirements:
95
- ${requirements}`
96
- : `Generate a Compact smart contract with these requirements:
97
- ${requirements}
98
-
99
- Contract type: ${options.contractType || "custom"}`;
100
- try {
101
- const code = await requestCompletion([{ role: "user", content: userPrompt }], {
102
- systemPrompt,
103
- maxTokens: 4096,
104
- temperature: 0.3, // Lower temperature for code generation
105
- modelPreferences: {
106
- hints: [{ name: "claude-3-sonnet" }],
107
- intelligencePriority: 0.9,
108
- speedPriority: 0.3,
109
- },
110
- });
111
- // Extract code from markdown if wrapped
112
- const extractedCode = code.includes("```")
113
- ? code
114
- .replace(/```compact?\n?/g, "")
115
- .replace(/```/g, "")
116
- .trim()
117
- : code.trim();
118
- // Generate explanation
119
- const explanation = await requestCompletion([
120
- {
121
- role: "user",
122
- content: `Briefly explain what this Compact contract does (2-3 sentences):
123
- \`\`\`compact
124
- ${extractedCode}
125
- \`\`\``,
126
- },
127
- ], {
128
- systemPrompt: "You are a Compact contract documentation expert. Be concise.",
129
- maxTokens: 256,
130
- temperature: 0.5,
131
- });
132
- return {
133
- code: extractedCode,
134
- explanation: explanation.trim(),
135
- warnings: [],
136
- };
137
- }
138
- catch (error) {
139
- logger.error("Contract generation failed", { error: String(error) });
140
- return {
141
- code: "",
142
- explanation: `Contract generation failed: ${String(error)}`,
143
- warnings: ["Generation failed - check logs for details"],
144
- };
145
- }
146
- }
147
- /**
148
- * Review contract code and suggest improvements
149
- */
150
- export async function reviewContract(code) {
151
- if (!isSamplingAvailable()) {
152
- return {
153
- summary: "Code review requires sampling capability",
154
- issues: [
155
- {
156
- severity: "info",
157
- message: "This feature requires a client that supports the sampling capability",
158
- },
159
- ],
160
- };
161
- }
162
- const systemPrompt = `You are a Compact smart contract security auditor.
163
- Review the provided contract for:
164
- 1. Security vulnerabilities
165
- 2. Privacy concerns (improper handling of shielded state)
166
- 3. Logic errors
167
- 4. Best practice violations
168
- 5. Gas/performance issues
169
-
170
- Respond in JSON format:
171
- {
172
- "summary": "Brief summary of the contract and overall quality",
173
- "issues": [
174
- {
175
- "severity": "error|warning|info",
176
- "line": optional_line_number,
177
- "message": "Description of the issue",
178
- "suggestion": "How to fix it"
179
- }
180
- ],
181
- "improvedCode": "Full improved contract code if changes are needed"
182
- }`;
183
- try {
184
- const response = await requestCompletion([
185
- {
186
- role: "user",
187
- content: `Review this Compact contract:\n\`\`\`compact\n${code}\n\`\`\``,
188
- },
189
- ], {
190
- systemPrompt,
191
- maxTokens: 4096,
192
- temperature: 0.2,
193
- });
194
- // Parse JSON response with error handling
195
- const jsonMatch = response.match(/\{[\s\S]*\}/);
196
- if (jsonMatch) {
197
- try {
198
- const parsed = JSON.parse(jsonMatch[0]);
199
- // Validate expected structure
200
- return {
201
- summary: typeof parsed.summary === "string"
202
- ? parsed.summary
203
- : "Review complete",
204
- issues: Array.isArray(parsed.issues) ? parsed.issues : [],
205
- improvedCode: typeof parsed.improvedCode === "string"
206
- ? parsed.improvedCode
207
- : undefined,
208
- };
209
- }
210
- catch (parseError) {
211
- logger.warn("Failed to parse JSON from LLM response", {
212
- error: String(parseError),
213
- });
214
- return {
215
- summary: response,
216
- issues: [],
217
- };
218
- }
219
- }
220
- return {
221
- summary: response,
222
- issues: [],
223
- };
224
- }
225
- catch (error) {
226
- logger.error("Contract review failed", { error: String(error) });
227
- return {
228
- summary: `Review failed: ${String(error)}`,
229
- issues: [
230
- {
231
- severity: "error",
232
- message: "Review failed - check logs for details",
233
- },
234
- ],
235
- };
236
- }
237
- }
238
- /**
239
- * Generate documentation for a contract
240
- */
241
- export async function generateDocumentation(code, format = "markdown") {
242
- if (!isSamplingAvailable()) {
243
- return "Documentation generation requires sampling capability";
244
- }
245
- const systemPrompt = format === "markdown"
246
- ? `Generate comprehensive Markdown documentation for this Compact contract.
247
- Include:
248
- - Overview and purpose
249
- - State variables (with privacy annotations)
250
- - Circuit functions with parameters and effects
251
- - Witness functions
252
- - Usage examples
253
- - Security considerations`
254
- : `Generate JSDoc-style documentation comments for this Compact contract.
255
- Add documentation comments above each:
256
- - Ledger field
257
- - Circuit function
258
- - Witness function
259
- - Type definition`;
260
- try {
261
- return await requestCompletion([
262
- {
263
- role: "user",
264
- content: `Generate ${format} documentation for:\n\`\`\`compact\n${code}\n\`\`\``,
265
- },
266
- ], {
267
- systemPrompt,
268
- maxTokens: 4096,
269
- temperature: 0.5,
270
- });
271
- }
272
- catch (error) {
273
- logger.error("Documentation generation failed", { error: String(error) });
274
- return `Documentation generation failed: ${String(error)}`;
275
- }
276
- }
277
- //# sourceMappingURL=sampling.js.map
@@ -1,106 +0,0 @@
1
- import { z } from "zod";
2
- import type { ExtendedToolDefinition } from "../types/index.js";
3
- export declare const AnalyzeContractInputSchema: z.ZodObject<{
4
- code: z.ZodString;
5
- checkSecurity: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
6
- }, "strip", z.ZodTypeAny, {
7
- code: string;
8
- checkSecurity: boolean;
9
- }, {
10
- code: string;
11
- checkSecurity?: boolean | undefined;
12
- }>;
13
- export declare const ExplainCircuitInputSchema: z.ZodObject<{
14
- circuitCode: z.ZodString;
15
- }, "strip", z.ZodTypeAny, {
16
- circuitCode: string;
17
- }, {
18
- circuitCode: string;
19
- }>;
20
- export type AnalyzeContractInput = z.infer<typeof AnalyzeContractInputSchema>;
21
- export type ExplainCircuitInput = z.infer<typeof ExplainCircuitInputSchema>;
22
- interface SecurityFinding {
23
- severity: "info" | "warning" | "error";
24
- message: string;
25
- line?: number;
26
- suggestion?: string;
27
- }
28
- /**
29
- * Analyze a Compact smart contract for structure, patterns, and potential issues
30
- */
31
- export declare function analyzeContract(input: AnalyzeContractInput): Promise<{
32
- summary: {
33
- hasLedger: boolean;
34
- hasCircuits: boolean;
35
- hasWitnesses: boolean;
36
- totalLines: number;
37
- publicCircuits: number;
38
- privateCircuits: number;
39
- publicState: number;
40
- privateState: number;
41
- };
42
- structure: {
43
- imports: string[];
44
- exports: string[];
45
- ledger: {
46
- name: string;
47
- type: string | undefined;
48
- isPrivate: boolean;
49
- }[];
50
- circuits: {
51
- name: string;
52
- isPublic: boolean;
53
- parameters: {
54
- name: string;
55
- type: string;
56
- }[] | undefined;
57
- returnType: string | undefined;
58
- }[];
59
- witnesses: {
60
- name: string;
61
- parameters: {
62
- name: string;
63
- type: string;
64
- }[] | undefined;
65
- returnType: string | undefined;
66
- }[];
67
- types: {
68
- name: string;
69
- definition: string | undefined;
70
- }[];
71
- };
72
- securityFindings: SecurityFinding[];
73
- recommendations: (string | undefined)[];
74
- }>;
75
- /**
76
- * Explain what a specific circuit does in plain language
77
- */
78
- export declare function explainCircuit(input: ExplainCircuitInput): Promise<{
79
- error: string;
80
- suggestion: string;
81
- circuitName?: undefined;
82
- isPublic?: undefined;
83
- parameters?: undefined;
84
- returnType?: undefined;
85
- explanation?: undefined;
86
- operations?: undefined;
87
- zkImplications?: undefined;
88
- privacyConsiderations?: undefined;
89
- } | {
90
- circuitName: string;
91
- isPublic: boolean;
92
- parameters: {
93
- name: string;
94
- type: string;
95
- }[] | undefined;
96
- returnType: string | undefined;
97
- explanation: string;
98
- operations: string[];
99
- zkImplications: string[];
100
- privacyConsiderations: string[];
101
- error?: undefined;
102
- suggestion?: undefined;
103
- }>;
104
- export declare const analyzeTools: ExtendedToolDefinition[];
105
- export {};
106
- //# sourceMappingURL=analyze.d.ts.map