actionmcp 0.0.0-stage → 0.1.0

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.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +74 -2
  3. package/dist/analyzer/config.d.ts +15 -0
  4. package/dist/analyzer/config.js +43 -0
  5. package/dist/analyzer/diagnostics.js +126 -0
  6. package/dist/analyzer/explicit.js +128 -0
  7. package/dist/analyzer/index.js +178 -0
  8. package/dist/analyzer/jsdoc.js +32 -0
  9. package/dist/analyzer/options.js +65 -0
  10. package/dist/analyzer/routes.js +81 -0
  11. package/dist/analyzer/scan.js +280 -0
  12. package/dist/analyzer/source.js +100 -0
  13. package/dist/analyzer/types.js +133 -0
  14. package/dist/cli/bin.d.ts +1 -0
  15. package/dist/cli/bin.js +5 -0
  16. package/dist/cli/commands.js +107 -0
  17. package/dist/cli/environment.js +53 -0
  18. package/dist/cli/index.js +97 -0
  19. package/dist/cli/output.js +27 -0
  20. package/dist/cli/project.js +33 -0
  21. package/dist/client.d.ts +6 -0
  22. package/dist/client.js +4 -0
  23. package/dist/config.d.ts +9 -0
  24. package/dist/config.js +84 -0
  25. package/dist/core/compare.js +6 -0
  26. package/dist/core/events.js +12 -0
  27. package/dist/core/execute.js +70 -0
  28. package/dist/core/formdata.js +15 -0
  29. package/dist/core/guards.js +8 -0
  30. package/dist/core/match.js +16 -0
  31. package/dist/core/names.js +51 -0
  32. package/dist/core/result.d.ts +18 -0
  33. package/dist/core/result.js +85 -0
  34. package/dist/core/schema.d.ts +6 -0
  35. package/dist/core/schema.js +90 -0
  36. package/dist/core/types.d.ts +34 -0
  37. package/dist/core/webmcp.js +62 -0
  38. package/dist/generator/index.js +36 -0
  39. package/dist/generator/render.js +91 -0
  40. package/dist/generator/watch.js +76 -0
  41. package/dist/index.d.ts +8 -0
  42. package/dist/index.js +5 -0
  43. package/dist/next/NavigateTool.js +40 -0
  44. package/dist/next/config-store.js +12 -0
  45. package/dist/next/redirect.js +15 -0
  46. package/dist/next/routes.d.ts +3 -0
  47. package/dist/next/routes.js +57 -0
  48. package/dist/react/AgentTools.d.ts +14 -0
  49. package/dist/react/AgentTools.js +35 -0
  50. package/dist/react/Confirm.d.ts +3 -0
  51. package/dist/react/Confirm.js +99 -0
  52. package/dist/react/Devtools.d.ts +2 -0
  53. package/dist/react/Devtools.js +13 -0
  54. package/dist/react/DevtoolsPanel.js +223 -0
  55. package/dist/react/Provider.d.ts +6 -0
  56. package/dist/react/Provider.js +21 -0
  57. package/dist/react/Registrar.js +12 -0
  58. package/dist/react/context.d.ts +14 -0
  59. package/dist/react/context.js +5 -0
  60. package/dist/react/useAgentTools.js +103 -0
  61. package/dist/registry.d.ts +4 -0
  62. package/dist/registry.js +4 -0
  63. package/dist/server/agent.d.ts +43 -0
  64. package/dist/server/agent.js +34 -0
  65. package/dist/server/index.d.ts +6 -0
  66. package/dist/server/index.js +4 -0
  67. package/dist/server/registry.d.ts +53 -0
  68. package/dist/server/registry.js +93 -0
  69. package/dist/server/resolve.js +68 -0
  70. package/package.json +96 -4
