@@ -13,11 +13,12 @@ import {
1313 TAG_EVENT_ID ,
1414 TAG_STATUS ,
1515 TAG_SERVER_IDENTIFIER ,
16+ MCPMETHODS ,
1617} from '@dvmcp/commons/core' ;
1718import { loggerBridge } from '@dvmcp/commons/core' ;
18- import { type NostrEvent , type EventTemplate , getEventHash } from 'nostr-tools' ;
19+ import { type NostrEvent , getEventHash } from 'nostr-tools' ;
1920import { getServerId } from './utils' ;
20- import { EncryptionManager } from '@dvmcp/commons/encryption' ;
21+ import { EncryptionManager , EncryptionMode } from '@dvmcp/commons/encryption' ;
2122import { EventPublisher } from '@dvmcp/commons/nostr' ;
2223
2324import { handleToolsList , handleToolsCall } from './handlers/tool-handlers' ;
@@ -203,7 +204,7 @@ export class DVMBridge {
203204 private async decryptEventAndExtractSender (
204205 giftWrapEvent : NostrEvent
205206 ) : Promise < {
206- eventTemplate : EventTemplate ;
207+ eventTemplate : NostrEvent ;
207208 realSenderPubkey : string ;
208209 } | null > {
209210 try {
@@ -221,15 +222,8 @@ export class DVMBridge {
221222 return null ;
222223 }
223224
224- const eventTemplate : EventTemplate = {
225- kind : decryptionResult . decryptedEvent . kind ,
226- content : decryptionResult . decryptedEvent . content ,
227- tags : decryptionResult . decryptedEvent . tags ,
228- created_at : decryptionResult . decryptedEvent . created_at ,
229- } ;
230-
231225 return {
232- eventTemplate,
226+ eventTemplate : decryptionResult . decryptedEvent ,
233227 realSenderPubkey : decryptionResult . sender ,
234228 } ;
235229 } catch ( error ) {
@@ -281,7 +275,9 @@ export class DVMBridge {
281275 }
282276
283277 // Handle regular unencrypted events
284- await this . processRegularRequest ( event ) ;
278+ if ( this . config . encryption ?. mode !== EncryptionMode . REQUIRED ) {
279+ await this . processRegularRequest ( event ) ;
280+ }
285281 } catch ( error ) {
286282 console . error ( 'Error handling request:' , error ) ;
287283 }
@@ -392,17 +388,17 @@ export class DVMBridge {
392388 } ;
393389
394390 switch ( method ) {
395- case ' initialize' :
391+ case MCPMETHODS . initialize :
396392 break ;
397- case ' ping' :
393+ case MCPMETHODS . ping :
398394 await handlePing (
399395 event ,
400396 this . keyManager ,
401397 this . relayHandler ,
402398 responseContext
403399 ) ;
404400 break ;
405- case 'tools/list' :
401+ case MCPMETHODS . toolsList :
406402 await handleToolsList (
407403 event ,
408404 this . mcpPool ,
@@ -411,7 +407,7 @@ export class DVMBridge {
411407 responseContext
412408 ) ;
413409 break ;
414- case 'tools/call' :
410+ case MCPMETHODS . toolsCall :
415411 await handleToolsCall (
416412 event ,
417413 this . mcpPool ,
@@ -421,7 +417,7 @@ export class DVMBridge {
421417 responseContext
422418 ) ;
423419 break ;
424- case 'resources/list' :
420+ case MCPMETHODS . resourcesList :
425421 await handleResourcesList (
426422 event ,
427423 this . mcpPool ,
@@ -430,7 +426,7 @@ export class DVMBridge {
430426 responseContext
431427 ) ;
432428 break ;
433- case 'resources/read' :
429+ case MCPMETHODS . resourcesRead :
434430 await handleResourcesRead (
435431 event ,
436432 this . mcpPool ,
@@ -440,7 +436,7 @@ export class DVMBridge {
440436 responseContext
441437 ) ;
442438 break ;
443- case 'resources/templates/list' :
439+ case MCPMETHODS . resourcesTemplatesList :
444440 await handleResourceTemplatesList (
445441 event ,
446442 this . mcpPool ,
@@ -449,7 +445,7 @@ export class DVMBridge {
449445 responseContext
450446 ) ;
451447 break ;
452- case 'prompts/list' :
448+ case MCPMETHODS . promptsList :
453449 await handlePromptsList (
454450 event ,
455451 this . mcpPool ,
@@ -458,7 +454,7 @@ export class DVMBridge {
458454 responseContext
459455 ) ;
460456 break ;
461- case 'prompts/get' :
457+ case MCPMETHODS . promptsGet :
462458 await handlePromptsGet (
463459 event ,
464460 this . mcpPool ,
@@ -467,7 +463,7 @@ export class DVMBridge {
467463 responseContext
468464 ) ;
469465 break ;
470- case 'completion/complete' :
466+ case MCPMETHODS . completionComplete :
471467 await handleCompletionComplete (
472468 event ,
473469 this . mcpPool ,
@@ -494,7 +490,7 @@ export class DVMBridge {
494490 await this . publishResponse ( notImpl , responseContext ) ;
495491 }
496492 } else if ( kind === NOTIFICATION_KIND ) {
497- if ( method === 'notifications/cancel' ) {
493+ if ( method === MCPMETHODS . notificationsCancel ) {
498494 const shouldEncryptResponse =
499495 this . encryptionManager ?. shouldEncryptResponse ( isEncrypted ) || false ;
500496
0 commit comments