@xpert-ai/plugin-sdk 3.18.1 → 3.18.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @xpert-ai/plugin-sdk
2
2
 
3
+ ## 3.18.2
4
+
5
+ ### Patch Changes
6
+
7
+ - e260743: plugin mcp
8
+ - Updated dependencies [e260743]
9
+ - @xpert-ai/contracts@3.18.1
10
+
3
11
  ## 3.18.1
4
12
 
5
13
  ### Patch Changes
package/README.md CHANGED
@@ -16,6 +16,57 @@ Run `nx test plugin-sdk` to execute the unit tests via [Jest](https://jestjs.io)
16
16
 
17
17
  [插件权限设计指南](./PERMISSIONS.md)
18
18
 
19
+ ## Decorator-driven business Tools
20
+
21
+ Use `@XpertToolProvider()` on one injectable business class and `@XpertTool()` on its methods when the same domain operation should be available as an Agent Middleware Tool, a host-native MCP Tool, or both. Register only the decorated class in the plugin Nest module; the host expands it into one native Toolset and the declared Middleware groups.
22
+
23
+ ```ts
24
+ import { XpertTool, XpertToolProvider, type XpertBusinessToolContext } from '@xpert-ai/plugin-sdk'
25
+ import { z } from 'zod/v3'
26
+
27
+ const inputSchema = z.object({ query: z.string().trim().min(1).max(200) }).strict()
28
+ const outputSchema = z.object({ items: z.array(z.object({ id: z.string() }).strict()) }).strict()
29
+ const resultsApp = {
30
+ key: 'order_results_app',
31
+ entry: 'dist/mcp-apps/order-results/index.html',
32
+ title: 'Order results',
33
+ csp: { connectDomains: [], resourceDomains: [] }
34
+ }
35
+
36
+ @XpertToolProvider({
37
+ provider: 'order_ops',
38
+ componentKey: 'order-operations',
39
+ name: 'Order Operations',
40
+ apps: [resultsApp],
41
+ defaultMiddleware: 'OrderCoordinationMiddleware',
42
+ middlewares: [{ provider: 'OrderCoordinationMiddleware', meta: coordinationMeta }]
43
+ })
44
+ export class OrderOperationsTools {
45
+ @XpertTool({
46
+ name: 'orders_search',
47
+ description: 'Search orders in the active organization.',
48
+ inputSchema,
49
+ outputSchema,
50
+ middleware: true,
51
+ mcp: {
52
+ behavior: { risk: 'read', sideEffect: 'none', idempotency: 'safe' },
53
+ requiredContext: ['tenant', 'organization', 'principal', 'execution'],
54
+ visibility: ['model', 'app'],
55
+ app: { resourceKey: resultsApp.key }
56
+ }
57
+ })
58
+ async search(input: z.infer<typeof inputSchema>, context: XpertBusinessToolContext) {
59
+ return this.service.search(context.organizationId, input)
60
+ }
61
+ }
62
+ ```
63
+
64
+ MCP exposure is explicit. Provide strict Zod input/output schemas and return an allowlisted DTO; the host validates the output and maps it to `structuredContent`. Invocation context is constructed for every call and must never be cached on the Provider singleton. `getMiddlewareExtensions()` may add Agent-only hooks such as `wrapToolCall`, but business-critical behavior belongs in the method or shared service.
65
+
66
+ For a host-native MCP App, declare each static HTML bundle once in the Provider's `apps` array, then bind a Tool with `mcp.app.resourceKey` and include `app` visibility. The App key must exist in the same Provider and its entry must be a relative `.html` path inside the packaged plugin. The host publishes the bundle as a `ui://` resource; plugins must not create a stdio server or put CSP/credentials in Tool results.
67
+
68
+ The host owns the public MCP endpoint identity. It combines the plugin's stable `artifactNamespace`, the Provider key, and an opaque scope hash; client names and product-specific identifiers do not belong in the slug. A tenant- or system-level plugin has one tenant-scoped Publication and capability snapshot, while each organization receives an independent access grant and organization-bound credential. An organization-level plugin receives a dedicated organization-scoped Publication.
69
+
19
70
  ## View extensions
20
71
 
21
72
  [View Extension Protocol](./docs/view-extension-protocol.md)