@mcp-b/webmcp-ts-sdk 1.0.1 → 1.0.2-beta.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/dist/index.d.ts +9 -9
- package/dist/index.js +14 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -7,25 +7,25 @@ import { Transport, Transport as Transport$1 } from "@modelcontextprotocol/sdk/s
|
|
|
7
7
|
//#region src/browser-server.d.ts
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Browser-optimized MCP Server for Web Model Context API (
|
|
10
|
+
* Browser-optimized MCP Server for Web Model Context API (navigator.modelContext).
|
|
11
11
|
*
|
|
12
|
-
* This class extends McpServer to support dynamic
|
|
13
|
-
* transport connection, which is required for the Web Model Context API
|
|
14
|
-
* where
|
|
12
|
+
* This class extends McpServer to support dynamic registration of tools, resources,
|
|
13
|
+
* and prompts after transport connection, which is required for the Web Model Context API
|
|
14
|
+
* where items are registered via navigator.modelContext.provideContext() at any time.
|
|
15
15
|
*
|
|
16
16
|
* Key differences from base McpServer:
|
|
17
|
-
* - Pre-registers tool capabilities before connection
|
|
18
|
-
* - Allows
|
|
19
|
-
* - Designed for browser environments where
|
|
17
|
+
* - Pre-registers tool, resource, and prompt capabilities before connection
|
|
18
|
+
* - Allows items to be registered after transport is connected
|
|
19
|
+
* - Designed for browser environments where items arrive asynchronously
|
|
20
20
|
*/
|
|
21
21
|
declare class BrowserMcpServer extends McpServer {
|
|
22
22
|
constructor(serverInfo: Implementation$1, options?: ServerOptions);
|
|
23
23
|
/**
|
|
24
|
-
* Override connect to ensure
|
|
24
|
+
* Override connect to ensure request handlers are initialized
|
|
25
25
|
* BEFORE the transport connection is established.
|
|
26
26
|
*
|
|
27
27
|
* This prevents the "Cannot register capabilities after connecting to transport"
|
|
28
|
-
* error when
|
|
28
|
+
* error when items are registered dynamically after connection.
|
|
29
29
|
*/
|
|
30
30
|
connect(transport: Transport$1): Promise<void>;
|
|
31
31
|
}
|
package/dist/index.js
CHANGED
|
@@ -5,31 +5,35 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
5
5
|
|
|
6
6
|
//#region src/browser-server.ts
|
|
7
7
|
/**
|
|
8
|
-
* Browser-optimized MCP Server for Web Model Context API (
|
|
8
|
+
* Browser-optimized MCP Server for Web Model Context API (navigator.modelContext).
|
|
9
9
|
*
|
|
10
|
-
* This class extends McpServer to support dynamic
|
|
11
|
-
* transport connection, which is required for the Web Model Context API
|
|
12
|
-
* where
|
|
10
|
+
* This class extends McpServer to support dynamic registration of tools, resources,
|
|
11
|
+
* and prompts after transport connection, which is required for the Web Model Context API
|
|
12
|
+
* where items are registered via navigator.modelContext.provideContext() at any time.
|
|
13
13
|
*
|
|
14
14
|
* Key differences from base McpServer:
|
|
15
|
-
* - Pre-registers tool capabilities before connection
|
|
16
|
-
* - Allows
|
|
17
|
-
* - Designed for browser environments where
|
|
15
|
+
* - Pre-registers tool, resource, and prompt capabilities before connection
|
|
16
|
+
* - Allows items to be registered after transport is connected
|
|
17
|
+
* - Designed for browser environments where items arrive asynchronously
|
|
18
18
|
*/
|
|
19
19
|
var BrowserMcpServer = class extends McpServer {
|
|
20
20
|
constructor(serverInfo, options) {
|
|
21
21
|
const enhancedOptions = {
|
|
22
22
|
...options,
|
|
23
|
-
capabilities: mergeCapabilities$1(options?.capabilities || {}, {
|
|
23
|
+
capabilities: mergeCapabilities$1(options?.capabilities || {}, {
|
|
24
|
+
tools: { listChanged: true },
|
|
25
|
+
resources: { listChanged: true },
|
|
26
|
+
prompts: { listChanged: true }
|
|
27
|
+
})
|
|
24
28
|
};
|
|
25
29
|
super(serverInfo, enhancedOptions);
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
28
|
-
* Override connect to ensure
|
|
32
|
+
* Override connect to ensure request handlers are initialized
|
|
29
33
|
* BEFORE the transport connection is established.
|
|
30
34
|
*
|
|
31
35
|
* This prevents the "Cannot register capabilities after connecting to transport"
|
|
32
|
-
* error when
|
|
36
|
+
* error when items are registered dynamically after connection.
|
|
33
37
|
*/
|
|
34
38
|
async connect(transport) {
|
|
35
39
|
this.setToolRequestHandlers();
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["BaseMcpServer","enhancedOptions: ServerOptions","mergeCapabilities"],"sources":["../src/browser-server.ts"],"sourcesContent":["import type { ServerOptions } from '@modelcontextprotocol/sdk/server/index.js';\nimport { McpServer as BaseMcpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { mergeCapabilities } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport type { Implementation } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Browser-optimized MCP Server for Web Model Context API (
|
|
1
|
+
{"version":3,"file":"index.js","names":["BaseMcpServer","enhancedOptions: ServerOptions","mergeCapabilities"],"sources":["../src/browser-server.ts"],"sourcesContent":["import type { ServerOptions } from '@modelcontextprotocol/sdk/server/index.js';\nimport { McpServer as BaseMcpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { mergeCapabilities } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport type { Implementation } from '@modelcontextprotocol/sdk/types.js';\n\n/**\n * Browser-optimized MCP Server for Web Model Context API (navigator.modelContext).\n *\n * This class extends McpServer to support dynamic registration of tools, resources,\n * and prompts after transport connection, which is required for the Web Model Context API\n * where items are registered via navigator.modelContext.provideContext() at any time.\n *\n * Key differences from base McpServer:\n * - Pre-registers tool, resource, and prompt capabilities before connection\n * - Allows items to be registered after transport is connected\n * - Designed for browser environments where items arrive asynchronously\n */\nexport class BrowserMcpServer extends BaseMcpServer {\n constructor(serverInfo: Implementation, options?: ServerOptions) {\n // Ensure tools, resources, and prompts capabilities are registered from the start\n const enhancedOptions: ServerOptions = {\n ...options,\n capabilities: mergeCapabilities(options?.capabilities || {}, {\n tools: { listChanged: true },\n resources: { listChanged: true },\n prompts: { listChanged: true },\n }),\n };\n\n super(serverInfo, enhancedOptions);\n }\n\n /**\n * Override connect to ensure request handlers are initialized\n * BEFORE the transport connection is established.\n *\n * This prevents the \"Cannot register capabilities after connecting to transport\"\n * error when items are registered dynamically after connection.\n */\n override async connect(transport: Transport): Promise<void> {\n // Call setToolRequestHandlers() BEFORE connecting the transport\n // This will:\n // 1. Register tool capabilities (won't throw since transport isn't connected yet)\n // 2. Set up ListTools and CallTool request handlers\n // 3. Set _toolHandlersInitialized = true\n //\n // After this, any future registerTool() calls will skip registerCapabilities()\n // because _toolHandlersInitialized is true, allowing dynamic tool registration\n\n // Type-safe access to private method - we need to call this internal method\n // to initialize tool handlers before connecting\n (this as unknown as { setToolRequestHandlers: () => void }).setToolRequestHandlers();\n\n // Now connect with the transport\n return super.connect(transport);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,IAAa,mBAAb,cAAsCA,UAAc;CAClD,YAAY,YAA4B,SAAyB;EAE/D,MAAMC,kBAAiC;GACrC,GAAG;GACH,cAAcC,oBAAkB,SAAS,gBAAgB,EAAE,EAAE;IAC3D,OAAO,EAAE,aAAa,MAAM;IAC5B,WAAW,EAAE,aAAa,MAAM;IAChC,SAAS,EAAE,aAAa,MAAM;IAC/B,CAAC;GACH;AAED,QAAM,YAAY,gBAAgB;;;;;;;;;CAUpC,MAAe,QAAQ,WAAqC;AAY1D,EAAC,KAA2D,wBAAwB;AAGpF,SAAO,MAAM,QAAQ,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-b/webmcp-ts-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2-beta.0",
|
|
4
4
|
"description": "TypeScript SDK adapter for Model Context Protocol with dynamic tool registration support for browsers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@modelcontextprotocol/sdk": "1.15.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@types/node": "
|
|
44
|
+
"@types/node": "22.17.2",
|
|
45
45
|
"tsdown": "^0.15.10",
|
|
46
46
|
"typescript": "^5.8.3"
|
|
47
47
|
},
|