@contextvm/ctxcn 1.0.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/LICENSE +21 -0
- package/README.md +178 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/src/__mocks__/mock-server.d.ts +2 -0
- package/dist/src/__mocks__/mock-server.d.ts.map +1 -0
- package/dist/src/__mocks__/mock-server.js +24 -0
- package/dist/src/__mocks__/mock-server.js.map +1 -0
- package/dist/src/commands/add.d.ts +2 -0
- package/dist/src/commands/add.d.ts.map +1 -0
- package/dist/src/commands/add.js +106 -0
- package/dist/src/commands/add.js.map +1 -0
- package/dist/src/commands/help.d.ts +2 -0
- package/dist/src/commands/help.d.ts.map +1 -0
- package/dist/src/commands/help.js +15 -0
- package/dist/src/commands/help.js.map +1 -0
- package/dist/src/commands/init.d.ts +2 -0
- package/dist/src/commands/init.d.ts.map +1 -0
- package/dist/src/commands/init.js +61 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/update.d.ts +2 -0
- package/dist/src/commands/update.d.ts.map +1 -0
- package/dist/src/commands/update.js +145 -0
- package/dist/src/commands/update.js.map +1 -0
- package/dist/src/config.d.ts +10 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +31 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/ctxcn/DemoServerClient.d.ts +38 -0
- package/dist/src/ctxcn/DemoServerClient.d.ts.map +1 -0
- package/dist/src/ctxcn/DemoServerClient.js +53 -0
- package/dist/src/ctxcn/DemoServerClient.js.map +1 -0
- package/dist/src/ctxcn/ExampleServersEverythingClient.d.ts +149 -0
- package/dist/src/ctxcn/ExampleServersEverythingClient.d.ts.map +1 -0
- package/dist/src/ctxcn/ExampleServersEverythingClient.js +118 -0
- package/dist/src/ctxcn/ExampleServersEverythingClient.js.map +1 -0
- package/dist/src/ctxcn/TestClient.d.ts +149 -0
- package/dist/src/ctxcn/TestClient.d.ts.map +1 -0
- package/dist/src/ctxcn/TestClient.js +118 -0
- package/dist/src/ctxcn/TestClient.js.map +1 -0
- package/dist/src/utils/cli.d.ts +7 -0
- package/dist/src/utils/cli.d.ts.map +1 -0
- package/dist/src/utils/cli.js +77 -0
- package/dist/src/utils/cli.js.map +1 -0
- package/dist/src/utils/schema.d.ts +11 -0
- package/dist/src/utils/schema.d.ts.map +1 -0
- package/dist/src/utils/schema.js +333 -0
- package/dist/src/utils/schema.js.map +1 -0
- package/dist/src/utils.d.ts +2 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +12 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client";
|
|
2
|
+
import { mkdir, writeFile, access, readdir } from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { toPascalCase } from "../utils";
|
|
5
|
+
import { loadConfig } from "../config";
|
|
6
|
+
import { askQuestion, askYesNo, closeReadlineInterface } from "../utils/cli";
|
|
7
|
+
import { generateClientCode } from "../utils/schema";
|
|
8
|
+
import { ApplesauceRelayPool, NostrClientTransport, PrivateKeySigner, } from "@contextvm/sdk";
|
|
9
|
+
async function findExistingClientFile(cwd, sourceDir) {
|
|
10
|
+
try {
|
|
11
|
+
const outputDir = path.join(cwd, sourceDir);
|
|
12
|
+
const existingFiles = await readdir(outputDir);
|
|
13
|
+
const existingClientFile = existingFiles.find((file) => file.endsWith(".ts") && file.includes("Client"));
|
|
14
|
+
return existingClientFile || null;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export async function handleUpdate(cwd, pubkey) {
|
|
21
|
+
console.log("đ Checking for configuration file...");
|
|
22
|
+
// Check if config file exists
|
|
23
|
+
const configPath = path.join(cwd, "ctxcn.config.json");
|
|
24
|
+
try {
|
|
25
|
+
await access(configPath);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error("â Error: Configuration file 'ctxcn.config.json' not found.");
|
|
29
|
+
console.error("Please run 'ctxcn init' first to create a configuration file.");
|
|
30
|
+
closeReadlineInterface();
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
const config = await loadConfig(cwd);
|
|
34
|
+
if (!config.addedClients || config.addedClients.length === 0) {
|
|
35
|
+
console.log("âšī¸ No clients have been added yet. Use 'ctxcn add <pubkey>' to add a client.");
|
|
36
|
+
closeReadlineInterface();
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
let targetPubkey;
|
|
40
|
+
if (pubkey) {
|
|
41
|
+
if (!config.addedClients.includes(pubkey)) {
|
|
42
|
+
console.log(`â Client with pubkey ${pubkey} is not in the list of added clients.`);
|
|
43
|
+
console.log("Added clients:");
|
|
44
|
+
config.addedClients.forEach((p, index) => {
|
|
45
|
+
console.log(` ${index + 1}. ${p}`);
|
|
46
|
+
});
|
|
47
|
+
closeReadlineInterface();
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
targetPubkey = pubkey;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// Show list of added clients and let user choose
|
|
54
|
+
console.log("\nđ Added Clients:");
|
|
55
|
+
config.addedClients.forEach((p, index) => {
|
|
56
|
+
console.log(` ${index + 1}. ${p}`);
|
|
57
|
+
});
|
|
58
|
+
const choice = await askQuestion("Enter the number of the client to update (or 'all' to update all)", "1");
|
|
59
|
+
if (choice.toLowerCase() === "all") {
|
|
60
|
+
// Update all clients
|
|
61
|
+
console.log("đ Updating all clients...");
|
|
62
|
+
for (const clientPubkey of config.addedClients) {
|
|
63
|
+
await updateSingleClient(cwd, config, clientPubkey);
|
|
64
|
+
}
|
|
65
|
+
console.log("â
All clients updated successfully.");
|
|
66
|
+
closeReadlineInterface();
|
|
67
|
+
process.exit(0);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const index = parseInt(choice) - 1;
|
|
71
|
+
if (index < 0 || index >= config.addedClients.length) {
|
|
72
|
+
console.error("â Invalid selection.");
|
|
73
|
+
closeReadlineInterface();
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
targetPubkey = config.addedClients[index];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
await updateSingleClient(cwd, config, targetPubkey);
|
|
80
|
+
closeReadlineInterface();
|
|
81
|
+
process.exit(0);
|
|
82
|
+
}
|
|
83
|
+
async function updateSingleClient(cwd, config, pubkey) {
|
|
84
|
+
console.log(`\nđ Updating client ${pubkey}...`);
|
|
85
|
+
const client = new Client({
|
|
86
|
+
name: `update-client`,
|
|
87
|
+
version: "1.0.0",
|
|
88
|
+
});
|
|
89
|
+
const transport = new NostrClientTransport({
|
|
90
|
+
signer: new PrivateKeySigner(config.privateKey),
|
|
91
|
+
relayHandler: new ApplesauceRelayPool(config.relays),
|
|
92
|
+
serverPubkey: pubkey,
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
await client.connect(transport);
|
|
96
|
+
const serverDetails = client.getServerVersion();
|
|
97
|
+
const toolListResult = await client.listTools();
|
|
98
|
+
await transport.close();
|
|
99
|
+
const newServerName = toPascalCase(serverDetails?.name || "UnknownServer");
|
|
100
|
+
// Check if there's an existing client file to determine the old name
|
|
101
|
+
const existingClientFile = await findExistingClientFile(cwd, config.source);
|
|
102
|
+
let oldServerName = null;
|
|
103
|
+
if (existingClientFile) {
|
|
104
|
+
// Extract the server name from the existing file
|
|
105
|
+
oldServerName = existingClientFile.replace("Client.ts", "");
|
|
106
|
+
}
|
|
107
|
+
let serverName = newServerName;
|
|
108
|
+
// Check if server name has changed
|
|
109
|
+
if (oldServerName && oldServerName !== newServerName) {
|
|
110
|
+
console.log(`\nâ ī¸ Server name has changed from '${oldServerName}' to '${newServerName}'.`);
|
|
111
|
+
const useNewName = await askYesNo("Do you want to use the new server name?", false);
|
|
112
|
+
if (!useNewName) {
|
|
113
|
+
serverName = oldServerName;
|
|
114
|
+
console.log(`Keeping the old server name: ${serverName}`);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
console.log(`Using the new server name: ${serverName}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
console.log(`\nđ Server Information:`);
|
|
121
|
+
console.log(` Name: ${serverDetails?.name || "Unknown"}`);
|
|
122
|
+
console.log(` Version: ${serverDetails?.version || "Unknown"}`);
|
|
123
|
+
console.log(` Tools found: ${toolListResult.tools.length}`);
|
|
124
|
+
console.log(`\nđ§ Available Tools:`);
|
|
125
|
+
toolListResult.tools.forEach((tool, index) => {
|
|
126
|
+
console.log(` ${index + 1}. ${tool.name}: ${tool.description || "No description"}`);
|
|
127
|
+
});
|
|
128
|
+
const confirm = await askYesNo("Do you want to update this client?", true);
|
|
129
|
+
if (!confirm) {
|
|
130
|
+
console.log("â Update cancelled.");
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const clientCode = await generateClientCode(pubkey, serverDetails, toolListResult, serverName);
|
|
134
|
+
const clientName = `${serverName}Client`;
|
|
135
|
+
const outputDir = path.join(cwd, config.source);
|
|
136
|
+
await mkdir(outputDir, { recursive: true });
|
|
137
|
+
const outputPath = path.join(outputDir, `${clientName}.ts`);
|
|
138
|
+
await writeFile(outputPath, clientCode);
|
|
139
|
+
console.log(`â
Updated client for ${serverName} at ${outputPath}`);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
console.error(`â Error updating client ${pubkey}:`, error);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../../src/commands/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,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AE,CAAC,CAAC;QAC5C,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,UAAU,KAAK,CAAC,CAAC;QAC5D,MAAM,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAExC,OAAO,CAAC,GAAG,CAAC,wBAAwB,UAAU,OAAO,UAAU,EAAE,CAAC,CAAC;IACrE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,2BAA2B,MAAM,GAAG,EAAE,KAAK,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface Config {
|
|
2
|
+
source: string;
|
|
3
|
+
relays: string[];
|
|
4
|
+
privateKey?: string;
|
|
5
|
+
addedClients?: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare const DEFAULT_CONFIG: Config;
|
|
8
|
+
export declare function loadConfig(cwd: string): Promise<Config>;
|
|
9
|
+
export declare function saveConfig(cwd: string, config: Config): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,eAAO,MAAM,cAAc,EAAE,MAI5B,CAAC;AAEF,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAoB7D;AAED,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG3E"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { promises as fs } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
export const DEFAULT_CONFIG = {
|
|
4
|
+
source: "src/ctxcn",
|
|
5
|
+
relays: ["ws://localhost:10547"],
|
|
6
|
+
addedClients: [],
|
|
7
|
+
};
|
|
8
|
+
export async function loadConfig(cwd) {
|
|
9
|
+
const configPath = path.join(cwd, "ctxcn.config.json");
|
|
10
|
+
try {
|
|
11
|
+
const configContent = await fs.readFile(configPath, "utf-8");
|
|
12
|
+
const userConfig = JSON.parse(configContent);
|
|
13
|
+
const config = { ...DEFAULT_CONFIG, ...userConfig };
|
|
14
|
+
if (typeof config.source !== "string" || !config.source) {
|
|
15
|
+
config.source = DEFAULT_CONFIG.source;
|
|
16
|
+
}
|
|
17
|
+
// Ensure addedClients is always an array
|
|
18
|
+
if (!config.addedClients || !Array.isArray(config.addedClients)) {
|
|
19
|
+
config.addedClients = [];
|
|
20
|
+
}
|
|
21
|
+
return config;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return DEFAULT_CONFIG;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export async function saveConfig(cwd, config) {
|
|
28
|
+
const configPath = path.join(cwd, "ctxcn.config.json");
|
|
29
|
+
await fs.writeFile(configPath, JSON.stringify(config, null, 2));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AASxB,MAAM,CAAC,MAAM,cAAc,GAAW;IACpC,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,CAAC,sBAAsB,CAAC;IAChC,YAAY,EAAE,EAAE;CACjB,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAW;IAC1C,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IACvD,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,UAAU,EAAE,CAAC;QAEpD,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACxD,MAAM,CAAC,MAAM,GAAG,cAAc,CAAC,MAAM,CAAC;QACxC,CAAC;QAED,yCAAyC;QACzC,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;YAChE,MAAM,CAAC,YAAY,GAAG,EAAE,CAAC;QAC3B,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,cAAc,CAAC;IACxB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAW,EAAE,MAAc;IAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IACvD,MAAM,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type NostrTransportOptions } from "@contextvm/sdk";
|
|
2
|
+
export type DemoServer = {
|
|
3
|
+
add: (a: number, b: number) => Promise<{
|
|
4
|
+
result: number;
|
|
5
|
+
}>;
|
|
6
|
+
echo: (input: string) => Promise<{
|
|
7
|
+
[k: string]: unknown;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
export declare class DemoServerClient implements DemoServer {
|
|
11
|
+
static readonly SERVER_PUBKEY = "ada13b4dbc773890a5e8e468b72418b9fffb51c40b78236819a721971b14fed1";
|
|
12
|
+
private client;
|
|
13
|
+
private transport;
|
|
14
|
+
constructor(options?: Partial<NostrTransportOptions> & {
|
|
15
|
+
privateKey?: string;
|
|
16
|
+
relays?: string[];
|
|
17
|
+
});
|
|
18
|
+
disconnect(): Promise<void>;
|
|
19
|
+
private call;
|
|
20
|
+
/**
|
|
21
|
+
* Add two numbers
|
|
22
|
+
* @param {number} a The first number to add
|
|
23
|
+
* @param {number} b The second number to add
|
|
24
|
+
* @returns {Promise<{ result: number; }>} The result of the add operation
|
|
25
|
+
*/
|
|
26
|
+
add(a: number, b: number): Promise<{
|
|
27
|
+
result: number;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Echoes a given input
|
|
31
|
+
* @param {string} input The input value to be echoed
|
|
32
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the echo operation
|
|
33
|
+
*/
|
|
34
|
+
echo(input: string): Promise<{
|
|
35
|
+
[k: string]: unknown;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=DemoServerClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DemoServerClient.d.ts","sourceRoot":"","sources":["../../../src/ctxcn/DemoServerClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,qBAAqB,EAG3B,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE,CACH,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,KACN,OAAO,CAAC;QACX,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;IACH,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;QAC/B,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB,CAAC,CAAC;CACJ,CAAC;AAEF,qBAAa,gBAAiB,YAAW,UAAU;IACjD,MAAM,CAAC,QAAQ,CAAC,aAAa,sEACwC;IACrE,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAY;gBAG3B,OAAO,GAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG;QACxC,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;KACd;IA6BF,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;YAInB,IAAI;IAWlB;;;;;OAKG;IACG,GAAG,CACP,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,OAAO,CAAC;QACT,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IAIF;;;;OAIG;IACG,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QACjC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB,CAAC;CAGH"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client";
|
|
2
|
+
import { NostrClientTransport, PrivateKeySigner, ApplesauceRelayPool, } from "@contextvm/sdk";
|
|
3
|
+
export class DemoServerClient {
|
|
4
|
+
static SERVER_PUBKEY = "ada13b4dbc773890a5e8e468b72418b9fffb51c40b78236819a721971b14fed1";
|
|
5
|
+
client;
|
|
6
|
+
transport;
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
this.client = new Client({
|
|
9
|
+
name: "DemoServerClient",
|
|
10
|
+
version: "1.0.0",
|
|
11
|
+
});
|
|
12
|
+
const { privateKey, relays = ["ws://localhost:10547"], signer = new PrivateKeySigner(privateKey), relayHandler = new ApplesauceRelayPool(relays), ...rest } = options;
|
|
13
|
+
this.transport = new NostrClientTransport({
|
|
14
|
+
serverPubkey: DemoServerClient.SERVER_PUBKEY,
|
|
15
|
+
signer,
|
|
16
|
+
relayHandler,
|
|
17
|
+
isStateless: true,
|
|
18
|
+
...rest,
|
|
19
|
+
});
|
|
20
|
+
// Auto-connect in constructor
|
|
21
|
+
this.client.connect(this.transport).catch((error) => {
|
|
22
|
+
console.error(`Failed to connect to server: ${error}`);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async disconnect() {
|
|
26
|
+
await this.transport.close();
|
|
27
|
+
}
|
|
28
|
+
async call(name, args) {
|
|
29
|
+
const result = await this.client.callTool({
|
|
30
|
+
name,
|
|
31
|
+
arguments: { ...args },
|
|
32
|
+
});
|
|
33
|
+
return result.structuredContent;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Add two numbers
|
|
37
|
+
* @param {number} a The first number to add
|
|
38
|
+
* @param {number} b The second number to add
|
|
39
|
+
* @returns {Promise<{ result: number; }>} The result of the add operation
|
|
40
|
+
*/
|
|
41
|
+
async add(a, b) {
|
|
42
|
+
return this.call("add", { a, b });
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Echoes a given input
|
|
46
|
+
* @param {string} input The input value to be echoed
|
|
47
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the echo operation
|
|
48
|
+
*/
|
|
49
|
+
async echo(input) {
|
|
50
|
+
return this.call("echo", { input });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=DemoServerClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DemoServerClient.js","sourceRoot":"","sources":["../../../src/ctxcn/DemoServerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAE1D,OAAO,EACL,oBAAoB,EAEpB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AAcxB,MAAM,OAAO,gBAAgB;IAC3B,MAAM,CAAU,aAAa,GAC3B,kEAAkE,CAAC;IAC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,EAAE,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,IAAI,CAAC,KAAa;QAGtB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACtC,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { type NostrTransportOptions } from "@contextvm/sdk";
|
|
2
|
+
export type ExampleServersEverything = {
|
|
3
|
+
echo: (message: string) => Promise<{
|
|
4
|
+
[k: string]: unknown;
|
|
5
|
+
}>;
|
|
6
|
+
add: (a: number, b: number) => Promise<{
|
|
7
|
+
[k: string]: unknown;
|
|
8
|
+
}>;
|
|
9
|
+
longRunningOperation: (duration?: number, steps?: number) => Promise<{
|
|
10
|
+
[k: string]: unknown;
|
|
11
|
+
}>;
|
|
12
|
+
printEnv: (args: {}) => Promise<{
|
|
13
|
+
[k: string]: unknown;
|
|
14
|
+
}>;
|
|
15
|
+
sampleLLM: (prompt: string, maxTokens?: number) => Promise<{
|
|
16
|
+
[k: string]: unknown;
|
|
17
|
+
}>;
|
|
18
|
+
getTinyImage: (args: {}) => Promise<{
|
|
19
|
+
[k: string]: unknown;
|
|
20
|
+
}>;
|
|
21
|
+
annotatedMessage: (messageType: string, includeImage?: boolean) => Promise<{
|
|
22
|
+
[k: string]: unknown;
|
|
23
|
+
}>;
|
|
24
|
+
getResourceReference: (resourceId: number) => Promise<{
|
|
25
|
+
[k: string]: unknown;
|
|
26
|
+
}>;
|
|
27
|
+
getResourceLinks: (count?: number) => Promise<{
|
|
28
|
+
[k: string]: unknown;
|
|
29
|
+
}>;
|
|
30
|
+
structuredContent: (location: string) => Promise<{
|
|
31
|
+
/**
|
|
32
|
+
* Temperature in celsius
|
|
33
|
+
*/
|
|
34
|
+
temperature: number;
|
|
35
|
+
/**
|
|
36
|
+
* Weather conditions description
|
|
37
|
+
*/
|
|
38
|
+
conditions: string;
|
|
39
|
+
/**
|
|
40
|
+
* Humidity percentage
|
|
41
|
+
*/
|
|
42
|
+
humidity: number;
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
export declare class ExampleServersEverythingClient implements ExampleServersEverything {
|
|
46
|
+
static readonly SERVER_PUBKEY = "e6bc4af0a6434e2486d382810d31092f27f616f08d76283f4c6017357f1b09f6";
|
|
47
|
+
private client;
|
|
48
|
+
private transport;
|
|
49
|
+
constructor(options?: Partial<NostrTransportOptions> & {
|
|
50
|
+
privateKey?: string;
|
|
51
|
+
relays?: string[];
|
|
52
|
+
});
|
|
53
|
+
disconnect(): Promise<void>;
|
|
54
|
+
private call;
|
|
55
|
+
/**
|
|
56
|
+
* Echoes back the input
|
|
57
|
+
* @param {string} message Message to echo
|
|
58
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the echo operation
|
|
59
|
+
*/
|
|
60
|
+
echo(message: string): Promise<{
|
|
61
|
+
[k: string]: unknown;
|
|
62
|
+
}>;
|
|
63
|
+
/**
|
|
64
|
+
* Adds two numbers
|
|
65
|
+
* @param {number} a First number
|
|
66
|
+
* @param {number} b Second number
|
|
67
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the add operation
|
|
68
|
+
*/
|
|
69
|
+
add(a: number, b: number): Promise<{
|
|
70
|
+
[k: string]: unknown;
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Demonstrates a long running operation with progress updates
|
|
74
|
+
* @param {number} duration [optional] Duration of the operation in seconds
|
|
75
|
+
* @param {number} steps [optional] Number of steps in the operation
|
|
76
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the longRunningOperation operation
|
|
77
|
+
*/
|
|
78
|
+
longRunningOperation(duration?: number, steps?: number): Promise<{
|
|
79
|
+
[k: string]: unknown;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Prints all environment variables, helpful for debugging MCP server configuration
|
|
83
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the printEnv operation
|
|
84
|
+
*/
|
|
85
|
+
printEnv(args: {}): Promise<{
|
|
86
|
+
[k: string]: unknown;
|
|
87
|
+
}>;
|
|
88
|
+
/**
|
|
89
|
+
* Samples from an LLM using MCP's sampling feature
|
|
90
|
+
* @param {string} prompt The prompt to send to the LLM
|
|
91
|
+
* @param {number} maxTokens [optional] Maximum number of tokens to generate
|
|
92
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the sampleLLM operation
|
|
93
|
+
*/
|
|
94
|
+
sampleLLM(prompt: string, maxTokens?: number): Promise<{
|
|
95
|
+
[k: string]: unknown;
|
|
96
|
+
}>;
|
|
97
|
+
/**
|
|
98
|
+
* Returns the MCP_TINY_IMAGE
|
|
99
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the getTinyImage operation
|
|
100
|
+
*/
|
|
101
|
+
getTinyImage(args: {}): Promise<{
|
|
102
|
+
[k: string]: unknown;
|
|
103
|
+
}>;
|
|
104
|
+
/**
|
|
105
|
+
* Demonstrates how annotations can be used to provide metadata about content
|
|
106
|
+
* @param {string} messageType Type of message to demonstrate different annotation patterns
|
|
107
|
+
* @param {boolean} includeImage [optional] Whether to include an example image
|
|
108
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the annotatedMessage operation
|
|
109
|
+
*/
|
|
110
|
+
annotatedMessage(messageType: string, includeImage?: boolean): Promise<{
|
|
111
|
+
[k: string]: unknown;
|
|
112
|
+
}>;
|
|
113
|
+
/**
|
|
114
|
+
* Returns a resource reference that can be used by MCP clients
|
|
115
|
+
* @param {number} resourceId ID of the resource to reference (1-100)
|
|
116
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the getResourceReference operation
|
|
117
|
+
*/
|
|
118
|
+
getResourceReference(resourceId: number): Promise<{
|
|
119
|
+
[k: string]: unknown;
|
|
120
|
+
}>;
|
|
121
|
+
/**
|
|
122
|
+
* Returns multiple resource links that reference different types of resources
|
|
123
|
+
* @param {number} count [optional] Number of resource links to return (1-10)
|
|
124
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the getResourceLinks operation
|
|
125
|
+
*/
|
|
126
|
+
getResourceLinks(count?: number): Promise<{
|
|
127
|
+
[k: string]: unknown;
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* Returns structured content along with an output schema for client data validation
|
|
131
|
+
* @param {string} location City name or zip code
|
|
132
|
+
* @returns {Promise<{ temperature: number; conditions: string; humidity: number; }>} The result of the structuredContent operation
|
|
133
|
+
*/
|
|
134
|
+
structuredContent(location: string): Promise<{
|
|
135
|
+
/**
|
|
136
|
+
* Temperature in celsius
|
|
137
|
+
*/
|
|
138
|
+
temperature: number;
|
|
139
|
+
/**
|
|
140
|
+
* Weather conditions description
|
|
141
|
+
*/
|
|
142
|
+
conditions: string;
|
|
143
|
+
/**
|
|
144
|
+
* Humidity percentage
|
|
145
|
+
*/
|
|
146
|
+
humidity: number;
|
|
147
|
+
}>;
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=ExampleServersEverythingClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExampleServersEverythingClient.d.ts","sourceRoot":"","sources":["../../../src/ctxcn/ExampleServersEverythingClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,qBAAqB,EAG3B,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;QAC/B,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB,CAAC,CAAC;IACL,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;QACnC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB,CAAC,CAAC;IACL,oBAAoB,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;QACjE,CAAC,CAAC,E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;IACG,oBAAoB,CACxB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;QACP,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB,CAAC;IAIF;;;;KAIC;IACG,gBAAgB,CACpB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC;QACP,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;KACtB,CAAC;IAIF;;;;KAIC;IACG,iBAAiB,CACrB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QACP;;UAEE;QACF,WAAW,EAAE,MAAM,CAAC;QACpB;;UAEE;QACF,UAAU,EAAE,MAAM,CAAC;QACnB;;UAEE;QACF,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CAGL"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client";
|
|
2
|
+
import { NostrClientTransport, PrivateKeySigner, ApplesauceRelayPool, } from "@contextvm/sdk";
|
|
3
|
+
export class ExampleServersEverythingClient {
|
|
4
|
+
static SERVER_PUBKEY = "e6bc4af0a6434e2486d382810d31092f27f616f08d76283f4c6017357f1b09f6";
|
|
5
|
+
client;
|
|
6
|
+
transport;
|
|
7
|
+
constructor(options = {}) {
|
|
8
|
+
this.client = new Client({
|
|
9
|
+
name: "ExampleServersEverythingClient",
|
|
10
|
+
version: "1.0.0",
|
|
11
|
+
});
|
|
12
|
+
const { privateKey, relays = ["ws://localhost:10547"], signer = new PrivateKeySigner(privateKey), relayHandler = new ApplesauceRelayPool(relays), ...rest } = options;
|
|
13
|
+
this.transport = new NostrClientTransport({
|
|
14
|
+
serverPubkey: ExampleServersEverythingClient.SERVER_PUBKEY,
|
|
15
|
+
signer,
|
|
16
|
+
relayHandler,
|
|
17
|
+
isStateless: true,
|
|
18
|
+
...rest,
|
|
19
|
+
});
|
|
20
|
+
// Auto-connect in constructor
|
|
21
|
+
this.client.connect(this.transport).catch((error) => {
|
|
22
|
+
console.error(`Failed to connect to server: ${error}`);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async disconnect() {
|
|
26
|
+
await this.transport.close();
|
|
27
|
+
}
|
|
28
|
+
async call(name, args) {
|
|
29
|
+
const result = await this.client.callTool({
|
|
30
|
+
name,
|
|
31
|
+
arguments: { ...args },
|
|
32
|
+
});
|
|
33
|
+
return result.structuredContent;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Echoes back the input
|
|
37
|
+
* @param {string} message Message to echo
|
|
38
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the echo operation
|
|
39
|
+
*/
|
|
40
|
+
async echo(message) {
|
|
41
|
+
return this.call("echo", { message });
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Adds two numbers
|
|
45
|
+
* @param {number} a First number
|
|
46
|
+
* @param {number} b Second number
|
|
47
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the add operation
|
|
48
|
+
*/
|
|
49
|
+
async add(a, b) {
|
|
50
|
+
return this.call("add", { a, b });
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Demonstrates a long running operation with progress updates
|
|
54
|
+
* @param {number} duration [optional] Duration of the operation in seconds
|
|
55
|
+
* @param {number} steps [optional] Number of steps in the operation
|
|
56
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the longRunningOperation operation
|
|
57
|
+
*/
|
|
58
|
+
async longRunningOperation(duration, steps) {
|
|
59
|
+
return this.call("longRunningOperation", { duration, steps });
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Prints all environment variables, helpful for debugging MCP server configuration
|
|
63
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the printEnv operation
|
|
64
|
+
*/
|
|
65
|
+
async printEnv(args) {
|
|
66
|
+
return this.call("printEnv", args);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Samples from an LLM using MCP's sampling feature
|
|
70
|
+
* @param {string} prompt The prompt to send to the LLM
|
|
71
|
+
* @param {number} maxTokens [optional] Maximum number of tokens to generate
|
|
72
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the sampleLLM operation
|
|
73
|
+
*/
|
|
74
|
+
async sampleLLM(prompt, maxTokens) {
|
|
75
|
+
return this.call("sampleLLM", { prompt, maxTokens });
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the MCP_TINY_IMAGE
|
|
79
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the getTinyImage operation
|
|
80
|
+
*/
|
|
81
|
+
async getTinyImage(args) {
|
|
82
|
+
return this.call("getTinyImage", args);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Demonstrates how annotations can be used to provide metadata about content
|
|
86
|
+
* @param {string} messageType Type of message to demonstrate different annotation patterns
|
|
87
|
+
* @param {boolean} includeImage [optional] Whether to include an example image
|
|
88
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the annotatedMessage operation
|
|
89
|
+
*/
|
|
90
|
+
async annotatedMessage(messageType, includeImage) {
|
|
91
|
+
return this.call("annotatedMessage", { messageType, includeImage });
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns a resource reference that can be used by MCP clients
|
|
95
|
+
* @param {number} resourceId ID of the resource to reference (1-100)
|
|
96
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the getResourceReference operation
|
|
97
|
+
*/
|
|
98
|
+
async getResourceReference(resourceId) {
|
|
99
|
+
return this.call("getResourceReference", { resourceId });
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns multiple resource links that reference different types of resources
|
|
103
|
+
* @param {number} count [optional] Number of resource links to return (1-10)
|
|
104
|
+
* @returns {Promise<{ [k: string]: unknown; }>} The result of the getResourceLinks operation
|
|
105
|
+
*/
|
|
106
|
+
async getResourceLinks(count) {
|
|
107
|
+
return this.call("getResourceLinks", { count });
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Returns structured content along with an output schema for client data validation
|
|
111
|
+
* @param {string} location City name or zip code
|
|
112
|
+
* @returns {Promise<{ temperature: number; conditions: string; humidity: number; }>} The result of the structuredContent operation
|
|
113
|
+
*/
|
|
114
|
+
async structuredContent(location) {
|
|
115
|
+
return this.call("structuredContent", { location });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=ExampleServersEverythingClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExampleServersEverythingClient.js","sourceRoot":"","sources":["../../../src/ctxcn/ExampleServersEverythingClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAE1D,OAAO,EACL,oBAAoB,EAEpB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AA8CxB,MAAM,OAAO,8BAA8B;IACzC,MAAM,CAAU,aAAa,GAAG,kEAAkE,CAAC;IAC3F,MAAM,CAAS;IACf,SAAS,CAAY;IAE7B,YACE,UAAuF,EAAE;QAEzF,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC;YACvB,IAAI,EAAE,gCAAgC;YACtC,OAAO,EAAE,OAAO;SACjB,CAAC,CAAC;QAEH,MAAM,EACJ,UAAU,EACV,MAAM,GAAG,CAAC,sBAAsB,CAAC,EACjC,MAAM,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC,EACzC,YAAY,GAAG,IAAI,mBAAmB,CAAC,MAAM,CAAC,EAC9C,GAAG,IAAI,EACR,GAAG,OAAO,CAAC;QAEZ,IAAI,CAAC,SAAS,GAAG,IAAI,oBAAoB,CAAC;YACxC,YAAY,EAAE,8BAA8B,CAAC,aAAa;YAC1D,MAAM;YACN,YAAY;YACZ,WAAW,EAAE,IAAI;YACjB,GAAG,IAAI;SACR,CAAC,CAAC;QAEH,8BAA8B;QAC9B,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK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