midnight-mcp 0.2.13 → 0.2.14

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.
package/README.md CHANGED
@@ -104,12 +104,12 @@ Add to `~/.codeium/windsurf/mcp_config.json`:
104
104
 
105
105
  ## What's Included
106
106
 
107
- ### 28 Tools
107
+ ### 29 Tools
108
108
 
109
109
  | Category | Tools | Description |
110
110
  | ----------------- | --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
111
111
  | **Search** | `search-compact`, `search-typescript`, `search-docs`, `fetch-docs` | Semantic search + live docs fetching |
112
- | **Analysis** | `analyze-contract`, `explain-circuit`, `extract-contract-structure` | Static analysis with 15+ checks (P0-P2 severity) |
112
+ | **Analysis** | `analyze-contract`, `explain-circuit`, `extract-contract-structure`, `compile-contract` | Static analysis + real compilation |
113
113
  | **Repository** | `get-file`, `list-examples`, `get-latest-updates` | Access files and examples |
114
114
  | **Versioning** | `get-version-info`, `check-breaking-changes`, `get-migration-guide`, `get-file-at-version`, `compare-syntax`, `get-latest-syntax` | Version tracking and migration |
115
115
  | **AI Generation** | `generate-contract`, `review-contract`, `document-contract` | AI-powered code generation _(requires sampling)_ |
@@ -119,6 +119,20 @@ Add to `~/.codeium/windsurf/mcp_config.json`:
119
119
 
120
120
  All tools are prefixed with `midnight-` (e.g., `midnight-search-compact`).
121
121
 
122
+ ### Real Contract Compilation
123
+
124
+ The `midnight-compile-contract` tool validates Compact code using a hosted compiler service:
125
+
126
+ ```
127
+ ✅ Compilation successful (Compiler v0.18.0) in 2841ms
128
+ ```
129
+
130
+ - **Fast mode** (`skipZk=true`): Syntax validation in ~1-2 seconds
131
+ - **Full mode** (`fullCompile=true`): Complete ZK circuit generation in ~10-30 seconds
132
+ - **Automatic fallback**: Falls back to static analysis if the compiler service is unavailable
133
+
134
+ This catches semantic errors that static analysis misses (sealed fields, disclose rules, type mismatches).
135
+
122
136
  ### MCP Capabilities
123
137
 
124
138
  | Capability | Feature |
package/dist/bin.js CHANGED
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  startHttpServer,
4
4
  startServer
5
- } from "./chunk-LXHUX67Z.js";
5
+ } from "./chunk-V7KK64OX.js";
6
6
  import {
7
7
  setOutputFormat
8
- } from "./chunk-FZI3KN52.js";
8
+ } from "./chunk-WYQRVPIQ.js";
9
9
 
10
10
  // src/bin.ts
11
11
  import { config } from "dotenv";
@@ -13,7 +13,7 @@ import { resolve } from "path";
13
13
  import yargs from "yargs";
14
14
  import { hideBin } from "yargs/helpers";
15
15
  config({ path: resolve(process.cwd(), ".env") });
