@corsenai/corsen-context 1.2.0 → 1.3.0

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Corsen AI
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Corsen AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,27 +1,27 @@
1
- # @corsenai/corsen-context
2
-
3
- The core engine of **[Corsen Context](https://github.com/CorsenAI/corsen-context)** — the Universal AI Context Layer that makes any website AI-native with an MCP server + enhanced `llms.txt`.
4
-
5
- ```bash
6
- npm install @corsenai/corsen-context
7
- ```
8
-
9
- ```typescript
10
- import { CorsenContext, createInMemoryProvider } from '@corsenai/corsen-context';
11
-
12
- const cc = new CorsenContext(
13
- { siteUrl: 'https://example.com' },
14
- createInMemoryProvider([
15
- { url: 'https://example.com/', title: 'Home', description: 'Welcome', markdown: '# Home', metadata: {}, type: 'page' },
16
- ]),
17
- );
18
-
19
- const server = cc.createMCPServer();
20
- const result = await server.handleRequest(requestBody, clientIp);
21
- ```
22
-
23
- This package provides the framework-agnostic core: the MCP JSON-RPC 2.0 server, `llms.txt` generators, HTML→Markdown converter, SSRF-safe fetching, rate limiting, caching, and the content-access policy.
24
-
25
- - **Full docs:** https://github.com/CorsenAI/corsen-context#readme
26
- - **Security model:** [SECURITY.md](https://github.com/CorsenAI/corsen-context/blob/main/SECURITY.md)
27
- - **License:** MIT
1
+ # @corsenai/corsen-context
2
+
3
+ The core engine of **[Corsen Context](https://github.com/CorsenAI/corsen-context)** — the Universal AI Context Layer that makes any website AI-native with an MCP server + enhanced `llms.txt`.
4
+
5
+ ```bash
6
+ npm install @corsenai/corsen-context
7
+ ```
8
+
9
+ ```typescript
10
+ import { CorsenContext, createInMemoryProvider } from '@corsenai/corsen-context';
11
+
12
+ const cc = new CorsenContext(
13
+ { siteUrl: 'https://example.com' },
14
+ createInMemoryProvider([
15
+ { url: 'https://example.com/', title: 'Home', description: 'Welcome', markdown: '# Home', metadata: {}, type: 'page' },
16
+ ]),
17
+ );
18
+
19
+ const server = cc.createMCPServer();
20
+ const result = await server.handleRequest(requestBody, clientIp);
21
+ ```
22
+
23
+ This package provides the framework-agnostic core: the MCP JSON-RPC 2.0 server, `llms.txt` generators, HTML→Markdown converter, SSRF-safe fetching, rate limiting, caching, and the content-access policy.
24
+
25
+ - **Full docs:** https://github.com/CorsenAI/corsen-context#readme
26
+ - **Security model:** [SECURITY.md](https://github.com/CorsenAI/corsen-context/blob/main/SECURITY.md)
27
+ - **License:** MIT
package/dist/index.d.mts CHANGED
@@ -379,13 +379,13 @@ declare class MCPServer {
379
379
  /**
380
380
  * Single source of truth for version strings.
381
381
  *
382
- * Keep CORSEN_CONTEXT_VERSION in sync with each package.json `version` on release
383
- * (the release tooling does this). serverInfo and the CLI both read from here so
384
- * the version can never silently drift between what is published and what is
385
- * reported over MCP.
382
+ * CORSEN_CONTEXT_VERSION is bumped by hand on every release, in the same
383
+ * commit that updates the package.json versions. serverInfo and the CLI both
384
+ * read from here so the version can never silently drift between what is
385
+ * published and what is reported over MCP.
386
386
  */
387
387
  /** Corsen Context release version. */
388
- declare const CORSEN_CONTEXT_VERSION = "1.2.0";
388
+ declare const CORSEN_CONTEXT_VERSION = "1.3.0";
389
389
  /** MCP protocol version implemented by this server. */
390
390
  declare const MCP_PROTOCOL_VERSION = "2025-11-25";
391
391
 
@@ -461,6 +461,64 @@ declare function mcpLinkTag(config: DiscoveryConfig): string;
461
461
  declare function generateLlmsTxt(config: ResolvedConfig, provider: ContentProvider): Promise<string>;
462
462
  declare function generateLlmsFullTxt(config: ResolvedConfig, provider: ContentProvider): Promise<string>;
463
463
 
464
+ /**
465
+ * WebMCP exposes the same tools to an agent running inside the page, through
466
+ * `document.modelContext`. The browser never reimplements a tool: it receives
467
+ * the definitions from the server and every `execute()` calls back into the
468
+ * existing MCP endpoint, so there is one implementation per runtime and one
469
+ * contract for every transport.
470
+ *
471
+ * Spec: https://webmachinelearning.github.io/webmcp/
472
+ */
473
+ /** Tool annotations defined by the WebMCP `ToolAnnotations` dictionary. */
474
+ interface WebMCPToolAnnotations {
475
+ /** Tool only reads state. Lets an agent decide when a call is safe. */
476
+ readOnlyHint: boolean;
477
+ /** Tool output is untrusted data, from the perspective of this site. */
478
+ untrustedContentHint: boolean;
479
+ }
480
+ interface WebMCPTool extends MCPToolDefinition {
481
+ annotations: WebMCPToolAnnotations;
482
+ }
483
+ interface WebMCPScriptConfig {
484
+ /**
485
+ * MCP endpoint the browser bridge calls. Defaults to `/v1/mcp`.
486
+ *
487
+ * The bridge is deliberately keyless: any credential embedded in a public
488
+ * page's script is disclosed to every visitor, so a key-protected endpoint
489
+ * should not enable the WebMCP bridge at all.
490
+ */
491
+ mcpEndpoint?: string;
492
+ }
493
+ /**
494
+ * Every tool Corsen Context exposes reads published site content, so all of
495
+ * them are read-only and all of them return untrusted data: page bodies come
496
+ * from authors, comments and imports, and an agent must treat that output as
497
+ * data rather than as instructions.
498
+ */
499
+ declare const WEBMCP_TOOL_ANNOTATIONS: Readonly<Record<string, WebMCPToolAnnotations>>;
500
+ /** Annotations for a tool. Unknown tools fall back to the safest pair. */
501
+ declare function webMCPAnnotationsFor(name: string): WebMCPToolAnnotations;
502
+ /** Attach WebMCP annotations to MCP tool definitions. */
503
+ declare function toWebMCPTools(tools: MCPToolDefinition[]): WebMCPTool[];
504
+ /**
505
+ * Build the inline script that registers the tools with the in-page agent.
506
+ *
507
+ * Deliberate constraints:
508
+ * - `exposedTo` is never set, so tools stay same-origin by default.
509
+ * - Registration is refused inside a frame: the Permissions Policy `tools`
510
+ * feature already defaults to `['self']`, and this keeps a same-origin
511
+ * frame from registering the set a second time.
512
+ * - The bridge only forwards calls to this site's own MCP endpoint; the page
513
+ * cannot introduce a tool the server does not already serve.
514
+ * - Every forwarded call carries the MCP-Protocol-Version header, which the
515
+ * endpoint requires on every request after initialize.
516
+ * - Chrome 153+ passes an AbortSignal as execute's second argument; the
517
+ * bridge forwards it to fetch, so a cancelled execution aborts the
518
+ * in-flight request instead of leaving work running.
519
+ */
520
+ declare function generateWebMCPScript(tools: WebMCPTool[], config?: WebMCPScriptConfig): string;
521
+
464
522
  declare function parseSitemap(sitemapUrl: string, maxPages?: number): Promise<SitemapEntry[]>;
465
523
  declare function discoverSitemap(siteUrl: string): Promise<string | null>;
466
524
 
@@ -794,4 +852,4 @@ declare class CorsenContext {
794
852
  };
795
853
  }
796
854
 
797
- export { API_VERSION, ApiKeyManager, type ApiKeyRecord, CORSEN_CONTEXT_VERSION, CREDIT_LINE, type CacheDriver, type ContentList, type ContentListItem, type ContentProvider, CorsenContext, type CorsenContextConfig, type DiscoveryConfig, type InMemoryPage, type JSONRPCRequest, type JSONRPCResponse, JSONRPC_ERRORS, type LogLevel, type Logger, type LoggerOptions, MAX_BODY_SIZE, MAX_JSON_DEPTH, type MCPCapabilities, type MCPResourceDefinition, MCPServer, type MCPToolDefinition, MCP_PROTOCOL_VERSION, MemoryCache, MemoryRateLimitStore, type PageContent, REQUEST_TIMEOUT_MS, type RateLimitResult, type RateLimitStore, RateLimiter, RedisCache, type RedisClient, RedisRateLimitStore, type ResolvedConfig, SECURITY_HEADERS, type SearchResult, type SitemapEntry, buildRateLimitKey, corsenContextConfigSchema, createInMemoryProvider, createLogger, createSitemapProvider, discoverSitemap, extractClientIp, extractMetadata, filterPublicPages, filterPublicSearchResults, generateLlmsFullTxt, generateLlmsTxt, generateRobotsTxt, generateWellKnownMcp, getLogger, getPageParamsSchema, hashApiKey, htmlToMarkdown, isPrivateIp, isPrivateUrl, isPublicListItem, isPublicPageContent, listContentParamsSchema, mcpLinkTag, mcpLogger, parseSitemap, resolveConfig, resolvePublicPageUrl, safeFetch, searchParamsSchema, securityLogger, setLogger, validateApiKey, validateHost, validateOrigin };
855
+ export { API_VERSION, ApiKeyManager, type ApiKeyRecord, CORSEN_CONTEXT_VERSION, CREDIT_LINE, type CacheDriver, type ContentList, type ContentListItem, type ContentProvider, CorsenContext, type CorsenContextConfig, type DiscoveryConfig, type InMemoryPage, type JSONRPCRequest, type JSONRPCResponse, JSONRPC_ERRORS, type LogLevel, type Logger, type LoggerOptions, MAX_BODY_SIZE, MAX_JSON_DEPTH, type MCPCapabilities, type MCPResourceDefinition, MCPServer, type MCPToolDefinition, MCP_PROTOCOL_VERSION, MemoryCache, MemoryRateLimitStore, type PageContent, REQUEST_TIMEOUT_MS, type RateLimitResult, type RateLimitStore, RateLimiter, RedisCache, type RedisClient, RedisRateLimitStore, type ResolvedConfig, SECURITY_HEADERS, type SearchResult, type SitemapEntry, WEBMCP_TOOL_ANNOTATIONS, type WebMCPScriptConfig, type WebMCPTool, type WebMCPToolAnnotations, buildRateLimitKey, corsenContextConfigSchema, createInMemoryProvider, createLogger, createSitemapProvider, discoverSitemap, extractClientIp, extractMetadata, filterPublicPages, filterPublicSearchResults, generateLlmsFullTxt, generateLlmsTxt, generateRobotsTxt, generateWebMCPScript, generateWellKnownMcp, getLogger, getPageParamsSchema, hashApiKey, htmlToMarkdown, isPrivateIp, isPrivateUrl, isPublicListItem, isPublicPageContent, listContentParamsSchema, mcpLinkTag, mcpLogger, parseSitemap, resolveConfig, resolvePublicPageUrl, safeFetch, searchParamsSchema, securityLogger, setLogger, toWebMCPTools, validateApiKey, validateHost, validateOrigin, webMCPAnnotationsFor };
package/dist/index.d.ts CHANGED
@@ -379,13 +379,13 @@ declare class MCPServer {
379
379
  /**
380
380
  * Single source of truth for version strings.
381
381
  *
382
- * Keep CORSEN_CONTEXT_VERSION in sync with each package.json `version` on release
383
- * (the release tooling does this). serverInfo and the CLI both read from here so
384
- * the version can never silently drift between what is published and what is
385
- * reported over MCP.
382
+ * CORSEN_CONTEXT_VERSION is bumped by hand on every release, in the same
383
+ * commit that updates the package.json versions. serverInfo and the CLI both
384
+ * read from here so the version can never silently drift between what is
385
+ * published and what is reported over MCP.
386
386
  */
387
387
  /** Corsen Context release version. */
388
- declare const CORSEN_CONTEXT_VERSION = "1.2.0";
388
+ declare const CORSEN_CONTEXT_VERSION = "1.3.0";
389
389
  /** MCP protocol version implemented by this server. */
390
390
  declare const MCP_PROTOCOL_VERSION = "2025-11-25";
391
391
 
@@ -461,6 +461,64 @@ declare function mcpLinkTag(config: DiscoveryConfig): string;
461
461
  declare function generateLlmsTxt(config: ResolvedConfig, provider: ContentProvider): Promise<string>;
462
462
  declare function generateLlmsFullTxt(config: ResolvedConfig, provider: ContentProvider): Promise<string>;
463
463
 
464
+ /**
465
+ * WebMCP exposes the same tools to an agent running inside the page, through
466
+ * `document.modelContext`. The browser never reimplements a tool: it receives
467
+ * the definitions from the server and every `execute()` calls back into the
468
+ * existing MCP endpoint, so there is one implementation per runtime and one
469
+ * contract for every transport.
470
+ *
471
+ * Spec: https://webmachinelearning.github.io/webmcp/
472
+ */
473
+ /** Tool annotations defined by the WebMCP `ToolAnnotations` dictionary. */
474
+ interface WebMCPToolAnnotations {
475
+ /** Tool only reads state. Lets an agent decide when a call is safe. */
476
+ readOnlyHint: boolean;
477
+ /** Tool output is untrusted data, from the perspective of this site. */
478
+ untrustedContentHint: boolean;
479
+ }
480
+ interface WebMCPTool extends MCPToolDefinition {
481
+ annotations: WebMCPToolAnnotations;
482
+ }
483
+ interface WebMCPScriptConfig {
484
+ /**
485
+ * MCP endpoint the browser bridge calls. Defaults to `/v1/mcp`.
486
+ *
487
+ * The bridge is deliberately keyless: any credential embedded in a public
488
+ * page's script is disclosed to every visitor, so a key-protected endpoint
489
+ * should not enable the WebMCP bridge at all.
490
+ */
491
+ mcpEndpoint?: string;
492
+ }
493
+ /**
494
+ * Every tool Corsen Context exposes reads published site content, so all of
495
+ * them are read-only and all of them return untrusted data: page bodies come
496
+ * from authors, comments and imports, and an agent must treat that output as
497
+ * data rather than as instructions.
498
+ */
499
+ declare const WEBMCP_TOOL_ANNOTATIONS: Readonly<Record<string, WebMCPToolAnnotations>>;
500
+ /** Annotations for a tool. Unknown tools fall back to the safest pair. */
501
+ declare function webMCPAnnotationsFor(name: string): WebMCPToolAnnotations;
502
+ /** Attach WebMCP annotations to MCP tool definitions. */
503
+ declare function toWebMCPTools(tools: MCPToolDefinition[]): WebMCPTool[];
504
+ /**
505
+ * Build the inline script that registers the tools with the in-page agent.
506
+ *
507
+ * Deliberate constraints:
508
+ * - `exposedTo` is never set, so tools stay same-origin by default.
509
+ * - Registration is refused inside a frame: the Permissions Policy `tools`
510
+ * feature already defaults to `['self']`, and this keeps a same-origin
511
+ * frame from registering the set a second time.
512
+ * - The bridge only forwards calls to this site's own MCP endpoint; the page
513
+ * cannot introduce a tool the server does not already serve.
514
+ * - Every forwarded call carries the MCP-Protocol-Version header, which the
515
+ * endpoint requires on every request after initialize.
516
+ * - Chrome 153+ passes an AbortSignal as execute's second argument; the
517
+ * bridge forwards it to fetch, so a cancelled execution aborts the
518
+ * in-flight request instead of leaving work running.
519
+ */
520
+ declare function generateWebMCPScript(tools: WebMCPTool[], config?: WebMCPScriptConfig): string;
521
+
464
522
  declare function parseSitemap(sitemapUrl: string, maxPages?: number): Promise<SitemapEntry[]>;
465
523
  declare function discoverSitemap(siteUrl: string): Promise<string | null>;
466
524
 
@@ -794,4 +852,4 @@ declare class CorsenContext {
794
852
  };
795
853
  }
796
854
 
797
- export { API_VERSION, ApiKeyManager, type ApiKeyRecord, CORSEN_CONTEXT_VERSION, CREDIT_LINE, type CacheDriver, type ContentList, type ContentListItem, type ContentProvider, CorsenContext, type CorsenContextConfig, type DiscoveryConfig, type InMemoryPage, type JSONRPCRequest, type JSONRPCResponse, JSONRPC_ERRORS, type LogLevel, type Logger, type LoggerOptions, MAX_BODY_SIZE, MAX_JSON_DEPTH, type MCPCapabilities, type MCPResourceDefinition, MCPServer, type MCPToolDefinition, MCP_PROTOCOL_VERSION, MemoryCache, MemoryRateLimitStore, type PageContent, REQUEST_TIMEOUT_MS, type RateLimitResult, type RateLimitStore, RateLimiter, RedisCache, type RedisClient, RedisRateLimitStore, type ResolvedConfig, SECURITY_HEADERS, type SearchResult, type SitemapEntry, buildRateLimitKey, corsenContextConfigSchema, createInMemoryProvider, createLogger, createSitemapProvider, discoverSitemap, extractClientIp, extractMetadata, filterPublicPages, filterPublicSearchResults, generateLlmsFullTxt, generateLlmsTxt, generateRobotsTxt, generateWellKnownMcp, getLogger, getPageParamsSchema, hashApiKey, htmlToMarkdown, isPrivateIp, isPrivateUrl, isPublicListItem, isPublicPageContent, listContentParamsSchema, mcpLinkTag, mcpLogger, parseSitemap, resolveConfig, resolvePublicPageUrl, safeFetch, searchParamsSchema, securityLogger, setLogger, validateApiKey, validateHost, validateOrigin };
855
+ export { API_VERSION, ApiKeyManager, type ApiKeyRecord, CORSEN_CONTEXT_VERSION, CREDIT_LINE, type CacheDriver, type ContentList, type ContentListItem, type ContentProvider, CorsenContext, type CorsenContextConfig, type DiscoveryConfig, type InMemoryPage, type JSONRPCRequest, type JSONRPCResponse, JSONRPC_ERRORS, type LogLevel, type Logger, type LoggerOptions, MAX_BODY_SIZE, MAX_JSON_DEPTH, type MCPCapabilities, type MCPResourceDefinition, MCPServer, type MCPToolDefinition, MCP_PROTOCOL_VERSION, MemoryCache, MemoryRateLimitStore, type PageContent, REQUEST_TIMEOUT_MS, type RateLimitResult, type RateLimitStore, RateLimiter, RedisCache, type RedisClient, RedisRateLimitStore, type ResolvedConfig, SECURITY_HEADERS, type SearchResult, type SitemapEntry, WEBMCP_TOOL_ANNOTATIONS, type WebMCPScriptConfig, type WebMCPTool, type WebMCPToolAnnotations, buildRateLimitKey, corsenContextConfigSchema, createInMemoryProvider, createLogger, createSitemapProvider, discoverSitemap, extractClientIp, extractMetadata, filterPublicPages, filterPublicSearchResults, generateLlmsFullTxt, generateLlmsTxt, generateRobotsTxt, generateWebMCPScript, generateWellKnownMcp, getLogger, getPageParamsSchema, hashApiKey, htmlToMarkdown, isPrivateIp, isPrivateUrl, isPublicListItem, isPublicPageContent, listContentParamsSchema, mcpLinkTag, mcpLogger, parseSitemap, resolveConfig, resolvePublicPageUrl, safeFetch, searchParamsSchema, securityLogger, setLogger, toWebMCPTools, validateApiKey, validateHost, validateOrigin, webMCPAnnotationsFor };
package/dist/index.js CHANGED
@@ -47,6 +47,7 @@ __export(index_exports, {
47
47
  RedisCache: () => RedisCache,
48
48
  RedisRateLimitStore: () => RedisRateLimitStore,
49
49
  SECURITY_HEADERS: () => SECURITY_HEADERS,
50
+ WEBMCP_TOOL_ANNOTATIONS: () => WEBMCP_TOOL_ANNOTATIONS,
50
51
  buildRateLimitKey: () => buildRateLimitKey,
51
52
  corsenContextConfigSchema: () => corsenContextConfigSchema,
52
53
  createInMemoryProvider: () => createInMemoryProvider,
@@ -60,6 +61,7 @@ __export(index_exports, {
60
61
  generateLlmsFullTxt: () => generateLlmsFullTxt,
61
62
  generateLlmsTxt: () => generateLlmsTxt,
62
63
  generateRobotsTxt: () => generateRobotsTxt,
64
+ generateWebMCPScript: () => generateWebMCPScript,
63
65
  generateWellKnownMcp: () => generateWellKnownMcp,
64
66
  getLogger: () => getLogger,
65
67
  getPageParamsSchema: () => getPageParamsSchema,
@@ -79,9 +81,11 @@ __export(index_exports, {
79
81
  searchParamsSchema: () => searchParamsSchema,
80
82
  securityLogger: () => securityLogger,
81
83
  setLogger: () => setLogger,
84
+ toWebMCPTools: () => toWebMCPTools,
82
85
  validateApiKey: () => validateApiKey,
83
86
  validateHost: () => validateHost,
84
- validateOrigin: () => validateOrigin
87
+ validateOrigin: () => validateOrigin,
88
+ webMCPAnnotationsFor: () => webMCPAnnotationsFor
85
89
  });
86
90
  module.exports = __toCommonJS(index_exports);
87
91
 
@@ -175,7 +179,7 @@ var SECURITY_HEADERS = {
175
179
  };
176
180
 
177
181
  // src/version.ts
178
- var CORSEN_CONTEXT_VERSION = "1.2.0";
182
+ var CORSEN_CONTEXT_VERSION = "1.3.0";
179
183
  var MCP_PROTOCOL_VERSION = "2025-11-25";
180
184
 
181
185
  // src/security.ts
@@ -1171,12 +1175,12 @@ var MCPServer = class _MCPServer {
1171
1175
  if (this.config.mcp.tools.includes("search_site")) {
1172
1176
  tools.push({
1173
1177
  name: "search_site",
1174
- description: "Search site content by keyword. Returns matching pages with snippets.",
1178
+ description: "Search this site's public content by keyword and get matching pages with titles, URLs and text snippets. Use this first when the user asks about something on this site and you do not know which page covers it. Read-only: returns content, never changes anything.",
1175
1179
  inputSchema: {
1176
1180
  type: "object",
1177
1181
  properties: {
1178
- query: { type: "string", description: "Search query" },
1179
- limit: { type: "number", description: "Max results (1-50, default 10)" }
1182
+ query: { type: "string", description: "Keywords to search for, in the site's own language. Use the user's words." },
1183
+ limit: { type: "number", description: "Maximum number of results to return (1-50, default 10)." }
1180
1184
  },
1181
1185
  required: ["query"]
1182
1186
  }
@@ -1185,11 +1189,11 @@ var MCPServer = class _MCPServer {
1185
1189
  if (this.config.mcp.tools.includes("get_page_content")) {
1186
1190
  tools.push({
1187
1191
  name: "get_page_content",
1188
- description: "Get full page content as clean markdown with metadata (title, description, dates).",
1192
+ description: "Read one page of this site in full, as clean markdown with its title, description and dates. Use this after search_site or get_sitemap to read a specific page. Read-only.",
1189
1193
  inputSchema: {
1190
1194
  type: "object",
1191
1195
  properties: {
1192
- uri: { type: "string", description: "Page URL or resource URI" }
1196
+ uri: { type: "string", description: "The page's absolute URL on this site, exactly as returned by search_site, list_content or get_sitemap." }
1193
1197
  },
1194
1198
  required: ["uri"]
1195
1199
  }
@@ -1198,13 +1202,13 @@ var MCPServer = class _MCPServer {
1198
1202
  if (this.config.mcp.tools.includes("list_content")) {
1199
1203
  tools.push({
1200
1204
  name: "list_content",
1201
- description: "List content by type (page, post, product) with pagination.",
1205
+ description: "Browse this site's public content by type (e.g. page, post, product) with pagination. Use to enumerate what the site publishes when a keyword search is too narrow. Read-only.",
1202
1206
  inputSchema: {
1203
1207
  type: "object",
1204
1208
  properties: {
1205
- type: { type: "string", description: "Content type (e.g., post, page, product, or any custom type)" },
1206
- page: { type: "number", description: "Page number (default 1)" },
1207
- limit: { type: "number", description: "Items per page (1-100, default 20)" }
1209
+ type: { type: "string", description: "The content type to list: post, page, product, or any custom type the site exposes." },
1210
+ page: { type: "number", description: "Result page number (default 1)." },
1211
+ limit: { type: "number", description: "Items per page (1-100, default 20)." }
1208
1212
  }
1209
1213
  }
1210
1214
  });
@@ -1212,7 +1216,7 @@ var MCPServer = class _MCPServer {
1212
1216
  if (this.config.mcp.tools.includes("get_sitemap")) {
1213
1217
  tools.push({
1214
1218
  name: "get_sitemap",
1215
- description: "Get structured sitemap of the entire site with URLs, titles, types, and dates.",
1219
+ description: "Get the structured sitemap of this site's public content: every URL with its title, type and last-modified date. Use for a complete overview of what the site exposes to agents. Read-only.",
1216
1220
  inputSchema: {
1217
1221
  type: "object",
1218
1222
  properties: {}
@@ -1565,6 +1569,82 @@ function extractMetadata(html) {
1565
1569
  return meta;
1566
1570
  }
1567
1571
 
1572
+ // src/webmcp.ts
1573
+ var WEBMCP_TOOL_ANNOTATIONS = Object.freeze(
1574
+ {
1575
+ search_site: { readOnlyHint: true, untrustedContentHint: true },
1576
+ get_page_content: { readOnlyHint: true, untrustedContentHint: true },
1577
+ list_content: { readOnlyHint: true, untrustedContentHint: true },
1578
+ get_sitemap: { readOnlyHint: true, untrustedContentHint: true }
1579
+ }
1580
+ );
1581
+ function webMCPAnnotationsFor(name) {
1582
+ return WEBMCP_TOOL_ANNOTATIONS[name] ?? { readOnlyHint: true, untrustedContentHint: true };
1583
+ }
1584
+ function toWebMCPTools(tools) {
1585
+ return tools.map((tool) => ({ ...tool, annotations: webMCPAnnotationsFor(tool.name) }));
1586
+ }
1587
+ function embedJson(value) {
1588
+ return JSON.stringify(value).replace(/</g, "\\u003c");
1589
+ }
1590
+ function generateWebMCPScript(tools, config = {}) {
1591
+ const endpoint = config.mcpEndpoint || "/v1/mcp";
1592
+ return `(function () {
1593
+ var tools = ${embedJson(tools)};
1594
+ var endpoint = ${embedJson(endpoint)};
1595
+ var protocolVersion = ${embedJson(MCP_PROTOCOL_VERSION)};
1596
+
1597
+ if (window.top !== window.self) return;
1598
+
1599
+ // Chrome 150 moved the getter to document and kept navigator as a
1600
+ // deprecated alias; support both while the origin trial runs.
1601
+ var mc = document.modelContext || navigator.modelContext;
1602
+ if (!mc || typeof mc.registerTool !== 'function') return;
1603
+
1604
+ function call(name, args, signal) {
1605
+ return fetch(endpoint, {
1606
+ method: 'POST',
1607
+ credentials: 'omit',
1608
+ signal: signal || null,
1609
+ // The endpoint rejects version-less calls: MCP requires the negotiated
1610
+ // protocol version header on every request after initialize.
1611
+ headers: {
1612
+ 'Content-Type': 'application/json',
1613
+ 'MCP-Protocol-Version': protocolVersion
1614
+ },
1615
+ body: JSON.stringify({
1616
+ jsonrpc: '2.0',
1617
+ id: Date.now(),
1618
+ method: 'tools/call',
1619
+ params: { name: name, arguments: args || {} }
1620
+ })
1621
+ })
1622
+ .then(function (res) {
1623
+ if (!res.ok) throw new Error('Corsen Context: MCP endpoint returned ' + res.status);
1624
+ return res.json();
1625
+ })
1626
+ .then(function (body) {
1627
+ if (body && body.error) throw new Error(body.error.message || 'MCP error');
1628
+ var content = body && body.result && body.result.content;
1629
+ if (!Array.isArray(content)) return '';
1630
+ return content
1631
+ .map(function (part) { return part && typeof part.text === 'string' ? part.text : ''; })
1632
+ .join('\\n');
1633
+ });
1634
+ }
1635
+
1636
+ tools.forEach(function (tool) {
1637
+ mc.registerTool({
1638
+ name: tool.name,
1639
+ description: tool.description,
1640
+ inputSchema: tool.inputSchema,
1641
+ annotations: tool.annotations,
1642
+ execute: function (input, options) { return call(tool.name, input, options && options.signal); }
1643
+ });
1644
+ });
1645
+ })();`;
1646
+ }
1647
+
1568
1648
  // src/redis-cache.ts
1569
1649
  var RedisCache = class {
1570
1650
  redis;
@@ -1842,6 +1922,7 @@ var CorsenContext = class {
1842
1922
  RedisCache,
1843
1923
  RedisRateLimitStore,
1844
1924
  SECURITY_HEADERS,
1925
+ WEBMCP_TOOL_ANNOTATIONS,
1845
1926
  buildRateLimitKey,
1846
1927
  corsenContextConfigSchema,
1847
1928
  createInMemoryProvider,
@@ -1855,6 +1936,7 @@ var CorsenContext = class {
1855
1936
  generateLlmsFullTxt,
1856
1937
  generateLlmsTxt,
1857
1938
  generateRobotsTxt,
1939
+ generateWebMCPScript,
1858
1940
  generateWellKnownMcp,
1859
1941
  getLogger,
1860
1942
  getPageParamsSchema,
@@ -1874,7 +1956,9 @@ var CorsenContext = class {
1874
1956
  searchParamsSchema,
1875
1957
  securityLogger,
1876
1958
  setLogger,
1959
+ toWebMCPTools,
1877
1960
  validateApiKey,
1878
1961
  validateHost,
1879
- validateOrigin
1962
+ validateOrigin,
1963
+ webMCPAnnotationsFor
1880
1964
  });
package/dist/index.mjs CHANGED
@@ -88,7 +88,7 @@ var SECURITY_HEADERS = {
88
88
  };
89
89
 
90
90
  // src/version.ts
91
- var CORSEN_CONTEXT_VERSION = "1.2.0";
91
+ var CORSEN_CONTEXT_VERSION = "1.3.0";
92
92
  var MCP_PROTOCOL_VERSION = "2025-11-25";
93
93
 
94
94
  // src/security.ts
@@ -1084,12 +1084,12 @@ var MCPServer = class _MCPServer {
1084
1084
  if (this.config.mcp.tools.includes("search_site")) {
1085
1085
  tools.push({
1086
1086
  name: "search_site",
1087
- description: "Search site content by keyword. Returns matching pages with snippets.",
1087
+ description: "Search this site's public content by keyword and get matching pages with titles, URLs and text snippets. Use this first when the user asks about something on this site and you do not know which page covers it. Read-only: returns content, never changes anything.",
1088
1088
  inputSchema: {
1089
1089
  type: "object",
1090
1090
  properties: {
1091
- query: { type: "string", description: "Search query" },
1092
- limit: { type: "number", description: "Max results (1-50, default 10)" }
1091
+ query: { type: "string", description: "Keywords to search for, in the site's own language. Use the user's words." },
1092
+ limit: { type: "number", description: "Maximum number of results to return (1-50, default 10)." }
1093
1093
  },
1094
1094
  required: ["query"]
1095
1095
  }
@@ -1098,11 +1098,11 @@ var MCPServer = class _MCPServer {
1098
1098
  if (this.config.mcp.tools.includes("get_page_content")) {
1099
1099
  tools.push({
1100
1100
  name: "get_page_content",
1101
- description: "Get full page content as clean markdown with metadata (title, description, dates).",
1101
+ description: "Read one page of this site in full, as clean markdown with its title, description and dates. Use this after search_site or get_sitemap to read a specific page. Read-only.",
1102
1102
  inputSchema: {
1103
1103
  type: "object",
1104
1104
  properties: {
1105
- uri: { type: "string", description: "Page URL or resource URI" }
1105
+ uri: { type: "string", description: "The page's absolute URL on this site, exactly as returned by search_site, list_content or get_sitemap." }
1106
1106
  },
1107
1107
  required: ["uri"]
1108
1108
  }
@@ -1111,13 +1111,13 @@ var MCPServer = class _MCPServer {
1111
1111
  if (this.config.mcp.tools.includes("list_content")) {
1112
1112
  tools.push({
1113
1113
  name: "list_content",
1114
- description: "List content by type (page, post, product) with pagination.",
1114
+ description: "Browse this site's public content by type (e.g. page, post, product) with pagination. Use to enumerate what the site publishes when a keyword search is too narrow. Read-only.",
1115
1115
  inputSchema: {
1116
1116
  type: "object",
1117
1117
  properties: {
1118
- type: { type: "string", description: "Content type (e.g., post, page, product, or any custom type)" },
1119
- page: { type: "number", description: "Page number (default 1)" },
1120
- limit: { type: "number", description: "Items per page (1-100, default 20)" }
1118
+ type: { type: "string", description: "The content type to list: post, page, product, or any custom type the site exposes." },
1119
+ page: { type: "number", description: "Result page number (default 1)." },
1120
+ limit: { type: "number", description: "Items per page (1-100, default 20)." }
1121
1121
  }
1122
1122
  }
1123
1123
  });
@@ -1125,7 +1125,7 @@ var MCPServer = class _MCPServer {
1125
1125
  if (this.config.mcp.tools.includes("get_sitemap")) {
1126
1126
  tools.push({
1127
1127
  name: "get_sitemap",
1128
- description: "Get structured sitemap of the entire site with URLs, titles, types, and dates.",
1128
+ description: "Get the structured sitemap of this site's public content: every URL with its title, type and last-modified date. Use for a complete overview of what the site exposes to agents. Read-only.",
1129
1129
  inputSchema: {
1130
1130
  type: "object",
1131
1131
  properties: {}
@@ -1478,6 +1478,82 @@ function extractMetadata(html) {
1478
1478
  return meta;
1479
1479
  }
1480
1480
 
1481
+ // src/webmcp.ts
1482
+ var WEBMCP_TOOL_ANNOTATIONS = Object.freeze(
1483
+ {
1484
+ search_site: { readOnlyHint: true, untrustedContentHint: true },
1485
+ get_page_content: { readOnlyHint: true, untrustedContentHint: true },
1486
+ list_content: { readOnlyHint: true, untrustedContentHint: true },
1487
+ get_sitemap: { readOnlyHint: true, untrustedContentHint: true }
1488
+ }
1489
+ );
1490
+ function webMCPAnnotationsFor(name) {
1491
+ return WEBMCP_TOOL_ANNOTATIONS[name] ?? { readOnlyHint: true, untrustedContentHint: true };
1492
+ }
1493
+ function toWebMCPTools(tools) {
1494
+ return tools.map((tool) => ({ ...tool, annotations: webMCPAnnotationsFor(tool.name) }));
1495
+ }
1496
+ function embedJson(value) {
1497
+ return JSON.stringify(value).replace(/</g, "\\u003c");
1498
+ }
1499
+ function generateWebMCPScript(tools, config = {}) {
1500
+ const endpoint = config.mcpEndpoint || "/v1/mcp";
1501
+ return `(function () {
1502
+ var tools = ${embedJson(tools)};
1503
+ var endpoint = ${embedJson(endpoint)};
1504
+ var protocolVersion = ${embedJson(MCP_PROTOCOL_VERSION)};
1505
+
1506
+ if (window.top !== window.self) return;
1507
+
1508
+ // Chrome 150 moved the getter to document and kept navigator as a
1509
+ // deprecated alias; support both while the origin trial runs.
1510
+ var mc = document.modelContext || navigator.modelContext;
1511
+ if (!mc || typeof mc.registerTool !== 'function') return;
1512
+
1513
+ function call(name, args, signal) {
1514
+ return fetch(endpoint, {
1515
+ method: 'POST',
1516
+ credentials: 'omit',
1517
+ signal: signal || null,
1518
+ // The endpoint rejects version-less calls: MCP requires the negotiated
1519
+ // protocol version header on every request after initialize.
1520
+ headers: {
1521
+ 'Content-Type': 'application/json',
1522
+ 'MCP-Protocol-Version': protocolVersion
1523
+ },
1524
+ body: JSON.stringify({
1525
+ jsonrpc: '2.0',
1526
+ id: Date.now(),
1527
+ method: 'tools/call',
1528
+ params: { name: name, arguments: args || {} }
1529
+ })
1530
+ })
1531
+ .then(function (res) {
1532
+ if (!res.ok) throw new Error('Corsen Context: MCP endpoint returned ' + res.status);
1533
+ return res.json();
1534
+ })
1535
+ .then(function (body) {
1536
+ if (body && body.error) throw new Error(body.error.message || 'MCP error');
1537
+ var content = body && body.result && body.result.content;
1538
+ if (!Array.isArray(content)) return '';
1539
+ return content
1540
+ .map(function (part) { return part && typeof part.text === 'string' ? part.text : ''; })
1541
+ .join('\\n');
1542
+ });
1543
+ }
1544
+
1545
+ tools.forEach(function (tool) {
1546
+ mc.registerTool({
1547
+ name: tool.name,
1548
+ description: tool.description,
1549
+ inputSchema: tool.inputSchema,
1550
+ annotations: tool.annotations,
1551
+ execute: function (input, options) { return call(tool.name, input, options && options.signal); }
1552
+ });
1553
+ });
1554
+ })();`;
1555
+ }
1556
+
1481
1557
  // src/redis-cache.ts
1482
1558
  var RedisCache = class {
1483
1559
  redis;
@@ -1754,6 +1830,7 @@ export {
1754
1830
  RedisCache,
1755
1831
  RedisRateLimitStore,
1756
1832
  SECURITY_HEADERS,
1833
+ WEBMCP_TOOL_ANNOTATIONS,
1757
1834
  buildRateLimitKey,
1758
1835
  corsenContextConfigSchema,
1759
1836
  createInMemoryProvider,
@@ -1767,6 +1844,7 @@ export {
1767
1844
  generateLlmsFullTxt,
1768
1845
  generateLlmsTxt,
1769
1846
  generateRobotsTxt,
1847
+ generateWebMCPScript,
1770
1848
  generateWellKnownMcp,
1771
1849
  getLogger,
1772
1850
  getPageParamsSchema,
@@ -1786,7 +1864,9 @@ export {
1786
1864
  searchParamsSchema,
1787
1865
  securityLogger,
1788
1866
  setLogger,
1867
+ toWebMCPTools,
1789
1868
  validateApiKey,
1790
1869
  validateHost,
1791
- validateOrigin
1870
+ validateOrigin,
1871
+ webMCPAnnotationsFor
1792
1872
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corsenai/corsen-context",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Universal AI Context Layer — MCP Server + Enhanced llms.txt for any website",
5
5
  "author": "Corsen AI <contact@corsen.ai>",
6
6
  "license": "MIT",