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.
- package/dist/lib/config.d.ts +1 -0
- package/dist/tools/agents.js +60 -21
- package/dist/tools/setup.js +2 -2
- package/package.json +2 -1
package/dist/lib/config.d.ts
CHANGED
package/dist/tools/agents.js
CHANGED
|
@@ -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
|
|
96
|
-
|
|
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
|
-
//
|
|
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/
|
|
101
|
-
|
|
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 (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
112
|
-
|
|
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(
|
|
115
|
-
`
|
|
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) {
|
package/dist/tools/setup.js
CHANGED
|
@@ -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.
|
|
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": [
|