@dritan/mcp 0.7.0 → 0.9.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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/dist/index.js +33 -17
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -79,13 +79,13 @@ npm run build && npm start
79
79
 
80
80
  ## Notes
81
81
 
82
- - Wallets default to `~/.config/dritan-mcp/wallets`.
82
+ - Wallets default to the current working directory (`process.cwd()`).
83
83
  - Private keys never leave local files; only public address/signature are returned.
84
84
  - `swap_sign_and_broadcast` signs locally, then broadcasts via Dritan.
85
85
  - `auth_set_api_key` activates a key for the running MCP process without restart.
86
86
  - `auth_set_api_key` and successful `x402_create_api_key` responses include a capability summary so agents can immediately guide users to next actions.
87
87
  - Agent onboarding without `DRITAN_API_KEY` should present two options:
88
- - Option 1: paid x402 flow (`x402_get_pricing` -> `x402_create_api_key_quote` -> user funds agent wallet -> `wallet_transfer_sol` -> `x402_create_api_key`).
88
+ - Option 1: paid x402 flow (`wallet_create_local` in current directory -> share wallet + backup file path -> user chooses SOL amount and funds agent wallet -> if no key exists use `x402_create_api_key_quote` -> `wallet_transfer_sol` -> `x402_create_api_key`).
89
89
  - Option 2: user gets a free key at `https://dritan.dev`.
90
90
  - `x402_create_api_key` auto-activates returned keys for the current MCP session.
91
91
  - `token_get_ohlcv_chart` returns a shareable chart URL plus a ready-to-send markdown image snippet.
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  import { mkdirSync, readFileSync, existsSync } from "node:fs";
3
- import { homedir } from "node:os";
4
3
  import { dirname, join, resolve } from "node:path";
5
4
  import { spawnSync } from "node:child_process";
6
5
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
@@ -9,7 +8,7 @@ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextpro
9
8
  import { DritanClient, MeteoraThsClient, } from "dritan-sdk";
10
9
  import { Connection, Keypair, PublicKey, SystemProgram, Transaction, VersionedTransaction, clusterApiUrl, } from "@solana/web3.js";
11
10
  import { z } from "zod";
12
- const DEFAULT_WALLET_DIR = join(homedir(), ".config", "dritan-mcp", "wallets");
11
+ const DEFAULT_WALLET_DIR = process.cwd();
13
12
  const LAMPORTS_PER_SOL = 1_000_000_000;
14
13
  function normalizeApiKey(value) {
15
14
  const trimmed = value?.trim();
@@ -67,9 +66,13 @@ const server = new Server({
67
66
  tools: {},
68
67
  },
69
68
  instructions: [
70
- "This server supports two API-key onboarding options when DRITAN_API_KEY is missing:",
71
- "1) x402 pay-per-use key flow: create wallet, receive SOL, create quote, forward payment, claim key.",
72
- "2) Free key flow: user creates a free API key at https://dritan.dev.",
69
+ "API-key onboarding policy when DRITAN_API_KEY is missing:",
70
+ "Default path is x402-first. Do not ask user for an API key first.",
71
+ "1) x402 pay-per-use key flow (default):",
72
+ " a) Create a local agent wallet with wallet_create_local (saved in current working directory by default).",
73
+ " b) Ask user how much SOL they want to allocate and provide both wallet address and backup file path.",
74
+ " c) If no active key exists, create quote -> pay from agent wallet -> claim key.",
75
+ "2) Fallback only: if user explicitly declines funding or x402 cannot proceed, then offer free key flow at https://dritan.dev.",
73
76
  "After key is obtained, set it with auth_set_api_key (no restart needed), or restart with DRITAN_API_KEY configured.",
74
77
  "Suggested setup command:",
75
78
  " claude mcp add dritan-mcp -e DRITAN_API_KEY=<your-key> -- npx @dritan/mcp@latest",
@@ -81,8 +84,9 @@ function getControlBaseUrl() {
81
84
  function missingApiKeyError() {
82
85
  return new Error([
83
86
  "Missing DRITAN_API_KEY in environment.",
84
- "Option 1 (paid): use x402 tools (x402_get_pricing, x402_create_api_key_quote, x402_create_api_key) and wallet tools.",
85
- "Option 2 (free): create a free key at https://dritan.dev and set DRITAN_API_KEY.",
87
+ "Onboarding is x402-first by default: use wallet and x402 tools before asking user for an API key.",
88
+ "Paid flow order: create wallet in current directory -> tell user funding amount + backup file path -> if no key exists then create/claim x402 key.",
89
+ "Fallback only if user declines funding or x402 is not possible: user can create a free key at https://dritan.dev and set DRITAN_API_KEY.",
86
90
  "You can activate a key immediately with auth_set_api_key without restarting MCP.",
87
91
  ].join(" "));
88
92
  }
@@ -471,7 +475,12 @@ function createLocalWalletFile(walletPath) {
471
475
  throw new Error(`solana-keygen failed (${cmd.status}): ${cmd.stderr || cmd.stdout}`);
472
476
  }
473
477
  const keypair = loadKeypairFromPath(walletPath);
474
- return { walletPath, address: keypair.publicKey.toBase58() };
478
+ return {
479
+ walletPath,
480
+ backupFilePath: walletPath,
481
+ walletDir: dir,
482
+ address: keypair.publicKey.toBase58(),
483
+ };
475
484
  }
476
485
  function loadKeypairFromPath(walletPath) {
477
486
  const bytes = JSON.parse(readFileSync(walletPath, "utf8"));
@@ -1107,11 +1116,11 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1107
1116
  preview: apiKeyPreview(activeApiKey),
1108
1117
  hint: apiKeySet
1109
1118
  ? "API key is configured."
1110
- : "Missing DRITAN_API_KEY. You can either use x402 onboarding tools or get a free key at https://dritan.dev.",
1119
+ : "Missing DRITAN_API_KEY. Start x402 flow first (wallet_create_local -> fund wallet -> quote/claim). Use free key only as fallback.",
1111
1120
  },
1112
1121
  ],
1113
1122
  nextAction: !apiKeySet
1114
- ? "Choose one: (1) x402 paid onboarding flow with wallet tools, or (2) get a free key at https://dritan.dev and set DRITAN_API_KEY."
1123
+ ? "Run x402-first onboarding now: wallet_create_local -> share wallet + backup file path -> ask funding amount -> x402_create_api_key_quote -> wallet_transfer_sol -> x402_create_api_key. Offer free key only if user declines or x402 cannot proceed."
1115
1124
  : !solanaCli.ok
1116
1125
  ? "Install Solana CLI using installHint, then retry wallet_create_local."
1117
1126
  : "Environment ready.",
@@ -1125,8 +1134,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1125
1134
  preview: apiKeyPreview(activeApiKey),
1126
1135
  controlBaseUrl: getControlBaseUrl(),
1127
1136
  onboardingOptions: [
1128
- "Option 1 (paid x402): create wallet -> receive user SOL -> x402 quote -> transfer -> claim key.",
1129
- "Option 2 (free): create key at https://dritan.dev and set it with auth_set_api_key.",
1137
+ "Default (x402-first): create wallet in current directory -> share wallet + backup file path -> user funds wallet -> if no key exists, quote/transfer/claim key.",
1138
+ "Fallback only: if user declines funding or x402 cannot proceed, user can create key at https://dritan.dev and set it with auth_set_api_key.",
1130
1139
  ],
1131
1140
  ...(activeApiKey ? buildPostAuthGuidance() : {}),
1132
1141
  });
