fix: issue with config file

This commit is contained in:
gzuuus
2025-03-25 18:47:38 +01:00
parent 93a8c49563
commit d44ab2fe27
5 changed files with 23 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
import { CONFIG } from './src/config';
import { getConfig } from './src/config';
import { DiscoveryServer } from './src/discovery-server';
import type { DVMAnnouncement } from './src/direct-discovery';
@@ -9,7 +9,8 @@ export interface DirectServerInfo {
async function main(directServerInfo?: DirectServerInfo | null) {
try {
const server = new DiscoveryServer(CONFIG);
const config = getConfig();
const server = new DiscoveryServer(config);
if (directServerInfo) {
// If we have direct server info, register tools from that server only
@@ -25,8 +26,8 @@ async function main(directServerInfo?: DirectServerInfo | null) {
await server.start();
}
console.log(`DVMCP Discovery Server (${CONFIG.mcp.version}) started`);
console.log(`Connected to ${CONFIG.nostr.relayUrls.length} relays`);
console.log(`DVMCP Discovery Server (${config.mcp.version}) started`);
console.log(`Connected to ${config.nostr.relayUrls.length} relays`);
// Handle shutdown
const cleanup = () => {

View File

@@ -1,6 +1,6 @@
{
"name": "@dvmcp/discovery",
"version": "0.1.15",
"version": "0.1.17",
"description": "Discovery service for MCP tools in the Nostr DVM ecosystem",
"module": "index.ts",
"type": "module",

View File

@@ -154,4 +154,11 @@ export function createDefaultConfig(relayUrls: string[]): Config {
};
}
export const CONFIG = loadConfig();
let _CONFIG: Config | null = null;
export function getConfig(): Config {
if (!_CONFIG) {
_CONFIG = loadConfig();
}
return _CONFIG;
}

View File

@@ -3,7 +3,7 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
import { type Event, type Filter } from 'nostr-tools';
import { RelayHandler } from '@dvmcp/commons/nostr/relay-handler';
import { createKeyManager } from '@dvmcp/commons/nostr/key-manager';
import { CONFIG, type Config } from './config';
import { getConfig, type Config } from './config';
import { DVM_ANNOUNCEMENT_KIND } from '@dvmcp/commons/constants';
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
import { ToolRegistry } from './tool-registry';
@@ -77,13 +77,14 @@ export class DiscoveryServer {
}
private isAllowedDVM(pubkey: string): boolean {
const config = getConfig();
if (
!CONFIG.whitelist?.allowedDVMs ||
CONFIG.whitelist.allowedDVMs.size == 0
!config.whitelist?.allowedDVMs ||
config.whitelist.allowedDVMs.size == 0
) {
return true;
}
return CONFIG.whitelist.allowedDVMs.has(pubkey);
return config.whitelist.allowedDVMs.has(pubkey);
}
private parseAnnouncement(content: string): DVMAnnouncement | null {

View File

@@ -1,6 +1,6 @@
import { expect, test, describe, beforeAll, afterAll } from 'bun:test';
import { DiscoveryServer } from './discovery-server';
import { CONFIG } from './config';
import { getConfig } from './config';
import {
server as mockRelay,
stop as stopRelay,
@@ -15,10 +15,11 @@ describe('DiscoveryServer E2E', () => {
mockRelay;
relayConnected = true;
const config = getConfig();
const testConfig = {
...CONFIG,
...config,
nostr: {
...CONFIG.nostr,
...config.nostr,
relayUrls: ['ws://localhost:3334'],
},
};