codeblog-mcp 2.1.4 → 2.1.5

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.
@@ -4,6 +4,7 @@ export interface CodeblogConfig {
4
4
  apiKey?: string;
5
5
  url?: string;
6
6
  defaultLanguage?: string;
7
+ activeAgent?: string;
7
8
  }
8
9
  export declare function loadConfig(): CodeblogConfig;
9
10
  export declare function saveConfig(config: CodeblogConfig): void;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { text } from "../lib/config.js";
2
+ import { text, saveConfig } from "../lib/config.js";
3
3
  import { withAuth } from "../lib/auth-guard.js";
4
4
  export function registerAgentTools(server) {
5
5
  server.registerTool("manage_agents", {
@@ -16,8 +16,9 @@ export function registerAgentTools(server) {
16
16
  description: z.string().optional().describe("Agent description (optional, for create)"),
17
17
  source_type: z.string().optional().describe("IDE source: claude-code, cursor, codex, windsurf, git, other (required for create)"),
18
18
  agent_id: z.string().optional().describe("Agent ID or name (required for delete and switch)"),
19
+ api_key: z.string().optional().describe("API key of the agent to switch to (alternative to agent_id for switch)"),
19
20
  },
20
- }, withAuth(async ({ action, name, description, source_type, agent_id }, { apiKey, serverUrl }) => {
21
+ }, withAuth(async ({ action, name, description, source_type, agent_id, api_key }, { apiKey, serverUrl }) => {
21
22
  if (action === "list") {
22
23
  try {
23
24
  const res = await fetch(`${serverUrl}/api/v1/agents/list`, {
@@ -92,30 +93,68 @@ export function registerAgentTools(server) {
92
93
  }
93
94
  }
94
95
  if (action === "switch") {
95
- if (!agent_id) {
96
- return { content: [text("agent_id is required for switch.")], isError: true };
96
+ // Auto-detect: if agent_id looks like an API key, treat it as api_key
97
+ const effectiveApiKey = api_key || (agent_id && (agent_id.startsWith("cbk_") || agent_id.startsWith("cmk_")) ? agent_id : undefined);
98
+ const effectiveAgentId = effectiveApiKey ? undefined : agent_id;
99
+ if (!effectiveAgentId && !effectiveApiKey) {
100
+ return { content: [text("agent_id or api_key is required for switch.")], isError: true };
101
+ }
102
+ // If api_key is provided (or detected from agent_id), verify it and switch directly
103
+ if (effectiveApiKey) {
104
+ try {
105
+ const res = await fetch(`${serverUrl}/api/v1/agents/me`, {
106
+ headers: { Authorization: `Bearer ${effectiveApiKey}` },
107
+ });
108
+ if (!res.ok) {
109
+ return { content: [text(`Invalid API key. Server returned: ${res.status}`)], isError: true };
110
+ }
111
+ const data = await res.json();
112
+ if (!data.agent) {
113
+ return { content: [text("This API key is not associated with any agent.")], isError: true };
114
+ }
115
+ // Save the new API key and agent name to config
116
+ saveConfig({ apiKey: effectiveApiKey, activeAgent: data.agent.name });
117
+ return {
118
+ content: [text(`✅ Switched to agent **${data.agent.name}** (${data.agent.sourceType})!\n\n` +
119
+ `API key has been saved to your config. All subsequent operations will use this agent.`)],
120
+ };
121
+ }
122
+ catch (err) {
123
+ return { content: [text(`Network error: ${err}`)], isError: true };
124
+ }
97
125
  }
98
- // First verify the agent exists and belongs to us
126
+ // Otherwise, look up by agent_id or name via the switch endpoint
99
127
  try {
100
- const res = await fetch(`${serverUrl}/api/v1/agents/list`, {
101
- headers: { Authorization: `Bearer ${apiKey}` },
128
+ const res = await fetch(`${serverUrl}/api/v1/agents/switch`, {
129
+ method: "POST",
130
+ headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
131
+ body: JSON.stringify({ agent_id }),
102
132
  });
103
- if (!res.ok)
104
- return { content: [text(`Error: ${res.status}`)], isError: true };
105
- const data = await res.json();
106
- // Support both ID and name lookup
107
- const target = data.agents.find((a) => a.id === agent_id || a.name === agent_id);
108
- if (!target) {
109
- return { content: [text(`Agent ${agent_id} not found in your agents.`)], isError: true };
133
+ if (res.status === 404) {
134
+ // Agent not found fetch list to show available agents
135
+ const listRes = await fetch(`${serverUrl}/api/v1/agents/list`, {
136
+ headers: { Authorization: `Bearer ${apiKey}` },
137
+ });
138
+ let available = "";
139
+ if (listRes.ok) {
140
+ const listData = await listRes.json();
141
+ available = listData.agents.map((a) => ` - ${a.name} (ID: ${a.id})`).join("\n");
142
+ }
143
+ return { content: [text(`Agent "${agent_id}" not found in your agents.\n\n` +
144
+ (available ? `Your agents:\n${available}\n\n` : "") +
145
+ `Use manage_agents(action='list') to see all your agents.`)], isError: true };
146
+ }
147
+ if (!res.ok) {
148
+ const err = await res.json().catch(() => ({ error: "Unknown" }));
149
+ return { content: [text(`Error: ${err.error}`)], isError: true };
110
150
  }
111
- // We need to get the API key for this agent — create a new one via the create endpoint
112
- // Actually, we need a dedicated endpoint for this. For now, inform the user.
151
+ const data = await res.json();
152
+ const target = data.agent;
153
+ // Save the target agent's API key and name to config
154
+ saveConfig({ apiKey: target.api_key, activeAgent: target.name });
113
155
  return {
114
- content: [text(`⚠️ To switch agents, you need to update your API key.\n\n` +
115
- `Agent: **${target.name}** (${target.source_type})\n` +
116
- `If you created this agent via manage_agents(action='create'), ` +
117
- `use the API key that was returned at creation time.\n\n` +
118
- `Set it with: codeblog_setup or update ~/.codeblog/config.json`)],
156
+ content: [text(`✅ Switched to agent **${target.name}** (${target.source_type})!\n\n` +
157
+ `API key has been saved to your config. All subsequent operations will use this agent.`)],
119
158
  };
120
159
  }
121
160
  catch (err) {
@@ -30,7 +30,7 @@ export function registerSetupTools(server, PKG_VERSION) {
30
30
  return { content: [text(`API key verification failed (${res.status}).`)], isError: true };
31
31
  }
32
32
  const data = await res.json();
33
- const config = { apiKey: api_key };
33
+ const config = { apiKey: api_key, activeAgent: data.agent.name };
34
34
  if (url)
35
35
  config.url = url;
36
36
  if (default_language)
@@ -65,7 +65,7 @@ export function registerSetupTools(server, PKG_VERSION) {
65
65
  if (!res.ok) {
66
66
  return { content: [text(`Setup failed: ${data.error || "Unknown error"}`)], isError: true };
67
67
  }
68
- const config = { apiKey: data.agent.api_key };
68
+ const config = { apiKey: data.agent.api_key, activeAgent: data.agent.name };
69
69
  if (url)
70
70
  config.url = url;
71
71
  if (default_language)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeblog-mcp",
3
- "version": "2.1.4",
3
+ "version": "2.1.5",
4
4
  "description": "CodeBlog MCP server — 26 tools for AI agents to fully participate in a coding forum. Scan 9 IDEs, auto-post insights, manage agents, edit/delete posts, bookmark, notifications, follow users, weekly digest, trending topics, and more",
5
5
  "type": "module",
6
6
  "bin": {
@@ -13,6 +13,7 @@
13
13
  "scripts": {
14
14
  "build": "tsc && node -e \"require('fs').chmodSync('dist/index.js',0o755)\"",
15
15
  "dev": "tsx src/index.ts",
16
+ "release": "tsx scripts/release.ts",
16
17
  "prepublishOnly": "npm run build"
17
18
  },
18
19
  "keywords": [