@mcp-b/global 1.0.5 → 1.0.7
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 +305 -328
- package/dist/index.umd.js +11 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +1 -1
- package/README +0 -167
- package/dist/index.umd +0 -11
package/package.json
CHANGED
package/README
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
# @mcp-b/global
|
|
2
|
-
|
|
3
|
-
Global bundle for MCP-B (Model Context Protocol - Browser) that provides a polyfill exposing `window.mcp` for easy script tag or CDN usage in browser environments.
|
|
4
|
-
|
|
5
|
-
This package creates a global MCP server instance, allowing seamless integration of Model Context Protocol capabilities directly in the browser. It's designed for scenarios where you want a drop-in polyfill without module bundlers, while also supporting modern ESM/CJS imports.
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- Auto-initializes on script load in browsers.
|
|
10
|
-
- Exposes `window.mcp` as an instance of `McpServer` from `@modelcontextprotocol/sdk`.
|
|
11
|
-
- Registers a default tool: `get_current_website_title` to retrieve the document title.
|
|
12
|
-
- Supports cleanup for testing or dynamic reloading.
|
|
13
|
-
- Built with security in mind (e.g., configurable allowed origins for transport).
|
|
14
|
-
- Lightweight and treeshaken for browser efficiency.
|
|
15
|
-
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
|
-
### Via NPM (for module-based projects)
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
npm install @mcp-b/global
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
or
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
yarn add @mcp-b/global
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
or
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
pnpm add @mcp-b/global
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### Via CDN (for script tag usage)
|
|
37
|
-
|
|
38
|
-
Use a CDN like unpkg or jsDelivr for direct browser inclusion:
|
|
39
|
-
|
|
40
|
-
```html
|
|
41
|
-
<script src="https://unpkg.com/@mcp-b/global@1.0.1/dist/index.umd.js"></script>
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
This will auto-initialize `window.mcp` upon loading.
|
|
45
|
-
|
|
46
|
-
## Usage
|
|
47
|
-
|
|
48
|
-
### Script Tag (Polyfill Mode)
|
|
49
|
-
|
|
50
|
-
Simply include the script in your HTML. The library will auto-initialize and expose `window.mcp`.
|
|
51
|
-
|
|
52
|
-
```html
|
|
53
|
-
<!DOCTYPE html>
|
|
54
|
-
<html lang="en">
|
|
55
|
-
<head>
|
|
56
|
-
<meta charset="UTF-8" />
|
|
57
|
-
<title>MCP-B Global Example</title>
|
|
58
|
-
<script src="https://unpkg.com/@mcp-b/global@1.0.1/dist/index.umd.js"></script>
|
|
59
|
-
</head>
|
|
60
|
-
<body>
|
|
61
|
-
<script>
|
|
62
|
-
// Wait for DOMContentLoaded if needed, but auto-init handles it
|
|
63
|
-
document.addEventListener("DOMContentLoaded", () => {
|
|
64
|
-
console.log(window.mcp); // McpServer instance
|
|
65
|
-
// Use window.mcp.registerTool(...) or other methods
|
|
66
|
-
});
|
|
67
|
-
</script>
|
|
68
|
-
</body>
|
|
69
|
-
</html>
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### Module Import (ESM/CJS)
|
|
73
|
-
|
|
74
|
-
For modern JavaScript projects:
|
|
75
|
-
|
|
76
|
-
```javascript
|
|
77
|
-
// ESM
|
|
78
|
-
import { initializeGlobalMCP } from "@mcp-b/global";
|
|
79
|
-
|
|
80
|
-
// or CJS
|
|
81
|
-
const { initializeGlobalMCP } = require("@mcp-b/global");
|
|
82
|
-
|
|
83
|
-
// Initialize manually
|
|
84
|
-
initializeGlobalMCP();
|
|
85
|
-
|
|
86
|
-
// Now window.mcp is available
|
|
87
|
-
console.log(window.mcp);
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
#### Cleanup
|
|
91
|
-
|
|
92
|
-
If you need to reset the instance (e.g., in tests or hot module replacement):
|
|
93
|
-
|
|
94
|
-
```javascript
|
|
95
|
-
import { cleanupGlobalMCP } from "@mcp-b/global";
|
|
96
|
-
|
|
97
|
-
cleanupGlobalMCP(); // Closes the server and removes window.mcp
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## API
|
|
101
|
-
|
|
102
|
-
### `initializeGlobalMCP(): void`
|
|
103
|
-
|
|
104
|
-
- Initializes the global MCP server if not already done.
|
|
105
|
-
- Safe to call multiple times (idempotent).
|
|
106
|
-
- Throws an error if initialization fails.
|
|
107
|
-
- In browser environments only; skips in non-browser contexts.
|
|
108
|
-
|
|
109
|
-
### `cleanupGlobalMCP(): void`
|
|
110
|
-
|
|
111
|
-
- Closes the MCP server connection.
|
|
112
|
-
- Removes `window.mcp`.
|
|
113
|
-
- Resets internal state for re-initialization.
|
|
114
|
-
|
|
115
|
-
### Global Exposure
|
|
116
|
-
|
|
117
|
-
After initialization:
|
|
118
|
-
|
|
119
|
-
- `window.mcp`: An instance of `McpServer` with:
|
|
120
|
-
- Server info: `{ name: hostname, version: '1.0.0' }`
|
|
121
|
-
- Capabilities: Supports tool list changes and debounced notifications.
|
|
122
|
-
- Default tool: `get_current_website_title` – Returns the current document title as `{ content: [{ type: 'text', text: title }] }`.
|
|
123
|
-
|
|
124
|
-
You can extend it by calling `window.mcp.registerTool(...)` or other MCP SDK methods.
|
|
125
|
-
|
|
126
|
-
## Configuration and Best Practices
|
|
127
|
-
|
|
128
|
-
- **Security**: The transport uses `allowedOrigins: ['*']` by default for broad compatibility. In production, restrict this to trusted origins (e.g., your domain) to prevent cross-origin issues. Modify the source or fork if needed.
|
|
129
|
-
- **Error Handling**: Tools and initialization include try-catch blocks for robustness.
|
|
130
|
-
- **Browser Compatibility**: Targets ES2018; works in modern browsers (Chrome 61+, Firefox 55+, Safari 11+, Edge 16+).
|
|
131
|
-
- **TypeScript**: Includes full type declarations for `window.mcp`.
|
|
132
|
-
|
|
133
|
-
## Dependencies
|
|
134
|
-
|
|
135
|
-
- `@mcp-b/transports`: For browser transport handling.
|
|
136
|
-
- `@modelcontextprotocol/sdk`: Core MCP SDK.
|
|
137
|
-
- `zod`: For schema validation (if used internally).
|
|
138
|
-
|
|
139
|
-
## Development
|
|
140
|
-
|
|
141
|
-
### Building
|
|
142
|
-
|
|
143
|
-
```bash
|
|
144
|
-
pnpm install
|
|
145
|
-
pnpm build
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
### Scripts
|
|
149
|
-
|
|
150
|
-
- `build`: Builds the library using tsup (ESM, CJS, UMD formats).
|
|
151
|
-
- `typecheck`: Runs TypeScript checks.
|
|
152
|
-
- `lint` / `format` / `check`: Uses Biome for code quality.
|
|
153
|
-
- `clean`: Removes build artifacts.
|
|
154
|
-
|
|
155
|
-
## License
|
|
156
|
-
|
|
157
|
-
MIT License. See [LICENSE](LICENSE) for details.
|
|
158
|
-
|
|
159
|
-
## Contributing
|
|
160
|
-
|
|
161
|
-
Contributions welcome! Fork the repo, create a branch, and submit a PR. Report issues at [GitHub Issues](https://github.com/MiguelsPizza/WebMCP/issues).
|
|
162
|
-
|
|
163
|
-
## Links
|
|
164
|
-
|
|
165
|
-
- [Repository](https://github.com/MiguelsPizza/WebMCP/tree/main/packages/global)
|
|
166
|
-
- [NPM Package](https://www.npmjs.com/package/@mcp-b/global)
|
|
167
|
-
- [Homepage](https://github.com/MiguelsPizza/WebMCP#readme)
|