This repository was archived by the owner on Jul 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.ts
More file actions
96 lines (81 loc) · 3.18 KB
/
Copy pathindex.ts
File metadata and controls
96 lines (81 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { loadDiscoveryConfig } from './src/config-loader';
import { DiscoveryServer } from './src/discovery-server';
import { UnifiedRegistration } from './src/unified-registration';
import { loggerDiscovery as logger } from '@dvmcp/commons/core';
import type { DvmcpDiscoveryConfig } from './src/config-schema';
import type { InitializeResult } from '@modelcontextprotocol/sdk/types.js';
export interface DirectServerInfo {
pubkey: string;
announcement: InitializeResult | null;
serverId?: string;
}
async function main(
directServerInfo?: DirectServerInfo | null,
preloadedConfig?: DvmcpDiscoveryConfig
) {
try {
const config = preloadedConfig || (await loadDiscoveryConfig());
const server = new DiscoveryServer(config);
if (directServerInfo) {
logger(`Using direct server with pubkey: ${directServerInfo.pubkey}`);
// Use unified registration for direct servers
const source = UnifiedRegistration.createDirectSource(
directServerInfo.pubkey,
directServerInfo.serverId!,
false // Default to no encryption support for direct servers
);
// Prepare capabilities from the announcement
const tools = Array.isArray(directServerInfo.announcement?.tools)
? directServerInfo.announcement.tools
: Array.isArray(directServerInfo.announcement?.capabilities?.tools)
? directServerInfo.announcement.capabilities.tools
: [];
const resources = Array.isArray(directServerInfo.announcement?.resources)
? directServerInfo.announcement.resources
: [];
const resourceTemplates = Array.isArray(
directServerInfo.announcement?.resourceTemplates
)
? directServerInfo.announcement.resourceTemplates
: [];
const prompts = Array.isArray(directServerInfo.announcement?.prompts)
? directServerInfo.announcement.prompts
: [];
const capabilities = {
serverInfo: directServerInfo.announcement!,
tools: tools.length > 0 ? tools : undefined,
resources: resources.length > 0 ? resources : undefined,
resourceTemplates:
resourceTemplates.length > 0 ? resourceTemplates : undefined,
prompts: prompts.length > 0 ? prompts : undefined,
};
// Register capabilities using unified registration
const stats = await server
.getUnifiedRegistration()
.registerServerCapabilities(source, capabilities);
logger(
`Direct server registration complete: ` +
`${stats.toolsCount} tools, ` +
`${stats.resourcesCount} resources, ` +
`${stats.resourceTemplatesCount} resource templates, ` +
`${stats.promptsCount} prompts`
);
// Start the MCP server
await server.start();
} else {
await server.start();
}
logger(`DVMCP Discovery Server (${config.mcp.version}) started`);
logger(`Connected to ${config.nostr.relayUrls.length} relays`);
const cleanup = () => {
server.cleanup();
process.exit(0);
};
process.on('SIGINT', cleanup);
process.on('SIGTERM', cleanup);
} catch (error) {
console.error('Failed to start server:', error);
process.exit(1);
}
}
export default main;