@mapled/mcp 0.18.0 → 0.18.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/README.md CHANGED
@@ -38,6 +38,8 @@ claude mcp add mapled -e MAPLED_MCP_TOKEN=mcp_live_… -- npx -y @mapled/mcp
38
38
 
39
39
  The token is scoped to one project. Set `MAPLED_API_URL` only if you're not on the default `https://api.mapled.io`.
40
40
 
41
+ Over either transport, a refusal reaches the agent as Mapled words it — a key that is taken, a plan still waiting for approval, the slug it sent that another record already has. An error whose text carries anything shaped like a Mapled key or token that the call didn't send itself reaches it as one constant sentence instead: no tool answer, its errors included, hands the agent a secret.
42
+
41
43
  ## Setting up a site
42
44
 
43
45
  For the first integration, propose one plan and let the owner approve it on a trusted Mapled screen:
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
- import { createApiClient, createTools } from "./tools.js";
4
+ import { createApiClient, registerTools } from "./tools.js";
5
5
  /** Mapled MCP server. Auth and scope come from the environment:
6
6
  MAPLED_MCP_TOKEN — the project token from Connect with AI (required)
7
7
  MAPLED_API_URL — API origin (default https://api.mapled.io) */
@@ -12,27 +12,8 @@ if (!token) {
12
12
  }
13
13
  const baseUrl = process.env.MAPLED_API_URL ?? "https://api.mapled.io";
14
14
  const server = new McpServer({ name: "mapled", version: "0.1.0" });
15
- const api = createApiClient(baseUrl, token);
16
- for (const tool of createTools(api)) {
17
- // The SDK's generic inference recurses on our union of shapes; the
18
- // runtime contract is identical, so erase the generics here.
19
- server.tool(tool.name, tool.description, tool.schema, async (args) => {
20
- try {
21
- const result = await tool.handler(args);
22
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
23
- }
24
- catch (err) {
25
- return {
26
- isError: true,
27
- content: [
28
- {
29
- type: "text",
30
- text: err instanceof Error ? err.message : "Mapled request failed.",
31
- },
32
- ],
33
- };
34
- }
35
- });
36
- }
15
+ // every call answers through runTool: an error reaches the model only
16
+ // as a text without a Mapled key or token in it (§36.12)
17
+ registerTools(server, createApiClient(baseUrl, token));
37
18
  const transport = new StdioServerTransport();
38
19
  await server.connect(transport);
package/dist/tools.d.ts CHANGED
@@ -4,6 +4,8 @@ import { z } from "zod";
4
4
  export type ApiClient = {
5
5
  request: (method: "GET" | "POST" | "PATCH", path: string, body?: unknown) => Promise<unknown>;
6
6
  };
7
+ /** What a call answers when its request never reached Mapled. */
8
+ export declare const UNREACHABLE = "The request didn't reach Mapled. Try again, or tell the person if it keeps failing: MAPLED_API_URL or MAPLED_MCP_TOKEN in the MCP settings may need a fresh copy. Don't ask them to paste the token into the conversation.";
7
9
  export declare function createApiClient(baseUrl: string, token: string): ApiClient;
8
10
  export declare const FIELD_TYPES: readonly ["short_text", "long_text", "rich_text", "slug", "image", "number", "boolean", "date", "relation", "enum", "url", "email", "group", "datetime", "file", "color", "json", "location", "computed"];
