@agentvalet/register 0.2.0 → 0.2.2
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/index.js +4 -1
- package/dist/mcp-server-DMQWPHYT.js +139 -0
- package/package.json +55 -53
package/dist/index.js
CHANGED
|
@@ -422,7 +422,7 @@ function ensureMcpJson() {
|
|
|
422
422
|
if (!agentId || !ownerId || !keyPath) return;
|
|
423
423
|
servers["agent-authority"] = {
|
|
424
424
|
command: "npx",
|
|
425
|
-
args: ["-y", "@agentvalet/mcp-server"],
|
|
425
|
+
args: ["-y", "@agentvalet/register", "mcp-server"],
|
|
426
426
|
env: {
|
|
427
427
|
AGENT_ID: agentId,
|
|
428
428
|
OWNER_ID: ownerId,
|
|
@@ -602,6 +602,9 @@ program.command("refresh").description("Refresh approved permissions and update
|
|
|
602
602
|
process.exit(3);
|
|
603
603
|
}
|
|
604
604
|
});
|
|
605
|
+
program.command("mcp-server").description("Start the AgentValet MCP server (stdio transport)").action(async () => {
|
|
606
|
+
await import("./mcp-server-DMQWPHYT.js");
|
|
607
|
+
});
|
|
605
608
|
program.parseAsync().catch((err) => {
|
|
606
609
|
console.error(err);
|
|
607
610
|
process.exit(3);
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// src/commands/mcp-server.ts
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import { SignJWT, importPKCS8 } from "jose";
|
|
7
|
+
if (!process.env.AGENT_PRIVATE_KEY && process.env.AGENT_PRIVATE_KEY_PATH) {
|
|
8
|
+
try {
|
|
9
|
+
process.env.AGENT_PRIVATE_KEY = readFileSync(process.env.AGENT_PRIVATE_KEY_PATH, "utf-8").trim();
|
|
10
|
+
} catch (err) {
|
|
11
|
+
process.stderr.write(`[agent-authority] Cannot read AGENT_PRIVATE_KEY_PATH: ${err instanceof Error ? err.message : err}
|
|
12
|
+
`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
var REQUIRED = ["AGENT_PRIVATE_KEY", "AGENT_ID", "OWNER_ID", "PROXY_URL"];
|
|
17
|
+
for (const key of REQUIRED) {
|
|
18
|
+
if (!process.env[key]) {
|
|
19
|
+
process.stderr.write(`[agent-authority] Missing env var: ${key}
|
|
20
|
+
`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
var AGENT_PRIVATE_KEY_RAW = process.env.AGENT_PRIVATE_KEY;
|
|
25
|
+
var AGENT_ID = process.env.AGENT_ID;
|
|
26
|
+
var OWNER_ID = process.env.OWNER_ID;
|
|
27
|
+
var PROXY_URL = process.env.PROXY_URL.replace(/\/$/, "");
|
|
28
|
+
var _privateKey = null;
|
|
29
|
+
var _keyError = null;
|
|
30
|
+
async function getPrivateKey() {
|
|
31
|
+
if (_keyError) throw new Error(_keyError);
|
|
32
|
+
if (_privateKey) return _privateKey;
|
|
33
|
+
if (AGENT_PRIVATE_KEY_RAW === "PENDING_FIRST_CALL") return null;
|
|
34
|
+
const raw = AGENT_PRIVATE_KEY_RAW.trim();
|
|
35
|
+
const pem = raw.startsWith("-----") ? raw.replace(/\\n/g, "\n") : `-----BEGIN PRIVATE KEY-----
|
|
36
|
+
${raw}
|
|
37
|
+
-----END PRIVATE KEY-----`;
|
|
38
|
+
try {
|
|
39
|
+
_privateKey = await importPKCS8(pem, "RS256");
|
|
40
|
+
return _privateKey;
|
|
41
|
+
} catch (err) {
|
|
42
|
+
_keyError = `Invalid private key: ${err instanceof Error ? err.message : err}`;
|
|
43
|
+
throw new Error(_keyError);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function signJWT() {
|
|
47
|
+
const key = await getPrivateKey();
|
|
48
|
+
if (!key) throw new Error("Private key not loaded");
|
|
49
|
+
return new SignJWT({ agent_id: AGENT_ID, owner_id: OWNER_ID }).setProtectedHeader({ alg: "RS256" }).setIssuedAt().setExpirationTime("60s").sign(key);
|
|
50
|
+
}
|
|
51
|
+
function fetchWithTimeout(url, init, ms = 15e3) {
|
|
52
|
+
const ac = new AbortController();
|
|
53
|
+
const t = setTimeout(() => ac.abort(), ms);
|
|
54
|
+
return fetch(url, { ...init, signal: ac.signal }).finally(() => clearTimeout(t));
|
|
55
|
+
}
|
|
56
|
+
async function bearerFetch(url, init) {
|
|
57
|
+
const token = await signJWT();
|
|
58
|
+
return fetchWithTimeout(url, {
|
|
59
|
+
...init,
|
|
60
|
+
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json", ...init.headers }
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function errResult(msg) {
|
|
64
|
+
return { content: [{ type: "text", text: msg }], isError: true };
|
|
65
|
+
}
|
|
66
|
+
var ALLOWED_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
67
|
+
var server = new Server(
|
|
68
|
+
{ name: "agent-authority", version: "1.0.0" },
|
|
69
|
+
{ capabilities: { tools: {} } }
|
|
70
|
+
);
|
|
71
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
72
|
+
tools: [
|
|
73
|
+
{
|
|
74
|
+
name: "list_platforms",
|
|
75
|
+
description: "List the platforms and permission scopes this agent has access to.",
|
|
76
|
+
inputSchema: { type: "object", properties: {} }
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "use_platform",
|
|
80
|
+
description: "Call an external platform API through the AgentValet proxy.",
|
|
81
|
+
inputSchema: {
|
|
82
|
+
type: "object",
|
|
83
|
+
properties: {
|
|
84
|
+
platform: { type: "string", description: "Platform ID (e.g. slack, github)" },
|
|
85
|
+
endpoint: { type: "string", description: "API path on the target platform" },
|
|
86
|
+
method: { type: "string", enum: ["GET", "POST", "PUT", "PATCH", "DELETE"] },
|
|
87
|
+
scope: { type: "string", description: "Permission scope required" },
|
|
88
|
+
data: { type: "object", description: "Optional request body" }
|
|
89
|
+
},
|
|
90
|
+
required: ["platform", "endpoint", "method", "scope"]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
}));
|
|
95
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
96
|
+
const { name, arguments: args } = request.params;
|
|
97
|
+
if (name === "list_platforms") {
|
|
98
|
+
if (AGENT_PRIVATE_KEY_RAW === "PENDING_FIRST_CALL") {
|
|
99
|
+
return errResult("Agent not yet activated \u2014 owner confirmation pending. Retry in 60 seconds.");
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const res = await bearerFetch(`${PROXY_URL}/v1/agent/permissions`, { method: "GET", headers: {} });
|
|
103
|
+
const body = await res.text();
|
|
104
|
+
if (!res.ok) return errResult(`Proxy error ${res.status}: ${body}`);
|
|
105
|
+
return { content: [{ type: "text", text: body }] };
|
|
106
|
+
} catch (e) {
|
|
107
|
+
return errResult(`Error: ${e instanceof Error ? e.message : e}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (name === "use_platform") {
|
|
111
|
+
if (AGENT_PRIVATE_KEY_RAW === "PENDING_FIRST_CALL") {
|
|
112
|
+
return errResult("Agent not yet activated \u2014 owner confirmation pending. Retry in 60 seconds.");
|
|
113
|
+
}
|
|
114
|
+
if (!args || typeof args.platform !== "string" || typeof args.endpoint !== "string" || typeof args.method !== "string" || typeof args.scope !== "string") {
|
|
115
|
+
return errResult("Missing required args: platform, endpoint, method, scope");
|
|
116
|
+
}
|
|
117
|
+
if (!ALLOWED_METHODS.includes(args.method)) return errResult(`Invalid method: ${args.method}`);
|
|
118
|
+
try {
|
|
119
|
+
const res = await bearerFetch(`${PROXY_URL}/v1/actions`, {
|
|
120
|
+
method: "POST",
|
|
121
|
+
body: JSON.stringify({
|
|
122
|
+
platform: args.platform,
|
|
123
|
+
endpoint: args.endpoint,
|
|
124
|
+
method: args.method,
|
|
125
|
+
scope: args.scope,
|
|
126
|
+
...args.data !== void 0 && { data: args.data }
|
|
127
|
+
})
|
|
128
|
+
});
|
|
129
|
+
const body = await res.text();
|
|
130
|
+
if (!res.ok) return errResult(`Proxy error ${res.status}: ${body}`);
|
|
131
|
+
return { content: [{ type: "text", text: body }] };
|
|
132
|
+
} catch (e) {
|
|
133
|
+
return errResult(`Error: ${e instanceof Error ? e.message : e}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return errResult(`Unknown tool: ${name}`);
|
|
137
|
+
});
|
|
138
|
+
var transport = new StdioServerTransport();
|
|
139
|
+
await server.connect(transport);
|
package/package.json
CHANGED
|
@@ -1,53 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@agentvalet/register",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Self-register AI agents with AgentValet",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
"agentvalet-register": "dist/index.js"
|
|
8
|
-
},
|
|
9
|
-
"files": [
|
|
10
|
-
"dist",
|
|
11
|
-
"README.md"
|
|
12
|
-
],
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
15
|
-
"dev": "tsx src/index.ts",
|
|
16
|
-
"test": "vitest run",
|
|
17
|
-
"typecheck": "tsc --noEmit",
|
|
18
|
-
"prepublishOnly": "pnpm build"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentvalet/register",
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "Self-register AI agents with AgentValet",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"agentvalet-register": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
15
|
+
"dev": "tsx src/index.ts",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"typecheck": "tsc --noEmit",
|
|
18
|
+
"prepublishOnly": "pnpm build"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
22
|
+
"chalk": "^5.3.0",
|
|
23
|
+
"commander": "^12.0.0",
|
|
24
|
+
"jose": "^6.2.2",
|
|
25
|
+
"ora": "^8.0.1",
|
|
26
|
+
"prompts": "^2.4.2",
|
|
27
|
+
"undici": "^6.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^20.0.0",
|
|
31
|
+
"@types/prompts": "^2.4.0",
|
|
32
|
+
"tsup": "^8.0.0",
|
|
33
|
+
"tsx": "^4.0.0",
|
|
34
|
+
"typescript": "^5.0.0",
|
|
35
|
+
"vitest": "^1.5.0"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/MCSEdwin/agentvalet.git",
|
|
43
|
+
"directory": "apps/cli"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"ai",
|
|
47
|
+
"agents",
|
|
48
|
+
"auth",
|
|
49
|
+
"credentials",
|
|
50
|
+
"mcp",
|
|
51
|
+
"valet",
|
|
52
|
+
"agentvalet"
|
|
53
|
+
],
|
|
54
|
+
"license": "MIT"
|
|
55
|
+
}
|