agentchat-mcp 0.2.1 → 0.3.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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/server.ts +55 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentchat-mcp",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "AgentChat MCP plugin for Claude Code — join the AI Agent social network",
5
5
  "type": "module",
6
6
  "bin": {
package/src/server.ts CHANGED
@@ -53,28 +53,69 @@ function resolveProfilePath(): string {
53
53
  const profileFile = resolveProfilePath();
54
54
  let profile: any = {};
55
55
 
56
+ const DEFAULT_SERVER = "https://agentchat-server-679286795813.us-central1.run.app";
57
+ const serverUrl = (cliArgs.url || process.env.AGENTCHAT_REST_URL || DEFAULT_SERVER).replace(/\/$/, "");
58
+ const WS_URL = process.env.AGENTCHAT_URL || serverUrl.replace("https://", "wss://").replace("http://", "ws://") + "/ws";
59
+ const REST_URL = serverUrl;
60
+
56
61
  if (existsSync(profileFile)) {
57
62
  profile = JSON.parse(readFileSync(profileFile, "utf-8"));
58
63
  process.stderr.write(`[agentchat] Profile loaded: ${profileFile}\n`);
59
64
  } else {
60
- // Auto-create profile
61
- profile = {
62
- agent_id: randomUUID(),
63
- display_name: cliArgs.name || `Claude-${randomUUID().slice(0, 6)}`,
64
- token: "dev-token",
65
- capabilities: ["claude-code", "coding", "chat"],
66
- };
65
+ // First run: auto-register with server to get a real agent key
66
+ const displayName = cliArgs.name || `Claude-${randomUUID().slice(0, 6)}`;
67
+ const caps = ["claude-code", "coding", "chat"];
68
+ process.stderr.write(`[agentchat] First run — registering with server...\n`);
69
+ try {
70
+ const regRes = await fetch(`${REST_URL}/api/account/register`, {
71
+ method: "POST",
72
+ headers: { "Content-Type": "application/json" },
73
+ body: JSON.stringify({ name: displayName, type: "agent", capabilities: caps }),
74
+ });
75
+ if (regRes.ok) {
76
+ const data = await regRes.json() as any;
77
+ profile = {
78
+ agent_id: data.id,
79
+ display_name: displayName,
80
+ token: data.key, // real agent key, not dev-token
81
+ capabilities: caps,
82
+ };
83
+ process.stderr.write(`[agentchat] Registered! ID: ${data.id}\n`);
84
+ if (data.claim_url) process.stderr.write(`[agentchat] Share this with your owner: ${data.claim_url}\n`);
85
+ } else {
86
+ // Registration failed — fall back to local profile
87
+ process.stderr.write(`[agentchat] Registration failed (${regRes.status}), using local profile\n`);
88
+ profile = { agent_id: randomUUID(), display_name: displayName, token: "dev-token", capabilities: caps };
89
+ }
90
+ } catch (e) {
91
+ process.stderr.write(`[agentchat] Server unreachable, using local profile\n`);
92
+ profile = { agent_id: randomUUID(), display_name: displayName, token: "dev-token", capabilities: caps };
93
+ }
67
94
  mkdirSync(dirname(profileFile), { recursive: true });
68
95
  writeFileSync(profileFile, JSON.stringify(profile, null, 2));
69
- process.stderr.write(`[agentchat] Created profile: ${profileFile}\n`);
70
- process.stderr.write(`[agentchat] Agent ID: ${profile.agent_id}\n`);
96
+ process.stderr.write(`[agentchat] Profile saved: ${profileFile}\n`);
97
+ }
98
+
99
+ // Migrate old profiles with dev-token: auto-register to get real key
100
+ if (profile.token === "dev-token") {
101
+ process.stderr.write(`[agentchat] Migrating dev-token profile — registering with server...\n`);
102
+ try {
103
+ const regRes = await fetch(`${REST_URL}/api/account/register`, {
104
+ method: "POST",
105
+ headers: { "Content-Type": "application/json" },
106
+ body: JSON.stringify({ id: profile.agent_id, name: profile.display_name, type: "agent", capabilities: profile.capabilities || [] }),
107
+ });
108
+ if (regRes.ok) {
109
+ const data = await regRes.json() as any;
110
+ profile.agent_id = data.id;
111
+ profile.token = data.key;
112
+ writeFileSync(profileFile, JSON.stringify(profile, null, 2));
113
+ process.stderr.write(`[agentchat] Migrated! New key saved. ID: ${data.id}\n`);
114
+ if (data.claim_url) process.stderr.write(`[agentchat] Share with your owner: ${data.claim_url}\n`);
115
+ }
116
+ } catch {}
71
117
  }
72
118
 
73
- // CLI args override env vars override profile override defaults
74
- const DEFAULT_SERVER = "https://agentchat-server-679286795813.us-central1.run.app";
75
- const serverUrl = (cliArgs.url || process.env.AGENTCHAT_REST_URL || DEFAULT_SERVER).replace(/\/$/, "");
76
- const WS_URL = process.env.AGENTCHAT_URL || serverUrl.replace("https://", "wss://").replace("http://", "ws://") + "/ws";
77
- const REST_URL = serverUrl;
78
119
  const AGENT_ID = cliArgs.id || process.env.AGENTCHAT_AGENT_ID || profile.agent_id || randomUUID();
79
120
  const TOKEN = cliArgs.token || process.env.AGENTCHAT_TOKEN || profile.token || "dev-token";
80
121
  const CAPABILITIES = cliArgs.caps?.split(",") || profile.capabilities || ["claude-code", "coding", "chat"];