9
11
  export type ToolDef = {
@@ -12,4 +14,26 @@ export type ToolDef = {
12
14
  schema: z.ZodRawShape;
13
15
  handler: (args: never) => Promise<unknown>;
14
16
  };
17
+ /** What a failed call answers when its own text can't pass. */
18
+ export declare const HELD_BACK = "Mapled couldn't complete this call, and its error can't be shown here. Try again, or tell the person if it keeps failing.";
19
+ /** The text an error reaches the model with (§36.12): its message when
20
+ routeText passes it — a route's refusal, as worded — or HELD_BACK.
21
+ `args` are the call's arguments, the runs the model sent. Never
22
+ throws: what escapes a tool's callback the SDK answers with, unread. */
23
+ export declare function errorText(err: unknown, args?: unknown): string;
24
+ export type ToolAnswer = {
25
+ content: {
26
+ type: "text";
27
+ text: string;
28
+ }[];
29
+ isError?: true;
30
+ };
31
+ /** One call as the model reads it, over stdio and the hosted /mcp alike:
32
+ the tool's answer as JSON, or an error that errorText lets through. */
33
+ export declare function runTool(tool: ToolDef, args: unknown): Promise<ToolAnswer>;
34
+ /** The one way a transport offers the tools: every call answers through
35
+ runTool, so no error text reaches the model past it. */
36
+ export declare function registerTools(server: {
37
+ tool: (...args: never[]) => unknown;
38
+ }, api: ApiClient): void;
15
39
  export declare function createTools(api: ApiClient): ToolDef[];
package/dist/tools.js CHANGED
@@ -1,15 +1,26 @@
1
1
  import { z } from "zod";
2
+ /** What a call answers when its request never reached Mapled. */
3
+ export const UNREACHABLE = "The request didn't reach Mapled. Try again, or tell the person if it keeps failing: MAPLED_API_URL or MAPLED_MCP_TOKEN in the MCP settings may need a fresh copy. Don't ask them to paste the token into the conversation.";
2
4
  export function createApiClient(baseUrl, token) {
3
5
  return {
4
6
  async request(method, path, body) {
5
- const res = await fetch(`${baseUrl}${path}`, {
6
- method,
7
- headers: {
8
- authorization: `Bearer ${token}`,
9
- ...(body !== undefined ? { "content-type": "application/json" } : {}),
10
- },
11
- body: body !== undefined ? JSON.stringify(body) : undefined,
12
- });
7
+ let res;
8
+ try {
9
+ res = await fetch(`${baseUrl}${path}`, {
10
+ method,
11
+ headers: {
12
+ authorization: `Bearer ${token}`,
13
+ ...(body !== undefined ? { "content-type": "application/json" } : {}),
14
+ },
15
+ body: body !== undefined ? JSON.stringify(body) : undefined,
16
+ });
17
+ }
18
+ catch {
19
+ // the runtime's text is no route's refusal, and it may quote the
20
+ // request: a header it refused names the token, in pieces too short
21
+ // for any text filter when line breaks cut it (§36.12)
22
+ throw new Error(UNREACHABLE);
23
+ }
13
24
  const payload = (await res.json().catch(() => null));
14
25
  if (!res.ok) {
15
26
  throw new Error(payload?.error?.message ?? `Mapled API error (${res.status}).`);
@@ -49,17 +60,87 @@ const COMPUTED_HELP = "For type computed only: { expression } — a formula over
49
60
  const WEBHOOK_SECRET_ENV = "MAPLED_WEBHOOK_SECRET";
50
61
  /** The header a publish webhook carries its signature in. */
51
62
  const SIGNATURE_HEADER = "x-mapled-signature";
52
- /** A text as the route words it, or nothing: an overlong text, a run of 24
53
- letters and digits (a signing secret is 48 hex digits) or a Mapled
54
- credential prefix never passes, so a secret sent whole or with its prefix
55
- can't reach the model. A text filter can't promise more — the route's
63
+ /** The prefix of every key and token Mapled issues — the report mask's
64
+ `KEYS` (apps/api/src/lib/reportRedaction.ts); the API's
65
+ `security/mcpErrors.test.ts` sends one of each kind through both
66
+ transports. */
67
+ const CREDENTIAL_PREFIX = /(?:whsec|mk_live|msk_live|mcp_live|mcp_oauth|mcp_refresh|mcp_code|mpv|mps)_/i;
68
+ /** What a reader takes a text for: compatibility forms read as ASCII
69
+ (fullwidth letters, the fullwidth low line), and marks, control
70
+ characters other than line breaks and tabs, and characters drawn as
71
+ nothing are gone — a key interleaved with them reads whole. */
72
+ const INVISIBLE = /[\p{M}\p{Cf}\p{Default_Ignorable_Code_Point}\p{Cn}\p{Cs}\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f]/gu;
73
+ const readAs = (text) => text.normalize("NFKD").replace(INVISIBLE, "");
74
+ /** Runs of a text that read as a key's or token's random part, each with
75
+ what makes it one:
76
+ - 24 letters and digits — a hex key or secret is 32 or 48;
77
+ - 24 or more characters of base64 or base64url that mix upper- and
78
+ lower-case letters, as a random one does — a key, a slug or a path
79
+ Mapled writes is lower-case, a constant's name upper-case;
80
+ - as many characters of base64url as a token's random part has, 43
81
+ (`generateToken`: 32 bytes), whatever its letters — a random one
82
+ can come out all in one case or with no letter at all. */
83
+ const RANDOM_RUNS = [
84
+ [/[A-Za-z0-9]{24,}/g, () => true],
85
+ [/[A-Za-z0-9+/=_-]{24,}/g, (run) => /[A-Z]/.test(run) && /[a-z]/.test(run)],
86
+ [/[A-Za-z0-9_-]{43,}/g, () => true],
87
+ ];
88
+ /** A text as the route words it, or nothing. It never passes when, read as
89
+ a reader would, it holds a Mapled key or token prefix in any letter
90
+ case or a run that reads as a random part (RANDOM_RUNS) the model
91
+ didn't send itself — or when it is longer than 1000 characters. A run
92
+ the model sent (`sent` — the call's arguments), echoed back, tells it
93
+ nothing: the slug it asked for that another record already has passes,
94
+ however long. So a credential whole, with its prefix or its random
95
+ part alone can't reach the model. A text filter can't promise more —
96
+ one split into short pieces or re-encoded passes — and the route's
56
97
  refusals have to pass as worded. */
57
- const routeText = (value) => typeof value === "string" &&
58
- value.length <= 1000 &&
59
- !/[A-Za-z0-9]{24}/.test(value) &&
60
- !/(?:whsec|mk_live|msk_live|mcp_live|mpv)_/i.test(value)
61
- ? value
62
- : undefined;
98
+ const routeText = (value, sent = "") => {
99
+ if (typeof value !== "string" || value.length > 1000)
100
+ return undefined;
101
+ const read = readAs(value);
102
+ if (CREDENTIAL_PREFIX.test(read))
103
+ return undefined;
104
+ const random = RANDOM_RUNS.flatMap(([runs, like]) => (read.match(runs) ?? []).filter((run) => like(run)));
105
+ if (random.length === 0)
106
+ return value;
107
+ const known = readAs(sent);
108
+ return random.every((run) => known.includes(run)) ? value : undefined;
109
+ };
110
+ /** What a failed call answers when its own text can't pass. */
111
+ export const HELD_BACK = "Mapled couldn't complete this call, and its error can't be shown here. Try again, or tell the person if it keeps failing.";
112
+ /** The text an error reaches the model with (§36.12): its message when
113
+ routeText passes it — a route's refusal, as worded — or HELD_BACK.
114
+ `args` are the call's arguments, the runs the model sent. Never
115
+ throws: what escapes a tool's callback the SDK answers with, unread. */
116
+ export function errorText(err, args) {
117
+ try {
118
+ return routeText(err instanceof Error ? err.message : undefined, JSON.stringify(args) ?? "") ?? HELD_BACK;
119
+ }
120
+ catch {
121
+ return HELD_BACK;
122
+ }
123
+ }
124
+ /** One call as the model reads it, over stdio and the hosted /mcp alike:
125
+ the tool's answer as JSON, or an error that errorText lets through. */
126
+ export async function runTool(tool, args) {
127
+ try {
128
+ const result = await tool.handler(args);
129
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
130
+ }
131
+ catch (err) {
132
+ return { isError: true, content: [{ type: "text", text: errorText(err, args) }] };
133
+ }
134
+ }
135
+ /** The one way a transport offers the tools: every call answers through
136
+ runTool, so no error text reaches the model past it. */
137
+ export function registerTools(server, api) {
138
+ for (const tool of createTools(api)) {
139
+ // The SDK's generic inference recurses on our union of shapes; the
140
+ // runtime contract is identical, so erase the generics here.
141
+ server.tool(tool.name, tool.description, tool.schema, (args) => runTool(tool, args));
142
+ }
143
+ }
63
144
  /** The address the route saved: the agent's own, as the URL parser writes it. */
64
145
  const savedUrl = (sent, answered) => {
65
146
  try {
@@ -105,7 +186,7 @@ function configureRevalidation(api) {
105
186
  hook = ((await api.request("PATCH", "/v1/agent/webhook", { url: args.url })) ?? {});
106
187
  }
107
188
  catch (err) {
108
- throw new Error(routeText(err instanceof Error ? err.message : undefined) ?? "Mapled couldn't save the webhook. Try again.");
189
+ throw new Error(routeText(err instanceof Error ? err.message : undefined, JSON.stringify(args)) ?? "Mapled couldn't save the webhook. Try again.");
109
190
  }
110
191
  const status = hook.signingSecret?.status;
111
192
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapled/mcp",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Mapled MCP server: lets AI agents build schema and content for one Mapled project.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://mapled.io",