File tree Expand file tree Collapse file tree 4 files changed +24
-19
lines changed Expand file tree Collapse file tree 4 files changed +24
-19
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env node
2+ import 'dotenv/config'
23import yargs , { type ArgumentsCamelCase } from 'yargs'
34import { 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
811const 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
3740async 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' ) {
Original file line number Diff line number Diff line change 1- import { createRequire } from 'module'
21import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
32import { registerTools } from '@/tools'
43import { registerResources } from '@/resources'
@@ -7,17 +6,10 @@ import { stdioServer } from './stdio'
76import { webServer } from './web'
87import type { OptionsType } from '@/types'
98
10- const dynamicImport = createRequire ( import . meta. url )
11- const pkg = dynamicImport ( '../package.json' )
12-
139const 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 )
Original file line number Diff line number Diff line change 11export interface OptionsType {
2+ name : string
3+ version : string
24 port : number
35}
Original file line number Diff line number Diff line change @@ -4,11 +4,16 @@ import html2md from 'html-to-md'
44import type { ArgumentsCamelCase } from 'yargs'
55import 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}
You can’t perform that action at this time.
0 commit comments