@workopilot/pluginapi-sdk 0.1.2 → 0.1.4

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/README.md CHANGED
@@ -46,6 +46,13 @@ Register exported handlers in the plugin manifest:
46
46
 
47
47
  ## Provided Types
48
48
 
49
+ ### Platform Service URL
50
+
51
+ Hosts configure `PLATFORM_SERVICE_URL` as an HTTP(S) origin without `/net-api`
52
+ (for example `https://agent.workopilot.com`). HTTP and MCP handlers receive the
53
+ normalized origin through `ctx.platformServiceUrl`. It contains no database
54
+ credentials. `readPlatformServiceUrl(value)` validates and normalizes this setting.
55
+
49
56
  ### Plugin Handler
50
57
 
51
58
  ```ts
@@ -53,6 +60,21 @@ PluginHandler
53
60
  PluginHandlerInput
54
61
  PluginRequest
55
62
  PluginContext
63
+
64
+ ### MCP Tool
65
+
66
+ Plugins can optionally export an MCP tool array from the module named by `plugin.json.mcp.toolsExport` (default: `mcpTools`):
67
+
68
+ ```json
69
+ {
70
+ "appCode": "my-app",
71
+ "mcp": {
72
+ "toolsExport": "mcpTools"
73
+ }
74
+ }
75
+ ```
76
+
77
+ Each tool uses `McpToolDefinition`, provides a JSON Schema `inputSchema`, and receives the same `ctx.currentUser`, database capability, logger, and request headers as an HTTP handler. The host owns MCP transport, authentication, and appCode grouping.
56
78
  ```
57
79
 
58
80
  Handlers receive:
package/dist/index.d.ts CHANGED
@@ -1,15 +1,22 @@
1
1
  export type PluginRouteMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
2
+ /** Normalize a configured platform origin before forwarding authentication headers. */
3
+ export declare function readPlatformServiceUrl(value: string | undefined): string;
2
4
  export interface PluginManifest {
3
5
  name: string;
4
6
  version: string;
5
7
  entry: string;
8
+ appCode?: string;
6
9
  routes: PluginRoute[];
10
+ mcp?: McpManifest;
7
11
  }
8
12
  export interface PluginRoute {
9
13
  method: PluginRouteMethod;
10
14
  path: string;
11
15
  handler: string;
12
16
  }
17
+ export interface McpManifest {
18
+ toolsExport?: string;
19
+ }
13
20
  export type QueryParam = string | number | boolean | Date | null;
14
21
  export interface DatabaseWriteResult {
15
22
  affectedRows: number;
@@ -45,6 +52,8 @@ export interface PluginRequest {
45
52
  headers: Record<string, string | string[] | undefined>;
46
53
  }
47
54
  export interface PluginContext {
55
+ /** 智能体平台服务域名,由宿主配置并注入,不包含 /net-api。 */
56
+ platformServiceUrl: string;
48
57
  database: DatabaseCapability;
49
58
  logger: PluginLogger;
50
59
  currentUser: CurrentUser;
@@ -54,3 +63,17 @@ export interface PluginHandlerInput {
54
63
  ctx: PluginContext;
55
64
  }
56
65
  export type PluginHandler = (input: PluginHandlerInput) => Promise<unknown> | unknown;
66
+ export type McpJsonSchema = Record<string, unknown>;
67
+ export interface McpToolDefinition {
68
+ name: string;
69
+ description: string;
70
+ inputSchema: McpJsonSchema;
71
+ handler: McpToolHandler;
72
+ }
73
+ export interface McpToolHandlerInput {
74
+ arguments: Record<string, unknown>;
75
+ request: PluginRequest;
76
+ ctx: PluginContext;
77
+ signal: AbortSignal;
78
+ }
79
+ export type McpToolHandler = (input: McpToolHandlerInput) => Promise<unknown> | unknown;
package/dist/index.js CHANGED
@@ -1 +1,11 @@
1
- export {};
1
+ /** Normalize a configured platform origin before forwarding authentication headers. */
2
+ export function readPlatformServiceUrl(value) {
3
+ if (!value?.trim())
4
+ throw new Error('Missing required environment variable: PLATFORM_SERVICE_URL');
5
+ const url = new URL(value.trim());
6
+ if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password ||
7
+ url.pathname !== '/' || url.search || url.hash) {
8
+ throw new Error('PLATFORM_SERVICE_URL must be an HTTP(S) origin without credentials, path, query or fragment.');
9
+ }
10
+ return url.origin;
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workopilot/pluginapi-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Workopilot plugin API SDK for database-capability plugins",
5
5
  "keywords": [
6
6
  "wiseai",