@graphitti/privy-core 0.1.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.
@@ -0,0 +1,14 @@
1
+ import type { ExecuteParams, PrivyCredentials, ToolResult } from "./types.js";
2
+ export declare function privyWhoami(_params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
3
+ export declare function privySearchWorkflows(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
4
+ export declare function privyGetListing(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
5
+ export declare function privyCallWorkflow(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
6
+ export declare function privyExecuteWorkflow(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
7
+ export declare function privyGetExecution(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
8
+ export declare function privyGetLinkedWallet(_params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
9
+ export declare function privyGetTreasury(_params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
10
+ export declare function privyListPayees(_params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
11
+ export declare function privyAddPayee(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
12
+ export declare function privyCreateTreasuryIntent(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
13
+ export declare function privyGetTreasuryIntent(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
14
+ export declare function privyApproveTreasuryIntent(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
@@ -0,0 +1,170 @@
1
+ import { readJson, fail, ok } from "./http.js";
2
+ import { strParam } from "./shared.js";
3
+ function baseUrl(credentials) {
4
+ return (credentials.GRAPHITTI_BASE_URL ?? "https://graphitti-five.vercel.app").replace(/\/$/, "");
5
+ }
6
+ function authHeaders(credentials) {
7
+ return {
8
+ Accept: "application/json",
9
+ "Content-Type": "application/json",
10
+ Authorization: `Bearer ${credentials.GRAPHITTI_API_KEY?.trim() ?? ""}`,
11
+ };
12
+ }
13
+ function requireGraphittiKey(credentials) {
14
+ if (!credentials.GRAPHITTI_API_KEY?.trim()) {
15
+ return fail("GRAPHITTI_API_KEY is not configured.");
16
+ }
17
+ return null;
18
+ }
19
+ async function b2bFetch(credentials, path, init) {
20
+ const keyError = requireGraphittiKey(credentials);
21
+ if (keyError) {
22
+ return keyError;
23
+ }
24
+ const response = await fetch(`${baseUrl(credentials)}/api/b2b/v1${path}`, {
25
+ ...init,
26
+ headers: { ...authHeaders(credentials), ...init?.headers },
27
+ });
28
+ const body = await readJson(response);
29
+ if (!response.ok) {
30
+ return fail(typeof body.error === "string" ? body.error : `Graphitti B2B HTTP ${response.status}`);
31
+ }
32
+ return ok(body);
33
+ }
34
+ export async function privyWhoami(_params, credentials) {
35
+ return b2bFetch(credentials, "/whoami");
36
+ }
37
+ export async function privySearchWorkflows(params, credentials) {
38
+ const url = new URL(`${baseUrl(credentials)}/api/b2b/v1/workflows`);
39
+ const q = strParam(params, "q");
40
+ const category = strParam(params, "category") ?? "privy";
41
+ if (q) {
42
+ url.searchParams.set("q", q);
43
+ }
44
+ url.searchParams.set("category", category);
45
+ const keyError = requireGraphittiKey(credentials);
46
+ if (keyError) {
47
+ return keyError;
48
+ }
49
+ const response = await fetch(url.toString(), { headers: authHeaders(credentials) });
50
+ const body = await readJson(response);
51
+ if (!response.ok) {
52
+ return fail(typeof body.error === "string" ? body.error : `Graphitti B2B HTTP ${response.status}`);
53
+ }
54
+ return ok({ ...body, query_url: url.toString() });
55
+ }
56
+ export async function privyGetListing(params, credentials) {
57
+ const slug = strParam(params, "slug");
58
+ if (!slug) {
59
+ return fail("slug is required");
60
+ }
61
+ return b2bFetch(credentials, `/listings/${encodeURIComponent(slug)}`);
62
+ }
63
+ export async function privyCallWorkflow(params, credentials) {
64
+ const slug = strParam(params, "slug");
65
+ if (!slug) {
66
+ return fail("slug is required");
67
+ }
68
+ const input = params.input && typeof params.input === "object" && !Array.isArray(params.input)
69
+ ? params.input
70
+ : {};
71
+ const keyError = requireGraphittiKey(credentials);
72
+ if (keyError) {
73
+ return keyError;
74
+ }
75
+ const response = await fetch(`${baseUrl(credentials)}/api/b2b/v1/listings/${encodeURIComponent(slug)}/call`, {
76
+ method: "POST",
77
+ headers: authHeaders(credentials),
78
+ body: JSON.stringify({ input }),
79
+ });
80
+ const body = await readJson(response);
81
+ if (response.status === 402) {
82
+ return ok({
83
+ payment_required: true,
84
+ status: 402,
85
+ details: body,
86
+ note: "Listed workflow requires payment or owner GRAPHITTI_API_KEY.",
87
+ });
88
+ }
89
+ if (!response.ok) {
90
+ return fail(typeof body.error === "string" ? body.error : `Graphitti B2B HTTP ${response.status}`);
91
+ }
92
+ return ok({ result: body, slug });
93
+ }
94
+ export async function privyExecuteWorkflow(params, credentials) {
95
+ const workflowId = strParam(params, "workflow_id") ?? strParam(params, "workflowId");
96
+ if (!workflowId) {
97
+ return fail("workflow_id is required");
98
+ }
99
+ const input = params.input && typeof params.input === "object" && !Array.isArray(params.input)
100
+ ? params.input
101
+ : {};
102
+ return b2bFetch(credentials, `/workflows/${encodeURIComponent(workflowId)}/execute`, {
103
+ method: "POST",
104
+ body: JSON.stringify({ input }),
105
+ });
106
+ }
107
+ export async function privyGetExecution(params, credentials) {
108
+ const executionId = strParam(params, "execution_id") ?? strParam(params, "executionId");
109
+ if (!executionId) {
110
+ return fail("execution_id is required");
111
+ }
112
+ return b2bFetch(credentials, `/workflows/executions/${encodeURIComponent(executionId)}`);
113
+ }
114
+ export async function privyGetLinkedWallet(_params, credentials) {
115
+ return b2bFetch(credentials, "/wallet");
116
+ }
117
+ export async function privyGetTreasury(_params, credentials) {
118
+ return b2bFetch(credentials, "/treasury");
119
+ }
120
+ export async function privyListPayees(_params, credentials) {
121
+ return b2bFetch(credentials, "/treasury/payees");
122
+ }
123
+ export async function privyAddPayee(params, credentials) {
124
+ const label = strParam(params, "label");
125
+ const address = strParam(params, "address");
126
+ if (!(label && address)) {
127
+ return fail("label and address are required");
128
+ }
129
+ return b2bFetch(credentials, "/treasury/payees", {
130
+ method: "POST",
131
+ body: JSON.stringify({
132
+ label,
133
+ address,
134
+ defaultAmountUsdc: strParam(params, "default_amount_usdc"),
135
+ chain: strParam(params, "chain") ?? "base_sepolia",
136
+ }),
137
+ });
138
+ }
139
+ export async function privyCreateTreasuryIntent(params, credentials) {
140
+ const amountUsdc = strParam(params, "amount_usdc") ?? strParam(params, "amountUsdc");
141
+ const toAddress = strParam(params, "to_address") ?? strParam(params, "toAddress");
142
+ if (!(amountUsdc && toAddress)) {
143
+ return fail("amount_usdc and to_address are required");
144
+ }
145
+ return b2bFetch(credentials, "/treasury/intents", {
146
+ method: "POST",
147
+ body: JSON.stringify({
148
+ amountUsdc,
149
+ toAddress,
150
+ payeeId: strParam(params, "payee_id") ?? strParam(params, "payeeId"),
151
+ }),
152
+ });
153
+ }
154
+ export async function privyGetTreasuryIntent(params, credentials) {
155
+ const intentId = strParam(params, "intent_id") ?? strParam(params, "intentId");
156
+ if (!intentId) {
157
+ return fail("intent_id is required");
158
+ }
159
+ return b2bFetch(credentials, `/treasury/intents/${encodeURIComponent(intentId)}`);
160
+ }
161
+ export async function privyApproveTreasuryIntent(params, credentials) {
162
+ const intentId = strParam(params, "intent_id") ?? strParam(params, "intentId");
163
+ if (!intentId) {
164
+ return fail("intent_id is required");
165
+ }
166
+ return b2bFetch(credentials, `/treasury/intents/${encodeURIComponent(intentId)}/approve`, {
167
+ method: "POST",
168
+ body: JSON.stringify({}),
169
+ });
170
+ }
package/dist/http.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export declare function readJson<T>(response: Response): Promise<T>;
2
+ export declare function fail(message: string): {
3
+ success: false;
4
+ error: string;
5
+ };
6
+ export declare function ok(data: Record<string, unknown>): {
7
+ success: true;
8
+ data: Record<string, unknown>;
9
+ };
package/dist/http.js ADDED
@@ -0,0 +1,18 @@
1
+ export async function readJson(response) {
2
+ const text = await response.text();
3
+ if (!text) {
4
+ return {};
5
+ }
6
+ try {
7
+ return JSON.parse(text);
8
+ }
9
+ catch {
10
+ return { message: text };
11
+ }
12
+ }
13
+ export function fail(message) {
14
+ return { success: false, error: message };
15
+ }
16
+ export function ok(data) {
17
+ return { success: true, data };
18
+ }
@@ -0,0 +1,2 @@
1
+ export { executePrivyTool, listAvailableTools, resolveCredentials, validatePrivyCredentials, PRIVY_TOOLS, PRIVY_TOOL_HANDLERS, } from "./execute.js";
2
+ export type { PrivyCredentials, PrivyToolDefinition, ToolResult } from "./types.js";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { executePrivyTool, listAvailableTools, resolveCredentials, validatePrivyCredentials, PRIVY_TOOLS, PRIVY_TOOL_HANDLERS, } from "./execute.js";
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ import { listAvailableTools } from "./catalog.js";
3
+ import { resolveCredentials } from "./credentials.js";
4
+ import { executePrivyTool } from "./execute.js";
5
+ const credentials = resolveCredentials();
6
+ function jsonRpc(id, result) {
7
+ return JSON.stringify({ jsonrpc: "2.0", id, result });
8
+ }
9
+ function jsonRpcError(id, code, message) {
10
+ return JSON.stringify({ jsonrpc: "2.0", id, error: { code, message } });
11
+ }
12
+ async function handleRequest(body) {
13
+ const id = body.id ?? null;
14
+ if (body.method === "initialize") {
15
+ return jsonRpc(id, {
16
+ protocolVersion: "2024-11-05",
17
+ capabilities: { tools: {} },
18
+ serverInfo: { name: "privy-protocol", version: "0.1.0" },
19
+ });
20
+ }
21
+ if (body.method === "tools/list") {
22
+ const tools = listAvailableTools(credentials).map((tool) => ({
23
+ name: tool.name,
24
+ description: tool.description,
25
+ inputSchema: tool.parameters,
26
+ }));
27
+ return jsonRpc(id, { tools });
28
+ }
29
+ if (body.method === "tools/call") {
30
+ const name = String(body.params?.name ?? "");
31
+ const args = (body.params?.arguments ?? {});
32
+ const result = await executePrivyTool(name, args, credentials);
33
+ const text = result.success
34
+ ? JSON.stringify(result.data, null, 2)
35
+ : result.error;
36
+ if (!result.success) {
37
+ return jsonRpc(id, {
38
+ content: [{ type: "text", text }],
39
+ isError: true,
40
+ });
41
+ }
42
+ return jsonRpc(id, {
43
+ content: [{ type: "text", text }],
44
+ });
45
+ }
46
+ return jsonRpcError(id, -32_601, `Method not found: ${body.method}`);
47
+ }
48
+ async function readStdin() {
49
+ const chunks = [];
50
+ for await (const chunk of process.stdin) {
51
+ chunks.push(Buffer.from(chunk));
52
+ }
53
+ return Buffer.concat(chunks).toString("utf8");
54
+ }
55
+ async function main() {
56
+ const raw = await readStdin();
57
+ if (!raw.trim()) {
58
+ process.stdout.write(jsonRpcError(null, -32_600, "Empty MCP request body"));
59
+ return;
60
+ }
61
+ let body;
62
+ try {
63
+ body = JSON.parse(raw);
64
+ }
65
+ catch {
66
+ process.stdout.write(jsonRpcError(null, -32_700, "Invalid JSON"));
67
+ return;
68
+ }
69
+ const response = await handleRequest(body);
70
+ process.stdout.write(`${response}\n`);
71
+ }
72
+ main().catch((error) => {
73
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
74
+ process.exit(1);
75
+ });
@@ -0,0 +1,23 @@
1
+ import type { ExecuteParams, PrivyCredentials, ToolResult } from "./types.js";
2
+ export declare function privyGetUser(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
3
+ export declare function privyListUsers(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
4
+ export declare function privyListWallets(_params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
5
+ export declare function privyCreateWallet(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
6
+ export declare function privyGetWallet(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
7
+ export declare function privyGetWalletByAddress(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
8
+ export declare function privyGetBalance(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
9
+ export declare function privyGetTransaction(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
10
+ export declare function privySignMessage(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
11
+ export declare function privySignTypedData(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
12
+ export declare function privySendTransaction(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
13
+ export declare function privyTransfer(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
14
+ export declare function privyWalletTransfer(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
15
+ export declare function privyWalletSwap(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
16
+ export declare function privyCreatePolicy(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
17
+ export declare function privyGetPolicy(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
18
+ export declare function privyCreateKeyQuorum(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
19
+ export declare function privyGetKeyQuorum(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
20
+ export declare function privyCreateTransferIntent(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
21
+ export declare function privyCreateRpcIntent(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
22
+ export declare function privyGetIntent(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;
23
+ export declare function privyListIntents(params: ExecuteParams, credentials: PrivyCredentials): Promise<ToolResult>;