@shelby-protocol/mcp 0.0.0-stage → 0.1.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 +104 -2
- package/dist/config.js +67 -0
- package/dist/load-env.js +12 -0
- package/dist/resources/how_to_connect_to_a_shelby_bucket_with_s3.md +107 -0
- package/dist/server.js +29 -0
- package/dist/services/ShelbyAccount.js +50 -0
- package/dist/services/ShelbyAdmin.js +109 -0
- package/dist/services/ShelbyObjects.js +171 -0
- package/dist/services/agentKey.js +63 -0
- package/dist/services/catalog.js +135 -0
- package/dist/tools/buckets.js +175 -0
- package/dist/tools/guide.js +21 -0
- package/dist/tools/index.js +16 -0
- package/dist/tools/key.js +32 -0
- package/dist/tools/objects.js +69 -0
- package/dist/tools/run.js +25 -0
- package/dist/tools/schemas.js +74 -0
- package/dist/utils/bucketName.js +33 -0
- package/dist/utils/errors.js +58 -0
- package/dist/utils/paths.js +87 -0
- package/package.json +49 -4
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export function formatError(error) {
|
|
2
|
+
if (error instanceof Error)
|
|
3
|
+
return error.message;
|
|
4
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
5
|
+
const { code, message } = error;
|
|
6
|
+
return code !== undefined ? `${message} (code ${code})` : String(message);
|
|
7
|
+
}
|
|
8
|
+
return JSON.stringify(error);
|
|
9
|
+
}
|
|
10
|
+
export const MISSING_AGENT_KEY_MESSAGE = `SHELBY_AGENT_KEY is not set. Create an agent key in the Shelby console (Integrations) and add it to the MCP configuration as an env var: SHELBY_AGENT_KEY=<your-agent-key>. On macOS you can store it in the keychain instead: security add-generic-password -s shelby-mcp -a SHELBY_AGENT_KEY -w`;
|
|
11
|
+
export const LEGACY_KEY_DATA_MESSAGE = "This key is an unscoped bot key, which can't read or write objects. Create an agent key limited to an organization, project or buckets in the Shelby console (Integrations), and set it as SHELBY_AGENT_KEY.";
|
|
12
|
+
const OUT_OF_SCOPE = "That is outside what this agent key can reach. Use get_shelby_agent_key_info to see its scope.";
|
|
13
|
+
/** The api-gateway's agent key rejections (`BotKeyDenied`), lowercased. */
|
|
14
|
+
const REJECTIONS = [
|
|
15
|
+
[
|
|
16
|
+
"agent key has expired",
|
|
17
|
+
"This agent key has expired. Create a new one in the Shelby console (Integrations).",
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
"agent keys aren't enabled",
|
|
21
|
+
"Agent keys aren't enabled on this Shelby deployment yet.",
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
"agent key is read-only",
|
|
25
|
+
"This agent key is read-only, so it can't change anything. Use a read-write agent key.",
|
|
26
|
+
],
|
|
27
|
+
["agent key does not have access", OUT_OF_SCOPE],
|
|
28
|
+
["agent keys can't call", OUT_OF_SCOPE],
|
|
29
|
+
[
|
|
30
|
+
"no longer a member of its organization",
|
|
31
|
+
"The agent key's owner is no longer a member of its organization, so the key no longer works.",
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
"belongs to a viewer",
|
|
35
|
+
"The agent key's owner is a Viewer in this organization, so the key can't make changes.",
|
|
36
|
+
],
|
|
37
|
+
];
|
|
38
|
+
/**
|
|
39
|
+
* Turn an api-gateway rejection of the agent key into a sentence that says what to
|
|
40
|
+
* do, or undefined when the response isn't about the key. `status` is 0 when unknown,
|
|
41
|
+
* as for admin API errors.
|
|
42
|
+
*/
|
|
43
|
+
export function explainAgentKeyRejection(status, body) {
|
|
44
|
+
if (status !== 0 && status !== 401 && status !== 403)
|
|
45
|
+
return undefined;
|
|
46
|
+
// S3 errors come from behind the gateway and echo the object key, which can contain
|
|
47
|
+
// any of the phrases below.
|
|
48
|
+
if (/<Error>[\s\S]*<Code>/.test(body))
|
|
49
|
+
return undefined;
|
|
50
|
+
const text = body.toLowerCase();
|
|
51
|
+
const rejection = REJECTIONS.find(([phrase]) => text.includes(phrase));
|
|
52
|
+
if (rejection)
|
|
53
|
+
return rejection[1];
|
|
54
|
+
if (status === 401 && text.includes("key not found")) {
|
|
55
|
+
return "The agent key was not recognized. It may have been revoked; check SHELBY_AGENT_KEY.";
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { lstat, realpath, stat } from "node:fs/promises";
|
|
2
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep, } from "node:path";
|
|
3
|
+
function isInside(dir, path) {
|
|
4
|
+
const rel = relative(dir, path);
|
|
5
|
+
return (rel === "" ||
|
|
6
|
+
(!isAbsolute(rel) && rel !== ".." && !rel.startsWith(`..${sep}`)));
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Local file access limited to a set of directories. Paths are compared after
|
|
10
|
+
* resolving symlinks, so neither `..` nor a link can reach outside them.
|
|
11
|
+
*/
|
|
12
|
+
export class AllowedDirs {
|
|
13
|
+
dirs;
|
|
14
|
+
realDirs;
|
|
15
|
+
constructor(dirs) {
|
|
16
|
+
this.dirs = dirs;
|
|
17
|
+
if (dirs.length === 0)
|
|
18
|
+
throw new Error("No allowed directories");
|
|
19
|
+
}
|
|
20
|
+
get list() {
|
|
21
|
+
return [...this.dirs];
|
|
22
|
+
}
|
|
23
|
+
async real() {
|
|
24
|
+
this.realDirs ??= Promise.all(this.dirs.map(async (dir) => {
|
|
25
|
+
try {
|
|
26
|
+
return await realpath(dir);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw new Error(`Allowed directory ${dir} doesn't exist`);
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
return this.realDirs;
|
|
33
|
+
}
|
|
34
|
+
async assertInside(path, shown) {
|
|
35
|
+
const dirs = await this.real();
|
|
36
|
+
if (!dirs.some((dir) => isInside(dir, path))) {
|
|
37
|
+
throw new Error(`${shown} is outside the directories this MCP may use (${this.dirs.join(", ")}). Start it with --allow-dir to allow another directory.`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Relative paths are taken from the first allowed directory. */
|
|
41
|
+
absolute(path) {
|
|
42
|
+
return resolve(this.dirs[0], path);
|
|
43
|
+
}
|
|
44
|
+
/** An existing regular file to read. */
|
|
45
|
+
async readableFile(path) {
|
|
46
|
+
const absolute = this.absolute(path);
|
|
47
|
+
let real;
|
|
48
|
+
try {
|
|
49
|
+
real = await realpath(absolute);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
throw new Error(`${path} doesn't exist`);
|
|
53
|
+
}
|
|
54
|
+
await this.assertInside(real, path);
|
|
55
|
+
if (!(await stat(real)).isFile()) {
|
|
56
|
+
throw new Error(`${path} is not a file`);
|
|
57
|
+
}
|
|
58
|
+
return real;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A path to write a new file at. The directory must exist and be allowed, and
|
|
62
|
+
* the path itself must not be a symlink or a directory.
|
|
63
|
+
*/
|
|
64
|
+
async writableFile(path, overwrite) {
|
|
65
|
+
const absolute = this.absolute(path);
|
|
66
|
+
let parent;
|
|
67
|
+
try {
|
|
68
|
+
parent = await realpath(dirname(absolute));
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
throw new Error(`The directory for ${path} doesn't exist`);
|
|
72
|
+
}
|
|
73
|
+
await this.assertInside(parent, path);
|
|
74
|
+
const target = join(parent, basename(absolute));
|
|
75
|
+
const existing = await lstat(target).catch(() => undefined);
|
|
76
|
+
if (existing?.isSymbolicLink()) {
|
|
77
|
+
throw new Error(`${path} is a symlink, so it won't be written`);
|
|
78
|
+
}
|
|
79
|
+
if (existing?.isDirectory()) {
|
|
80
|
+
throw new Error(`${path} is a directory`);
|
|
81
|
+
}
|
|
82
|
+
if (existing && !overwrite) {
|
|
83
|
+
throw new Error(`${path} already exists. Pass overwrite to replace it.`);
|
|
84
|
+
}
|
|
85
|
+
return target;
|
|
86
|
+
}
|
|
87
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shelby-protocol/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"main": "dist/server.js",
|
|
5
|
+
"module": "dist/server.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"shelby-mcp": "dist/server.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"mcp",
|
|
11
|
+
"shelby",
|
|
12
|
+
"s3",
|
|
13
|
+
"storage"
|
|
14
|
+
],
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"description": "An MCP server that lets agents manage Shelby buckets",
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22.12.0"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"package.json"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "rm -rf dist && tsc && cp -r src/resources dist/ && chmod +x dist/server.js",
|
|
27
|
+
"start": "npm run build && tsx src/server.ts",
|
|
28
|
+
"dev": "npm run build && fastmcp dev src/server.ts",
|
|
29
|
+
"prepublishOnly": "npm run build",
|
|
30
|
+
"bundle": "npm run build && node scripts/bundle.mjs",
|
|
31
|
+
"lint": "biome ci . && tsc --noEmit",
|
|
32
|
+
"pretest": "npm run build",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"format": "biome check --write ."
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@aptos-labs/api-gateway-admin-api-client": "^4.9.0",
|
|
38
|
+
"fastmcp": "^4.3.2",
|
|
39
|
+
"zod": "^4.4.3"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@anthropic-ai/mcpb": "^2.1.2",
|
|
43
|
+
"@biomejs/biome": "^2.5.1",
|
|
44
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
45
|
+
"@tsconfig/node22": "^22.0.5",
|
|
46
|
+
"@types/node": "^25.9.3",
|
|
47
|
+
"tsx": "^4.22.4",
|
|
48
|
+
"typescript": "^6.0.3",
|
|
49
|
+
"vitest": "^4.1.9"
|
|
50
|
+
}
|
|
51
|
+
}
|