16
- var CURRENT_VERSION = "0.2.13";
16
+ var CURRENT_VERSION = "0.2.14";
17
17
  process.on("uncaughtException", (error) => {
18
18
  console.error("Uncaught exception:", error);
19
19
  process.exit(1);
@@ -25,7 +25,7 @@ import {
25
25
  validateNumber,
26
26
  validateQuery,
27
27
  vectorStore
28
- } from "./chunk-FZI3KN52.js";
28
+ } from "./chunk-WYQRVPIQ.js";
29
29
 
30
30
  // src/tools/search/schemas.ts
31
31
  import { z } from "zod";
@@ -733,6 +733,144 @@ var AnalyzeContractInputSchema = z2.object({
733
733
  var ExplainCircuitInputSchema = z2.object({
734
734
  circuitCode: z2.string().describe("Circuit definition from Compact")
735
735
  });
736
+ var CompileContractInputSchema = z2.object({
737
+ code: z2.string().describe("Compact contract source code to compile"),
738
+ skipZk: z2.boolean().optional().default(true).describe(
739
+ "Skip ZK circuit generation for faster syntax-only validation (default: true)"
740
+ ),
741
+ fullCompile: z2.boolean().optional().default(false).describe(
742
+ "Perform full compilation including ZK generation (slower but complete)"
743
+ )
744
+ });
745
+
746
+ // src/services/compiler.ts
747
+ var COMPILER_API_URL = process.env.COMPACT_COMPILER_URL || "https://compact-playground.onrender.com";
748
+ var COMPILER_TIMEOUT = 3e4;
749
+ var MAX_CODE_SIZE = 100 * 1024;
750
+ async function compileContract(code, options = {}) {
751
+ if (!code || typeof code !== "string") {
752
+ return {
753
+ success: false,
754
+ message: "No code provided",
755
+ error: "INVALID_INPUT",
756
+ serviceAvailable: true
757
+ };
758
+ }
759
+ if (code.length > MAX_CODE_SIZE) {
760
+ return {
761
+ success: false,
762
+ message: `Code exceeds maximum size of ${MAX_CODE_SIZE / 1024}KB`,
763
+ error: "CODE_TOO_LARGE",
764
+ serviceAvailable: true
765
+ };
766
+ }
767
+ try {
768
+ const controller = new AbortController();
769
+ const timeoutId = setTimeout(() => controller.abort(), COMPILER_TIMEOUT);
770
+ const requestBody = {
771
+ code,
772
+ options: {
773
+ wrapWithDefaults: options.wrapWithDefaults ?? true,
774
+ skipZk: options.skipZk ?? true
775
+ // Default to fast syntax-only validation
776
+ }
777
+ };
778
+ logger.info("Sending code to compiler service", {
779
+ codeLength: code.length,
780
+ options: requestBody.options
781
+ });
782
+ const response = await fetch(`${COMPILER_API_URL}/compile`, {
783
+ method: "POST",
784
+ headers: {
785
+ "Content-Type": "application/json"
786
+ },
787
+ body: JSON.stringify(requestBody),
788
+ signal: controller.signal
789
+ });
790
+ clearTimeout(timeoutId);
791
+ if (!response.ok) {
792
+ const errorText = await response.text().catch(() => "Unknown error");
793
+ logger.error("Compiler API returned error status", {
794
+ status: response.status,
795
+ error: errorText
796
+ });
797
+ return {
798
+ success: false,
799
+ message: `Compiler service error: ${response.status}`,
800
+ error: "API_ERROR",
801
+ serviceAvailable: response.status < 500
802
+ };
803
+ }
804
+ const result = await response.json();
805
+ if (result.success) {
806
+ const outputInfo = typeof result.output === "object" && result.output !== null ? result.output : {};
807
+ logger.info("Compilation successful", {
808
+ compilerVersion: result.compilerVersion,
809
+ executionTime: result.executionTime,
810
+ circuits: outputInfo.circuits?.length || 0,
811
+ warnings: result.warnings?.length || 0
812
+ });
813
+ const version = result.compilerVersion || "unknown";
814
+ const execTime = result.executionTime ? ` in ${result.executionTime}ms` : "";
815
+ return {
816
+ success: true,
817
+ compilerVersion: version,
818
+ message: `\u2705 Compilation successful (Compiler v${version})${execTime}`,
819
+ circuits: outputInfo.circuits || [],
820
+ ledgerFields: outputInfo.ledgerFields || [],
821
+ exports: outputInfo.exports || [],
822
+ warnings: result.warnings || [],
823
+ serviceAvailable: true
824
+ };
825
+ } else {
826
+ const errors = result.errors || [];
827
+ const firstError = errors[0];
828
+ logger.info("Compilation failed", {
829
+ error: result.error,
830
+ errorCount: errors.length,
831
+ output: result.output,
832
+ firstError
833
+ });
834
+ let errorMessage = result.output || result.message || result.error || "Compilation failed";
835
+ if (firstError) {
836
+ errorMessage = `Line ${firstError.line}:${firstError.column} - ${firstError.message}`;
837
+ }
838
+ return {
839
+ success: false,
840
+ message: errorMessage,
841
+ error: result.error || "COMPILE_ERROR",
842
+ errors,
843
+ errorDetails: firstError ? {
844
+ line: firstError.line,
845
+ column: firstError.column,
846
+ errorType: firstError.severity
847
+ } : result.details,
848
+ serviceAvailable: true
849
+ };
850
+ }
851
+ } catch (error) {
852
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
853
+ if (error instanceof Error && error.name === "AbortError") {
854
+ logger.warn("Compiler request timed out");
855
+ return {
856
+ success: false,
857
+ message: "Compilation timed out - the contract may be too complex",
858
+ error: "TIMEOUT",
859
+ serviceAvailable: true
860
+ };
861
+ }
862
+ logger.error("Compiler service request failed", { error: errorMessage });
863
+ return {
864
+ success: false,
865
+ message: `Failed to connect to compiler service: ${errorMessage}`,
866
+ error: "CONNECTION_FAILED",
867
+ serviceAvailable: false
868
+ };
869
+ }
870
+ }
871
+ function getCompilerUrl() {
872
+ return COMPILER_API_URL;
873
+ }
736
874
 
737
875
  // src/tools/analyze/handlers.ts
738
876
  async function analyzeContract(input) {
@@ -954,6 +1092,86 @@ function getPrivacyConsiderations(circuit) {
954
1092
  }
955
1093
  return considerations;
956
1094
  }
1095
+ async function compileContract2(input) {
1096
+ logger.info("Compiling Compact contract via hosted service", {
1097
+ codeLength: input.code.length,
1098
+ skipZk: input.skipZk,
1099
+ fullCompile: input.fullCompile
1100
+ });
1101
+ const skipZk = input.fullCompile ? false : input.skipZk ?? true;
1102
+ const result = await compileContract(input.code, {
1103
+ wrapWithDefaults: true,
1104
+ skipZk
1105
+ });
1106
+ if (result.success) {
1107
+ return {
1108
+ success: true,
1109
+ message: result.message,
1110
+ compilerVersion: result.compilerVersion,
1111
+ compilationMode: skipZk ? "syntax-only" : "full",
1112
+ validationType: "compiler",
1113
+ output: {
1114
+ circuits: result.circuits || [],
1115
+ ledgerFields: result.ledgerFields || [],
1116
+ exports: result.exports || []
1117
+ },
1118
+ warnings: result.warnings || [],
1119
+ serviceUrl: getCompilerUrl()
1120
+ };
1121
+ } else {
1122
+ if (!result.serviceAvailable) {
1123
+ logger.warn(
1124
+ "Compiler service unavailable, falling back to static analysis",
1125
+ { error: result.error }
1126
+ );
1127
+ const staticResult = await analyzeContract({
1128
+ code: input.code,
1129
+ checkSecurity: true
1130
+ });
1131
+ const securityWarnings = (staticResult.securityFindings || []).map(
1132
+ (f) => `[${f.severity}] ${f.message}`
1133
+ );
1134
+ return {
1135
+ success: true,
1136
+ // Static analysis succeeded
1137
+ message: "Static analysis completed (compiler service unavailable)",
1138
+ validationType: "static-analysis-fallback",
1139
+ compilationMode: "none",
1140
+ serviceAvailable: false,
1141
+ serviceUrl: getCompilerUrl(),
1142
+ fallbackReason: result.message,
1143
+ warnings: securityWarnings,
1144
+ staticAnalysis: {
1145
+ summary: staticResult.summary,
1146
+ structure: staticResult.structure,
1147
+ securityFindings: staticResult.securityFindings,
1148
+ recommendations: staticResult.recommendations
1149
+ }
1150
+ };
1151
+ }
1152
+ const errorInfo = {
1153
+ success: false,
1154
+ message: result.message,
1155
+ error: result.error,
1156
+ validationType: "compiler",
1157
+ serviceAvailable: result.serviceAvailable,
1158
+ serviceUrl: getCompilerUrl()
1159
+ };
1160
+ if (result.errorDetails) {
1161
+ errorInfo.location = {
1162
+ line: result.errorDetails.line,
1163
+ column: result.errorDetails.column,
1164
+ errorType: result.errorDetails.errorType
1165
+ };
1166
+ }
1167
+ if (result.error === "TIMEOUT") {
1168
+ errorInfo.hint = "The contract may be too complex. Try simplifying or breaking it into smaller pieces.";
1169
+ } else if (result.errorDetails?.line) {
1170
+ errorInfo.hint = `Check line ${result.errorDetails.line} for the issue.`;
1171
+ }
1172
+ return errorInfo;
1173
+ }
1174
+ }
957
1175
 
958
1176
  // src/tools/analyze/tools.ts
959
1177
  var analyzeContractOutputSchema = {
@@ -1098,6 +1316,99 @@ var explainCircuitOutputSchema = {
1098
1316
  ],
1099
1317
  description: "Detailed circuit explanation with privacy analysis"
1100
1318
  };
1319
+ var compileContractOutputSchema = {
1320
+ type: "object",
1321
+ properties: {
1322
+ success: {
1323
+ type: "boolean",
1324
+ description: "Whether compilation/validation succeeded"
1325
+ },
1326
+ message: {
1327
+ type: "string",
1328
+ description: "Human-readable status message"
1329
+ },
1330
+ validationType: {
1331
+ type: "string",
1332
+ enum: ["compiler", "static-analysis-fallback"],
1333
+ description: "Type of validation performed - compiler (real) or static-analysis-fallback (when service unavailable)"
1334
+ },
1335
+ compilerVersion: {
1336
+ type: "string",
1337
+ description: "Version of the Compact compiler used (if available)"
1338
+ },
1339
+ compilationMode: {
1340
+ type: "string",
1341
+ enum: ["syntax-only", "full", "none"],
1342
+ description: "Type of compilation performed"
1343
+ },
1344
+ output: {
1345
+ type: "object",
1346
+ properties: {
1347
+ circuits: {
1348
+ type: "array",
1349
+ items: { type: "string" },
1350
+ description: "List of compiled circuits"
1351
+ },
1352
+ ledgerFields: {
1353
+ type: "array",
1354
+ items: { type: "string" },
1355
+ description: "List of ledger fields"
1356
+ },
1357
+ exports: {
1358
+ type: "array",
1359
+ items: { type: "string" },
1360
+ description: "List of exported symbols"
1361
+ }
1362
+ }
1363
+ },
1364
+ warnings: {
1365
+ type: "array",
1366
+ items: { type: "string" },
1367
+ description: "Compiler warnings or fallback warnings"
1368
+ },
1369
+ error: {
1370
+ type: "string",
1371
+ description: "Error code if compilation failed"
1372
+ },
1373
+ location: {
1374
+ type: "object",
1375
+ properties: {
1376
+ line: { type: "number" },
1377
+ column: { type: "number" },
1378
+ errorType: { type: "string" }
1379
+ },
1380
+ description: "Location of error if applicable"
1381
+ },
1382
+ hint: {
1383
+ type: "string",
1384
+ description: "Helpful hint for resolving the issue"
1385
+ },
1386
+ serviceUrl: {
1387
+ type: "string",
1388
+ description: "URL of the compiler service used"
1389
+ },
1390
+ serviceAvailable: {
1391
+ type: "boolean",
1392
+ description: "Whether the compiler service is available"
1393
+ },
1394
+ fallbackReason: {
1395
+ type: "string",
1396
+ description: "Reason for falling back to static analysis (if applicable)"
1397
+ },
1398
+ staticAnalysis: {
1399
+ type: "object",
1400
+ description: "Static analysis results (only present when using fallback)",
1401
+ properties: {
1402
+ summary: { type: "object" },
1403
+ structure: { type: "object" },
1404
+ securityFindings: { type: "array" },
1405
+ recommendations: { type: "array" }
1406
+ }
1407
+ }
1408
+ },
1409
+ required: ["success", "message", "validationType"],
1410
+ description: "Compilation result with detailed output, or static analysis fallback if service unavailable"
1411
+ };
1101
1412
  var analyzeTools = [
1102
1413
  {
1103
1414
  name: "midnight-analyze-contract",
@@ -1161,6 +1472,59 @@ USAGE GUIDANCE:
1161
1472
  category: "analyze"
1162
1473
  },
1163
1474
  handler: explainCircuit
1475
+ },
1476
+ {
1477
+ name: "midnight-compile-contract",
1478
+ description: `\u{1F527} REAL COMPILATION - Compile Compact code using the hosted compiler service.
1479
+
1480
+ Unlike static analysis tools, this ACTUALLY COMPILES the contract and returns real compiler errors.
1481
+
1482
+ Use this to:
1483
+ \u2022 Validate that generated code compiles before showing to users
1484
+ \u2022 Get actual compiler error messages with line numbers
1485
+ \u2022 Check if a contract is syntactically and semantically correct
1486
+
1487
+ Options:
1488
+ \u2022 skipZk=true (default): Fast syntax validation only (~1-2s)
1489
+ \u2022 fullCompile=true: Full compilation with ZK circuit generation (~10-30s)
1490
+
1491
+ FALLBACK BEHAVIOR:
1492
+ \u2022 If the compiler service is unavailable, automatically falls back to static analysis
1493
+ \u2022 Check 'validationType' in response: 'compiler' = real compilation, 'static-analysis-fallback' = fallback mode
1494
+ \u2022 Fallback provides structure/security analysis but may miss semantic errors
1495
+
1496
+ USAGE GUIDANCE:
1497
+ \u2022 Call after generating or modifying Compact code
1498
+ \u2022 Use skipZk=true for quick validation during development
1499
+ \u2022 Use fullCompile=true for final validation before deployment`,
1500
+ inputSchema: {
1501
+ type: "object",
1502
+ properties: {
1503
+ code: {
1504
+ type: "string",
1505
+ description: "Compact contract source code to compile"
1506
+ },
1507
+ skipZk: {
1508
+ type: "boolean",
1509
+ description: "Skip ZK circuit generation for faster syntax-only validation (default: true)"
1510
+ },
1511
+ fullCompile: {
1512
+ type: "boolean",
1513
+ description: "Perform full compilation including ZK generation (slower but complete)"
1514
+ }
1515
+ },
1516
+ required: ["code"]
1517
+ },
1518
+ outputSchema: compileContractOutputSchema,
1519
+ annotations: {
1520
+ readOnlyHint: true,
1521
+ idempotentHint: true,
1522
+ openWorldHint: true,
1523
+ // Makes network requests
1524
+ title: "\u{1F527} Compile Contract",
1525
+ category: "analyze"
1526
+ },
1527
+ handler: compileContract2
1164
1528
  }
1165
1529
  ];
1166
1530
 
@@ -10821,4 +11185,4 @@ export {
10821
11185
  startServer,
10822
11186
  startHttpServer
10823
11187
  };
10824
- //# sourceMappingURL=chunk-LXHUX67Z.js.map
11188
+ //# sourceMappingURL=chunk-V7KK64OX.js.map
@@ -1593,7 +1593,7 @@ var releaseTracker = new ReleaseTracker();
1593
1593
 
1594
1594
  // src/utils/health.ts
1595
1595
  var startTime = Date.now();
1596
- var VERSION = "0.2.13";
1596
+ var VERSION = "0.2.14";
1597
1597
  async function checkGitHubAPI() {
1598
1598
  const start = Date.now();
1599
1599
  try {
@@ -1621,7 +1621,7 @@ async function checkGitHubAPI() {
1621
1621
  }
1622
1622
  async function checkVectorStore() {
1623
1623
  try {
1624
- const { vectorStore: vectorStore2 } = await import("./db-33TMMHCY.js");
1624
+ const { vectorStore: vectorStore2 } = await import("./db-UKVEAHIX.js");
1625
1625
  if (vectorStore2) {
1626
1626
  return {
1627
1627
  status: "pass",
@@ -2096,7 +2096,7 @@ function serialize(data) {
2096
2096
  }
2097
2097
 
2098
2098
  // src/utils/version.ts
2099
- var CURRENT_VERSION = "0.2.13";
2099
+ var CURRENT_VERSION = "0.2.14";
2100
2100
 
2101
2101
  // src/db/vectorStore.ts
2102
2102
  var VectorStore = class {
@@ -2305,4 +2305,4 @@ export {
2305
2305
  serialize,
2306
2306
  CURRENT_VERSION
2307
2307
  };
2308
- //# sourceMappingURL=chunk-FZI3KN52.js.map
2308
+ //# sourceMappingURL=chunk-WYQRVPIQ.js.map
@@ -0,0 +1,7 @@
1
+ import {
2
+ vectorStore
3
+ } from "./chunk-WYQRVPIQ.js";
4
+ export {
5
+ vectorStore
6
+ };
7
+ //# sourceMappingURL=db-UKVEAHIX.js.map
package/dist/index.js CHANGED
@@ -9,10 +9,10 @@ import {
9
9
  promptDefinitions,
10
10
  startHttpServer,
11
11
  startServer
12
- } from "./chunk-LXHUX67Z.js";
12
+ } from "./chunk-V7KK64OX.js";
13
13
  import {
14
14
  logger
15
- } from "./chunk-FZI3KN52.js";
15
+ } from "./chunk-WYQRVPIQ.js";
16
16
  export {
17
17
  allResources,
18
18
  allTools,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midnight-mcp",
3
- "version": "0.2.13",
3
+ "version": "0.2.14",
4
4
  "description": "Model Context Protocol Server for Midnight Blockchain Development",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,7 +0,0 @@
1
- import {
2
- vectorStore
3
- } from "./chunk-FZI3KN52.js";
4
- export {
5
- vectorStore
6
- };
7
- //# sourceMappingURL=db-33TMMHCY.js.map