Skip to content

Commit 8472be9

Browse files
committed
refactor: move package info to options and simplify imports
1 parent f8ad5fb commit 8472be9

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

src/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/usr/bin/env node
2+
import 'dotenv/config'
23
import yargs, { type ArgumentsCamelCase } from 'yargs'
34
import { hideBin } from 'yargs/helpers'
4-
import { startWebServer, startStdioServer } from './services'
5-
import { getOptions } from './utils'
6-
import 'dotenv/config'
5+
import { startWebServer, startStdioServer } from '@/services'
6+
import { getOptions } from '@/utils'
7+
import pkg from '../package.json' with { type: 'json' }
8+
9+
const name = 'doc-mcp-server'
710

811
const argv = await yargs()
9-
.scriptName('doc-mcp-server')
12+
.scriptName(name)
1013
.usage('$0 <command> [options]')
1114
.command(
1215
'stdio',
@@ -35,7 +38,10 @@ if (!argv._[0]) {
3538
}
3639

3740
async function startServer(mode: string, argv: ArgumentsCamelCase) {
38-
const options = getOptions(argv)
41+
const options = getOptions(argv, {
42+
name,
43+
version: pkg.version,
44+
})
3945
if (mode === 'stdio') {
4046
startStdioServer(options).catch(console.error)
4147
} else if (mode === 'web') {

src/services/index.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createRequire } from 'module'
21
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
32
import { registerTools } from '@/tools'
43
import { registerResources } from '@/resources'
@@ -7,17 +6,10 @@ import { stdioServer } from './stdio'
76
import { webServer } from './web'
87
import type { OptionsType } from '@/types'
98

10-
const dynamicImport = createRequire(import.meta.url)
11-
const pkg = dynamicImport('../package.json')
12-
139
const createServer = (options: OptionsType) => {
1410
const server = new McpServer({
15-
name: pkg.name,
16-
version: pkg.version,
17-
// capabilities: {
18-
// resources: {},
19-
// tools: {},
20-
// },
11+
name: options.name,
12+
version: options.version,
2113
})
2214
registerTools(server, options)
2315
registerResources(server, options)

src/types/global.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export interface OptionsType {
2+
name: string
3+
version: string
24
port: number
35
}

src/utils/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import html2md from 'html-to-md'
44
import type { ArgumentsCamelCase } from 'yargs'
55
import type { DocSearchHitType, OptionsType, SearchAlgoliaParamsType } from '@/types'
66

7-
export function getOptions(argv: ArgumentsCamelCase) {
7+
export function getOptions(
8+
argv: ArgumentsCamelCase,
9+
pkg: {
10+
name: string
11+
version: string
12+
},
13+
) {
814
return {
9-
url: argv.url,
10-
key: argv.key,
11-
secretKey: argv.secret_key,
15+
name: pkg.name,
16+
version: pkg.version,
1217
port: argv.port,
1318
} as OptionsType
1419
}

0 commit comments

Comments
 (0)