@farming-labs/theme 0.1.22 → 0.1.24

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,59 @@ 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, llms }) {
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
+ llms: {
175
+ enabled: llms.enabled,
176
+ txt: `${DEFAULT_DOCS_API_ROUTE}?format=llms`,
177
+ full: `${DEFAULT_DOCS_API_ROUTE}?format=llms-full`
178
+ },
179
+ mcp: {
180
+ enabled: mcp.enabled,
181
+ endpoint: mcp.route,
182
+ name: mcp.name,
183
+ version: mcp.version,
184
+ tools: mcp.tools
185
+ },
186
+ feedback: {
187
+ enabled: feedback.enabled,
188
+ schema: feedback.schemaRoute,
189
+ submit: feedback.route,
190
+ schemaQuery: `${DEFAULT_DOCS_API_ROUTE}?feedback=agent&schema=1`,
191
+ submitQuery: `${DEFAULT_DOCS_API_ROUTE}?feedback=agent`
192
+ },
193
+ instructions: {
194
+ preferMarkdownRoutes: true,
195
+ useMcpWhenAvailable: true,
196
+ readFeedbackSchemaBeforeSubmitting: true,
197
+ doNotAssumeFeedbackPayloadShape: true
198
+ }
199
+ };
200
+ }
146
201
  function isPlainObject(value) {
147
202
  return typeof value === "object" && value !== null && !Array.isArray(value);
148
203
  }
@@ -808,6 +863,7 @@ function createDocsAPI(options) {
808
863
  const aiConfig = options?.ai ?? readAIConfig(root);
809
864
  const searchConfig = options?.search;
810
865
  const llmsConfig = readLlmsTxtConfig(root);
866
+ const mcpConfig = resolveDocsMcpConfig(options?.mcp ?? readMcpConfig(root), { defaultName: llmsConfig.siteTitle ?? "Documentation" });
811
867
  function resolveDocsDirCandidates(locale) {
812
868
  const relativeCandidates = /* @__PURE__ */ new Set();
813
869
  if (path.isAbsolute(contentDir)) return [locale ? path.join(contentDir, locale) : contentDir];
@@ -927,6 +983,16 @@ function createDocsAPI(options) {
927
983
  async GET(request) {
928
984
  const ctx = resolveContextFromRequest(request);
929
985
  const url = new URL(request.url);
986
+ if (resolveAgentSpecRequest(url)) return Response.json(buildAgentSpec({
987
+ origin: url.origin,
988
+ entry,
989
+ mcp: mcpConfig,
990
+ feedback: agentFeedbackConfig,
991
+ llms: llmsConfig
992
+ }), { headers: {
993
+ "Cache-Control": "public, max-age=0, s-maxage=3600",
994
+ "X-Robots-Tag": "noindex"
995
+ } });
930
996
  const agentFeedbackRequest = resolveAgentFeedbackRequest(url, agentFeedbackConfig);
931
997
  if (agentFeedbackRequest) {
932
998
  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.24",
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.24"
137
137
  },
138
138
  "peerDependencies": {
139
139
  "@farming-labs/docs": ">=0.0.1",