@tarielai/mcp-client 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/README.md +27 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/index.test.js +24 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @tarielai/mcp-client
|
|
2
|
+
|
|
3
|
+
Typed [Model Context Protocol](https://modelcontextprotocol.io/) client for the Tariel app (`/api/mcp`).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Public registry (recommended):
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @tarielai/mcp-client
|
|
11
|
+
```
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { TarielMcpClient } from "@tarielai/mcp-client";
|
|
16
|
+
|
|
17
|
+
const client = new TarielMcpClient({
|
|
18
|
+
baseUrl: "https://YOUR_APP_ORIGIN",
|
|
19
|
+
accessToken: process.env.TARIEL_ACCESS_TOKEN!,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
await client.connect();
|
|
23
|
+
const agents = await client.agents.list();
|
|
24
|
+
await client.close();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Requires a Tariel account with **FEATURE_MCP** and an MCP-scoped API key (`pf_live_*`).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export type TarielMcpClientOptions = {
|
|
2
|
+
/** App origin, e.g. https://app.tariel.ai (no trailing slash). */
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
/** Personal API key (pf_live_…) or Keycloak access JWT. */
|
|
5
|
+
accessToken: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class TarielMcpClient {
|
|
8
|
+
private readonly baseUrl;
|
|
9
|
+
private readonly accessToken;
|
|
10
|
+
private client;
|
|
11
|
+
private transport;
|
|
12
|
+
constructor(options: TarielMcpClientOptions);
|
|
13
|
+
get mcpUrl(): string;
|
|
14
|
+
connect(): Promise<void>;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
callTool<T = unknown>(name: string, args?: Record<string, unknown>): Promise<T>;
|
|
17
|
+
readonly projection: {
|
|
18
|
+
export: (args: {
|
|
19
|
+
asset: string;
|
|
20
|
+
exchange?: string;
|
|
21
|
+
agg?: number;
|
|
22
|
+
time?: string;
|
|
23
|
+
t?: string;
|
|
24
|
+
format?: "json" | "markdown" | "md" | "svg";
|
|
25
|
+
}) => Promise<string>;
|
|
26
|
+
credits: () => Promise<unknown>;
|
|
27
|
+
};
|
|
28
|
+
readonly news: {
|
|
29
|
+
list: (args: Record<string, unknown>) => Promise<unknown>;
|
|
30
|
+
article: (args: {
|
|
31
|
+
articleId: string;
|
|
32
|
+
asset?: string;
|
|
33
|
+
}) => Promise<unknown>;
|
|
34
|
+
};
|
|
35
|
+
readonly anchors: {
|
|
36
|
+
list: () => Promise<unknown>;
|
|
37
|
+
get: (id: string) => Promise<unknown>;
|
|
38
|
+
};
|
|
39
|
+
readonly agents: {
|
|
40
|
+
list: () => Promise<unknown>;
|
|
41
|
+
get: (id: string) => Promise<unknown>;
|
|
42
|
+
};
|
|
43
|
+
readonly orders: {
|
|
44
|
+
list: (args?: Record<string, unknown>) => Promise<unknown>;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export declare function cursorMcpConfig(input: {
|
|
48
|
+
baseUrl: string;
|
|
49
|
+
accessToken: string;
|
|
50
|
+
serverName?: string;
|
|
51
|
+
}): string;
|
|
52
|
+
export declare function mcpRemoteStdioConfig(input: {
|
|
53
|
+
baseUrl: string;
|
|
54
|
+
accessToken: string;
|
|
55
|
+
serverName?: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BAEF,MAAM;MAClB;IAEF,QAAQ,CAAC,MAAM;;kBAED,MAAM;MAClB;IAEF,QAAQ,CAAC,MAAM;sBACG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;MAEvC;CACL;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,MAAM,CAiBT;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,MAAM,CAkBT"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
3
|
+
import { PACKAGE_VERSION } from "./version.js";
|
|
4
|
+
function normalizeBaseUrl(baseUrl) {
|
|
5
|
+
return baseUrl.replace(/\/+$/, "");
|
|
6
|
+
}
|
|
7
|
+
function textFromToolContent(content) {
|
|
8
|
+
if (!content?.length)
|
|
9
|
+
return "";
|
|
10
|
+
return content
|
|
11
|
+
.filter((c) => c.type === "text" && typeof c.text === "string")
|
|
12
|
+
.map((c) => c.text)
|
|
13
|
+
.join("\n");
|
|
14
|
+
}
|
|
15
|
+
export class TarielMcpClient {
|
|
16
|
+
baseUrl;
|
|
17
|
+
accessToken;
|
|
18
|
+
client = null;
|
|
19
|
+
transport = null;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.baseUrl = normalizeBaseUrl(options.baseUrl);
|
|
22
|
+
this.accessToken = options.accessToken.trim();
|
|
23
|
+
if (!this.accessToken) {
|
|
24
|
+
throw new Error("accessToken is required");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
get mcpUrl() {
|
|
28
|
+
return `${this.baseUrl}/api/mcp`;
|
|
29
|
+
}
|
|
30
|
+
async connect() {
|
|
31
|
+
if (this.client)
|
|
32
|
+
return;
|
|
33
|
+
this.transport = new StreamableHTTPClientTransport(new URL(this.mcpUrl), {
|
|
34
|
+
requestInit: {
|
|
35
|
+
headers: {
|
|
36
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
this.client = new Client({
|
|
41
|
+
name: "@tarielai/mcp-client",
|
|
42
|
+
version: PACKAGE_VERSION,
|
|
43
|
+
});
|
|
44
|
+
await this.client.connect(this.transport);
|
|
45
|
+
}
|
|
46
|
+
async close() {
|
|
47
|
+
if (this.client) {
|
|
48
|
+
await this.client.close();
|
|
49
|
+
this.client = null;
|
|
50
|
+
}
|
|
51
|
+
this.transport = null;
|
|
52
|
+
}
|
|
53
|
+
async callTool(name, args = {}) {
|
|
54
|
+
await this.connect();
|
|
55
|
+
const result = await this.client.callTool({ name, arguments: args });
|
|
56
|
+
const content = result.content;
|
|
57
|
+
if (result.isError) {
|
|
58
|
+
throw new Error(textFromToolContent(content) || `Tool ${name} failed`);
|
|
59
|
+
}
|
|
60
|
+
const text = textFromToolContent(content);
|
|
61
|
+
if (!text)
|
|
62
|
+
return undefined;
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(text);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return text;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
projection = {
|
|
71
|
+
export: (args) => this.callTool("tariel_projection_export", args),
|
|
72
|
+
credits: () => this.callTool("tariel_projection_credits"),
|
|
73
|
+
};
|
|
74
|
+
news = {
|
|
75
|
+
list: (args) => this.callTool("tariel_news_list", args),
|
|
76
|
+
article: (args) => this.callTool("tariel_news_article", args),
|
|
77
|
+
};
|
|
78
|
+
anchors = {
|
|
79
|
+
list: () => this.callTool("tariel_anchors_list"),
|
|
80
|
+
get: (id) => this.callTool("tariel_anchors_get", { id }),
|
|
81
|
+
};
|
|
82
|
+
agents = {
|
|
83
|
+
list: () => this.callTool("tariel_agents_list"),
|
|
84
|
+
get: (id) => this.callTool("tariel_agents_get", { id }),
|
|
85
|
+
};
|
|
86
|
+
orders = {
|
|
87
|
+
list: (args) => this.callTool("tariel_orders_list", args ?? {}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export function cursorMcpConfig(input) {
|
|
91
|
+
const name = input.serverName ?? "tariel";
|
|
92
|
+
const url = `${normalizeBaseUrl(input.baseUrl)}/api/mcp`;
|
|
93
|
+
return JSON.stringify({
|
|
94
|
+
mcpServers: {
|
|
95
|
+
[name]: {
|
|
96
|
+
url,
|
|
97
|
+
headers: {
|
|
98
|
+
Authorization: `Bearer ${input.accessToken}`,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
}, null, 2);
|
|
103
|
+
}
|
|
104
|
+
export function mcpRemoteStdioConfig(input) {
|
|
105
|
+
const name = input.serverName ?? "tariel";
|
|
106
|
+
const url = `${normalizeBaseUrl(input.baseUrl)}/api/mcp`;
|
|
107
|
+
return JSON.stringify({
|
|
108
|
+
mcpServers: {
|
|
109
|
+
[name]: {
|
|
110
|
+
command: "npx",
|
|
111
|
+
args: ["-y", "mcp-remote", url],
|
|
112
|
+
env: {
|
|
113
|
+
AUTHORIZATION: `Bearer ${input.accessToken}`,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
}, null, 2);
|
|
118
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { cursorMcpConfig, mcpRemoteStdioConfig } from "./index.js";
|
|
3
|
+
describe("@tarielai/mcp-client config helpers", () => {
|
|
4
|
+
it("builds Cursor remote MCP config", () => {
|
|
5
|
+
const json = cursorMcpConfig({
|
|
6
|
+
baseUrl: "https://app.example.com/",
|
|
7
|
+
accessToken: "pf_live_test",
|
|
8
|
+
serverName: "tariel",
|
|
9
|
+
});
|
|
10
|
+
const parsed = JSON.parse(json);
|
|
11
|
+
expect(parsed.mcpServers.tariel.url).toBe("https://app.example.com/api/mcp");
|
|
12
|
+
expect(parsed.mcpServers.tariel.headers.Authorization).toBe("Bearer pf_live_test");
|
|
13
|
+
});
|
|
14
|
+
it("builds mcp-remote stdio bridge config", () => {
|
|
15
|
+
const json = mcpRemoteStdioConfig({
|
|
16
|
+
baseUrl: "https://app.example.com",
|
|
17
|
+
accessToken: "jwt-token",
|
|
18
|
+
});
|
|
19
|
+
const parsed = JSON.parse(json);
|
|
20
|
+
expect(parsed.mcpServers.tariel.command).toBe("npx");
|
|
21
|
+
expect(parsed.mcpServers.tariel.args[2]).toBe("https://app.example.com/api/mcp");
|
|
22
|
+
expect(parsed.mcpServers.tariel.env.AUTHORIZATION).toContain("jwt-token");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,eAAO,MAAM,eAAe,UAAU,CAAC"}
|
package/dist/version.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tarielai/mcp-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Typed MCP client for the Tariel API server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://www.tariel.ai",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"registry": "https://registry.npmjs.org/"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"prebuild": "node scripts/write-version.mjs",
|
|
27
|
+
"build": "tsc -p tsconfig.build.json",
|
|
28
|
+
"pretest": "node scripts/write-version.mjs",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"prepare": "npm run build"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@modelcontextprotocol/sdk": "^1.26.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"typescript": "^5.9.3",
|
|
37
|
+
"vitest": "^3.2.4"
|
|
38
|
+
}
|
|
39
|
+
}
|