@@ -1149,7 +1158,10 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1149
1158
  const input = walletCreateSchema.parse(args);
1150
1159
  const walletPath = toWalletPath(input.name, input.walletDir);
1151
1160
  const created = createLocalWalletFile(walletPath);
1152
- return ok(created);
1161
+ return ok({
1162
+ ...created,
1163
+ fundingInstruction: "Ask the user how much SOL they want to allocate to this wallet, and tell them this backup file path.",
1164
+ });
1153
1165
  }
1154
1166
  case "wallet_get_address": {
1155
1167
  const input = walletPathSchema.parse(args);
@@ -1220,20 +1232,24 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1220
1232
  return ok({
1221
1233
  ...(pricing ?? {}),
1222
1234
  onboardingOptions: [
1223
- "Option 1 (paid x402): create wallet -> receive user SOL -> x402 quote -> forward payment -> claim key.",
1224
- "Option 2 (free): user gets API key at https://dritan.dev and provides it as DRITAN_API_KEY.",
1235
+ "Default (x402-first): create wallet in current directory -> share wallet + backup path -> user funds wallet -> if no key exists, quote/payment/claim.",
1236
+ "Fallback only: user gets API key at https://dritan.dev and provides it as DRITAN_API_KEY if x402 cannot proceed.",
1225
1237
  ],
1226
1238
  });
1227
1239
  }
1228
1240
  case "x402_create_api_key_quote": {
1229
1241
  const input = x402QuoteSchema.parse(args);
1230
1242
  const client = getX402Client();
1243
+ const activeApiKey = getActiveApiKey();
1231
1244
  const quote = await x402CreateQuote(client, input);
1232
1245
  return ok({
1233
1246
  ...(quote ?? {}),
1247
+ apiKeyAlreadyConfigured: !!activeApiKey,
1248
+ keyPreview: apiKeyPreview(activeApiKey),
1234
1249
  nextSteps: [
1235
- "If user picked paid flow, ensure agent has a local wallet (wallet_create_local + wallet_get_address).",
1236
- "User funds the agent wallet.",
1250
+ "Ensure agent has a local wallet in current directory (wallet_create_local + wallet_get_address) and tell user the backup file path.",
1251
+ "Ask user how much SOL they want to allocate; user funds the agent wallet.",
1252
+ "Only proceed if no API key is active; otherwise skip paid key creation.",
1237
1253
  "Transfer quoted SOL amount to receiver wallet using wallet_transfer_sol.",
1238
1254
  "Claim key with x402_create_api_key using returned tx signature (MCP auto-activates returned apiKey).",
1239
1255
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dritan/mcp",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "MCP server for Dritan SDK market data and local Solana wallet swap execution",