@farming-labs/theme 0.1.22 → 0.1.23

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.
@@ -43,6 +43,8 @@ interface DocsAPIOptions {
43
43
  search?: boolean | DocsSearchConfig;
44
44
  /** Feedback configuration */
45
45
  feedback?: boolean | FeedbackConfig;
46
+ /** MCP configuration used for the agent discovery spec. */
47
+ mcp?: boolean | DocsMcpConfig;
46
48
  }
47
49
  interface DocsMCPAPIOptions {
48
50
  rootDir?: string;
package/dist/docs-api.mjs CHANGED
@@ -4,7 +4,7 @@ import fs from "node:fs";
4
4
  import path from "node:path";
5
5
  import matter from "gray-matter";
6
6
  import { performDocsSearch, resolveChangelogConfig, resolveDocsI18n, resolveDocsLocale, resolveSearchRequestConfig } from "@farming-labs/docs";
7
- import { createDocsMcpHttpHandler, createFilesystemDocsMcpSource } from "@farming-labs/docs/server";
7
+ import { createDocsMcpHttpHandler, createFilesystemDocsMcpSource, resolveDocsMcpConfig } from "@farming-labs/docs/server";
8
8
 
9
9
  //#region src/docs-api.ts
10
10
  /**
@@ -32,6 +32,8 @@ const FILE_EXTS = [
32
32
  "jsx",
33
33
  "js"
34
34
  ];
35
+ const DEFAULT_DOCS_API_ROUTE = "/api/docs";
36
+ const DEFAULT_AGENT_SPEC_ROUTE = "/api/docs/agent/spec";
35
37
  const DEFAULT_AGENT_FEEDBACK_ROUTE = "/api/docs/agent/feedback";
36
38
  const DEFAULT_AGENT_FEEDBACK_PAYLOAD_SCHEMA = {
37
39
  type: "object",
@@ -143,6 +145,54 @@ function resolveAgentFeedbackRequest(url, feedback) {
143
145
  if (pathname === feedback.route) return { kind: "submit" };
144
146
  return null;
145
147
  }
148
+ function resolveAgentSpecRequest(url) {
149
+ if (url.searchParams.get("agent")?.trim() === "spec") return true;
150
+ return normalizeUrlPath(url.pathname) === DEFAULT_AGENT_SPEC_ROUTE;
151
+ }
152
+ function buildAgentSpec({ origin, entry, mcp, feedback }) {
153
+ const normalizedEntry = normalizePathSegment(entry) || "docs";
154
+ return {
155
+ version: "1",
156
+ name: "@farming-labs/docs",
157
+ baseUrl: origin,
158
+ api: {
159
+ docs: DEFAULT_DOCS_API_ROUTE,
160
+ agentSpec: DEFAULT_AGENT_SPEC_ROUTE,
161
+ agentSpecQuery: `${DEFAULT_DOCS_API_ROUTE}?agent=spec`
162
+ },
163
+ markdown: {
164
+ enabled: true,
165
+ pagePattern: `/${normalizedEntry}/{slug}.md`,
166
+ rootPage: `/${normalizedEntry}.md`,
167
+ apiPattern: `${DEFAULT_DOCS_API_ROUTE}?format=markdown&path={slug}`,
168
+ resolutionOrder: [
169
+ "agent.md",
170
+ "Agent blocks",
171
+ "page markdown"
172
+ ]
173
+ },
174
+ mcp: {
175
+ enabled: mcp.enabled,
176
+ endpoint: mcp.route,
177
+ name: mcp.name,
178
+ version: mcp.version,
179
+ tools: mcp.tools
180
+ },
181
+ feedback: {
182
+ enabled: feedback.enabled,
183
+ schema: feedback.schemaRoute,
184
+ submit: feedback.route,
185
+ schemaQuery: `${DEFAULT_DOCS_API_ROUTE}?feedback=agent&schema=1`,
186
+ submitQuery: `${DEFAULT_DOCS_API_ROUTE}?feedback=agent`
187
+ },
188
+ instructions: {
189
+ preferMarkdownRoutes: true,
190
+ useMcpWhenAvailable: true,
191
+ readFeedbackSchemaBeforeSubmitting: true,
192
+ doNotAssumeFeedbackPayloadShape: true
193
+ }
194
+ };
195
+ }
146
196
  function isPlainObject(value) {
147
197
  return typeof value === "object" && value !== null && !Array.isArray(value);
148
198
  }
@@ -808,6 +858,7 @@ function createDocsAPI(options) {
808
858
  const aiConfig = options?.ai ?? readAIConfig(root);
809
859
  const searchConfig = options?.search;
810
860
  const llmsConfig = readLlmsTxtConfig(root);
861
+ const mcpConfig = resolveDocsMcpConfig(options?.mcp ?? readMcpConfig(root), { defaultName: llmsConfig.siteTitle ?? "Documentation" });
811
862
  function resolveDocsDirCandidates(locale) {
812
863
  const relativeCandidates = /* @__PURE__ */ new Set();
813
864
  if (path.isAbsolute(contentDir)) return [locale ? path.join(contentDir, locale) : contentDir];
@@ -927,6 +978,15 @@ function createDocsAPI(options) {
927
978
  async GET(request) {
928
979
  const ctx = resolveContextFromRequest(request);
929
980
  const url = new URL(request.url);
981
+ if (resolveAgentSpecRequest(url)) return Response.json(buildAgentSpec({
982
+ origin: url.origin,
983
+ entry,
984
+ mcp: mcpConfig,
985
+ feedback: agentFeedbackConfig
986
+ }), { headers: {
987
+ "Cache-Control": "public, max-age=0, s-maxage=3600",
988
+ "X-Robots-Tag": "noindex"
989
+ } });
930
990
  const agentFeedbackRequest = resolveAgentFeedbackRequest(url, agentFeedbackConfig);
931
991
  if (agentFeedbackRequest) {
932
992
  if (agentFeedbackRequest.kind === "submit") return Response.json({ error: "Method Not Allowed" }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -133,7 +133,7 @@
133
133
  "tsdown": "^0.20.3",
134
134
  "typescript": "^5.9.3",
135
135
  "vitest": "^3.2.4",
136
- "@farming-labs/docs": "0.1.22"
136
+ "@farming-labs/docs": "0.1.23"
137
137
  },
138
138
  "peerDependencies": {
139
139
  "@farming-labs/docs": ">=0.0.1",