@interopio/mcp-web 0.1.0-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/readme.md ADDED
@@ -0,0 +1,691 @@
1
+ # @interopio/mcp-web
2
+
3
+ ## Table of Contents
4
+
5
+ - [Introduction](#introduction)
6
+ - [Installation](#installation)
7
+ - [Core Concepts](#core-concepts)
8
+ - [MCP Protocol](#mcp-protocol)
9
+ - [Web Transport](#web-transport)
10
+ - [Server vs Client](#server-vs-client)
11
+ - [io.Connect Integration](#ioconnect-integration)
12
+ - [API Reference](#api-reference)
13
+ - [ClientFactory](#clientfactory)
14
+ - [ServerFactory](#serverfactory)
15
+ - [Client Configuration](#client-configuration)
16
+ - [Server Configuration](#server-configuration)
17
+ - [Client API](#client-api)
18
+ - [Configuration](#configuration)
19
+ - [Client Configuration Options](#client-configuration-options)
20
+ - [Server Configuration Options](#server-configuration-options)
21
+ - [Integration Options](#integration-options)
22
+ - [Server as io.Connect Browser Plugin](#server-as-ioconnect-browser-plugin)
23
+ - [Server within Web Application](#server-within-web-application)
24
+ - [Client in Web Application](#client-in-web-application)
25
+ - [Examples](#examples)
26
+ - [Basic Server Setup (Plugin)](#basic-server-setup-plugin)
27
+ - [Basic Server Setup (Direct)](#basic-server-setup-direct)
28
+ - [Basic Client Setup](#basic-client-setup)
29
+ - [Client with Custom Capabilities](#client-with-custom-capabilities)
30
+ - [Complete Integration Example](#complete-integration-example)
31
+
32
+ ---
33
+
34
+ ## Introduction
35
+
36
+ `@interopio/mcp-web` is a TypeScript library that enables web applications to serve and consume Model Context Protocol (MCP) capabilities within a browser environment. The package provides two distinct functionalities:
37
+
38
+ - **MCP Server** - Delivers the capabilities of `@interopio/mcp-core` from web applications, without requiring a traditional Node.js server environment
39
+ - **MCP Client** - Allows web applications to connect as MCP clients to the MCP Server component
40
+
41
+ ### Key Features
42
+
43
+ - Web-based MCP transport implementation using io.Connect Browser
44
+ - Seamless integration with io.Connect Browser as a plugin or standalone
45
+ - Full MCP specification compliance
46
+ - TypeScript support with comprehensive type definitions
47
+ - Built-in schema validation and error handling
48
+ - Support for all MCP capabilities: tools, resources, prompts, and sampling
49
+
50
+ ### Target Audience
51
+
52
+ This package is designed for developers building web applications in io.Connect Browser environments who need to expose or consume MCP capabilities without running traditional server infrastructure.
53
+
54
+ ---
55
+
56
+ ## Installation
57
+
58
+ Install the package using npm:
59
+
60
+ ```bash
61
+ npm install @interopio/mcp-web
62
+ ```
63
+
64
+ Or using yarn:
65
+
66
+ ```bash
67
+ yarn add @interopio/mcp-web
68
+ ```
69
+
70
+ ### Requirements
71
+
72
+ - `@interopio/browser` or `@interopio/desktop` - io.Connect Browser/Desktop API
73
+ - `@interopio/mcp-core` - Core MCP implementation (peer dependency)
74
+ - `@modelcontextprotocol/sdk` - Model Context Protocol SDK
75
+
76
+ ---
77
+
78
+ ## Core Concepts
79
+
80
+ ### Web Transport
81
+
82
+ Traditional MCP implementations use standard I/O or HTTP-based transports. `@interopio/mcp-web` implements a custom web transport layer using io.Connect Browser's interop system, enabling MCP communication between web applications without requiring external servers.
83
+
84
+ ### Server vs Client
85
+
86
+ - **MCP Server**: Exposes MCP capabilities (tools, resources, prompts) that can be consumed by MCP clients. The server uses `@interopio/mcp-core` internally to provide these capabilities.
87
+ - **MCP Client**: Connects to an MCP server to discover and invoke available capabilities. The client implements the MCP client specification from `@modelcontextprotocol/sdk`.
88
+
89
+ ### io.Connect Integration
90
+
91
+ The package leverages io.Connect Browser's interop methods for communication:
92
+
93
+ - **Server** registers the method `io.mcp.web.server` to receive client requests
94
+ - **Client** registers the method `io.mcp.web.client` to receive server responses
95
+ - Communication is instance-specific, supporting multiple client connections
96
+
97
+ ---
98
+
99
+ ## API Reference
100
+
101
+ ### ClientFactory
102
+
103
+ Factory function to create an MCP client instance.
104
+
105
+ ```typescript
106
+ type IoIntelMCPWebClientFactoryFunction = (
107
+ io: IOConnectBrowser.API | IOConnectDesktop.API,
108
+ config: IoIntelMCPWeb.Client.Config,
109
+ ) => Promise<IoIntelMCPWeb.Client.API>;
110
+ ```
111
+
112
+ **Parameters:**
113
+
114
+ - `io`: io.Connect Browser or Desktop API instance
115
+ - `config`: Client configuration object
116
+
117
+ **Returns:** Promise that resolves to the Client API
118
+
119
+ **Example:**
120
+
121
+ ```typescript
122
+ import { ClientFactory } from "@interopio/mcp-web";
123
+
124
+ const clientApi = await ClientFactory(io, {
125
+ capabilities: {
126
+ sampling: {},
127
+ elicitation: {},
128
+ },
129
+ });
130
+ ```
131
+
132
+ ---
133
+
134
+ ### ServerFactory
135
+
136
+ Factory function to create and start an MCP server instance.
137
+
138
+ ```typescript
139
+ type IoIntelMCPWebServerFactoryFunction = (
140
+ io: IOConnectBrowser.API | IOConnectDesktop.API,
141
+ config: IoIntelMCPWeb.Server.Config,
142
+ ) => Promise<void>;
143
+ ```
144
+
145
+ **Parameters:**
146
+
147
+ - `io`: io.Connect Browser or Desktop API instance
148
+ - `config`: Server configuration object including license key
149
+
150
+ **Returns:** Promise that resolves when server is started
151
+
152
+ **Example:**
153
+
154
+ ```typescript
155
+ import { ServerFactory } from "@interopio/mcp-web";
156
+
157
+ await ServerFactory(io, {
158
+ licenseKey: "your-license-key",
159
+ mcpCoreServer: {
160
+ tools: {
161
+ static: {
162
+ methods: [...],
163
+ intents: [...]
164
+ }
165
+ }
166
+ }
167
+ });
168
+ ```
169
+
170
+ ---
171
+
172
+ ### Client Configuration
173
+
174
+ ```typescript
175
+ interface Config {
176
+ enforceStrictCapabilities?: boolean; // default: true
177
+ debouncedNotificationMethods?: string[]; // default: []
178
+ capabilities: {
179
+ sampling?: Record<string, any>;
180
+ elicitation?: Record<string, any>;
181
+ experimental?: Record<string, any>;
182
+ };
183
+ }
184
+ ```
185
+
186
+ **Properties:**
187
+
188
+ - `enforceStrictCapabilities`: When `true`, enforces strict capability checking against server capabilities
189
+ - `debouncedNotificationMethods`: Array of notification method names to debounce
190
+ - `capabilities`: Client capabilities to advertise to the server
191
+ - `sampling`: Sampling capability configuration
192
+ - `elicitation`: Elicitation capability configuration
193
+ - `experimental`: Experimental features configuration
194
+
195
+ ---
196
+
197
+ ### Server Configuration
198
+
199
+ ```typescript
200
+ interface Config {
201
+ licenseKey: string;
202
+ mcpCoreServer?: Omit<IoIntelMCPCore.McpServerConfig, "name" | "title">;
203
+ mcpWorkingContext?: IoIntelMCPCore.WorkingContextConfig;
204
+ }
205
+ ```
206
+
207
+ **Properties:**
208
+
209
+ - `licenseKey`: **Required**. io.Intelligence license key
210
+ - `mcpCoreServer`: Optional MCP Core server configuration (tools, resources, prompts, etc.)
211
+ - `mcpWorkingContext`: Optional working context configuration for MCP Core
212
+
213
+ > **Note:** The `name` and `title` fields are automatically set to "iointel-mcp-web" and "IOIntel MCP Web" respectively.
214
+
215
+ ---
216
+
217
+ ### Client API
218
+
219
+ The Client API provides access to the underlying MCP client instance.
220
+
221
+ ```typescript
222
+ interface API {
223
+ mcpClient: MCPClient;
224
+ }
225
+ ```
226
+
227
+ **Properties:**
228
+
229
+ - `mcpClient`: The `@modelcontextprotocol/sdk` Client instance with full MCP client capabilities
230
+
231
+ **Common Client Operations:**
232
+
233
+ ```typescript
234
+ // List available tools
235
+ const tools = await clientApi.mcpClient.listTools();
236
+
237
+ // Call a tool
238
+ const result = await clientApi.mcpClient.callTool({
239
+ name: "tool-name",
240
+ arguments: {
241
+ /* tool arguments */
242
+ },
243
+ });
244
+
245
+ // List available resources
246
+ const resources = await clientApi.mcpClient.listResources();
247
+
248
+ // Read a resource
249
+ const resource = await clientApi.mcpClient.readResource({
250
+ uri: "resource://example",
251
+ });
252
+
253
+ // List available prompts
254
+ const prompts = await clientApi.mcpClient.listPrompts();
255
+
256
+ // Get a prompt
257
+ const prompt = await clientApi.mcpClient.getPrompt({
258
+ name: "prompt-name",
259
+ arguments: {
260
+ /* prompt arguments */
261
+ },
262
+ });
263
+ ```
264
+
265
+ ---
266
+
267
+ ## Configuration
268
+
269
+ ### Client Configuration Options
270
+
271
+ | Option | Type | Required | Default | Description |
272
+ | ------------------------------ | -------- | -------- | ------- | ------------------------------------ |
273
+ | `capabilities` | object | Yes | - | Client capabilities to advertise |
274
+ | `capabilities.sampling` | object | No | - | Sampling capability configuration |
275
+ | `capabilities.elicitation` | object | No | - | Elicitation capability configuration |
276
+ | `capabilities.experimental` | object | No | - | Experimental features configuration |
277
+ | `enforceStrictCapabilities` | boolean | No | `true` | Enforce strict capability checking |
278
+ | `debouncedNotificationMethods` | string[] | No | `[]` | Notification methods to debounce |
279
+
280
+ **Configuration Rules:**
281
+
282
+ - The `capabilities` object must be provided with at least one capability defined
283
+ - `enforceStrictCapabilities` defaults to `true` for safer operation
284
+ - Debounced notification methods help reduce redundant notifications for high-frequency events
285
+
286
+ ---
287
+
288
+ ### Server Configuration Options
289
+
290
+ | Option | Type | Required | Default | Description |
291
+ | ------------------- | ------ | -------- | ------- | ----------------------------- |
292
+ | `licenseKey` | string | Yes | - | io.Intelligence license key |
293
+ | `mcpCoreServer` | object | No | `{}` | MCP Core server configuration |
294
+ | `mcpWorkingContext` | object | No | - | Working context configuration |
295
+
296
+ **Configuration Rules:**
297
+
298
+ - `licenseKey` is mandatory and must be a valid io.Intelligence license
299
+ - `mcpCoreServer` accepts any valid `@interopio/mcp-core` configuration except `name` and `title`
300
+ - Refer to `@interopio/mcp-core` documentation for detailed server configuration options
301
+
302
+ ---
303
+
304
+ ## Integration Options
305
+
306
+ ### Server as io.Connect Browser Plugin
307
+
308
+ The recommended approach for io.Connect Browser Platform administrators is to define the MCP server as a plugin. This provides centralized control over MCP capabilities.
309
+
310
+ **Advantages:**
311
+
312
+ - Centralized configuration and management
313
+ - Single server instance for all connected clients
314
+ - Platform-level control over capabilities
315
+ - Automatic lifecycle management
316
+
317
+ **Example:**
318
+
319
+ ```typescript
320
+ import IOBrowserPlatform from "@interopio/browser-platform";
321
+ import { ServerFactory } from "@interopio/mcp-web";
322
+
323
+ const platformConfig = {
324
+ plugins: {
325
+ definitions: [
326
+ {
327
+ name: "io.MCPWeb",
328
+ start: ServerFactory,
329
+ critical: true,
330
+ config: {
331
+ licenseKey: "your-license-key",
332
+ mcpCoreServer: {
333
+ tools: {
334
+ static: {
335
+ methods: [...],
336
+ intents: [...]
337
+ }
338
+ }
339
+ }
340
+ }
341
+ }
342
+ ]
343
+ }
344
+ };
345
+
346
+ await IOBrowserPlatform(platformConfig);
347
+ ```
348
+
349
+ ---
350
+
351
+ ### Server within Web Application
352
+
353
+ Developers can also instantiate the MCP server directly within their web application.
354
+
355
+ **Advantages:**
356
+
357
+ - Application-specific configuration
358
+ - Full control over server lifecycle
359
+ - Custom capability exposure
360
+
361
+ **Example:**
362
+
363
+ ```typescript
364
+ import IOBrowser from "@interopio/browser";
365
+ import { ServerFactory } from "@interopio/mcp-web";
366
+
367
+ const io = await IOBrowser();
368
+
369
+ await ServerFactory(io, {
370
+ licenseKey: "your-license-key",
371
+ mcpCoreServer: {
372
+ tools: {
373
+ static: {
374
+ methods: [
375
+ {
376
+ name: "calculate",
377
+ description: "Perform calculation",
378
+ inputSchema: {
379
+ type: "object",
380
+ properties: {
381
+ operation: { type: "string" },
382
+ a: { type: "number" },
383
+ b: { type: "number" },
384
+ },
385
+ },
386
+ },
387
+ ],
388
+ },
389
+ },
390
+ },
391
+ });
392
+ ```
393
+
394
+ ---
395
+
396
+ ### Client in Web Application
397
+
398
+ Any web application can become an MCP client to consume capabilities from the MCP server.
399
+
400
+ **Example:**
401
+
402
+ ```typescript
403
+ import IOBrowser from "@interopio/browser";
404
+ import { ClientFactory } from "@interopio/mcp-web";
405
+
406
+ const io = await IOBrowser();
407
+
408
+ const clientApi = await ClientFactory(io, {
409
+ enforceStrictCapabilities: true,
410
+ capabilities: {
411
+ sampling: {},
412
+ elicitation: {},
413
+ },
414
+ });
415
+
416
+ // Use the MCP client
417
+ const tools = await clientApi.mcpClient.listTools();
418
+ console.log("Available tools:", tools);
419
+ ```
420
+
421
+ ---
422
+
423
+ ## Examples
424
+
425
+ ### Basic Server Setup (Plugin)
426
+
427
+ Configure MCP server as an io.Connect Browser plugin:
428
+
429
+ ```typescript
430
+ import IOBrowserPlatform from "@interopio/browser-platform";
431
+ import { ServerFactory, IoIntelMCPWeb } from "@interopio/mcp-web";
432
+
433
+ const mcpWebServerConfig: IoIntelMCPWeb.Server.Config = {
434
+ licenseKey: process.env.IO_INTELLIGENCE_LICENSE_KEY,
435
+ mcpCoreServer: {
436
+ tools: {
437
+ static: {
438
+ methods: [
439
+ {
440
+ name: "getUserInfo",
441
+ description: "Get current user information",
442
+ inputSchema: {
443
+ type: "object",
444
+ properties: {},
445
+ },
446
+ },
447
+ ],
448
+ },
449
+ },
450
+ },
451
+ };
452
+
453
+ const platformConfig = {
454
+ plugins: {
455
+ definitions: [
456
+ {
457
+ name: "io.MCPWeb",
458
+ start: ServerFactory,
459
+ critical: true,
460
+ config: mcpWebServerConfig,
461
+ },
462
+ ],
463
+ },
464
+ };
465
+
466
+ const { io, platform } = await IOBrowserPlatform(platformConfig);
467
+ ```
468
+
469
+ ---
470
+
471
+ ### Basic Server Setup (Direct)
472
+
473
+ Start an MCP server directly in your application:
474
+
475
+ ```typescript
476
+ import IOBrowser from "@interopio/browser";
477
+ import { ServerFactory } from "@interopio/mcp-web";
478
+
479
+ async function startMCPServer() {
480
+ const io = await IOBrowser();
481
+
482
+ await ServerFactory(io, {
483
+ licenseKey: "your-license-key-here",
484
+ mcpCoreServer: {
485
+ tools: {
486
+ static: {
487
+ methods: [
488
+ {
489
+ name: "echo",
490
+ description: "Echo back the input message",
491
+ inputSchema: {
492
+ type: "object",
493
+ properties: {
494
+ message: { type: "string" },
495
+ },
496
+ required: ["message"],
497
+ },
498
+ },
499
+ ],
500
+ },
501
+ },
502
+ },
503
+ });
504
+
505
+ console.log("MCP Server started successfully");
506
+ }
507
+
508
+ startMCPServer();
509
+ ```
510
+
511
+ ---
512
+
513
+ ### Basic Client Setup
514
+
515
+ Connect to an MCP server from a web application:
516
+
517
+ ```typescript
518
+ import IOBrowser from "@interopio/browser";
519
+ import { ClientFactory } from "@interopio/mcp-web";
520
+
521
+ async function connectToMCPServer() {
522
+ const io = await IOBrowser();
523
+
524
+ const clientApi = await ClientFactory(io, {
525
+ capabilities: {
526
+ sampling: {},
527
+ elicitation: {},
528
+ },
529
+ });
530
+
531
+ // List available tools
532
+ const toolsResult = await clientApi.mcpClient.listTools();
533
+ console.log("Available tools:", toolsResult.tools);
534
+
535
+ // Call a tool
536
+ const result = await clientApi.mcpClient.callTool({
537
+ name: "echo",
538
+ arguments: { message: "Hello, MCP!" },
539
+ });
540
+
541
+ console.log("Tool result:", result);
542
+ }
543
+
544
+ connectToMCPServer();
545
+ ```
546
+
547
+ ---
548
+
549
+ ### Client with Custom Capabilities
550
+
551
+ Configure a client with specific capabilities and options:
552
+
553
+ ```typescript
554
+ import IOBrowser from "@interopio/browser";
555
+ import { ClientFactory } from "@interopio/mcp-web";
556
+
557
+ async function advancedClientSetup() {
558
+ const io = await IOBrowser();
559
+
560
+ const clientApi = await ClientFactory(io, {
561
+ enforceStrictCapabilities: true,
562
+ debouncedNotificationMethods: ["notifications/resources/list_changed"],
563
+ capabilities: {
564
+ sampling: {
565
+ maxTokens: 1000,
566
+ temperature: 0.7,
567
+ },
568
+ elicitation: {
569
+ enabled: true,
570
+ },
571
+ experimental: {
572
+ featureX: { enabled: true },
573
+ },
574
+ },
575
+ });
576
+
577
+ // Client is now ready with custom capabilities
578
+ const resources = await clientApi.mcpClient.listResources();
579
+ console.log("Available resources:", resources);
580
+ }
581
+
582
+ advancedClientSetup();
583
+ ```
584
+
585
+ ---
586
+
587
+ ### Complete Integration Example
588
+
589
+ A full example showing server and client integration in separate applications:
590
+
591
+ **Application 1 (Server):**
592
+
593
+ ```typescript
594
+ import IOBrowser from "@interopio/browser";
595
+ import { ServerFactory } from "@interopio/mcp-web";
596
+
597
+ async function startServer() {
598
+ const io = await IOBrowser({
599
+ application: "mcp-server-app",
600
+ });
601
+
602
+ await ServerFactory(io, {
603
+ licenseKey: "your-license-key",
604
+ mcpCoreServer: {
605
+ tools: {
606
+ static: {
607
+ methods: [
608
+ {
609
+ name: "getWeather",
610
+ description: "Get weather for a location",
611
+ inputSchema: {
612
+ type: "object",
613
+ properties: {
614
+ location: {
615
+ type: "string",
616
+ description: "City name",
617
+ },
618
+ },
619
+ required: ["location"],
620
+ },
621
+ },
622
+ ],
623
+ },
624
+ },
625
+ resources: {
626
+ static: [
627
+ {
628
+ uri: "config://app-settings",
629
+ name: "Application Settings",
630
+ mimeType: "application/json",
631
+ },
632
+ ],
633
+ },
634
+ },
635
+ });
636
+
637
+ console.log("MCP Server is running");
638
+ }
639
+
640
+ startServer();
641
+ ```
642
+
643
+ **Application 2 (Client):**
644
+
645
+ ```typescript
646
+ import IOBrowser from "@interopio/browser";
647
+ import { ClientFactory } from "@interopio/mcp-web";
648
+
649
+ async function startClient() {
650
+ const io = await IOBrowser({
651
+ application: "mcp-client-app",
652
+ });
653
+
654
+ const clientApi = await ClientFactory(io, {
655
+ enforceStrictCapabilities: true,
656
+ capabilities: {
657
+ sampling: {},
658
+ elicitation: {},
659
+ },
660
+ });
661
+
662
+ // Discover available tools
663
+ const { tools } = await clientApi.mcpClient.listTools();
664
+ console.log(
665
+ "Available tools:",
666
+ tools.map((t) => t.name),
667
+ );
668
+
669
+ // Call the weather tool
670
+ const weatherResult = await clientApi.mcpClient.callTool({
671
+ name: "getWeather",
672
+ arguments: { location: "London" },
673
+ });
674
+ console.log("Weather result:", weatherResult.content);
675
+
676
+ // List available resources
677
+ const { resources } = await clientApi.mcpClient.listResources();
678
+ console.log(
679
+ "Available resources:",
680
+ resources.map((r) => r.uri),
681
+ );
682
+
683
+ // Read a resource
684
+ const settingsResource = await clientApi.mcpClient.readResource({
685
+ uri: "config://app-settings",
686
+ });
687
+ console.log("Settings:", settingsResource.contents);
688
+ }
689
+
690
+ startClient();
691
+ ```