@contextvm/sdk 0.1.11 → 0.1.13
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 +19 -143
- package/dist/esm/core/constants.d.ts +4 -0
- package/dist/esm/core/constants.d.ts.map +1 -1
- package/dist/esm/core/constants.js +4 -0
- package/dist/esm/core/constants.js.map +1 -1
- package/dist/esm/core/encryption.d.ts +4 -3
- package/dist/esm/core/encryption.d.ts.map +1 -1
- package/dist/esm/core/encryption.js +10 -6
- package/dist/esm/core/encryption.js.map +1 -1
- package/dist/esm/core/interfaces.d.ts +10 -3
- package/dist/esm/core/interfaces.d.ts.map +1 -1
- package/dist/esm/core/utils/logger.d.ts +24 -0
- package/dist/esm/core/utils/logger.d.ts.map +1 -0
- package/dist/esm/core/utils/logger.js +60 -0
- package/dist/esm/core/utils/logger.js.map +1 -0
- package/dist/esm/core/utils/serializers.d.ts +2 -3
- package/dist/esm/core/utils/serializers.d.ts.map +1 -1
- package/dist/esm/core/utils/serializers.js +5 -3
- package/dist/esm/core/utils/serializers.js.map +1 -1
- package/dist/esm/core/utils/utils.d.ts +14 -0
- package/dist/esm/core/utils/utils.d.ts.map +1 -1
- package/dist/esm/core/utils/utils.js +25 -0
- package/dist/esm/core/utils/utils.js.map +1 -1
- package/dist/esm/gateway/index.d.ts.map +1 -1
- package/dist/esm/gateway/index.js +12 -8
- package/dist/esm/gateway/index.js.map +1 -1
- package/dist/esm/proxy/index.d.ts.map +1 -1
- package/dist/esm/proxy/index.js +10 -8
- package/dist/esm/proxy/index.js.map +1 -1
- package/dist/esm/relay/simple-relay-pool.d.ts +17 -0
- package/dist/esm/relay/simple-relay-pool.d.ts.map +1 -1
- package/dist/esm/relay/simple-relay-pool.js +81 -7
- package/dist/esm/relay/simple-relay-pool.js.map +1 -1
- package/dist/esm/signer/private-key-signer.d.ts +7 -1
- package/dist/esm/signer/private-key-signer.d.ts.map +1 -1
- package/dist/esm/signer/private-key-signer.js +14 -3
- package/dist/esm/signer/private-key-signer.js.map +1 -1
- package/dist/esm/transport/base-nostr-transport.d.ts +2 -2
- package/dist/esm/transport/base-nostr-transport.d.ts.map +1 -1
- package/dist/esm/transport/base-nostr-transport.js +21 -2
- package/dist/esm/transport/base-nostr-transport.js.map +1 -1
- package/dist/esm/transport/nostr-client-transport.d.ts +2 -6
- package/dist/esm/transport/nostr-client-transport.d.ts.map +1 -1
- package/dist/esm/transport/nostr-client-transport.js +10 -8
- package/dist/esm/transport/nostr-client-transport.js.map +1 -1
- package/dist/esm/transport/nostr-server-transport.d.ts.map +1 -1
- package/dist/esm/transport/nostr-server-transport.js +11 -8
- package/dist/esm/transport/nostr-server-transport.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ContextVM SDK
|
|
2
2
|
|
|
3
|
-
A JavaScript/TypeScript SDK that implements the Context Vending Machine
|
|
3
|
+
A JavaScript/TypeScript SDK that implements the Context Vending Machine Protocol, bridging Nostr and Model Context Protocol (MCP) to enable decentralized access and exposure of computational services.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
The
|
|
7
|
+
The ContextVM Protocol defines how Nostr and Model Context Machines can be used to expose MCP server capabilities, enabling standardized usage of these resources through a decentralized, cryptographically secure messaging system.
|
|
8
8
|
|
|
9
|
-
This SDK provides the necessary components to interact with the
|
|
9
|
+
This SDK provides the necessary components to interact with the ContextVM Protocol:
|
|
10
10
|
|
|
11
11
|
- **Core Module**: Contains fundamental definitions, constants, interfaces, and utilities (e.g., encryption, serialization).
|
|
12
12
|
- **Transports**: Critical for communication, providing `NostrClientTransport` and `NostrServerTransport` implementations for enabling MCP over Nostr.
|
|
@@ -19,158 +19,34 @@ Both the Proxy and Gateway leverage Nostr transports, allowing existing MCP serv
|
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
1. **Clone the repository:**
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
git clone https://github.com/ContextVM/ts-sdk.git
|
|
28
|
-
cd ts-sdk
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
2. **Install dependencies:**
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
bun install
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
3. **Build the project:**
|
|
38
|
-
```bash
|
|
39
|
-
bun run build
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Usage
|
|
43
|
-
|
|
44
|
-
The SDK provides methods for bridging MCP and Nostr. At its core, the SDK relies on Nostr transports and utilities to facilitate communication.
|
|
45
|
-
|
|
46
|
-
### Core Building Blocks: Signers and Relay Pools
|
|
47
|
-
|
|
48
|
-
The SDK provides default implementations: `PrivateKeySigner` implements the `NostrSigner` interface, and `SimpleRelayPool` implements the `RelayHandler` interface. You can extend the SDK's capabilities by creating custom implementations that satisfy these interfaces, allowing you to integrate with different signing mechanisms or relay management logic.ª
|
|
49
|
-
|
|
50
|
-
### Nostr Transports
|
|
51
|
-
|
|
52
|
-
The SDK provides specialized transports to send and receive MCP messages over the Nostr network.
|
|
53
|
-
|
|
54
|
-
#### `NostrClientTransport`
|
|
55
|
-
|
|
56
|
-
Used by MCP clients to connect to remote MCP servers exposed via Nostr.
|
|
57
|
-
|
|
58
|
-
```typescript
|
|
59
|
-
import { Client } from '@modelcontextprotocol/sdk/client';
|
|
60
|
-
import { NostrClientTransport } from '@ctxvm/sdk/transport';
|
|
61
|
-
import { EncryptionMode } from '@ctxvm/sdk/core';
|
|
62
|
-
|
|
63
|
-
// Public key of the target MCP server on Nostr
|
|
64
|
-
const REMOTE_SERVER_PUBKEY = 'remote_server_public_key_here';
|
|
65
|
-
|
|
66
|
-
const clientNostrTransport = new NostrClientTransport({
|
|
67
|
-
signer: signer, // Your NostrSigner instance
|
|
68
|
-
relayHandler: relayPool, // Your RelayHandler instance
|
|
69
|
-
serverPubkey: REMOTE_SERVER_PUBKEY, // Public key of the target MCP server
|
|
70
|
-
encryptionMode: EncryptionMode.OPTIONAL, // Optional: REQUIRED, OPTIONAL (default), or DISABLED
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const mcpClient = new Client();
|
|
74
|
-
|
|
75
|
-
// To connect the MCP client:
|
|
76
|
-
await mcpClient.connect(clientNostrTransport);
|
|
77
|
-
// Subsequent MCP calls (e.g., listTools, callTool) would use this transport.
|
|
78
|
-
await mcpClient.listTools();
|
|
79
|
-
// await mcpClient.close();
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
#### `NostrServerTransport`
|
|
83
|
-
|
|
84
|
-
Used by MCP servers to expose their capabilities to Nostr clients.
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server';
|
|
88
|
-
import { NostrServerTransport } from '@ctxvm/sdk/transport';
|
|
89
|
-
import { EncryptionMode } from '@ctxvm/sdk/core';
|
|
90
|
-
// Assume signer and relayPool are configured as shown above.
|
|
91
|
-
|
|
92
|
-
const server = new McpServer({
|
|
93
|
-
name: 'demo-server',
|
|
94
|
-
version: '1.0.0',
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Before connecting, register your MCP server's capabilities.
|
|
98
|
-
|
|
99
|
-
const serverNostrTransport = new NostrServerTransport({
|
|
100
|
-
signer: signer, // Server's NostrSigner instance
|
|
101
|
-
relayHandler: relayPool, // Server's RelayHandler instance
|
|
102
|
-
isPublicServer: true, // Optional: set to true to announce server capabilities via Nostr events
|
|
103
|
-
encryptionMode: EncryptionMode.OPTIONAL, // Optional: REQUIRED, OPTIONAL (default), or DISABLED
|
|
104
|
-
serverInfo: {
|
|
105
|
-
// Optional: Information for public announcements
|
|
106
|
-
name: 'Nostr MCP Example Server',
|
|
107
|
-
website: 'https://example.com/mcp-server',
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// To connect the MCP server and make it available via Nostr:
|
|
112
|
-
await mcpServer.connect(serverNostrTransport);
|
|
113
|
-
// This will keep the server running and listening for Nostr events.
|
|
114
|
-
// To gracefully shut down: await mcpServer.close();
|
|
22
|
+
```bash
|
|
23
|
+
npm install @contextvm/sdk
|
|
115
24
|
```
|
|
116
25
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
The SDK also provides higher-level components that leverage these transports to bridge conventional MCP setups with Nostr.
|
|
26
|
+
**Note:** You can use your preferred package manager to install the SDK.
|
|
120
27
|
|
|
121
|
-
|
|
28
|
+
## Usage
|
|
122
29
|
|
|
123
|
-
|
|
30
|
+
Visit the [ContextVM documentation](https://contextvm.org) for information on how to use ContextVM.
|
|
124
31
|
|
|
125
|
-
|
|
126
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/stdio';
|
|
127
|
-
import { NostrMCPProxy } from '@ctxvm/sdk/proxy';
|
|
32
|
+
## Development
|
|
128
33
|
|
|
129
|
-
|
|
130
|
-
const hostTransport = new StdioServerTransport();
|
|
34
|
+
This project requires [Bun](https://bun.sh/) (version 1.2.0 or higher).
|
|
131
35
|
|
|
132
|
-
|
|
133
|
-
mcpHostTransport: hostTransport, // Your local client's transport
|
|
134
|
-
nostrTransportOptions: {
|
|
135
|
-
signer: signer,
|
|
136
|
-
relayHandler: relayPool,
|
|
137
|
-
serverPubkey: REMOTE_SERVER_PUBKEY, // Target the remote MCP server public key via Nostr
|
|
138
|
-
},
|
|
139
|
-
});
|
|
36
|
+
1. Clone the repository:
|
|
140
37
|
|
|
141
|
-
|
|
142
|
-
|
|
38
|
+
```bash
|
|
39
|
+
git clone https://github.com/ContextVM/ts-sdk.git
|
|
40
|
+
cd ts-sdk
|
|
143
41
|
```
|
|
144
42
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
Allows an existing MCP server (e.g., communicating via a mcp transport) to expose its capabilities through Nostr. The gateway uses `NostrServerTransport` internally.
|
|
43
|
+
2. Install dependencies:
|
|
148
44
|
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
import { NostrMCPGateway } from '@ctxvm/sdk/gateway';
|
|
152
|
-
|
|
153
|
-
// This transport defines how the Gateway connects to your traditional MCP server.
|
|
154
|
-
const serverTransport = new StdioClientTransport({
|
|
155
|
-
command: 'bun',
|
|
156
|
-
args: ['path/to/your/mcp-server.ts'],
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
const gateway = new NostrMCPGateway({
|
|
160
|
-
mcpServerTransport: serverTransport, // Your existing MCP server's transport
|
|
161
|
-
nostrTransportOptions: {
|
|
162
|
-
signer: signer,
|
|
163
|
-
relayHandler: relayPool,
|
|
164
|
-
isPublicServer: true, // Set to true to announce server capabilities to Nostr clients for discovery
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// To start the gateway and expose your MCP server to Nostr clients:
|
|
169
|
-
await gateway.start();
|
|
170
|
-
// The gateway will run indefinitely, relaying messages between Nostr and your MCP server.
|
|
45
|
+
```bash
|
|
46
|
+
bun install
|
|
171
47
|
```
|
|
172
48
|
|
|
173
|
-
|
|
49
|
+
### Running Tests
|
|
174
50
|
|
|
175
51
|
To run the test suite, use Bun:
|
|
176
52
|
|
|
@@ -62,4 +62,8 @@ export declare const NOSTR_TAGS: {
|
|
|
62
62
|
readonly SUPPORT_ENCRYPTION: "support_encryption";
|
|
63
63
|
};
|
|
64
64
|
export declare const announcementMethods: AnnouncementMethods;
|
|
65
|
+
/**
|
|
66
|
+
* Maximum allowed message size in bytes (1MB)
|
|
67
|
+
*/
|
|
68
|
+
export declare const MAX_MESSAGE_SIZE: number;
|
|
65
69
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/core/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,QAAQ,CAAC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C"}
|
|
@@ -67,4 +67,8 @@ export const announcementMethods = {
|
|
|
67
67
|
resourceTemplates: 'resources/templates/list',
|
|
68
68
|
prompts: 'prompts/list',
|
|
69
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Maximum allowed message size in bytes (1MB)
|
|
72
|
+
*/
|
|
73
|
+
export const MAX_MESSAGE_SIZE = 1024 * 1024;
|
|
70
74
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/core/constants.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AAEnC;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,GAAG;IACX;;OAEG;IACH,QAAQ,EAAE,GAAG;IACb;;OAEG;IACH,UAAU,EAAE,KAAK;IACjB;;OAEG;IACH,IAAI,EAAE,MAAM;IACZ;;OAEG;IACH,OAAO,EAAE,SAAS;IAClB;;OAEG;IACH,OAAO,EAAE,SAAS;IAClB;;OAEG;IACH,kBAAkB,EAAE,oBAAoB;CAChC,CAAC;AAEX,MAAM,CAAC,MAAM,mBAAmB,GAAwB;IACtD,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,YAAY;IACnB,SAAS,EAAE,gBAAgB;IAC3B,iBAAiB,EAAE,0BAA0B;IAC7C,OAAO,EAAE,cAAc;CACf,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/core/constants.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AAEnC;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEvC;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,GAAG;IACX;;OAEG;IACH,QAAQ,EAAE,GAAG;IACb;;OAEG;IACH,UAAU,EAAE,KAAK;IACjB;;OAEG;IACH,IAAI,EAAE,MAAM;IACZ;;OAEG;IACH,OAAO,EAAE,SAAS;IAClB;;OAEG;IACH,OAAO,EAAE,SAAS;IAClB;;OAEG;IACH,kBAAkB,EAAE,oBAAoB;CAChC,CAAC;AAEX,MAAM,CAAC,MAAM,mBAAmB,GAAwB;IACtD,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,YAAY;IACnB,SAAS,EAAE,gBAAgB;IAC3B,iBAAiB,EAAE,0BAA0B;IAC7C,OAAO,EAAE,cAAc;CACf,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NostrEvent } from 'nostr-tools/pure';
|
|
2
|
+
import { NostrSigner } from './interfaces.js';
|
|
2
3
|
/**
|
|
3
4
|
* Encrypts a JSON-RPC message using a simplified NIP-17/NIP-59 gift wrap scheme.
|
|
4
5
|
* The message is encrypted with NIP-44 and wrapped in a kind 1059 event.
|
|
@@ -8,11 +9,11 @@ import { NostrEvent } from 'nostr-tools/pure';
|
|
|
8
9
|
*/
|
|
9
10
|
export declare function encryptMessage(message: string, recipientPublicKey: string): NostrEvent;
|
|
10
11
|
/**
|
|
11
|
-
* Decrypts a gift-wrapped Nostr event.
|
|
12
|
+
* Decrypts a gift-wrapped Nostr event using the signer's decryption methods.
|
|
12
13
|
* @param event The gift wrap event (kind 1059).
|
|
13
|
-
* @param
|
|
14
|
+
* @param signer The NostrSigner instance for decryption.
|
|
14
15
|
* @returns The decrypted message content.
|
|
15
16
|
* @throws If the event is not a valid gift wrap or decryption fails.
|
|
16
17
|
*/
|
|
17
|
-
export declare function decryptMessage(event: NostrEvent,
|
|
18
|
+
export declare function decryptMessage(event: NostrEvent, signer: NostrSigner): Promise<string>;
|
|
18
19
|
//# sourceMappingURL=encryption.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../../src/core/encryption.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,UAAU,EACX,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../../src/core/encryption.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,UAAU,EACX,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,kBAAkB,EAAE,MAAM,GACzB,UAAU,CAiBZ;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,CAAC,CAcjB"}
|
|
@@ -23,18 +23,22 @@ export function encryptMessage(message, recipientPublicKey) {
|
|
|
23
23
|
return finalizeEvent(giftWrap, giftWrapPrivateKey);
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* Decrypts a gift-wrapped Nostr event.
|
|
26
|
+
* Decrypts a gift-wrapped Nostr event using the signer's decryption methods.
|
|
27
27
|
* @param event The gift wrap event (kind 1059).
|
|
28
|
-
* @param
|
|
28
|
+
* @param signer The NostrSigner instance for decryption.
|
|
29
29
|
* @returns The decrypted message content.
|
|
30
30
|
* @throws If the event is not a valid gift wrap or decryption fails.
|
|
31
31
|
*/
|
|
32
|
-
export function decryptMessage(event,
|
|
32
|
+
export async function decryptMessage(event, signer) {
|
|
33
|
+
var _a;
|
|
33
34
|
if (event.kind !== GIFT_WRAP_KIND) {
|
|
34
35
|
throw new Error('Event is not a gift wrap.');
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
// Use the signer's nip44 decryption if available
|
|
38
|
+
if ((_a = signer.nip44) === null || _a === void 0 ? void 0 : _a.decrypt) {
|
|
39
|
+
return await signer.nip44.decrypt(event.pubkey, event.content);
|
|
40
|
+
}
|
|
41
|
+
// If no nip44 support, throw an error since we can't access the private key directly
|
|
42
|
+
throw new Error('Signer does not support NIP-44 decryption. Please use a signer with nip44 support.');
|
|
39
43
|
}
|
|
40
44
|
//# sourceMappingURL=encryption.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../../src/core/encryption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,YAAY,GAEb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"encryption.js","sourceRoot":"","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MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACjE,CAAC;IAED,qFAAqF;IACrF,MAAM,IAAI,KAAK,CACb,oFAAoF,CACrF,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InitializeRequest, ListPromptsRequest, ListResourcesRequest, ListResourceTemplatesRequest, ListToolsRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
import type { Filter, NostrEvent } from 'nostr-tools';
|
|
2
|
+
import type { EventTemplate, Filter, NostrEvent } from 'nostr-tools';
|
|
3
3
|
/**
|
|
4
4
|
* Defines the encryption mode for the transport.
|
|
5
5
|
* - `optional`: Encrypts messages if the incoming message was encrypted.
|
|
@@ -16,8 +16,15 @@ export declare enum EncryptionMode {
|
|
|
16
16
|
*/
|
|
17
17
|
export interface NostrSigner {
|
|
18
18
|
getPublicKey(): Promise<string>;
|
|
19
|
-
signEvent(event:
|
|
20
|
-
|
|
19
|
+
signEvent(event: EventTemplate): Promise<NostrEvent>;
|
|
20
|
+
nip04?: {
|
|
21
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
22
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
23
|
+
};
|
|
24
|
+
nip44?: {
|
|
25
|
+
encrypt: (pubkey: string, plaintext: string) => Promise<string>;
|
|
26
|
+
decrypt: (pubkey: string, ciphertext: string) => Promise<string>;
|
|
27
|
+
};
|
|
21
28
|
}
|
|
22
29
|
/**
|
|
23
30
|
* A generic interface for Nostr relays.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/core/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;AAC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AI,CAAC,CAAC;IAChD,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,SAAS,CACP,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EACpC,MAAM,CAAC,EAAE,MAAM,IAAI,GAClB,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,WAAW,IAAI,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACpC,KAAK,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAClC,SAAS,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC1C,iBAAiB,EAAE,4BAA4B,CAAC,QAAQ,CAAC,CAAC;IAC1D,OAAO,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAC;CACvC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
2
|
+
export interface LogEntry {
|
|
3
|
+
level: LogLevel;
|
|
4
|
+
timestamp: string;
|
|
5
|
+
module: string;
|
|
6
|
+
message: string;
|
|
7
|
+
data?: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface Logger {
|
|
10
|
+
debug(message: string, data?: unknown): void;
|
|
11
|
+
info(message: string, data?: unknown): void;
|
|
12
|
+
warn(message: string, data?: unknown): void;
|
|
13
|
+
error(message: string, data?: unknown): void;
|
|
14
|
+
withModule(newModule: string): Logger;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a logger for the specified module with configurable log level
|
|
18
|
+
*/
|
|
19
|
+
export declare function createLogger(module: string, minLevel?: LogLevel): Logger;
|
|
20
|
+
/**
|
|
21
|
+
* Default logger instance for the application
|
|
22
|
+
*/
|
|
23
|
+
export declare const logger: Logger;
|
|
24
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,QAAQ,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7C,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;CACvC;AASD;;GAEG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,QAAQ,GAAE,QAAiB,GAC1B,MAAM,CAwCR;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,QAAyD,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const LOG_LEVELS = {
|
|
2
|
+
debug: 0,
|
|
3
|
+
info: 1,
|
|
4
|
+
warn: 2,
|
|
5
|
+
error: 3,
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Creates a logger for the specified module with configurable log level
|
|
9
|
+
*/
|
|
10
|
+
export function createLogger(module, minLevel = 'info') {
|
|
11
|
+
const minLevelValue = LOG_LEVELS[minLevel];
|
|
12
|
+
const shouldLog = (level) => LOG_LEVELS[level] >= minLevelValue;
|
|
13
|
+
const formatMessage = (entry) => {
|
|
14
|
+
const { level, timestamp, module, message, data } = entry;
|
|
15
|
+
let formatted = `[${timestamp}] [${level.toUpperCase()}] [${module}] ${message}`;
|
|
16
|
+
if (data !== undefined) {
|
|
17
|
+
const dataStr = typeof data === 'string' ? data : JSON.stringify(data);
|
|
18
|
+
formatted += ` ${dataStr}`;
|
|
19
|
+
}
|
|
20
|
+
return formatted;
|
|
21
|
+
};
|
|
22
|
+
const log = (level, message, data) => {
|
|
23
|
+
if (!shouldLog(level))
|
|
24
|
+
return;
|
|
25
|
+
const entry = {
|
|
26
|
+
level,
|
|
27
|
+
timestamp: new Date().toISOString(),
|
|
28
|
+
module,
|
|
29
|
+
message,
|
|
30
|
+
data,
|
|
31
|
+
};
|
|
32
|
+
console.error(formatMessage(entry));
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
debug: (message, data) => log('debug', message, data),
|
|
36
|
+
info: (message, data) => log('info', message, data),
|
|
37
|
+
warn: (message, data) => log('warn', message, data),
|
|
38
|
+
error: (message, data) => log('error', message, data),
|
|
39
|
+
withModule: (newModule) => createLogger(newModule, minLevel),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Default logger instance for the application
|
|
44
|
+
*/
|
|
45
|
+
export const logger = createLogger('ctxvm', getLogLevelFromEnv() || 'error');
|
|
46
|
+
/**
|
|
47
|
+
* Get log level from environment variables, handling both Node.js and browser environments
|
|
48
|
+
*/
|
|
49
|
+
function getLogLevelFromEnv() {
|
|
50
|
+
if (typeof process !== 'undefined' && process.env && process.env.LOG_LEVEL) {
|
|
51
|
+
return process.env.LOG_LEVEL;
|
|
52
|
+
}
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
+
if (typeof window !== 'undefined' && window.LOG_LEVEL) {
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
+
return window.LOG_LEVEL;
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../src/core/utils/logger.ts"],"names":[],"mappings":"AAkBA,MAAM,UAAU,GAA6B;IAC3C,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAc,EACd,WAAqB,MAAM;IAE3B,MAAM,aAAa,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IAE3C,MAAM,SAAS,GAAG,CAAC,KAAe,EAAW,EAAE,CAC7C,UAAU,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC;IAErC,MAAM,aAAa,GAAG,CAAC,KAAe,EAAU,EAAE;QAChD,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;QAC1D,IAAI,SAAS,GAAG,IAAI,SAAS,MAAM,KAAK,CAAC,WAAW,EAAE,MAAM,MAAM,KAAK,OAAO,EAAE,CAAC;QAEjF,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,MAAM,OAAO,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACvE,SAAS,IAAI,IAAI,OAAO,EAAE,CAAC;QAC7B,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,MAAM,GAAG,GAAG,CAAC,KAAe,EAAE,OAAe,EAAE,IAAc,EAAQ,EAAE;QACrE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;YAA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B,CAAC;IAC/C,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -14,10 +14,9 @@ export declare function mcpToNostrEvent(mcpMessage: JSONRPCMessage, pubkey: stri
|
|
|
14
14
|
* Deserializes a Nostr event into an MCP message.
|
|
15
15
|
*
|
|
16
16
|
* @param event The Nostr event to deserialize.
|
|
17
|
-
* @returns An MCP request or response object
|
|
18
|
-
* @throws Error if the event content is not valid JSON
|
|
17
|
+
* @returns An MCP request or response object, or null if the event content is not valid JSON
|
|
19
18
|
*/
|
|
20
|
-
export declare function nostrEventToMcpMessage(event: NostrEvent): JSONRPCMessage;
|
|
19
|
+
export declare function nostrEventToMcpMessage(event: NostrEvent): JSONRPCMessage | null;
|
|
21
20
|
/**
|
|
22
21
|
* Extracts a specific tag from a Nostr event.
|
|
23
22
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializers.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/serializers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"serializers.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/serializers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAIzE;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,cAAc,EAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,MAAM,EAAE,EAAO,GACpB,aAAa,CAQf;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,UAAU,GAChB,cAAc,GAAG,IAAI,CAUvB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,EACxB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAGpB"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createLogger } from './logger.js';
|
|
2
|
+
const logger = createLogger('serializers');
|
|
1
3
|
/**
|
|
2
4
|
* Serializes an MCP message into a Nostr event object.
|
|
3
5
|
*
|
|
@@ -20,8 +22,7 @@ export function mcpToNostrEvent(mcpMessage, pubkey, kind, tags = []) {
|
|
|
20
22
|
* Deserializes a Nostr event into an MCP message.
|
|
21
23
|
*
|
|
22
24
|
* @param event The Nostr event to deserialize.
|
|
23
|
-
* @returns An MCP request or response object
|
|
24
|
-
* @throws Error if the event content is not valid JSON
|
|
25
|
+
* @returns An MCP request or response object, or null if the event content is not valid JSON
|
|
25
26
|
*/
|
|
26
27
|
export function nostrEventToMcpMessage(event) {
|
|
27
28
|
try {
|
|
@@ -29,7 +30,8 @@ export function nostrEventToMcpMessage(event) {
|
|
|
29
30
|
return content;
|
|
30
31
|
}
|
|
31
32
|
catch (error) {
|
|
32
|
-
|
|
33
|
+
logger.error(`Invalid JSON in Nostr event content: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
34
|
+
return null;
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializers.js","sourceRoot":"","sources":["../../../../src/core/utils/serializers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serializers.js","sourceRoot":"","sources":["../../../../src/core/utils/serializers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;AAC3C;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,UAA0B,EAC1B,MAAc,EACd,IAAY,EACZ,OAAmB,EAAE;IAErB,OAAO;QACL,MAAM;QACN,IAAI;QACJ,IAAI;QACJ,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;QACnC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;KAC1C,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAiB;IAEjB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1C,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CACV,wCAAwC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CACnG,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAwB,EACxB,OAAe;IAEf,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC;IAC/C,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClC,CAAC"}
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
+
import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sleeps for a specified number of milliseconds.
|
|
4
|
+
* @param ms The number of milliseconds to sleep.
|
|
5
|
+
* @returns A promise that resolves after the specified number of milliseconds.
|
|
6
|
+
*/
|
|
1
7
|
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* Validates message size
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateMessageSize(message: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Validates a message using the MCP SDK's schema
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateMessage(message: unknown): JSONRPCMessage | null;
|
|
2
16
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,GAAI,IAAI,MAAM,qBACmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEf,MAAM,oCAAoC,CAAC;AAG5C;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAI,IAAI,MAAM,qBACmB,CAAC;AAEpD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAG5D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAMvE"}
|
|
@@ -1,2 +1,27 @@
|
|
|
1
|
+
import { JSONRPCMessageSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { MAX_MESSAGE_SIZE } from '../constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Sleeps for a specified number of milliseconds.
|
|
5
|
+
* @param ms The number of milliseconds to sleep.
|
|
6
|
+
* @returns A promise that resolves after the specified number of milliseconds.
|
|
7
|
+
*/
|
|
1
8
|
export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
9
|
+
/**
|
|
10
|
+
* Validates message size
|
|
11
|
+
*/
|
|
12
|
+
export function validateMessageSize(message) {
|
|
13
|
+
const size = new Blob([message]).size;
|
|
14
|
+
return size <= MAX_MESSAGE_SIZE;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Validates a message using the MCP SDK's schema
|
|
18
|
+
*/
|
|
19
|
+
export function validateMessage(message) {
|
|
20
|
+
try {
|
|
21
|
+
return JSONRPCMessageSchema.parse(message);
|
|
22
|
+
}
|
|
23
|
+
catch (_a) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
2
27
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/core/utils/utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAClC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/core/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oBAAoB,GACrB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAClC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAEpD;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IACtC,OAAO,IAAI,IAAI,gBAAgB,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,IAAI,CAAC;QACH,OAAO,oBAAoB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/gateway/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,EAEL,2BAA2B,EAC5B,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/gateway/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,EAEL,2BAA2B,EAC5B,MAAM,wCAAwC,CAAC;AAKhD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,kGAAkG;IAClG,kBAAkB,EAAE,SAAS,CAAC;IAC9B,yDAAyD;IACzD,qBAAqB,EAAE,2BAA2B,CAAC;CACpD;AAED;;;;;;GAMG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAY;IAC/C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAuB;IAC5D,OAAO,CAAC,SAAS,CAAS;gBAEd,OAAO,EAAE,sBAAsB;IAS3C;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAsB1B;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAmBnC;;OAEG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBlC;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAIxB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;;OAGG;IACI,QAAQ,IAAI,OAAO;CAG3B"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { NostrServerTransport, } from '../transport/nostr-server-transport.js';
|
|
2
|
+
import { createLogger } from '../core/utils/logger.js';
|
|
3
|
+
const logger = createLogger('gateway');
|
|
2
4
|
/**
|
|
3
5
|
* The main gateway class that orchestrates communication between Nostr clients
|
|
4
6
|
* and a local MCP server. It acts as a bridge, receiving MCP requests via Nostr
|
|
@@ -19,6 +21,7 @@ export class NostrMCPGateway {
|
|
|
19
21
|
setupEventHandlers() {
|
|
20
22
|
// Forward messages from Nostr to the MCP server, handling any potential errors.
|
|
21
23
|
this.nostrServerTransport.onmessage = (message) => {
|
|
24
|
+
logger.debug('Received message from Nostr:', message);
|
|
22
25
|
this.mcpServerTransport
|
|
23
26
|
.send(message)
|
|
24
27
|
.catch(this.handleServerError.bind(this));
|
|
@@ -27,6 +30,7 @@ export class NostrMCPGateway {
|
|
|
27
30
|
this.nostrServerTransport.onclose = this.handleNostrClose.bind(this);
|
|
28
31
|
// Forward messages from the MCP server to the Nostr transport, handling any potential errors.
|
|
29
32
|
this.mcpServerTransport.onmessage = (message) => {
|
|
33
|
+
logger.debug('Received message from MCP server:', message);
|
|
30
34
|
this.nostrServerTransport
|
|
31
35
|
.send(message)
|
|
32
36
|
.catch(this.handleNostrError.bind(this));
|
|
@@ -46,10 +50,10 @@ export class NostrMCPGateway {
|
|
|
46
50
|
await this.mcpServerTransport.start();
|
|
47
51
|
await this.nostrServerTransport.start();
|
|
48
52
|
this.isRunning = true;
|
|
49
|
-
|
|
53
|
+
logger.info('NostrMCPGateway started successfully');
|
|
50
54
|
}
|
|
51
55
|
catch (error) {
|
|
52
|
-
|
|
56
|
+
logger.error('Failed to start NostrMCPGateway:', error);
|
|
53
57
|
await this.stop();
|
|
54
58
|
throw error;
|
|
55
59
|
}
|
|
@@ -66,10 +70,10 @@ export class NostrMCPGateway {
|
|
|
66
70
|
await this.nostrServerTransport.close();
|
|
67
71
|
await this.mcpServerTransport.close();
|
|
68
72
|
this.isRunning = false;
|
|
69
|
-
|
|
73
|
+
logger.info('NostrMCPGateway stopped successfully');
|
|
70
74
|
}
|
|
71
75
|
catch (error) {
|
|
72
|
-
|
|
76
|
+
logger.error('Error stopping NostrMCPGateway:', error);
|
|
73
77
|
throw error;
|
|
74
78
|
}
|
|
75
79
|
}
|
|
@@ -78,26 +82,26 @@ export class NostrMCPGateway {
|
|
|
78
82
|
* @param error The error that occurred.
|
|
79
83
|
*/
|
|
80
84
|
handleNostrError(error) {
|
|
81
|
-
|
|
85
|
+
logger.error('Nostr transport error:', error);
|
|
82
86
|
}
|
|
83
87
|
/**
|
|
84
88
|
* Handles the Nostr transport closing.
|
|
85
89
|
*/
|
|
86
90
|
handleNostrClose() {
|
|
87
|
-
|
|
91
|
+
logger.info('Nostr transport closed');
|
|
88
92
|
}
|
|
89
93
|
/**
|
|
90
94
|
* Handles errors from the MCP server transport.
|
|
91
95
|
* @param error The error that occurred.
|
|
92
96
|
*/
|
|
93
97
|
handleServerError(error) {
|
|
94
|
-
|
|
98
|
+
logger.error('MCP server transport error:', error);
|
|
95
99
|
}
|
|
96
100
|
/**
|
|
97
101
|
* Handles the MCP server transport closing.
|
|
98
102
|
*/
|
|
99
103
|
handleServerClose() {
|
|
100
|
-
|
|
104
|
+
logger.info('MCP server transport closed');
|
|
101
105
|
}
|
|
102
106
|
/**
|
|
103
107
|
* Gets the current status of the gateway.
|