tru-mcp 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.
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/dist/api-client.d.ts +107 -0
- package/dist/api-client.js +75 -0
- package/dist/api-client.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +2 -0
- package/dist/init.js +155 -0
- package/dist/init.js.map +1 -0
- package/dist/tools/check_charge_status.d.ts +23 -0
- package/dist/tools/check_charge_status.js +60 -0
- package/dist/tools/check_charge_status.js.map +1 -0
- package/dist/tools/check_identity.d.ts +23 -0
- package/dist/tools/check_identity.js +56 -0
- package/dist/tools/check_identity.js.map +1 -0
- package/dist/tools/check_request_status.d.ts +23 -0
- package/dist/tools/check_request_status.js +87 -0
- package/dist/tools/check_request_status.js.map +1 -0
- package/dist/tools/create_charge.d.ts +46 -0
- package/dist/tools/create_charge.js +135 -0
- package/dist/tools/create_charge.js.map +1 -0
- package/dist/tools/discover_apps.d.ts +18 -0
- package/dist/tools/discover_apps.js +56 -0
- package/dist/tools/discover_apps.js.map +1 -0
- package/dist/tools/initiate_oauth.d.ts +23 -0
- package/dist/tools/initiate_oauth.js +75 -0
- package/dist/tools/initiate_oauth.js.map +1 -0
- package/dist/tools/read_skill.d.ts +23 -0
- package/dist/tools/read_skill.js +50 -0
- package/dist/tools/read_skill.js.map +1 -0
- package/dist/tools/register_app.d.ts +35 -0
- package/dist/tools/register_app.js +83 -0
- package/dist/tools/register_app.js.map +1 -0
- package/dist/tools/request_credentials.d.ts +27 -0
- package/dist/tools/request_credentials.js +63 -0
- package/dist/tools/request_credentials.js.map +1 -0
- package/dist/tools/request_virtual_card.d.ts +33 -0
- package/dist/tools/request_virtual_card.js +124 -0
- package/dist/tools/request_virtual_card.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const registerAppTool: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
service_name: z.ZodString;
|
|
7
|
+
display_name: z.ZodString;
|
|
8
|
+
owner_email: z.ZodString;
|
|
9
|
+
description: z.ZodOptional<z.ZodString>;
|
|
10
|
+
website: z.ZodOptional<z.ZodString>;
|
|
11
|
+
allowed_fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
12
|
+
redirect_uris: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
13
|
+
};
|
|
14
|
+
handler: (args: {
|
|
15
|
+
service_name: string;
|
|
16
|
+
display_name: string;
|
|
17
|
+
owner_email: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
website?: string;
|
|
20
|
+
allowed_fields?: string[];
|
|
21
|
+
redirect_uris?: string[];
|
|
22
|
+
}) => Promise<{
|
|
23
|
+
content: {
|
|
24
|
+
type: "text";
|
|
25
|
+
text: string;
|
|
26
|
+
}[];
|
|
27
|
+
isError?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
content: {
|
|
30
|
+
type: "text";
|
|
31
|
+
text: string;
|
|
32
|
+
}[];
|
|
33
|
+
isError: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { registerApp } from "../api-client.js";
|
|
3
|
+
export const registerAppTool = {
|
|
4
|
+
name: "register_app",
|
|
5
|
+
description: "[Developer tool] Register a new app on the tru platform. This is for developers integrating tru into their service — not for end users. " +
|
|
6
|
+
"Returns an API key that the developer must save immediately.",
|
|
7
|
+
inputSchema: {
|
|
8
|
+
service_name: z
|
|
9
|
+
.string()
|
|
10
|
+
.describe("Lowercase slug for the app (letters, numbers, hyphens). Must be unique."),
|
|
11
|
+
display_name: z
|
|
12
|
+
.string()
|
|
13
|
+
.describe("Human-friendly display name for the app"),
|
|
14
|
+
owner_email: z
|
|
15
|
+
.string()
|
|
16
|
+
.describe("Email of the tru user who will own this app"),
|
|
17
|
+
description: z
|
|
18
|
+
.string()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe("One-line description of what the app does"),
|
|
21
|
+
website: z
|
|
22
|
+
.string()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe("The app's public URL"),
|
|
25
|
+
allowed_fields: z
|
|
26
|
+
.array(z.string())
|
|
27
|
+
.optional()
|
|
28
|
+
.describe("Credential fields this app can request (e.g. ['name', 'email', 'phone'])"),
|
|
29
|
+
redirect_uris: z
|
|
30
|
+
.array(z.string())
|
|
31
|
+
.optional()
|
|
32
|
+
.describe("OAuth redirect URIs for the app"),
|
|
33
|
+
},
|
|
34
|
+
handler: async (args) => {
|
|
35
|
+
try {
|
|
36
|
+
const result = await registerApp(args);
|
|
37
|
+
return {
|
|
38
|
+
content: [
|
|
39
|
+
{
|
|
40
|
+
type: "text",
|
|
41
|
+
text: [
|
|
42
|
+
`App registered successfully.`,
|
|
43
|
+
``,
|
|
44
|
+
`App ID: ${result.app.id}`,
|
|
45
|
+
`Service name: ${result.app.service_name}`,
|
|
46
|
+
`Display name: ${result.app.display_name}`,
|
|
47
|
+
`Status: ${result.app.status}`,
|
|
48
|
+
``,
|
|
49
|
+
`API Key: ${result.api_key}`,
|
|
50
|
+
``,
|
|
51
|
+
`WARNING: Save this API key now — it cannot be retrieved later.`,
|
|
52
|
+
`Use it as TRU_API_KEY when configuring the tru MCP server or REST API.`,
|
|
53
|
+
].join("\n"),
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
60
|
+
if (message.includes("409")) {
|
|
61
|
+
return {
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
type: "text",
|
|
65
|
+
text: `An app with service_name "${args.service_name}" already exists. Choose a different name.`,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
isError: true,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
content: [
|
|
73
|
+
{
|
|
74
|
+
type: "text",
|
|
75
|
+
text: `Error registering app: ${message}`,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
isError: true,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=register_app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register_app.js","sourceRoot":"","sources":["../../src/tools/register_app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,cAAc;IACpB,WAAW,EACT,0IAA0I;QAC1I,8DAA8D;IAChE,WAAW,EAAE;QACX,YAAY,EAAE,CAAC;aACZ,MAAM,EAAE;aACR,QAAQ,CAAC,yEAAyE,CAAC;QACtF,YAAY,EAAE,CAAC;aACZ,MAAM,EAAE;aACR,QAAQ,CAAC,yCAAyC,CAAC;QACtD,WAAW,EAAE,CAAC;aACX,MAAM,EAAE;aACR,QAAQ,CAAC,6CAA6C,CAAC;QAC1D,WAAW,EAAE,CAAC;aACX,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CAAC,2CAA2C,CAAC;QACxD,OAAO,EAAE,CAAC;aACP,MAAM,EAAE;aACR,QAAQ,EAAE;aACV,QAAQ,CAAC,sBAAsB,CAAC;QACnC,cAAc,EAAE,CAAC;aACd,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;aACjB,QAAQ,EAAE;aACV,QAAQ,CAAC,0EAA0E,CAAC;QACvF,aAAa,EAAE,CAAC;aACb,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;aACjB,QAAQ,EAAE;aACV,QAAQ,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 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const requestCredentialsTool: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
email: z.ZodString;
|
|
7
|
+
service: z.ZodString;
|
|
8
|
+
fields: z.ZodArray<z.ZodString>;
|
|
9
|
+
};
|
|
10
|
+
handler: (args: {
|
|
11
|
+
email: string;
|
|
12
|
+
service: string;
|
|
13
|
+
fields: string[];
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
content: {
|
|
16
|
+
type: "text";
|
|
17
|
+
text: string;
|
|
18
|
+
}[];
|
|
19
|
+
isError?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
content: {
|
|
22
|
+
type: "text";
|
|
23
|
+
text: string;
|
|
24
|
+
}[];
|
|
25
|
+
isError: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { checkIdentity, requestCredentials } from "../api-client.js";
|
|
3
|
+
export const requestCredentialsTool = {
|
|
4
|
+
name: "request_credentials",
|
|
5
|
+
description: "Request specific credential fields from a tru user. The user will be notified and must approve the request on their dashboard.",
|
|
6
|
+
inputSchema: {
|
|
7
|
+
email: z.string().describe("Email address of the tru user"),
|
|
8
|
+
service: z.string().describe("Name of the service requesting credentials"),
|
|
9
|
+
fields: z
|
|
10
|
+
.array(z.string())
|
|
11
|
+
.describe("List of fields to request, e.g. ['name', 'email', 'phone', 'address', 'banking']"),
|
|
12
|
+
},
|
|
13
|
+
handler: async (args) => {
|
|
14
|
+
try {
|
|
15
|
+
// First check if the user exists and is verified
|
|
16
|
+
const identity = await checkIdentity(args.email);
|
|
17
|
+
if (!identity.verified) {
|
|
18
|
+
const reason = identity.reason === "user_not_found"
|
|
19
|
+
? "No tru account found for this email."
|
|
20
|
+
: identity.reason === "not_verified"
|
|
21
|
+
? "This user has not completed tru identity verification."
|
|
22
|
+
: identity.reason === "no_vault"
|
|
23
|
+
? "This user's credential vault is not populated."
|
|
24
|
+
: `User is not verified (${identity.reason}).`;
|
|
25
|
+
return {
|
|
26
|
+
content: [
|
|
27
|
+
{
|
|
28
|
+
type: "text",
|
|
29
|
+
text: `Cannot request credentials: ${reason}`,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
// User is verified — create the credential request
|
|
35
|
+
const request = await requestCredentials(args.email, args.service, args.fields);
|
|
36
|
+
const lines = [
|
|
37
|
+
`Credential request created successfully.`,
|
|
38
|
+
``,
|
|
39
|
+
`Request ID: ${request.id}`,
|
|
40
|
+
`User: ${args.email}`,
|
|
41
|
+
`Service: ${args.service}`,
|
|
42
|
+
`Fields requested: ${args.fields.join(", ")}`,
|
|
43
|
+
`Status: pending`,
|
|
44
|
+
``,
|
|
45
|
+
`The user has been notified and must approve this request on their tru dashboard.`,
|
|
46
|
+
`Use the check_request_status tool with request ID "${request.id}" to check if the user has responded.`,
|
|
47
|
+
];
|
|
48
|
+
return {
|
|
49
|
+
content: [{ type: "text", text: lines.join("\n") }],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
54
|
+
return {
|
|
55
|
+
content: [
|
|
56
|
+
{ type: "text", text: `Error requesting credentials: ${message}` },
|
|
57
|
+
],
|
|
58
|
+
isError: true,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=request_credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request_credentials.js","sourceRoot":"","sources":["../../src/tools/request_credentials.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAErE,MAAM,CAAC,MAAM,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,SAAS,IAAI,CAAC,KAAK,EAAE;gBACrB,YAAY,IAAI,CAAC,OAAO,EAAE;gBAC1B,qBAAqB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBAC7C,iBAAiB;gBACjB,EAAE;gBACF,kFAAkF;gBAClF,sDAAsD,OAAO,CAAC,EAAE,uCAAuC;aACxG,CAAC;YAEF,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;aAC7D,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,OAAO;gBACL,OAAO,EAAE;oBACP,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,iCAAiC,OAAO,EAAE,EAAE;iBAC5E;gBACD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const requestVirtualCardTool: {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
inputSchema: {
|
|
6
|
+
email: z.ZodString;
|
|
7
|
+
amount_cents: z.ZodNumber;
|
|
8
|
+
description: z.ZodOptional<z.ZodString>;
|
|
9
|
+
target_service: z.ZodOptional<z.ZodString>;
|
|
10
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
11
|
+
action: z.ZodOptional<z.ZodString>;
|
|
12
|
+
};
|
|
13
|
+
handler: (args: {
|
|
14
|
+
email: string;
|
|
15
|
+
amount_cents: number;
|
|
16
|
+
description?: string;
|
|
17
|
+
target_service?: string;
|
|
18
|
+
currency?: string;
|
|
19
|
+
action?: string;
|
|
20
|
+
}) => Promise<{
|
|
21
|
+
content: {
|
|
22
|
+
type: "text";
|
|
23
|
+
text: string;
|
|
24
|
+
}[];
|
|
25
|
+
isError?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
content: {
|
|
28
|
+
type: "text";
|
|
29
|
+
text: string;
|
|
30
|
+
}[];
|
|
31
|
+
isError: boolean;
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { requestAgentCard } from "../api-client.js";
|
|
3
|
+
export const requestVirtualCardTool = {
|
|
4
|
+
name: "request_virtual_card",
|
|
5
|
+
description: "Request a one-time virtual card to make a purchase on behalf of a user. " +
|
|
6
|
+
"The card is issued instantly if the user's agent rules allow it. " +
|
|
7
|
+
"If the amount exceeds the user's spending limits, the request is escalated " +
|
|
8
|
+
"for manual approval in the user's tru dashboard. " +
|
|
9
|
+
"The card auto-expires after 60 minutes and can only be used once.",
|
|
10
|
+
inputSchema: {
|
|
11
|
+
email: z.string().describe("Email address of the tru user who will be charged"),
|
|
12
|
+
amount_cents: z
|
|
13
|
+
.number()
|
|
14
|
+
.int()
|
|
15
|
+
.positive()
|
|
16
|
+
.describe("Amount in cents (e.g. 4999 for $49.99)"),
|
|
17
|
+
description: z
|
|
18
|
+
.string()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe("What this purchase is for (shown to the user)"),
|
|
21
|
+
target_service: z
|
|
22
|
+
.string()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe("The merchant or service where this card will be used (e.g. 'clayking.com')"),
|
|
25
|
+
currency: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe("Currency code (default: 'usd')"),
|
|
29
|
+
action: z
|
|
30
|
+
.string()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe("The action being performed (e.g. 'purchase products', 'book flight'). Used to evaluate action permission rules."),
|
|
33
|
+
},
|
|
34
|
+
handler: async (args) => {
|
|
35
|
+
try {
|
|
36
|
+
const result = await requestAgentCard(args.email, args.amount_cents, args.description, args.target_service, args.currency, args.action);
|
|
37
|
+
if (result.status === "escalated") {
|
|
38
|
+
return {
|
|
39
|
+
content: [
|
|
40
|
+
{
|
|
41
|
+
type: "text",
|
|
42
|
+
text: [
|
|
43
|
+
`Escalated: This purchase requires user approval.`,
|
|
44
|
+
`Reason: ${result.rule_evaluation?.reason || "Exceeds spending limits"}`,
|
|
45
|
+
`Charge request ID: ${result.charge_request_id}`,
|
|
46
|
+
``,
|
|
47
|
+
`The user needs to approve this in their tru dashboard.`,
|
|
48
|
+
`You can check the status with the check_request_status tool.`,
|
|
49
|
+
].join("\n"),
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const card = result.virtual_card;
|
|
55
|
+
if (!card) {
|
|
56
|
+
return {
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: "text",
|
|
60
|
+
text: "Error: Card was approved but no card details were returned.",
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
isError: true,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const amount = (args.amount_cents / 100).toFixed(2);
|
|
67
|
+
return {
|
|
68
|
+
content: [
|
|
69
|
+
{
|
|
70
|
+
type: "text",
|
|
71
|
+
text: [
|
|
72
|
+
`Virtual card issued successfully.`,
|
|
73
|
+
``,
|
|
74
|
+
`Card number: ${card.number}`,
|
|
75
|
+
`Expiry: ${String(card.exp_month).padStart(2, "0")}/${card.exp_year}`,
|
|
76
|
+
`CVC: ${card.cvc}`,
|
|
77
|
+
`Brand: ${card.brand}`,
|
|
78
|
+
``,
|
|
79
|
+
`Spending limit: $${amount} ${args.currency || "USD"}`,
|
|
80
|
+
`Target: ${args.target_service || "Any merchant"}`,
|
|
81
|
+
``,
|
|
82
|
+
`This card is single-use and expires in 60 minutes.`,
|
|
83
|
+
`Do not share these details with the user — use them to complete the purchase.`,
|
|
84
|
+
].join("\n"),
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
91
|
+
// Parse structured error responses
|
|
92
|
+
if (message.includes("rules_denied")) {
|
|
93
|
+
return {
|
|
94
|
+
content: [
|
|
95
|
+
{
|
|
96
|
+
type: "text",
|
|
97
|
+
text: `Denied: The user's agent rules do not allow this purchase. ${message}`,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (message.includes("no_payment_method")) {
|
|
103
|
+
return {
|
|
104
|
+
content: [
|
|
105
|
+
{
|
|
106
|
+
type: "text",
|
|
107
|
+
text: `The user has no payment method on file. They need to add a card in their tru dashboard first.`,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
content: [
|
|
114
|
+
{
|
|
115
|
+
type: "text",
|
|
116
|
+
text: `Error requesting virtual card: ${message}`,
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
isError: true,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=request_virtual_card.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request_virtual_card.js","sourceRoot":"","sources":["../../src/tools/request_virtual_card.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,IAAI,EAAE,sBAAsB;IAC5B,WAAW,EACT,0EAA0E;QAC1E,mEAAmE;QACnE,6EAA6E;QAC7E,mDAAmD;QACnD,mEAAmE;IACrE,WAAW,EAAE;QACX,KAAK,EAAE,CAAC,CAAC,MAAM,EAA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,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,CAAC;gBAC1C,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAe;4BACrB,IAAI,EAAE,+FAA+F;yBACtG;qBACF;iBACF,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,kCAAkC,OAAO,EAAE;qBAClD;iBACF;gBACD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tru-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for tru — portable identity and billing for AI agents",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"tru-mcp": "dist/index.js",
|
|
8
|
+
"tru-mcp-init": "./dist/init.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "tsx src/index.ts",
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"start": "node dist/index.js",
|
|
19
|
+
"prepublishOnly": "npm run build"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"mcp",
|
|
23
|
+
"model-context-protocol",
|
|
24
|
+
"tru",
|
|
25
|
+
"identity",
|
|
26
|
+
"billing",
|
|
27
|
+
"ai-agents",
|
|
28
|
+
"claude"
|
|
29
|
+
],
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/dwurtz/tru"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.5.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^22.10.7",
|
|
43
|
+
"tsx": "^4.19.2",
|
|
44
|
+
"typescript": "^5.7.3"
|
|
45
|
+
}
|
|
46
|
+
}
|