feat: add server assembly and stdio entry
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
export const parseArgs = (
|
||||
argv: string[],
|
||||
env: NodeJS.ProcessEnv = process.env
|
||||
): { configPath?: string } => {
|
||||
const flagIndex = argv.indexOf('--config')
|
||||
if (flagIndex !== -1 && argv[flagIndex + 1]) {
|
||||
return { configPath: argv[flagIndex + 1] }
|
||||
}
|
||||
return { configPath: env.DBMOLE_CONFIG }
|
||||
}
|
||||
+35
-1
@@ -1 +1,35 @@
|
||||
export const placeholder = true
|
||||
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
||||
import { parseArgs } from './cli.js'
|
||||
import { createRegistry } from './config/registry.js'
|
||||
import { defaultStorePath } from './config/store.js'
|
||||
import { createManager } from './db/manager.js'
|
||||
import { createServer } from './server.js'
|
||||
|
||||
const main = async () => {
|
||||
const { configPath } = parseArgs(process.argv.slice(2))
|
||||
const registry = createRegistry({ storePath: defaultStorePath(), configPath })
|
||||
const manager = createManager(registry)
|
||||
const server = createServer(registry, manager)
|
||||
|
||||
let shuttingDown = false
|
||||
const shutdown = async () => {
|
||||
if (shuttingDown) {
|
||||
return
|
||||
}
|
||||
shuttingDown = true
|
||||
await manager.disposeAll().catch(() => {})
|
||||
process.exit(0)
|
||||
}
|
||||
process.on('SIGINT', shutdown)
|
||||
process.on('SIGTERM', shutdown)
|
||||
process.stdin.on('close', shutdown)
|
||||
|
||||
await server.connect(new StdioServerTransport())
|
||||
console.error('dbmole: MCP server listening on stdio')
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
console.error('dbmole: fatal: ' + message)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
||||
import type { Registry } from './config/registry.js'
|
||||
import type { Manager } from './db/manager.js'
|
||||
import { registerConnectionTools } from './tools/connections.js'
|
||||
import { registerQueryTools } from './tools/query.js'
|
||||
import { registerSchemaTools } from './tools/schema.js'
|
||||
|
||||
export const SERVER_VERSION = '0.1.0'
|
||||
|
||||
export const createServer = (registry: Registry, manager: Manager): McpServer => {
|
||||
const server = new McpServer({ name: 'dbmole-mcp', version: SERVER_VERSION })
|
||||
registerConnectionTools(server, registry, manager)
|
||||
registerQueryTools(server, manager)
|
||||
registerSchemaTools(server, manager)
|
||||
return server
|
||||
}
|
||||
Reference in New Issue
Block a user