@capyclaw/plugin-generator 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/create-doc-model.mjs +128 -0
- package/bin/create-plugin.mjs +460 -0
- package/bin/pack-plugin.mjs +93 -0
- package/package.json +19 -4
- package/templates/doc-model/README.md.tmpl +51 -0
- package/templates/doc-model/schema.mjs.tmpl +69 -0
- package/templates/doc-model/test.mjs.tmpl +92 -0
- package/templates/doc-model/tools.mjs.tmpl +169 -0
- package/templates/plugin/contract/contract.json.tmpl +14 -0
- package/templates/plugin/editor/app.js.tmpl +44 -0
- package/templates/plugin/editor/index.html.tmpl +38 -0
- package/templates/plugin/lib/host.mjs.tmpl +27 -0
- package/templates/plugin/server/impl.mjs.tmpl +14 -0
- package/templates/plugin/server/relay.mjs.tmpl +82 -0
- package/templates/plugin/server/tools.mjs.tmpl +62 -0
- package/README.md +0 -3
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP 工具面:能力声明 → 注册表 → 工具清单。
|
|
3
|
+
*
|
|
4
|
+
* 新增工具:在 impl.mjs 写实现,这里 defineTool 声明 schema,并加入能力。
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
defineTool, defineCapability, createRegistry, createMcpHandler,
|
|
8
|
+
createCapabilityReport, buildInstructions,
|
|
9
|
+
} from './shared/tool-host.mjs'
|
|
10
|
+
import { echo, capabilities as capabilitiesImpl } from './impl.mjs'
|
|
11
|
+
|
|
12
|
+
export const contractVersion = '1.0.0'
|
|
13
|
+
|
|
14
|
+
const echoTool = defineTool({
|
|
15
|
+
name: '{{TOOL_PREFIX}}_echo',
|
|
16
|
+
description: '回显输入文本,用于验证服务连通性。',
|
|
17
|
+
inputSchema: {
|
|
18
|
+
type: 'object',
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
properties: {
|
|
21
|
+
text: { type: 'string', maxLength: 2000, description: '要回显的文本' },
|
|
22
|
+
},
|
|
23
|
+
required: ['text'],
|
|
24
|
+
},
|
|
25
|
+
handler: (args) => ({ content: [{ type: 'text', text: echo(args) }] }),
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const capabilitiesTool = defineTool({
|
|
29
|
+
name: '{{TOOL_PREFIX}}_capabilities',
|
|
30
|
+
description: '返回契约版本、工具清单和能力说明。',
|
|
31
|
+
inputSchema: { type: 'object', additionalProperties: false, properties: {} },
|
|
32
|
+
kind: 'read',
|
|
33
|
+
handler: () => ({ content: [{ type: 'text', text: JSON.stringify(capabilitiesImpl(), null, 2) }] }),
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const capability = defineCapability({
|
|
37
|
+
id: '{{SLUG}}',
|
|
38
|
+
title: '{{TITLE}}',
|
|
39
|
+
description: '{{DESCRIPTION}}',
|
|
40
|
+
tags: ['service'],
|
|
41
|
+
tools: [echoTool, capabilitiesTool],
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
export const registry = createRegistry([capability], {
|
|
45
|
+
report: ({ editorUrl = '', runtime = {}, ...rest }) => createCapabilityReport({
|
|
46
|
+
...rest,
|
|
47
|
+
contractVersion,
|
|
48
|
+
packageVersion: '{{VERSION}}',
|
|
49
|
+
editorUrl,
|
|
50
|
+
runtime,
|
|
51
|
+
}),
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
export const tools = registry.TOOLS
|
|
55
|
+
export const callTool = (name, args) => registry.TOOL_IMPL[name]?.(args)
|
|
56
|
+
export function capabilities() { return registry.ctx.contract.report() }
|
|
57
|
+
|
|
58
|
+
export function createMcp(serverInfo, instructions) {
|
|
59
|
+
return createMcpHandler({ registry, serverInfo, instructions })
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { buildInstructions }
|
package/README.md
DELETED