@kya-os/mcp-i 0.1.0-alpha.2.1 → 0.1.0-alpha.2.3
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 +271 -47
- package/dist/index.d.ts +63 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +298 -55
- package/dist/index.js.map +1 -1
- package/dist/registry/cursor.d.ts +25 -0
- package/dist/registry/cursor.d.ts.map +1 -0
- package/dist/registry/cursor.js +108 -0
- package/dist/registry/cursor.js.map +1 -0
- package/dist/registry/glama.d.ts +25 -0
- package/dist/registry/glama.d.ts.map +1 -0
- package/dist/registry/glama.js +111 -0
- package/dist/registry/glama.js.map +1 -0
- package/dist/registry/index.d.ts +43 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +96 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/knowthat.d.ts +28 -0
- package/dist/registry/knowthat.d.ts.map +1 -0
- package/dist/registry/knowthat.js +113 -0
- package/dist/registry/knowthat.js.map +1 -0
- package/dist/registry/smithery.d.ts +29 -0
- package/dist/registry/smithery.d.ts.map +1 -0
- package/dist/registry/smithery.js +119 -0
- package/dist/registry/smithery.js.map +1 -0
- package/dist/types.d.ts +91 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +22 -4
- package/dist/auto-enhance.d.ts +0 -41
- package/dist/auto-enhance.d.ts.map +0 -1
- package/dist/auto-enhance.js +0 -193
- package/dist/auto-enhance.js.map +0 -1
- package/dist/auto-init.d.ts +0 -12
- package/dist/auto-init.d.ts.map +0 -1
- package/dist/auto-init.js +0 -166
- package/dist/auto-init.js.map +0 -1
- package/dist/patch.d.ts +0 -22
- package/dist/patch.d.ts.map +0 -1
- package/dist/patch.js +0 -164
- package/dist/patch.js.map +0 -1
- package/dist/transparent.d.ts +0 -40
- package/dist/transparent.d.ts.map +0 -1
- package/dist/transparent.js +0 -167
- package/dist/transparent.js.map +0 -1
package/dist/patch.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Monkey-patch approach for zero-code integration
|
|
4
|
-
*
|
|
5
|
-
* This can be loaded before any MCP server code to automatically
|
|
6
|
-
* add identity to all servers without any code changes.
|
|
7
|
-
*
|
|
8
|
-
* Usage: node -r @kya-os/mcp-i/patch your-server.js
|
|
9
|
-
*/
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.addIdentityToResponse = addIdentityToResponse;
|
|
15
|
-
exports.wrapHandler = wrapHandler;
|
|
16
|
-
exports.patchServerInstance = patchServerInstance;
|
|
17
|
-
const index_1 = require("./index");
|
|
18
|
-
const module_1 = __importDefault(require("module"));
|
|
19
|
-
// Store identity globally
|
|
20
|
-
let identity = null;
|
|
21
|
-
// Store original constructors
|
|
22
|
-
const originalConstructors = new Map();
|
|
23
|
-
/**
|
|
24
|
-
* Wrap a response to add identity without changing its type
|
|
25
|
-
*/
|
|
26
|
-
async function addIdentityToResponse(response) {
|
|
27
|
-
if (!response || typeof response !== 'object' || Array.isArray(response)) {
|
|
28
|
-
return response;
|
|
29
|
-
}
|
|
30
|
-
// Initialize identity if needed
|
|
31
|
-
if (!identity) {
|
|
32
|
-
identity = await index_1.MCPIdentity.init();
|
|
33
|
-
}
|
|
34
|
-
// Create identity metadata
|
|
35
|
-
const timestamp = new Date().toISOString();
|
|
36
|
-
const contentToSign = JSON.stringify({
|
|
37
|
-
...response,
|
|
38
|
-
_mcp_identity: {
|
|
39
|
-
did: identity.did,
|
|
40
|
-
timestamp,
|
|
41
|
-
conformanceLevel: 2
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
const signature = await identity.sign(contentToSign);
|
|
45
|
-
// Create a new object that includes _mcp_identity
|
|
46
|
-
// but maintains the original prototype chain
|
|
47
|
-
const enhancedResponse = Object.create(Object.getPrototypeOf(response));
|
|
48
|
-
Object.assign(enhancedResponse, response);
|
|
49
|
-
// Add _mcp_identity as a non-enumerable property
|
|
50
|
-
Object.defineProperty(enhancedResponse, '_mcp_identity', {
|
|
51
|
-
value: {
|
|
52
|
-
did: identity.did,
|
|
53
|
-
signature,
|
|
54
|
-
timestamp,
|
|
55
|
-
conformanceLevel: 2
|
|
56
|
-
},
|
|
57
|
-
writable: false,
|
|
58
|
-
enumerable: false,
|
|
59
|
-
configurable: true
|
|
60
|
-
});
|
|
61
|
-
// Override toJSON to include _mcp_identity
|
|
62
|
-
const hasToJSON = 'toJSON' in enhancedResponse && typeof enhancedResponse.toJSON === 'function';
|
|
63
|
-
if (!hasToJSON) {
|
|
64
|
-
Object.defineProperty(enhancedResponse, 'toJSON', {
|
|
65
|
-
value: function () {
|
|
66
|
-
const obj = {};
|
|
67
|
-
for (const key in this) {
|
|
68
|
-
if (this.hasOwnProperty(key)) {
|
|
69
|
-
obj[key] = this[key];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
obj._mcp_identity = this._mcp_identity;
|
|
73
|
-
return obj;
|
|
74
|
-
},
|
|
75
|
-
writable: true,
|
|
76
|
-
enumerable: false,
|
|
77
|
-
configurable: true
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return enhancedResponse;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Wrap a handler function to add identity to its responses
|
|
84
|
-
*/
|
|
85
|
-
function wrapHandler(handler) {
|
|
86
|
-
return async function (...args) {
|
|
87
|
-
const result = await handler.apply(this, args);
|
|
88
|
-
return addIdentityToResponse(result);
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Patch a server instance to wrap all its handler methods
|
|
93
|
-
*/
|
|
94
|
-
function patchServerInstance(instance) {
|
|
95
|
-
// Methods to wrap
|
|
96
|
-
const methodsToWrap = ['setRequestHandler', 'tool', 'resource', 'prompt'];
|
|
97
|
-
methodsToWrap.forEach(methodName => {
|
|
98
|
-
if (typeof instance[methodName] === 'function') {
|
|
99
|
-
const original = instance[methodName];
|
|
100
|
-
instance[methodName] = function (...args) {
|
|
101
|
-
// Find the handler function in the arguments
|
|
102
|
-
const handlerIndex = args.findIndex(arg => typeof arg === 'function');
|
|
103
|
-
if (handlerIndex !== -1) {
|
|
104
|
-
args[handlerIndex] = wrapHandler(args[handlerIndex]);
|
|
105
|
-
}
|
|
106
|
-
return original.apply(this, args);
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
return instance;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Override require to patch MCP SDK modules
|
|
114
|
-
*/
|
|
115
|
-
const originalRequire = module_1.default.prototype.require;
|
|
116
|
-
module_1.default.prototype.require = function (id) {
|
|
117
|
-
const exports = originalRequire.apply(this, [id]);
|
|
118
|
-
// Check if this is an MCP SDK module
|
|
119
|
-
if (id.includes('@modelcontextprotocol/sdk')) {
|
|
120
|
-
// Patch Server constructor
|
|
121
|
-
if (exports.Server && !originalConstructors.has('Server')) {
|
|
122
|
-
originalConstructors.set('Server', exports.Server);
|
|
123
|
-
exports.Server = class extends originalConstructors.get('Server') {
|
|
124
|
-
constructor(...args) {
|
|
125
|
-
super(...args);
|
|
126
|
-
patchServerInstance(this);
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
// Copy static properties
|
|
130
|
-
Object.setPrototypeOf(exports.Server, originalConstructors.get('Server'));
|
|
131
|
-
Object.getOwnPropertyNames(originalConstructors.get('Server')).forEach(prop => {
|
|
132
|
-
if (prop !== 'prototype' && prop !== 'constructor' && prop !== 'length' && prop !== 'name') {
|
|
133
|
-
exports.Server[prop] = originalConstructors.get('Server')[prop];
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
// Patch McpServer constructor
|
|
138
|
-
if (exports.McpServer && !originalConstructors.has('McpServer')) {
|
|
139
|
-
originalConstructors.set('McpServer', exports.McpServer);
|
|
140
|
-
exports.McpServer = class extends originalConstructors.get('McpServer') {
|
|
141
|
-
constructor(...args) {
|
|
142
|
-
super(...args);
|
|
143
|
-
patchServerInstance(this);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
// Copy static properties
|
|
147
|
-
Object.setPrototypeOf(exports.McpServer, originalConstructors.get('McpServer'));
|
|
148
|
-
Object.getOwnPropertyNames(originalConstructors.get('McpServer')).forEach(prop => {
|
|
149
|
-
if (prop !== 'prototype' && prop !== 'constructor' && prop !== 'length' && prop !== 'name') {
|
|
150
|
-
exports.McpServer[prop] = originalConstructors.get('McpServer')[prop];
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return exports;
|
|
156
|
-
};
|
|
157
|
-
// Initialize identity on load
|
|
158
|
-
index_1.MCPIdentity.init().then(i => {
|
|
159
|
-
identity = i;
|
|
160
|
-
console.log('[MCP-I] Auto-patch loaded. Identity initialized:', i.did);
|
|
161
|
-
}).catch(err => {
|
|
162
|
-
console.error('[MCP-I] Failed to initialize identity:', err.message);
|
|
163
|
-
});
|
|
164
|
-
//# sourceMappingURL=patch.js.map
|
package/dist/patch.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../src/patch.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;AA8KM,sDAAqB;AAAE,kCAAW;AAAE,kDAAmB;AA5KhE,mCAAsC;AACtC,oDAA4B;AAE5B,0BAA0B;AAC1B,IAAI,QAAQ,GAAuB,IAAI,CAAC;AAExC,8BAA8B;AAC9B,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAe,CAAC;AAEpD;;GAEG;AACH,KAAK,UAAU,qBAAqB,CAAC,QAAa;IAChD,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,KAAK,CAAC,OA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B,mBAAW,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;IAC1B,QAAQ,GAAG,CAAC,CAAC;IACb,OAAO,CAAC,GAAG,CAAC,kDAAkD,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;AACzE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;IACb,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AACvE,CAAC,CAAC,CAAC"}
|
package/dist/transparent.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Transparent MCP-I integration
|
|
3
|
-
*
|
|
4
|
-
* This module provides completely transparent integration without changing types
|
|
5
|
-
* or requiring any code modifications to existing MCP servers.
|
|
6
|
-
*/
|
|
7
|
-
import { MCPIdentity } from './index';
|
|
8
|
-
/**
|
|
9
|
-
* Create a transparent proxy that adds _mcp_identity to responses
|
|
10
|
-
* without changing the type signature
|
|
11
|
-
*/
|
|
12
|
-
export declare function createTransparentProxy<T extends object>(target: T): T;
|
|
13
|
-
/**
|
|
14
|
-
* Enhance an MCP server transparently
|
|
15
|
-
* Returns the same server instance with no type changes
|
|
16
|
-
*/
|
|
17
|
-
export declare function enhanceServer<T extends object>(server: T): Promise<T>;
|
|
18
|
-
/**
|
|
19
|
-
* Wrap a server constructor to automatically enhance instances
|
|
20
|
-
*/
|
|
21
|
-
export declare function wrapServerConstructor<T extends new (...args: any[]) => any>(ServerClass: T): T;
|
|
22
|
-
/**
|
|
23
|
-
* Alternative approach: Middleware pattern
|
|
24
|
-
* This allows users to wrap individual handlers
|
|
25
|
-
*/
|
|
26
|
-
export declare function withIdentity<T extends (...args: any[]) => any>(handler: T): T;
|
|
27
|
-
/**
|
|
28
|
-
* Ultra-simple one-liner integration
|
|
29
|
-
* Usage: const server = await addIdentity(new Server(...));
|
|
30
|
-
*/
|
|
31
|
-
export declare function addIdentity<T extends object>(server: T): Promise<T>;
|
|
32
|
-
/**
|
|
33
|
-
* Export the identity instance for direct access if needed
|
|
34
|
-
*/
|
|
35
|
-
export declare function getIdentity(): MCPIdentity | null;
|
|
36
|
-
/**
|
|
37
|
-
* Manual initialization (optional)
|
|
38
|
-
*/
|
|
39
|
-
export declare function init(options?: any): Promise<MCPIdentity>;
|
|
40
|
-
//# sourceMappingURL=transparent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transparent.d.ts","sourceRoot":"","sources":["../src/transparent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAKtC;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CA+DrE;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAQ3E;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACzE,WAAW,EAAE,CAAC,GACb,CAAC,CAcH;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAqC7E;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAEzE;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,WAAW,GAAG,IAAI,CAEhD;AAED;;GAEG;AACH,wBAAsB,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,CAK9D"}
|
package/dist/transparent.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Transparent MCP-I integration
|
|
4
|
-
*
|
|
5
|
-
* This module provides completely transparent integration without changing types
|
|
6
|
-
* or requiring any code modifications to existing MCP servers.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.createTransparentProxy = createTransparentProxy;
|
|
10
|
-
exports.enhanceServer = enhanceServer;
|
|
11
|
-
exports.wrapServerConstructor = wrapServerConstructor;
|
|
12
|
-
exports.withIdentity = withIdentity;
|
|
13
|
-
exports.addIdentity = addIdentity;
|
|
14
|
-
exports.getIdentity = getIdentity;
|
|
15
|
-
exports.init = init;
|
|
16
|
-
const index_1 = require("./index");
|
|
17
|
-
// Global identity instance
|
|
18
|
-
let identity = null;
|
|
19
|
-
/**
|
|
20
|
-
* Create a transparent proxy that adds _mcp_identity to responses
|
|
21
|
-
* without changing the type signature
|
|
22
|
-
*/
|
|
23
|
-
function createTransparentProxy(target) {
|
|
24
|
-
return new Proxy(target, {
|
|
25
|
-
get(obj, prop) {
|
|
26
|
-
const value = obj[prop];
|
|
27
|
-
// Only proxy functions
|
|
28
|
-
if (typeof value !== 'function') {
|
|
29
|
-
return value;
|
|
30
|
-
}
|
|
31
|
-
// Return a wrapped function
|
|
32
|
-
return async function (...args) {
|
|
33
|
-
// Call the original function
|
|
34
|
-
const result = await value.apply(this, args);
|
|
35
|
-
// If result is an object (response), enhance it
|
|
36
|
-
if (result && typeof result === 'object' && !Array.isArray(result)) {
|
|
37
|
-
// Initialize identity if needed
|
|
38
|
-
if (!identity) {
|
|
39
|
-
identity = await index_1.MCPIdentity.init();
|
|
40
|
-
}
|
|
41
|
-
// Create signature
|
|
42
|
-
const timestamp = new Date().toISOString();
|
|
43
|
-
const contentToSign = JSON.stringify({
|
|
44
|
-
...result,
|
|
45
|
-
_mcp_identity: {
|
|
46
|
-
did: identity.did,
|
|
47
|
-
timestamp,
|
|
48
|
-
conformanceLevel: 2
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
const signature = await identity.sign(contentToSign);
|
|
52
|
-
// Add identity using a symbol to avoid type conflicts
|
|
53
|
-
const identitySymbol = Symbol.for('_mcp_identity');
|
|
54
|
-
result[identitySymbol] = {
|
|
55
|
-
did: identity.did,
|
|
56
|
-
signature,
|
|
57
|
-
timestamp,
|
|
58
|
-
conformanceLevel: 2
|
|
59
|
-
};
|
|
60
|
-
// Override JSON serialization to include _mcp_identity
|
|
61
|
-
if (!result.toJSON) {
|
|
62
|
-
Object.defineProperty(result, 'toJSON', {
|
|
63
|
-
value: function () {
|
|
64
|
-
return {
|
|
65
|
-
...this,
|
|
66
|
-
_mcp_identity: this[identitySymbol]
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
enumerable: false,
|
|
70
|
-
configurable: true
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return result;
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Enhance an MCP server transparently
|
|
81
|
-
* Returns the same server instance with no type changes
|
|
82
|
-
*/
|
|
83
|
-
async function enhanceServer(server) {
|
|
84
|
-
// Initialize identity
|
|
85
|
-
if (!identity) {
|
|
86
|
-
identity = await index_1.MCPIdentity.init();
|
|
87
|
-
}
|
|
88
|
-
// Create a transparent proxy
|
|
89
|
-
return createTransparentProxy(server);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Wrap a server constructor to automatically enhance instances
|
|
93
|
-
*/
|
|
94
|
-
function wrapServerConstructor(ServerClass) {
|
|
95
|
-
return class extends ServerClass {
|
|
96
|
-
constructor(...args) {
|
|
97
|
-
super(...args);
|
|
98
|
-
// Schedule enhancement after construction
|
|
99
|
-
setImmediate(async () => {
|
|
100
|
-
// Replace this instance's methods with proxied versions
|
|
101
|
-
const proxy = await enhanceServer(this);
|
|
102
|
-
Object.setPrototypeOf(this, Object.getPrototypeOf(proxy));
|
|
103
|
-
Object.assign(this, proxy);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Alternative approach: Middleware pattern
|
|
110
|
-
* This allows users to wrap individual handlers
|
|
111
|
-
*/
|
|
112
|
-
function withIdentity(handler) {
|
|
113
|
-
return (async function (...args) {
|
|
114
|
-
// Initialize identity if needed
|
|
115
|
-
if (!identity) {
|
|
116
|
-
identity = await index_1.MCPIdentity.init();
|
|
117
|
-
}
|
|
118
|
-
// Call the original handler
|
|
119
|
-
const result = await handler(...args);
|
|
120
|
-
// If result is an object, add identity
|
|
121
|
-
if (result && typeof result === 'object' && !Array.isArray(result)) {
|
|
122
|
-
const timestamp = new Date().toISOString();
|
|
123
|
-
const contentToSign = JSON.stringify({
|
|
124
|
-
...result,
|
|
125
|
-
_mcp_identity: {
|
|
126
|
-
did: identity.did,
|
|
127
|
-
timestamp,
|
|
128
|
-
conformanceLevel: 2
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
const signature = await identity.sign(contentToSign);
|
|
132
|
-
// Use Object.assign to maintain the original type
|
|
133
|
-
return Object.assign(result, {
|
|
134
|
-
_mcp_identity: {
|
|
135
|
-
did: identity.did,
|
|
136
|
-
signature,
|
|
137
|
-
timestamp,
|
|
138
|
-
conformanceLevel: 2
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
return result;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Ultra-simple one-liner integration
|
|
147
|
-
* Usage: const server = await addIdentity(new Server(...));
|
|
148
|
-
*/
|
|
149
|
-
async function addIdentity(server) {
|
|
150
|
-
return enhanceServer(server);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Export the identity instance for direct access if needed
|
|
154
|
-
*/
|
|
155
|
-
function getIdentity() {
|
|
156
|
-
return identity;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Manual initialization (optional)
|
|
160
|
-
*/
|
|
161
|
-
async function init(options) {
|
|
162
|
-
if (!identity) {
|
|
163
|
-
identity = await index_1.MCPIdentity.init(options);
|
|
164
|
-
}
|
|
165
|
-
return identity;
|
|
166
|
-
}
|
|
167
|
-
//# sourceMappingURL=transparent.js.map
|
package/dist/transparent.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transparent.js","sourceRoot":"","sources":["../src/transparent.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAWH,wDA+DC;AAMD,sCAQC;AAKD,sDAgBC;AAMD,oCAqCC;AAMD,kCAEC;AAKD,kCAEC;AAKD,oBAKC;AA/KD,mCAAsC;AAEtC,2BAA2B;AAC3B,IAAI,QAAQ,GAAuB,IAAI,CAAC;AAExC;;;GAGG;AACH,SAAgB,sBAAsB,CAAmB,MAAS;IAChE,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;QACvB,GAAG,CAAC,GAAQ,EAAE,IAAqB;YACjC,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;YAExB,uBAAuB;YACvB,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;gBAChC,OAAO,KAAK,CAAC;YACf,CAAC;YAED,4BAA4B;YAC5B,OAAO,KAAK,WAAqB,GAAG,IAAW;gBAC7C,6BAA6B;gBAC7B,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAE7C,gDAAgD;gBAChD,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;oBACnE,gCAAgC;oBAChC,IAAI,CAAC,QAAQ,EAAE,CAAC;wBACd,QAAQ,GAAG,MAAM,mBAAW,CAAC,IAAI,EAAE,CAAC;oBACtC,CAAC;oBAED,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