@jclvsh/xmark 0.6.1 → 0.7.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.
- package/README.md +15 -0
- package/dist/commands/usage.js +12 -0
- package/dist/hosted-transport.d.ts +19 -0
- package/dist/hosted-transport.js +67 -0
- package/dist/hosted.d.ts +9 -0
- package/dist/hosted.js +15 -1
- package/dist/tool-policy.js +8 -0
- package/dist/tools/usage.js +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,6 +32,19 @@ Optionally override the API host (default is `https://api.xmark.dev`):
|
|
|
32
32
|
export XMARK_API_URL=https://api.xmark.dev
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
## Hosted endpoint
|
|
36
|
+
|
|
37
|
+
Clients that connect to a remote MCP server can use the hosted endpoint instead of this package:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
https://api.xmark.dev/mcp
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- Transport: MCP streamable HTTP, `POST` only.
|
|
44
|
+
- Registry: listed in the [official MCP registry](https://registry.modelcontextprotocol.io) as `io.github.JCLVSH/xmark`.
|
|
45
|
+
- Auth: `Authorization: Bearer nt_live_...` (the same API key; its scopes apply). `initialize` and `tools/list` answer without a key, so a client can read the tool list before signing up; calling a tool needs the key.
|
|
46
|
+
- Tools: the class of each hosted tool is listed at https://www.xmark.dev/docs#mcp-hosted.
|
|
47
|
+
|
|
35
48
|
## Tools exposed via MCP
|
|
36
49
|
|
|
37
50
|
| Tool | What it does |
|
|
@@ -46,6 +59,7 @@ export XMARK_API_URL=https://api.xmark.dev
|
|
|
46
59
|
| `get_conversation_messages` | A conversation's message history. |
|
|
47
60
|
| `delete_conversation` | Permanently delete a conversation. |
|
|
48
61
|
| `get_usage` | Plan + quota usage (chat this month, syncs today, bookmark count). |
|
|
62
|
+
| `get_affiliate` | Affiliate status, link, sign-ups, and commission totals (stdio only). |
|
|
49
63
|
|
|
50
64
|
## CLI commands
|
|
51
65
|
|
|
@@ -60,6 +74,7 @@ xmark conversations
|
|
|
60
74
|
xmark messages <conversation-id>
|
|
61
75
|
xmark delete-conversation <conversation-id>
|
|
62
76
|
xmark usage
|
|
77
|
+
xmark affiliate
|
|
63
78
|
```
|
|
64
79
|
|
|
65
80
|
Global flags: `--format table` renders paginated lists as a table (default is `json`).
|
package/dist/commands/usage.js
CHANGED
|
@@ -12,4 +12,16 @@ export function registerUsageCommands(program, client) {
|
|
|
12
12
|
handleError(error);
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
+
program
|
|
16
|
+
.command("affiliate")
|
|
17
|
+
.description("Your affiliate status, link, sign-ups, and commission totals")
|
|
18
|
+
.action(async () => {
|
|
19
|
+
try {
|
|
20
|
+
const result = await client.get("/affiliate");
|
|
21
|
+
formatOutput(result, getFormat(program.opts()));
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
handleError(error);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
15
27
|
}
|
|
@@ -8,3 +8,22 @@ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
8
8
|
* opens an event stream that never ends).
|
|
9
9
|
*/
|
|
10
10
|
export declare function serveStatelessMcp(server: McpServer, request: Request): Promise<Response>;
|
|
11
|
+
/**
|
|
12
|
+
* True when a JSON-RPC payload (one message or a batch) only asks who the server is and which
|
|
13
|
+
* tools it has. A host may answer these without a key, so an agent or a directory can see what
|
|
14
|
+
* the server does before signing up. Every message must be on the list: one tool call in a
|
|
15
|
+
* batch makes the whole payload need a key.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isDiscoveryPayload(payload: unknown): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* True when the request's body is a discovery payload. Reads a clone, so the request can still
|
|
20
|
+
* be served afterwards, and stops at MAX_DISCOVERY_BODY_BYTES: a larger body, or a chunked one
|
|
21
|
+
* with no Content-Length, is never buffered whole.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isDiscoveryRequest(request: Request): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* The API client for a keyless discovery server: it has no key, so every use throws. Listing
|
|
26
|
+
* tools never touches the client; a tool call that reached this server would fail here, before
|
|
27
|
+
* any REST request.
|
|
28
|
+
*/
|
|
29
|
+
export declare function keylessClient<Client extends object>(): Client;
|
package/dist/hosted-transport.js
CHANGED
|
@@ -15,3 +15,70 @@ export async function serveStatelessMcp(server, request) {
|
|
|
15
15
|
await server.connect(transport);
|
|
16
16
|
return transport.handleRequest(request);
|
|
17
17
|
}
|
|
18
|
+
/** JSON-RPC methods that describe the server and change nothing. */
|
|
19
|
+
const DISCOVERY_METHODS = new Set(["initialize", "notifications/initialized", "ping", "tools/list"]);
|
|
20
|
+
/** A handshake is three messages; a longer keyless batch is not a handshake. */
|
|
21
|
+
const MAX_DISCOVERY_BATCH = 10;
|
|
22
|
+
/**
|
|
23
|
+
* True when a JSON-RPC payload (one message or a batch) only asks who the server is and which
|
|
24
|
+
* tools it has. A host may answer these without a key, so an agent or a directory can see what
|
|
25
|
+
* the server does before signing up. Every message must be on the list: one tool call in a
|
|
26
|
+
* batch makes the whole payload need a key.
|
|
27
|
+
*/
|
|
28
|
+
export function isDiscoveryPayload(payload) {
|
|
29
|
+
const messages = Array.isArray(payload) ? payload : [payload];
|
|
30
|
+
if (messages.length === 0 || messages.length > MAX_DISCOVERY_BATCH)
|
|
31
|
+
return false;
|
|
32
|
+
return messages.every((message) => {
|
|
33
|
+
if (typeof message !== "object" || message === null)
|
|
34
|
+
return false;
|
|
35
|
+
const method = message.method;
|
|
36
|
+
return typeof method === "string" && DISCOVERY_METHODS.has(method);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** A handshake fits in a few hundred bytes; a keyless body past this is not one. */
|
|
40
|
+
const MAX_DISCOVERY_BODY_BYTES = 16_384;
|
|
41
|
+
/**
|
|
42
|
+
* True when the request's body is a discovery payload. Reads a clone, so the request can still
|
|
43
|
+
* be served afterwards, and stops at MAX_DISCOVERY_BODY_BYTES: a larger body, or a chunked one
|
|
44
|
+
* with no Content-Length, is never buffered whole.
|
|
45
|
+
*/
|
|
46
|
+
export async function isDiscoveryRequest(request) {
|
|
47
|
+
const stream = request.clone().body;
|
|
48
|
+
if (!stream)
|
|
49
|
+
return false;
|
|
50
|
+
const reader = stream.getReader();
|
|
51
|
+
const bytes = new Uint8Array(MAX_DISCOVERY_BODY_BYTES);
|
|
52
|
+
let size = 0;
|
|
53
|
+
try {
|
|
54
|
+
for (;;) {
|
|
55
|
+
const { done, value } = await reader.read();
|
|
56
|
+
if (done)
|
|
57
|
+
break;
|
|
58
|
+
if (size + value.byteLength > MAX_DISCOVERY_BODY_BYTES) {
|
|
59
|
+
// Not awaited: cancelling one side of a cloned body only settles once the other
|
|
60
|
+
// side is cancelled too, and the caller is about to answer without reading it.
|
|
61
|
+
void reader.cancel().catch(() => undefined);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
bytes.set(value, size);
|
|
65
|
+
size += value.byteLength;
|
|
66
|
+
}
|
|
67
|
+
return isDiscoveryPayload(JSON.parse(new TextDecoder().decode(bytes.subarray(0, size))));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The API client for a keyless discovery server: it has no key, so every use throws. Listing
|
|
75
|
+
* tools never touches the client; a tool call that reached this server would fail here, before
|
|
76
|
+
* any REST request.
|
|
77
|
+
*/
|
|
78
|
+
export function keylessClient() {
|
|
79
|
+
return new Proxy({}, {
|
|
80
|
+
get(_target, property) {
|
|
81
|
+
throw new Error(`an api key is required (client.${String(property)} was used without one)`);
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
package/dist/hosted.d.ts
CHANGED
|
@@ -8,3 +8,12 @@ export interface HostedMcpOptions {
|
|
|
8
8
|
}
|
|
9
9
|
/** One hosted MCP request: a per-request client and server over the stateless transport. */
|
|
10
10
|
export declare function handleHostedMcpRequest(request: Request, options: HostedMcpOptions): Promise<Response>;
|
|
11
|
+
/**
|
|
12
|
+
* One keyless discovery request (initialize, tools/list): the same hosted server and tool list,
|
|
13
|
+
* built on a client that cannot make a REST call. The host checks the request with
|
|
14
|
+
* isDiscoveryRequest first; anything else needs a key and goes to handleHostedMcpRequest.
|
|
15
|
+
*/
|
|
16
|
+
export declare function handleHostedMcpDiscovery(request: Request, options: {
|
|
17
|
+
version: string;
|
|
18
|
+
}): Promise<Response>;
|
|
19
|
+
export { isDiscoveryPayload, isDiscoveryRequest } from "./hosted-transport.js";
|
package/dist/hosted.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { XmarkClient } from "./client.js";
|
|
2
|
-
import { serveStatelessMcp } from "./hosted-transport.js";
|
|
2
|
+
import { keylessClient, serveStatelessMcp } from "./hosted-transport.js";
|
|
3
3
|
import { createXmarkServer } from "./server.js";
|
|
4
4
|
/** One hosted MCP request: a per-request client and server over the stateless transport. */
|
|
5
5
|
export function handleHostedMcpRequest(request, options) {
|
|
@@ -7,3 +7,17 @@ export function handleHostedMcpRequest(request, options) {
|
|
|
7
7
|
const server = createXmarkServer({ client, version: options.version, profile: "hosted" });
|
|
8
8
|
return serveStatelessMcp(server, request);
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* One keyless discovery request (initialize, tools/list): the same hosted server and tool list,
|
|
12
|
+
* built on a client that cannot make a REST call. The host checks the request with
|
|
13
|
+
* isDiscoveryRequest first; anything else needs a key and goes to handleHostedMcpRequest.
|
|
14
|
+
*/
|
|
15
|
+
export function handleHostedMcpDiscovery(request, options) {
|
|
16
|
+
const server = createXmarkServer({
|
|
17
|
+
client: keylessClient(),
|
|
18
|
+
version: options.version,
|
|
19
|
+
profile: "hosted",
|
|
20
|
+
});
|
|
21
|
+
return serveStatelessMcp(server, request);
|
|
22
|
+
}
|
|
23
|
+
export { isDiscoveryPayload, isDiscoveryRequest } from "./hosted-transport.js";
|
package/dist/tool-policy.js
CHANGED
|
@@ -5,6 +5,11 @@ const hosted = (category, toolClass) => ({
|
|
|
5
5
|
hosted: true,
|
|
6
6
|
category,
|
|
7
7
|
});
|
|
8
|
+
const localOnly = (category, toolClass) => ({
|
|
9
|
+
class: toolClass,
|
|
10
|
+
hosted: false,
|
|
11
|
+
category,
|
|
12
|
+
});
|
|
8
13
|
export const TOOL_POLICY = {
|
|
9
14
|
// bookmarks
|
|
10
15
|
list_bookmarks: hosted("bookmarks", "read"),
|
|
@@ -22,6 +27,9 @@ export const TOOL_POLICY = {
|
|
|
22
27
|
// usage
|
|
23
28
|
get_usage: hosted("usage", "read"),
|
|
24
29
|
get_changelog: hosted("usage", "read"),
|
|
30
|
+
// stdio only for now: the hosted tool set is pinned to what is under review at Meta
|
|
31
|
+
// (__tests__/server.test.ts). Read-only; applying and payouts stay in the app and with the admin.
|
|
32
|
+
get_affiliate: localOnly("usage", "read"),
|
|
25
33
|
};
|
|
26
34
|
export const toolPolicy = (name) => toolPolicyFor(TOOL_POLICY, name);
|
|
27
35
|
export const isToolEnabled = (name, profile) => isToolEnabledIn(TOOL_POLICY, name, profile);
|
package/dist/tools/usage.js
CHANGED
|
@@ -20,4 +20,13 @@ export function registerUsageTools(server, client) {
|
|
|
20
20
|
return formatMcpError(error);
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
+
server.tool("get_affiliate", 'the user\'s affiliate status ("none" if they have not applied), code and link, sign-up count, commission totals in US cents (in the hold, payable, paid out), and the program terms. read-only; applying is done in the app at /settings/affiliate.', {}, async () => {
|
|
24
|
+
try {
|
|
25
|
+
const result = await client.get("/affiliate");
|
|
26
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return formatMcpError(error);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
23
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jclvsh/xmark",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"mcpName": "io.github.JCLVSH/xmark",
|
|
5
5
|
"description": "MCP server and CLI for the xmark API — chat with your X bookmarks from inside Claude Code, Cursor, or any MCP client.",
|
|
6
6
|
"type": "module",
|