Skip to content

Commit 0ea0ed4

Browse files
committed
feat: update
1 parent d9745e1 commit 0ea0ed4

8 files changed

Lines changed: 62 additions & 19 deletions

File tree

.cursor/mcp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"mcpServers": {
33
"arkts": {
44
"command": "node",
5-
"args": ["dist/bin.mjs"]
5+
"args": [".cache/bin.cjs"]
66
}
77
}
88
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"axios": "^1.15.0",
5151
"minisearch": "^7.2.0",
5252
"nodejieba": "^3.5.8",
53+
"source-map-support": "^0.5.21",
5354
"zod": "^4.3.6"
5455
},
5556
"devDependencies": {

pnpm-lock.yaml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import process from 'node:process'
33
import { StdioServerTransport } from '@modelcontextprotocol/server'
44
import { createArktsMcpServer } from './index'
5+
import 'source-map-support/register'
56

67
async function main(): Promise<void> {
78
const server = await createArktsMcpServer()

src/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,27 @@ export async function createArktsMcpServer(options: ArktsMcpServerOptions = {}):
2222
// Lazy or eager load the tools
2323
if (import.meta.env.BUILD_TYPE === 'BIN') {
2424
const mods = Object.entries(import.meta.glob<ToolModule>('./tools/**/*.tool.{ts,md}', { eager: true }))
25-
for (const [path, mod] of mods) {
26-
installTools(path, mod, mods)
27-
}
25+
await Promise.all(mods.map(async ([path, mod]) => /* @__PURE__ */ await installTools(path, mod, mods)))
2826
}
2927
else {
3028
const mods = Object.entries(import.meta.glob<ToolModule>('./tools/**/*.tool.{ts,md}'))
31-
for (const [path, mod] of mods) {
32-
if (path.endsWith('.md')) continue
33-
installTools(path, await mod(), mods)
34-
}
29+
await Promise.all(mods.map(async ([path, mod]) => /* @__PURE__ */ await installTools(path, await mod(), mods)))
3530
}
3631

3732
return server
3833

3934
async function installTools(path: string, module: ToolModule, mods: [string, (() => Promise<ToolModule>) | ToolModule][]): Promise<void> {
4035
if (typeof module.default === 'object' && module.default !== null) {
36+
const description = await findDescription(path, mods)
37+
const title = await findTitle(description ?? '')
38+
4139
server.registerTool(module.default.name, {
42-
description: await findDescription(path, mods),
40+
title,
41+
description,
4342
...module.default,
4443
}, module.default.execute)
4544
}
46-
module.install?.(server)
45+
await module.install?.(server)
4746
}
4847

4948
async function findDescription(path: string, mods: [string, (() => Promise<ToolModule | MarkdownModule>) | ToolModule | MarkdownModule][]): Promise<string | undefined> {
@@ -54,4 +53,10 @@ export async function createArktsMcpServer(options: ArktsMcpServerOptions = {}):
5453
return loadedMod.default as string
5554
}
5655
}
56+
57+
async function findTitle(description: string): Promise<string | undefined> {
58+
const maybeTitle = description.trim().split('\n')?.[0]
59+
if (maybeTitle?.startsWith('# ')) return maybeTitle.slice(2)
60+
return undefined
61+
}
5762
}

src/tools/docs/getCatalogTree.tool.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ export async function requestCatalogTree(language: 'cn' | 'en'): Promise<Catalog
5151
return response.data
5252
}
5353

54-
export async function searchCatalogTree(
55-
text: string,
56-
flattenTree: FlattenCatalogTreeItem[],
57-
): Promise<SearchResult[]> {
54+
export async function searchCatalogTree(text: string, flattenTree: FlattenCatalogTreeItem[]): Promise<SearchResult[]> {
5855
const miniSearch = new MiniSearch({
5956
fields: ['nodeName'],
6057
idField: 'nodeId',

src/tools/types.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import type { McpServer, StandardSchemaWithJSON, ToolCallback } from '@modelcontextprotocol/server'
1+
import type { McpServer, StandardSchemaWithJSON, ToolAnnotations, ToolCallback } from '@modelcontextprotocol/server'
22
import type { Awaitable } from '@vstils/core'
33

44
export type InstallHook = (server: McpServer) => Awaitable<unknown>
55

66
export interface McpTool<OutputArgs extends StandardSchemaWithJSON = StandardSchemaWithJSON, InputArgs extends StandardSchemaWithJSON | undefined = undefined> {
77
readonly name: string
8+
readonly title?: string
89
readonly description?: string
910
readonly inputSchema?: InputArgs
1011
readonly outputSchema?: OutputArgs
12+
readonly annotations?: ToolAnnotations
13+
readonly _meta?: Record<string, unknown>
1114
readonly execute: ToolCallback<InputArgs>
1215
}
1316

@@ -16,6 +19,8 @@ export interface ToolModule {
1619
readonly default?: McpTool
1720
}
1821

19-
export function defineMcpTool<OutputArgs extends StandardSchemaWithJSON = StandardSchemaWithJSON, InputArgs extends StandardSchemaWithJSON | undefined = undefined>(mcpTool: McpTool<OutputArgs, InputArgs>): McpTool<OutputArgs, InputArgs> {
20-
return mcpTool
21-
}
22+
// eslint-disable-next-line antfu/top-level-function
23+
export const defineMcpTool = <
24+
OutputArgs extends StandardSchemaWithJSON = StandardSchemaWithJSON,
25+
InputArgs extends StandardSchemaWithJSON | undefined = undefined,
26+
>(mcpTool: McpTool<OutputArgs, InputArgs>): McpTool<OutputArgs, InputArgs> => mcpTool

vite.config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,24 @@ export default defineConfig({
2020
format: 'esm',
2121
minify: true,
2222
dts: false,
23+
sourcemap: 'inline',
2324
env: { BUILD_TYPE: 'BIN' },
2425
plugins: [markdownPlugin],
2526
deps: {
2627
onlyBundle: false,
2728
},
28-
copy: './src/assets',
2929
} satisfies PackUserConfig,
3030
{
3131
entry: 'src/index.ts',
3232
format: ['esm', 'cjs'],
3333
dts: true,
34+
sourcemap: 'inline',
3435
env: { BUILD_TYPE: 'LIB' },
3536
plugins: [markdownPlugin],
3637
deps: {
3738
onlyBundle: false,
3839
},
40+
copy: 'src/assets',
3941
} satisfies PackUserConfig,
4042
process.argv.includes('--build-exe')
4143
? ({
@@ -44,6 +46,7 @@ export default defineConfig({
4446
outDir: '.cache',
4547
// Use BIN here so the Rolldown graph matches dist/bin.cjs. EXE previously produced a
4648
// lazy-init Zod layout that broke @modelcontextprotocol/server's module-scope z.url().
49+
sourcemap: 'inline',
4750
env: { BUILD_TYPE: 'BIN' },
4851
deps: {
4952
alwaysBundle: Object.keys(packageJson.dependencies).map(dep => new RegExp(`^${dep}`)),
@@ -54,6 +57,15 @@ export default defineConfig({
5457
outDir: 'target',
5558
fileName: 'arkts-mcp',
5659
},
60+
minify: {
61+
compress: {
62+
keepNames: {
63+
class: true,
64+
function: true,
65+
},
66+
},
67+
mangle: false,
68+
},
5769
plugins: [markdownPlugin, nodejiebaPlugin],
5870
copy: [
5971
...nodejiebaPlugin.api?.buildCopyConfig(baseCopyDir) ?? [],

0 commit comments

Comments
 (0)