@anaella/mcp 0.1.0 → 0.2.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/dist/{chunk-GXJ2ADGM.js → chunk-UVDX2Y2D.js} +47 -81
- package/dist/http.js +13 -7
- package/dist/index.js +2 -2
- package/package.json +11 -4
|
@@ -1,87 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// src/client.ts
|
|
4
|
-
var AnaellaApiError = class extends Error {
|
|
5
|
-
constructor(status, code, message, details) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.status = status;
|
|
8
|
-
this.code = code;
|
|
9
|
-
this.details = details;
|
|
10
|
-
this.name = "AnaellaApiError";
|
|
11
|
-
}
|
|
12
|
-
status;
|
|
13
|
-
code;
|
|
14
|
-
details;
|
|
15
|
-
};
|
|
16
|
-
var AnaellaClient = class {
|
|
17
|
-
apiKey;
|
|
18
|
-
baseUrl;
|
|
19
|
-
constructor(opts) {
|
|
20
|
-
this.apiKey = opts.apiKey;
|
|
21
|
-
this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
|
|
22
|
-
}
|
|
23
|
-
async request(method, path, body) {
|
|
24
|
-
let res;
|
|
25
|
-
try {
|
|
26
|
-
res = await fetch(this.baseUrl + path, {
|
|
27
|
-
method,
|
|
28
|
-
headers: {
|
|
29
|
-
authorization: `Bearer ${this.apiKey}`,
|
|
30
|
-
...body === void 0 ? {} : { "content-type": "application/json" }
|
|
31
|
-
},
|
|
32
|
-
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
33
|
-
});
|
|
34
|
-
} catch (e) {
|
|
35
|
-
throw new AnaellaApiError(
|
|
36
|
-
0,
|
|
37
|
-
"network_error",
|
|
38
|
-
`Could not reach anaella API: ${e.message}`
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
const raw = await res.text();
|
|
42
|
-
let json;
|
|
43
|
-
try {
|
|
44
|
-
json = raw ? JSON.parse(raw) : void 0;
|
|
45
|
-
} catch {
|
|
46
|
-
json = void 0;
|
|
47
|
-
}
|
|
48
|
-
if (!res.ok) {
|
|
49
|
-
const env = json?.error;
|
|
50
|
-
throw new AnaellaApiError(
|
|
51
|
-
res.status,
|
|
52
|
-
env?.code ?? "error",
|
|
53
|
-
env?.message ?? `HTTP ${res.status}${raw ? `: ${raw.slice(0, 200)}` : ""}`,
|
|
54
|
-
env?.details
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
return json;
|
|
58
|
-
}
|
|
59
|
-
listChannels() {
|
|
60
|
-
return this.request("GET", "/v1/channels");
|
|
61
|
-
}
|
|
62
|
-
createPost(body) {
|
|
63
|
-
return this.request("POST", "/v1/posts", body);
|
|
64
|
-
}
|
|
65
|
-
listPosts(opts = {}) {
|
|
66
|
-
const q = new URLSearchParams();
|
|
67
|
-
if (opts.limit !== void 0) q.set("limit", String(opts.limit));
|
|
68
|
-
if (opts.cursor !== void 0) q.set("cursor", String(opts.cursor));
|
|
69
|
-
const qs = q.toString();
|
|
70
|
-
return this.request("GET", `/v1/posts${qs ? `?${qs}` : ""}`);
|
|
71
|
-
}
|
|
72
|
-
getPost(id) {
|
|
73
|
-
return this.request("GET", `/v1/posts/${encodeURIComponent(id)}`);
|
|
74
|
-
}
|
|
75
|
-
deletePost(id) {
|
|
76
|
-
return this.request("DELETE", `/v1/posts/${encodeURIComponent(id)}`);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
3
|
// src/config.ts
|
|
81
4
|
function loadConfig(env) {
|
|
5
|
+
const apiUrl = env.ANAELLA_API_URL?.replace(/\/+$/, "") || "https://api.anaella.com";
|
|
82
6
|
return {
|
|
83
7
|
apiKey: env.ANAELLA_API_KEY,
|
|
84
|
-
|
|
8
|
+
// Used for tool calls — internal Docker host in prod (http://anaella-api:3333).
|
|
9
|
+
apiUrl,
|
|
10
|
+
// Advertised to MCP clients in the 401 WWW-Authenticate pointer, so it must
|
|
11
|
+
// be publicly reachable. Falls back to apiUrl when not set (e.g. stdio users
|
|
12
|
+
// whose apiUrl is already their public URL).
|
|
13
|
+
publicApiUrl: env.ANAELLA_PUBLIC_API_URL?.replace(/\/+$/, "") || apiUrl
|
|
85
14
|
};
|
|
86
15
|
}
|
|
87
16
|
|
|
@@ -90,6 +19,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
90
19
|
|
|
91
20
|
// src/tools.ts
|
|
92
21
|
import { z } from "zod";
|
|
22
|
+
import { AnaellaApiError } from "@anaella/client";
|
|
93
23
|
var ok = (data) => ({
|
|
94
24
|
content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
|
|
95
25
|
});
|
|
@@ -98,7 +28,9 @@ var fail = (err) => {
|
|
|
98
28
|
const detail = err.details?.length ? `
|
|
99
29
|
Details: ${JSON.stringify(err.details)}` : "";
|
|
100
30
|
return {
|
|
101
|
-
content: [
|
|
31
|
+
content: [
|
|
32
|
+
{ type: "text", text: `Error [${err.code}] (HTTP ${err.status}): ${err.message}${detail}` }
|
|
33
|
+
],
|
|
102
34
|
isError: true
|
|
103
35
|
};
|
|
104
36
|
}
|
|
@@ -134,7 +66,9 @@ function buildTools(client) {
|
|
|
134
66
|
firstComment: z.string().max(2e3).optional()
|
|
135
67
|
}
|
|
136
68
|
},
|
|
137
|
-
handler: wrap(
|
|
69
|
+
handler: wrap(
|
|
70
|
+
(args) => client.createPost(args)
|
|
71
|
+
)
|
|
138
72
|
},
|
|
139
73
|
{
|
|
140
74
|
name: "list_posts",
|
|
@@ -162,6 +96,39 @@ function buildTools(client) {
|
|
|
162
96
|
inputSchema: { id: z.string() }
|
|
163
97
|
},
|
|
164
98
|
handler: wrap((args) => client.deletePost(args.id))
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "get_analytics",
|
|
102
|
+
config: {
|
|
103
|
+
description: "Organization-wide analytics: overall totals plus a per-platform breakdown. Optional `period`: 24h | 7d | 30d | 90d | 1y (default 30d).",
|
|
104
|
+
inputSchema: {
|
|
105
|
+
period: z.enum(["24h", "7d", "30d", "90d", "1y"]).optional()
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
handler: wrap((args) => client.getAnalytics(args))
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "get_post_analytics",
|
|
112
|
+
config: {
|
|
113
|
+
description: "Analytics for a single post by id: aggregate totals, growth vs the previous period, and history. Optional `period`: 24h | 7d | 30d | 90d | 1y.",
|
|
114
|
+
inputSchema: {
|
|
115
|
+
id: z.string().describe("Post id"),
|
|
116
|
+
period: z.enum(["24h", "7d", "30d", "90d", "1y"]).optional()
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
handler: wrap(
|
|
120
|
+
(args) => client.getPostAnalytics(args.id, { period: args.period })
|
|
121
|
+
)
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "upload_media",
|
|
125
|
+
config: {
|
|
126
|
+
description: "Register public media URLs as reusable resources WITHOUT creating a post. Returns resource ids usable as create_post media ({ id }); each file downloads in the background.",
|
|
127
|
+
inputSchema: {
|
|
128
|
+
urls: z.array(z.string()).min(1).describe("Public media URLs to register")
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
handler: wrap((args) => client.uploadUrls(args.urls))
|
|
165
132
|
}
|
|
166
133
|
];
|
|
167
134
|
}
|
|
@@ -176,7 +143,6 @@ function buildServer(client) {
|
|
|
176
143
|
}
|
|
177
144
|
|
|
178
145
|
export {
|
|
179
|
-
AnaellaClient,
|
|
180
146
|
loadConfig,
|
|
181
147
|
buildServer
|
|
182
148
|
};
|
package/dist/http.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
AnaellaClient,
|
|
4
3
|
buildServer,
|
|
5
4
|
loadConfig
|
|
6
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-UVDX2Y2D.js";
|
|
7
6
|
|
|
8
7
|
// src/http.ts
|
|
9
8
|
import http from "http";
|
|
10
9
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
10
|
+
import { AnaellaClient } from "@anaella/client";
|
|
11
11
|
function readBody(req) {
|
|
12
12
|
return new Promise((resolve) => {
|
|
13
13
|
const chunks = [];
|
|
@@ -28,7 +28,7 @@ function sendJson(res, status, body) {
|
|
|
28
28
|
res.writeHead(status, { "content-type": "application/json" });
|
|
29
29
|
res.end(JSON.stringify(body));
|
|
30
30
|
}
|
|
31
|
-
function createHttpServer(apiUrl) {
|
|
31
|
+
function createHttpServer(apiUrl, publicApiUrl = apiUrl) {
|
|
32
32
|
return http.createServer(async (req, res) => {
|
|
33
33
|
const url = req.url ?? "";
|
|
34
34
|
if (req.method === "GET" && url === "/health") {
|
|
@@ -42,9 +42,15 @@ function createHttpServer(apiUrl) {
|
|
|
42
42
|
}
|
|
43
43
|
const authz = req.headers.authorization ?? "";
|
|
44
44
|
if (!/^Bearer\s+ana_/i.test(authz)) {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
res.writeHead(401, {
|
|
46
|
+
"content-type": "application/json",
|
|
47
|
+
"www-authenticate": `Bearer resource_metadata="${publicApiUrl.replace(/\/+$/, "")}/.well-known/oauth-protected-resource"`
|
|
47
48
|
});
|
|
49
|
+
res.end(
|
|
50
|
+
JSON.stringify({
|
|
51
|
+
error: { code: "unauthorized", message: "Authorization: Bearer ana_\u2026 is required" }
|
|
52
|
+
})
|
|
53
|
+
);
|
|
48
54
|
return;
|
|
49
55
|
}
|
|
50
56
|
const apiKey = authz.replace(/^Bearer\s+/i, "");
|
|
@@ -69,9 +75,9 @@ function createHttpServer(apiUrl) {
|
|
|
69
75
|
});
|
|
70
76
|
}
|
|
71
77
|
function main() {
|
|
72
|
-
const { apiUrl } = loadConfig(process.env);
|
|
78
|
+
const { apiUrl, publicApiUrl } = loadConfig(process.env);
|
|
73
79
|
const port = Number(process.env.PORT) || 3e3;
|
|
74
|
-
const server = createHttpServer(apiUrl);
|
|
80
|
+
const server = createHttpServer(apiUrl, publicApiUrl);
|
|
75
81
|
server.listen(port, () => {
|
|
76
82
|
process.stderr.write(`[anaella-mcp] HTTP server listening on :${port} \u2192 ${apiUrl}
|
|
77
83
|
`);
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
AnaellaClient,
|
|
4
3
|
buildServer,
|
|
5
4
|
loadConfig
|
|
6
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-UVDX2Y2D.js";
|
|
7
6
|
|
|
8
7
|
// src/index.ts
|
|
9
8
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
9
|
+
import { AnaellaClient } from "@anaella/client";
|
|
10
10
|
async function main() {
|
|
11
11
|
const { apiKey, apiUrl } = loadConfig(process.env);
|
|
12
12
|
if (!apiKey) {
|
package/package.json
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anaella/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "MCP server for anaella.com — schedule and publish social posts via the /v1 API.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
"bin": {
|
|
7
|
+
"anaella-mcp": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
9
15
|
"scripts": {
|
|
10
16
|
"build": "tsup",
|
|
11
17
|
"prepublishOnly": "npm run build",
|
|
@@ -14,6 +20,7 @@
|
|
|
14
20
|
"smoke": "bun run src/smoke.ts"
|
|
15
21
|
},
|
|
16
22
|
"dependencies": {
|
|
23
|
+
"@anaella/client": "^0.1.6",
|
|
17
24
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
18
25
|
"zod": "^3.25.76"
|
|
19
26
|
},
|