@@ -0,0 +1,53 @@
1
+ import { StandardSchemaV1 } from "@standard-schema/spec";
2
+ import { ConfirmPolicy, JsonSchema, RouteEntry, ServerFunction, ToolAdapter, ToolAnnotations } from "../core/types.js";
3
+ import { AgentToolOptions } from "./agent.js";
4
+ declare const REGISTRY: unique symbol;
5
+ export type ToolKind = 'agent' | 'jsdoc' | 'explicit';
6
+ export interface AdaptedAction {
7
+ readonly action: ServerFunction;
8
+ readonly adapter: ToolAdapter;
9
+ }
10
+ export interface AgentToolDefinition {
11
+ readonly action: ServerFunction;
12
+ readonly options: AgentToolOptions;
13
+ readonly adapter?: ToolAdapter;
14
+ }
15
+ export interface JsdocToolEntry {
16
+ action: ServerFunction;
17
+ description: string;
18
+ inputSchema?: JsonSchema;
19
+ annotations?: Partial<ToolAnnotations>;
20
+ adapter?: ToolAdapter;
21
+ validated: false;
22
+ }
23
+ export interface RegistryEntry {
24
+ readonly name: string;
25
+ readonly kind: ToolKind;
26
+ readonly action: ServerFunction;
27
+ readonly title?: string;
28
+ readonly description: string;
29
+ readonly input?: StandardSchemaV1;
30
+ readonly output?: StandardSchemaV1;
31
+ readonly inputSchema?: JsonSchema;
32
+ readonly annotations: ToolAnnotations;
33
+ readonly confirm: ConfirmPolicy;
34
+ readonly adapter?: ToolAdapter;
35
+ }
36
+ export interface AgentToolRegistry {
37
+ readonly [REGISTRY]: true;
38
+ readonly entries: readonly RegistryEntry[];
39
+ readonly routes: readonly RouteEntry[];
40
+ }
41
+ export interface RegistrySources {
42
+ agent?: Record<string, ServerFunction>;
43
+ jsdoc?: Record<string, JsdocToolEntry>;
44
+ explicit?: AgentToolRegistry;
45
+ routes?: RouteEntry[];
46
+ }
47
+ export declare function fromFormDataAction(action: (previousState: never, formData: FormData) => Promise<unknown>): AdaptedAction;
48
+ export declare function fromFormAction(action: (formData: FormData) => Promise<unknown>): AdaptedAction;
49
+ export declare function fromSafeAction(action: (input: never) => Promise<unknown>): AdaptedAction;
50
+ export declare function tool(action: ServerFunction | AdaptedAction, options: AgentToolOptions): AgentToolDefinition;
51
+ export declare function defineAgentTools(tools: Record<string, AgentToolDefinition | ServerFunction>): AgentToolRegistry;
52
+ export declare function createRegistry(sources: RegistrySources): AgentToolRegistry;
53
+ export {};
@@ -0,0 +1,93 @@
1
+ import { isNonEmptyString } from "../core/guards.js";
2
+ import { readAgentMeta } from "./agent.js";
3
+ // src/server/registry.ts
4
+ const REGISTRY = Symbol.for("actionmcp.registry");
5
+ function fromFormDataAction(action) {
6
+ return {
7
+ action,
8
+ adapter: "formdata"
9
+ };
10
+ }
11
+ function fromFormAction(action) {
12
+ return {
13
+ action,
14
+ adapter: "form"
15
+ };
16
+ }
17
+ function fromSafeAction(action) {
18
+ return {
19
+ action,
20
+ adapter: "safe-action"
21
+ };
22
+ }
23
+ function tool(action, options) {
24
+ if (!isNonEmptyString(options.description)) throw new TypeError("tool() requires a non-empty description.");
25
+ return typeof action === "function" ? {
26
+ action,
27
+ options
28
+ } : {
29
+ action: action.action,
30
+ options,
31
+ adapter: action.adapter
32
+ };
33
+ }
34
+ function defineAgentTools(tools) {
35
+ return buildRegistry(Object.entries(tools).map(([key, definition]) => typeof definition === "function" ? entryFromAgent(key, definition) : entryFromOptions(key, "explicit", definition)), []);
36
+ }
37
+ function createRegistry(sources) {
38
+ const explicit = sources.explicit?.entries ?? [];
39
+ const explicitActions = new Set(explicit.map((entry) => entry.action));
40
+ return buildRegistry([...[...Object.entries(sources.agent ?? {}).map(([name, action]) => entryFromAgent(name, action)), ...Object.entries(sources.jsdoc ?? {}).map(([name, entry]) => entryFromJsdoc(name, entry))].filter((entry) => !explicitActions.has(entry.action)), ...explicit], [...sources.routes ?? [], ...sources.explicit?.routes ?? []]);
41
+ }
42
+ function buildRegistry(entries, routes) {
43
+ return {
44
+ [REGISTRY]: true,
45
+ entries,
46
+ routes
47
+ };
48
+ }
49
+ function entryFromAgent(name, action) {
50
+ const meta = readAgentMeta(action);
51
+ if (!meta) throw new TypeError(`The export registered as "${name}" is not wrapped in agent().`);
52
+ return entryFromOptions(name, "agent", {
53
+ action,
54
+ options: meta.options
55
+ });
56
+ }
57
+ function entryFromOptions(key, kind, definition) {
58
+ const { action, options, adapter } = definition;
59
+ return {
60
+ name: options.name ?? key,
61
+ kind,
62
+ action,
63
+ description: options.description,
64
+ annotations: resolveAnnotations(options.readOnly, options.consequential, options.untrustedOutput),
65
+ confirm: options.confirm ?? "consequential",
66
+ ...options.title ? { title: options.title } : {},
67
+ ...options.input ? { input: options.input } : {},
68
+ ...options.output ? { output: options.output } : {},
69
+ ...adapter ? { adapter } : {}
70
+ };
71
+ }
72
+ function entryFromJsdoc(name, entry) {
73
+ const { readOnlyHint, consequentialHint, untrustedContentHint } = entry.annotations ?? {};
74
+ return {
75
+ name,
76
+ kind: "jsdoc",
77
+ action: entry.action,
78
+ description: entry.description,
79
+ annotations: resolveAnnotations(readOnlyHint, consequentialHint, untrustedContentHint),
80
+ confirm: "consequential",
81
+ ...entry.inputSchema ? { inputSchema: entry.inputSchema } : {},
82
+ ...entry.adapter ? { adapter: entry.adapter } : {}
83
+ };
84
+ }
85
+ function resolveAnnotations(readOnly, consequential, untrustedOutput) {
86
+ const readOnlyHint = readOnly ?? false;
87
+ return {
88
+ readOnlyHint,
89
+ consequentialHint: consequential ?? !readOnlyHint,
90
+ untrustedContentHint: untrustedOutput ?? false
91
+ };
92
+ }
93
+ export { createRegistry, defineAgentTools, fromFormAction, fromFormDataAction, fromSafeAction, resolveAnnotations, tool };
@@ -0,0 +1,68 @@
1
+ import { createSelector } from "../core/match.js";
2
+ import { applyPrefix, checkToolNames, describeNameIssue } from "../core/names.js";
3
+ import { convertSchema } from "../core/schema.js";
4
+ // src/server/resolve.ts
5
+ const resolved = /* @__PURE__ */ new WeakMap();
6
+ function resolveTools(registry) {
7
+ let tools = resolved.get(registry);
8
+ if (!tools) {
9
+ tools = registry.entries.map(resolveEntry);
10
+ resolved.set(registry, tools);
11
+ }
12
+ return tools;
13
+ }
14
+ function selectTools(registry, selection) {
15
+ const isSelected = createSelector(selection);
16
+ const tools = resolveTools(registry).filter((tool) => isSelected(tool.name)).map((tool) => ({
17
+ ...tool,
18
+ name: applyPrefix(tool.name, selection.prefix)
19
+ }));
20
+ const issues = checkToolNames(tools.map((tool) => tool.name));
21
+ if (issues.length === 0) return tools;
22
+ const message = issues.map(describeNameIssue).join(" ");
23
+ if (process.env.NODE_ENV !== "production") throw new Error(`actionmcp: ${message}`);
24
+ console.warn(`actionmcp: ${message}`);
25
+ const rejected = new Set(issues.map((issue) => issue.name));
26
+ return tools.filter((tool) => !rejected.has(tool.name));
27
+ }
28
+ function wrapOutputSchema(data) {
29
+ return {
30
+ type: "object",
31
+ properties: {
32
+ ok: { type: "boolean" },
33
+ data,
34
+ error: {
35
+ type: "object",
36
+ properties: {
37
+ code: { type: "string" },
38
+ message: { type: "string" }
39
+ },
40
+ required: ["code", "message"]
41
+ }
42
+ },
43
+ required: ["ok"]
44
+ };
45
+ }
46
+ function resolveEntry(entry) {
47
+ const inputSchema = entry.inputSchema ?? convertEntrySchema(entry, "input");
48
+ const outputSchema = convertEntrySchema(entry, "output");
49
+ return {
50
+ name: entry.name,
51
+ description: entry.description,
52
+ annotations: entry.annotations,
53
+ confirm: entry.confirm,
54
+ action: entry.action,
55
+ ...entry.title ? { title: entry.title } : {},
56
+ ...inputSchema ? { inputSchema } : {},
57
+ ...outputSchema ? { outputSchema: wrapOutputSchema(outputSchema) } : {},
58
+ ...entry.adapter ? { adapter: entry.adapter } : {}
59
+ };
60
+ }
61
+ function convertEntrySchema(entry, direction) {
62
+ const schema = entry[direction];
63
+ if (!schema) return void 0;
64
+ const conversion = convertSchema(schema, direction);
65
+ if (conversion.ok) return conversion.schema;
66
+ if (process.env.NODE_ENV !== "production") console.warn(`actionmcp: AT101 The ${direction} schema of "${entry.name}" cannot be converted to JSON Schema, so the tool is registered without it. ${conversion.reason}`);
67
+ }
68
+ export { resolveTools, selectTools, wrapOutputSchema };
package/package.json CHANGED
@@ -1,6 +1,98 @@
1
1
  {
2
2
  "name": "actionmcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "WebMCP tools from your Server Actions. Opt-in, typed, safe by default.",
5
+ "license": "MIT",
6
+ "author": "Valentin Galfre",
7
+ "homepage": "https://github.com/galfrevn/actionmcp#readme",
8
+ "bugs": "https://github.com/galfrevn/actionmcp/issues",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/galfrevn/actionmcp.git",
12
+ "directory": "packages/actionmcp"
13
+ },
14
+ "keywords": [
15
+ "webmcp",
16
+ "mcp",
17
+ "nextjs",
18
+ "server-actions",
19
+ "server-functions",
20
+ "ai-agents",
21
+ "standard-schema"
22
+ ],
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "bin": {
26
+ "actionmcp": "./dist/cli/bin.js"
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "publishConfig": {
32
+ "access": "public",
33
+ "provenance": true
34
+ },
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "default": "./dist/index.js"
39
+ },
40
+ "./server": {
41
+ "types": "./dist/server/index.d.ts",
42
+ "default": "./dist/server/index.js"
43
+ },
44
+ "./client": {
45
+ "types": "./dist/client.d.ts",
46
+ "default": "./dist/client.js"
47
+ },
48
+ "./config": {
49
+ "types": "./dist/config.d.ts",
50
+ "default": "./dist/config.js"
51
+ },
52
+ "./registry": {
53
+ "types": "./dist/registry.d.ts",
54
+ "default": "./dist/registry.js"
55
+ },
56
+ "./package.json": "./package.json"
57
+ },
58
+ "scripts": {
59
+ "build": "tsdown",
60
+ "test": "vitest run --coverage",
61
+ "typecheck": "tsc --noEmit"
62
+ },
63
+ "engines": {
64
+ "node": ">=22.18"
65
+ },
66
+ "peerDependencies": {
67
+ "next": "^16.0.0",
68
+ "react": "^19.2.0",
69
+ "react-dom": "^19.2.0"
70
+ },
71
+ "dependencies": {
72
+ "@standard-schema/spec": "^1.1.0",
73
+ "@w3c/webmcp-polyfill": "^0.2.0",
74
+ "oxc-parser": "^0.160.0",
75
+ "tinyglobby": "^0.2.17",
76
+ "ts-json-schema-generator": "~2.10.0",
77
+ "typescript": "~6.0.3",
78
+ "webmcp-types": "^0.2.0"
79
+ },
80
+ "devDependencies": {
81
+ "@types/node": "^24.19.2",
82
+ "@types/react": "^19.2.0",
83
+ "@types/react-dom": "^19.2.0",
84
+ "@valibot/to-json-schema": "^1.8.0",
85
+ "@vitest/coverage-v8": "^5.0.0",
86
+ "arktype": "^2.2.10",
87
+ "jsdom": "^27.0.0",
88
+ "next": "16.4.6",
89
+ "next-safe-action": "^8.7.4",
90
+ "react": "19.3.1",
91
+ "react-dom": "19.3.1",
92
+ "rolldown": "^1.3.3",
93
+ "tsdown": "^0.23.7",
94
+ "valibot": "^1.5.0",
95
+ "vitest": "^5.0.0",
96
+ "zod": "^4.6.7"
97
+ }
98
+ }