@farming-labs/next 0.1.32 → 0.1.33

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 (2) hide show
  1. package/dist/config.mjs +20 -10
  2. package/package.json +3 -3
package/dist/config.mjs CHANGED
@@ -150,6 +150,8 @@ const DEFAULT_AGENT_SPEC_ROUTE = "/api/docs/agent/spec";
150
150
  const DEFAULT_AGENT_SPEC_WELL_KNOWN_ROUTE = "/.well-known/agent";
151
151
  const DEFAULT_AGENT_SPEC_WELL_KNOWN_JSON_ROUTE = "/.well-known/agent.json";
152
152
  const DEFAULT_AGENT_FEEDBACK_ROUTE = "/api/docs/agent/feedback";
153
+ const DEFAULT_MCP_ROUTE = "/api/docs/mcp";
154
+ const DEFAULT_MCP_PUBLIC_ROUTE = "/mcp";
153
155
  const DEFAULT_LLMS_TXT_ROUTE = "/llms.txt";
154
156
  const DEFAULT_LLMS_FULL_TXT_ROUTE = "/llms-full.txt";
155
157
  const DEFAULT_LLMS_TXT_WELL_KNOWN_ROUTE = "/.well-known/llms.txt";
@@ -636,11 +638,11 @@ function readMcpConfig(root) {
636
638
  const content = readFileSync(configPath, "utf-8");
637
639
  if (content.match(/mcp\s*:\s*false/)) return {
638
640
  enabled: false,
639
- route: "/api/docs/mcp"
641
+ route: DEFAULT_MCP_ROUTE
640
642
  };
641
643
  if (content.match(/mcp\s*:\s*true/)) return {
642
644
  enabled: true,
643
- route: "/api/docs/mcp"
645
+ route: DEFAULT_MCP_ROUTE
644
646
  };
645
647
  const block = extractObjectLiteral(content, "mcp");
646
648
  if (!block) continue;
@@ -648,23 +650,23 @@ function readMcpConfig(root) {
648
650
  const routeMatch = block.match(/route\s*:\s*["']([^"']+)["']/);
649
651
  return {
650
652
  enabled: enabledMatch ? enabledMatch[1] !== "false" : true,
651
- route: normalizeRoutePath(routeMatch?.[1] ?? "/api/docs/mcp")
653
+ route: normalizeRoutePath(routeMatch?.[1] ?? DEFAULT_MCP_ROUTE)
652
654
  };
653
655
  } catch {
654
656
  return {
655
657
  enabled: true,
656
- route: "/api/docs/mcp"
658
+ route: DEFAULT_MCP_ROUTE
657
659
  };
658
660
  }
659
661
  }
660
662
  return {
661
663
  enabled: true,
662
- route: "/api/docs/mcp"
664
+ route: DEFAULT_MCP_ROUTE
663
665
  };
664
666
  }
665
667
  function normalizeRoutePath(route) {
666
668
  const normalized = `/${route}`.replace(/\/+/g, "/");
667
- return normalized !== "/" ? normalized.replace(/\/+$/, "") : "/api/docs/mcp";
669
+ return normalized !== "/" ? normalized.replace(/\/+$/, "") : DEFAULT_MCP_ROUTE;
668
670
  }
669
671
  function normalizeAgentFeedbackRoute(route, fallback = DEFAULT_AGENT_FEEDBACK_ROUTE) {
670
672
  if (!route || route.trim().length === 0) return fallback;
@@ -771,6 +773,13 @@ function buildLlmsTxtRewrites() {
771
773
  }
772
774
  ];
773
775
  }
776
+ function buildMcpRewrites(config) {
777
+ if (!config.enabled || config.route === DEFAULT_MCP_PUBLIC_ROUTE) return [];
778
+ return [{
779
+ source: DEFAULT_MCP_PUBLIC_ROUTE,
780
+ destination: config.route
781
+ }];
782
+ }
774
783
  function buildAgentFeedbackRewrites(config) {
775
784
  if (!config.enabled) return [];
776
785
  return [{
@@ -792,9 +801,10 @@ function dedupeRewrites(rewrites) {
792
801
  }
793
802
  return result;
794
803
  }
795
- function mergeDocsMarkdownRewrites(entry, agentFeedback, result) {
804
+ function mergeDocsMarkdownRewrites(entry, mcp, agentFeedback, result) {
796
805
  const autoRewrites = [
797
806
  ...buildAgentSpecRewrites(),
807
+ ...buildMcpRewrites(mcp),
798
808
  ...buildLlmsTxtRewrites(),
799
809
  ...buildDocsMarkdownRewrites(entry),
800
810
  ...buildAgentFeedbackRewrites(agentFeedback)
@@ -834,7 +844,7 @@ function withDocs(nextConfig = {}) {
834
844
  }
835
845
  const mcp = readMcpConfig(root);
836
846
  const docsMcpRouteDir = join(root, appDir, "api", "docs", "mcp");
837
- if (mcp.enabled && mcp.route === "/api/docs/mcp" && !isStaticExport && !hasFile(docsMcpRouteDir, "route")) {
847
+ if (mcp.enabled && mcp.route === DEFAULT_MCP_ROUTE && !isStaticExport && !hasFile(docsMcpRouteDir, "route")) {
838
848
  mkdirSync(docsMcpRouteDir, { recursive: true });
839
849
  writeFileSync(join(docsMcpRouteDir, "route.ts"), DOCS_MCP_ROUTE_TEMPLATE);
840
850
  }
@@ -985,13 +995,13 @@ function withDocs(nextConfig = {}) {
985
995
  if (!isStaticExport) {
986
996
  const existingRewrites = nextConfig.rewrites;
987
997
  nextConfig.rewrites = async () => {
988
- return mergeDocsMarkdownRewrites(entry, agentFeedback, typeof existingRewrites === "function" ? await existingRewrites() : existingRewrites);
998
+ return mergeDocsMarkdownRewrites(entry, mcp, agentFeedback, typeof existingRewrites === "function" ? await existingRewrites() : existingRewrites);
989
999
  };
990
1000
  }
991
1001
  nextConfig.outputFileTracingIncludes = {
992
1002
  ...existingTracingIncludes,
993
1003
  "/api/docs": [...new Set([...existingTracingIncludes["/api/docs"] ?? [], docsTraceGlob])],
994
- "/api/docs/mcp": [...new Set([...existingTracingIncludes["/api/docs/mcp"] ?? [], docsTraceGlob])]
1004
+ [DEFAULT_MCP_ROUTE]: [...new Set([...existingTracingIncludes[DEFAULT_MCP_ROUTE] ?? [], docsTraceGlob])]
995
1005
  };
996
1006
  return withMDX(nextConfig);
997
1007
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/next",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
4
4
  "description": "Next.js adapter for @farming-labs/docs — MDX config wrapper",
5
5
  "keywords": [
6
6
  "docs",
@@ -95,8 +95,8 @@
95
95
  "tsdown": "^0.20.3",
96
96
  "typescript": "^5.9.3",
97
97
  "vitest": "^3.2.4",
98
- "@farming-labs/theme": "0.1.32",
99
- "@farming-labs/docs": "0.1.32"
98
+ "@farming-labs/docs": "0.1.33",
99
+ "@farming-labs/theme": "0.1.33"
100
100
  },
101
101
  "peerDependencies": {
102
102
  "@farming-labs/docs": ">=0.0.1",