mirror of
https://github.com/aljazceru/dvmcp.git
synced 2025-12-17 21:34:24 +01:00
fix: issue with config file
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { CONFIG } from './src/config';
|
import { getConfig } from './src/config';
|
||||||
import { DiscoveryServer } from './src/discovery-server';
|
import { DiscoveryServer } from './src/discovery-server';
|
||||||
import type { DVMAnnouncement } from './src/direct-discovery';
|
import type { DVMAnnouncement } from './src/direct-discovery';
|
||||||
|
|
||||||
@@ -9,7 +9,8 @@ export interface DirectServerInfo {
|
|||||||
|
|
||||||
async function main(directServerInfo?: DirectServerInfo | null) {
|
async function main(directServerInfo?: DirectServerInfo | null) {
|
||||||
try {
|
try {
|
||||||
const server = new DiscoveryServer(CONFIG);
|
const config = getConfig();
|
||||||
|
const server = new DiscoveryServer(config);
|
||||||
|
|
||||||
if (directServerInfo) {
|
if (directServerInfo) {
|
||||||
// If we have direct server info, register tools from that server only
|
// 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();
|
await server.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`DVMCP Discovery Server (${CONFIG.mcp.version}) started`);
|
console.log(`DVMCP Discovery Server (${config.mcp.version}) started`);
|
||||||
console.log(`Connected to ${CONFIG.nostr.relayUrls.length} relays`);
|
console.log(`Connected to ${config.nostr.relayUrls.length} relays`);
|
||||||
|
|
||||||
// Handle shutdown
|
// Handle shutdown
|
||||||
const cleanup = () => {
|
const cleanup = () => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@dvmcp/discovery",
|
"name": "@dvmcp/discovery",
|
||||||
"version": "0.1.15",
|
"version": "0.1.17",
|
||||||
"description": "Discovery service for MCP tools in the Nostr DVM ecosystem",
|
"description": "Discovery service for MCP tools in the Nostr DVM ecosystem",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|||||||
import { type Event, type Filter } from 'nostr-tools';
|
import { type Event, type Filter } from 'nostr-tools';
|
||||||
import { RelayHandler } from '@dvmcp/commons/nostr/relay-handler';
|
import { RelayHandler } from '@dvmcp/commons/nostr/relay-handler';
|
||||||
import { createKeyManager } from '@dvmcp/commons/nostr/key-manager';
|
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 { DVM_ANNOUNCEMENT_KIND } from '@dvmcp/commons/constants';
|
||||||
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
|
import type { Tool } from '@modelcontextprotocol/sdk/types.js';
|
||||||
import { ToolRegistry } from './tool-registry';
|
import { ToolRegistry } from './tool-registry';
|
||||||
@@ -77,13 +77,14 @@ export class DiscoveryServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private isAllowedDVM(pubkey: string): boolean {
|
private isAllowedDVM(pubkey: string): boolean {
|
||||||
|
const config = getConfig();
|
||||||
if (
|
if (
|
||||||
!CONFIG.whitelist?.allowedDVMs ||
|
!config.whitelist?.allowedDVMs ||
|
||||||
CONFIG.whitelist.allowedDVMs.size == 0
|
config.whitelist.allowedDVMs.size == 0
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return CONFIG.whitelist.allowedDVMs.has(pubkey);
|
return config.whitelist.allowedDVMs.has(pubkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseAnnouncement(content: string): DVMAnnouncement | null {
|
private parseAnnouncement(content: string): DVMAnnouncement | null {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { expect, test, describe, beforeAll, afterAll } from 'bun:test';
|
import { expect, test, describe, beforeAll, afterAll } from 'bun:test';
|
||||||
import { DiscoveryServer } from './discovery-server';
|
import { DiscoveryServer } from './discovery-server';
|
||||||
import { CONFIG } from './config';
|
import { getConfig } from './config';
|
||||||
import {
|
import {
|
||||||
server as mockRelay,
|
server as mockRelay,
|
||||||
stop as stopRelay,
|
stop as stopRelay,
|
||||||
@@ -15,10 +15,11 @@ describe('DiscoveryServer E2E', () => {
|
|||||||
mockRelay;
|
mockRelay;
|
||||||
relayConnected = true;
|
relayConnected = true;
|
||||||
|
|
||||||
|
const config = getConfig();
|
||||||
const testConfig = {
|
const testConfig = {
|
||||||
...CONFIG,
|
...config,
|
||||||
nostr: {
|
nostr: {
|
||||||
...CONFIG.nostr,
|
...config.nostr,
|
||||||
relayUrls: ['ws://localhost:3334'],
|
relayUrls: ['ws://localhost:3334'],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user